[Ovirt-devel] [PATCH] restructure wui kickstarts and create setup scripts for RPM

Perry N. Myers pmyers at redhat.com
Fri Apr 4 01:18:07 UTC 2008


Restructured the wui production and devel kickstart posts so that most of
the functionality is moved into two scripts (ovirt-add-host and
ovirt-wui-install).

The post sections now contain just those steps that are specific to
creating a production or development appliance.  This way, users who want
to install on existing OSs can just run ovirt-wui-install manually.

Spec file is updated to pull in the new scripts and omit the outdated
scripts. Removed the references to the FreeIPA F7 repo, since those RPMs
were very out of date.  Until we move to F9, we need to put the ipa RPMs
into the ovirt-management repository.

NOTE: The ovirt-fix-ipa script is a temporary hack so that the ipa server
can run on the same host as the oVirt WUI.  As soon as we get RPMs from
FreeIPA that have the ipa server running in /ipa this will go away.

This seems like a huge patch, but a lot of it is moving blocks of code
from the .ks files to other scripts.  Most of the functionality is maintained.

Signed-off-by: Perry Myers <pmyers at redhat.com>


diff --git a/wui-appliance/common-post.ks b/wui-appliance/common-post.ks
index 9b1efa6..3bd6b4d 100644
--- a/wui-appliance/common-post.ks
+++ b/wui-appliance/common-post.ks
@@ -19,94 +19,45 @@ cat <<EOF > /etc/issue
 EOF
 cp /etc/issue /etc/issue.net
 
-# postgres commands used at first boot to setup the database
-cat > /usr/share/ovirt-wui/psql.cmds << \EOF
-CREATE USER ovirt WITH PASSWORD 'v23zj59an';
-CREATE DATABASE ovirt;
-GRANT ALL PRIVILEGES ON DATABASE ovirt to ovirt;
-CREATE DATABASE ovirt_test;
-GRANT ALL PRIVILEGES ON DATABASE ovirt_test to ovirt;
-EOF
-chmod a+r /usr/share/ovirt-wui/psql.cmds
-
-# turn on tftp in xinetd
-sed -i -e 's/\(.*\)disable\(.*\)= yes/\1disable\2= no/' /etc/xinetd.d/tftp
-
-# setup an NTP step-ticker
-echo "0.fedora.pool.ntp.org" >> /etc/ntp/step-tickers
-
-# setup gssapi in the mech_list
-if [ `egrep -c '^mech_list: gssapi' /etc/sasl2/libvirt.conf` -eq 0 ]; then
-   sed -i -e 's/^\([[:space:]]*mech_list.*\)/#\1/' /etc/sasl2/libvirt.conf
-   echo "mech_list: gssapi" >> /etc/sasl2/libvirt.conf
-fi
-
-# a script to create the default principals we need
-cat > /root/create_default_principals.py << \EOF
-#!/usr/bin/python
-
-import krbV
-import os, string, re
-import socket
-import shutil
-
-def kadmin_local(command):
-        ret = os.system("/usr/kerberos/sbin/kadmin.local -q '" + command + "'")
-        if ret != 0:
-                raise
-
-default_realm = krbV.Context().default_realm
-
-# here, generate the libvirt/ principle for this machine, necessary
-# for taskomatic and host-browser
-this_libvirt_princ = 'libvirt/' + socket.gethostname() + '@' + default_realm
-kadmin_local('addprinc -randkey +requires_preauth ' + this_libvirt_princ)
-kadmin_local('ktadd -k /usr/share/ovirt-wui/ovirt.keytab ' + this_libvirt_princ)
-
-# We need to replace the KrbAuthRealms in the ovirt-wui http configuration
-# file to be the correct Realm (i.e. default_realm)
-ovirtconfname = '/etc/httpd/conf.d/ovirt-wui.conf'
-ipaconfname = '/etc/httpd/conf.d/ipa.conf'
-
-# make sure we skip this on subsequent runs of this script
-if string.find(file(ipaconfname, 'rb').read(), '<VirtualHost *:8089>') < 0:
-    ipaconf = open(ipaconfname, 'r')
-    ipatext = ipaconf.readlines()
-    ipaconf.close()
-
-    ipaconf2 = open(ipaconfname, 'w')
-    print >>ipaconf2, "Listen 8089"
-    print >>ipaconf2, "NameVirtualHost *:8089"
-    print >>ipaconf2, "<VirtualHost *:8089>"
-    for line in ipatext:
-        newline = re.sub(r'(.*RewriteCond %{HTTP_HOST}.*)', r'#\1', line)
-        newline = re.sub(r'(.*RewriteRule \^/\(.*\).*)', r'#\1', newline)
-        newline = re.sub(r'(.*RewriteCond %{SERVER_PORT}.*)', r'#\1', newline)
-        newline = re.sub(r'(.*RewriteCond %{REQUEST_URI}.*)', r'#\1', newline)
-        ipaconf2.write(newline)
-    print >>ipaconf2, "</VirtualHost>"
-    ipaconf2.close()
-
-ovirtconf = open(ovirtconfname, 'r')
-ovirttext = ovirtconf.readlines()
-ovirtconf.close()
-
-ovirtconf2 = open(ovirtconfname, 'w')
-for line in ovirttext:
-    newline = re.sub(r'(.*)KrbAuthRealms.*', r'\1KrbAuthRealms ' + default_realm, line)
-    ovirtconf2.write(newline)
-ovirtconf2.close()
-EOF
-chmod +x /root/create_default_principals.py
-
-# set up the yum repos
-cat > /etc/yum.repos.d/freeipa.repo << \EOF
-[freeipa]
-name=FreeIPA Development
-baseurl=http://freeipa.com/downloads/devel/rpms/F7/$basearch/
-enabled=1
-gpgcheck=0
+cat > /etc/init.d/ovirt-wui-first-run << \EOF
+#!/bin/bash
+#
+# ovirt-wui-first-run First run configuration for Ovirt WUI appliance
+#
+# chkconfig: 3 96 01
+# description: ovirt wui appliance first run configuration
+#
+
+# Source functions library
+. /etc/init.d/functions
+
+start() {
+       echo -n "Starting ovirt-wui-first-run: "
+
+       /usr/bin/ovirt-wui-install > /var/log/ovirt-wui-first-run.log 2>&1
+
+       RETVAL=$?
+       if [ $RETVAL -eq 0 ]; then
+               echo_success
+       else
+               echo_failure
+       fi
+       echo
+}
+
+case "$1" in
+  start)
+        start
+        ;;
+  *)
+        echo "Usage: ovirt-wui-first-run {start}"
+        exit 2
+esac
+
+/sbin/chkconfig ovirt-wui-first-run off
 EOF
+chmod +x /etc/init.d/ovirt-wui-first-run
+/sbin/chkconfig ovirt-wui-first-run on
 
 cat > /etc/yum.repos.d/ovirt-management.repo << \EOF
 [ovirt-management]
diff --git a/wui-appliance/devel-post.ks b/wui-appliance/devel-post.ks
index e6df344..7494506 100644
--- a/wui-appliance/devel-post.ks
+++ b/wui-appliance/devel-post.ks
@@ -167,13 +167,13 @@ chmod +x /etc/dhclient-exit-hooks
 # make sure that we get a kerberos principal on every boot
 echo "/etc/cron.hourly/ovirtadmin.cron" >> /etc/rc.d/rc.local
 
-cat > /etc/init.d/ovirt-app-first-run << \EOF
+cat > /etc/init.d/ovirt-wui-dev-first-run << \EOF
 #!/bin/bash
 #
-# ovirt-app-first-run First run configuration for Ovirt WUI appliance
+# ovirt-wui-dev-first-run First run configuration for Ovirt WUI Dev appliance
 #
-# chkconfig: 3 99 01
-# description: ovirt appliance first run configuration
+# chkconfig: 3 95 01
+# description: ovirt dev wui appliance first run configuration
 #
 
 # Source functions library
@@ -182,35 +182,17 @@ cat > /etc/init.d/ovirt-app-first-run << \EOF
 KADMIN=/usr/kerberos/sbin/kadmin.local
 
 start() {
-       echo -n "Starting ovirt-app-first-run: "
+       echo -n "Starting ovirt-dev-wui-first-run: "
        (
        # set up freeipa
-       /usr/sbin/ipa-server-install -r PRIV.OVIRT.ORG -p ovirtwui -P ovirtwui -a ovirtwui --hostname management.priv.ovirt.org -u admin -U
+       /usr/sbin/ipa-server-install -r PRIV.OVIRT.ORG -p ovirtwui -P ovirtwui -a ovirtwui --hostname management.priv.ovirt.org -u dirsrv -U
 
        # now create the ovirtadmin user
        $KADMIN -q 'addprinc -randkey ovirtadmin at PRIV.OVIRT.ORG'
        $KADMIN -q 'ktadd -k /usr/share/ovirt-wui/ovirtadmin.tab ovirtadmin at PRIV.OVIRT.ORG'
        /etc/cron.hourly/ovirtadmin.cron
 
-       /root/create_default_principals.py
-
-       # create_default_principals munges the apache config, so we have to
-       # restart it here
-       service httpd restart
-
-       service postgresql initdb
-       echo "local all all trust" > /var/lib/pgsql/data/pg_hba.conf
-       echo "host all all 127.0.0.1 255.255.255.0 trust" >> /var/lib/pgsql/data/pg_hba.conf
-       service postgresql start
-
-       su - postgres -c "/usr/bin/psql -f /usr/share/ovirt-wui/psql.cmds"
-
-       cd /usr/share/ovirt-wui ; rake db:migrate
-       /usr/bin/ovirt_grant_admin_privileges.sh ovirtadmin
-
-       service ovirt-wui restart
-
-       ) > /root/ovirt-app-first-run.log 2>&1
+       ) > /var/log/ovirt-wui-dev-first-run.log 2>&1
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                echo_success
@@ -225,14 +207,14 @@ case "$1" in
         start
         ;;
   *)
-        echo "Usage: ovirt {start}"
+        echo "Usage: ovirt-wui-dev-first-run {start}"
         exit 2
 esac
 
-/sbin/chkconfig ovirt-app-first-run off
+/sbin/chkconfig ovirt-wui-dev-first-run off
 EOF
-chmod +x /etc/init.d/ovirt-app-first-run
-/sbin/chkconfig ovirt-app-first-run on
+chmod +x /etc/init.d/ovirt-wui-dev-first-run
+/sbin/chkconfig ovirt-wui-dev-first-run on
 
 # Setup the iscsi stuff to be ready on each boot.  Since tgtadm does not use
 # a config file append what we need to the rc.local file.  Note that this for
diff --git a/wui-appliance/production-post.ks b/wui-appliance/production-post.ks
index 875f391..e69de29 100644
--- a/wui-appliance/production-post.ks
+++ b/wui-appliance/production-post.ks
@@ -1,76 +0,0 @@
-cat > /root/add_host_principal.py << \EOF
-#!/usr/bin/python
-
-import krbV
-import os
-import socket
-import shutil
-import sys
-
-def kadmin_local(command):
-        ret = os.system("/usr/kerberos/sbin/kadmin.local -q '" + command + "'")
-        if ret != 0:
-                raise
-
-def get_ip(hostname):
-        return socket.gethostbyname(hostname)
-
-if len(sys.argv) != 2:
-        print "Usage: add_host_principal.py <hostname>"
-        sys.exit(1)
-
-
-default_realm = krbV.Context().default_realm
-
-ipaddr = get_ip(sys.argv[1])
-
-libvirt_princ = 'libvirt/' + sys.argv[1] + '@' + default_realm
-outname = '/usr/share/ipa/html/' + ipaddr + '-libvirt.tab'
-
-# here, generate the libvirt/ principle for this machine, necessary
-# for taskomatic and host-browser
-kadmin_local('addprinc -randkey +requires_preauth ' + libvirt_princ)
-kadmin_local('ktadd -k ' + outname + ' ' + libvirt_princ)
-
-# make sure it is readable by apache
-os.chmod(outname, 0644)
-EOF
-chmod +x /root/add_host_principal.py
-
-cat > /etc/init.d/ovirt-app-first-run << \EOF
-#!/bin/bash
-#
-# ovirt-app-first-run First run configuration for Ovirt WUI appliance
-#
-# chkconfig: 3 99 01
-# description: ovirt appliance first run configuration
-#
-
-# Source functions library
-. /etc/init.d/functions
-
-start() {
-       service postgresql initdb
-       echo "local all all trust" > /var/lib/pgsql/data/pg_hba.conf
-       echo "host all all 127.0.0.1 255.255.255.0 trust" >> /var/lib/pgsql/data/pg_hba.conf
-       service postgresql start
-
-       su - postgres -c "/usr/bin/psql -f /usr/share/ovirt-wui/psql.cmds"
-
-       cd /usr/share/ovirt-wui ; rake db:migrate
-       /usr/bin/ovirt_grant_admin_privileges.sh admin
-}
-
-case "$1" in
-  start)
-        start
-        ;;
-  *)
-        echo "Usage: ovirt {start}"
-        exit 2
-esac
-
-chkconfig ovirt-app-first-run off
-EOF
-chmod +x /etc/init.d/ovirt-app-first-run
-/sbin/chkconfig ovirt-app-first-run on
\ No newline at end of file
diff --git a/wui-appliance/wui-app-i386.ks b/wui-appliance/wui-app-i386.ks
index 4d53c0b..38f80d4 100644
--- a/wui-appliance/wui-app-i386.ks
+++ b/wui-appliance/wui-app-i386.ks
@@ -8,7 +8,6 @@ url --url http://download.fedora.redhat.com/pub/fedora/linux/releases/8/Fedora/i
 
 repo --name=f8 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-8&arch=i386
 repo --name=f8-updates --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f8&arch=i386
-repo --name=freeipa --baseurl=http://freeipa.com/downloads/devel/rpms/F7/i386/ --includepkgs=ipa*
 repo --name=ovirt-management --baseurl=http://ovirt.et.redhat.com/repos/ovirt-management-repo/i386/
 
 %packages
diff --git a/wui-appliance/wui-app-x86_64.ks b/wui-appliance/wui-app-x86_64.ks
index 6d192b3..4dfa1a3 100644
--- a/wui-appliance/wui-app-x86_64.ks
+++ b/wui-appliance/wui-app-x86_64.ks
@@ -7,7 +7,6 @@ url --url http://download.fedora.redhat.com/pub/fedora/linux/releases/8/Fedora/x
 
 repo --name=f8 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-8&arch=x86_64
 repo --name=f8-updates --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f8&arch=x86_64
-repo --name=freeipa --baseurl=http://freeipa.com/downloads/devel/rpms/F7/x86_64/ --includepkgs=ipa*
 repo --name=ovirt-management --baseurl=http://ovirt.et.redhat.com/repos/ovirt-management-repo/x86_64/
 
 %packages
diff --git a/wui-appliance/wui-devel-i386.ks b/wui-appliance/wui-devel-i386.ks
index 4b3502f..f552521 100644
--- a/wui-appliance/wui-devel-i386.ks
+++ b/wui-appliance/wui-devel-i386.ks
@@ -12,7 +12,6 @@ logvol /iscsi5 --name=iSCSI5 --vgname=VolGroup00 --size=64 --grow
 
 repo --name=f8 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-8&arch=i386
 repo --name=f8-updates --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f8&arch=i386
-repo --name=freeipa --baseurl=http://freeipa.com/downloads/devel/rpms/F7/i386/ --includepkgs=ipa*
 repo --name=ovirt-management --baseurl=http://ovirt.et.redhat.com/repos/ovirt-management-repo/i386/
 
 %packages
diff --git a/wui-appliance/wui-devel-x86_64.ks b/wui-appliance/wui-devel-x86_64.ks
index 871ca87..e4b7076 100644
--- a/wui-appliance/wui-devel-x86_64.ks
+++ b/wui-appliance/wui-devel-x86_64.ks
@@ -12,7 +12,6 @@ logvol /iscsi5 --name=iSCSI5 --vgname=VolGroup00 --size=64 --grow
 
 repo --name=f8 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-8&arch=x86_64
 repo --name=f8-updates --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f8&arch=x86_64
-repo --name=freeipa --baseurl=http://freeipa.com/downloads/devel/rpms/F7/x86_64/ --includepkgs=ipa*
 repo --name=ovirt-management --baseurl=http://ovirt.et.redhat.com/repos/ovirt-management-repo/x86_64/
 
 %packages
diff --git a/wui/ovirt-wui.spec b/wui/ovirt-wui.spec
index a627a73..d8a21fa 100644
--- a/wui/ovirt-wui.spec
+++ b/wui/ovirt-wui.spec
@@ -83,9 +83,9 @@ touch %{buildroot}%{_localstatedir}/log/%{name}/host-status.log
 %{__rm} -f %{buildroot}%{app_root}/host-browser/*.c
 %{__rm} -f %{buildroot}%{app_root}/task-omatic/.gitignore
 
-%{__cp} -a %{pbuild}/scripts/ovirt_create_db.sh %{buildroot}%{_bindir}
-%{__cp} -a %{pbuild}/scripts/ovirt_grant_admin_privileges.sh %{buildroot}%{_bindir}
-%{__cp} -a %{pbuild}/scripts/ovirt_reset_db.sh %{buildroot}%{_bindir}
+%{__cp} -a %{pbuild}/scripts/ovirt-add-host %{buildroot}%{_bindir}
+%{__cp} -a %{pbuild}/scripts/ovirt-wui-install %{buildroot}%{_bindir}
+%{__cp} -a %{pbuild}/scripts/ovirt-fix-ipa %{buildroot}%{_bindir}
 %{__rm} -rf %{buildroot}%{app_root}/tmp 
 %{__mkdir} %{buildroot}%{_localstatedir}/lib/%{name}/tmp
 %{__ln_s} %{_localstatedir}/lib/%{name}/tmp %{buildroot}%{app_root}/tmp
@@ -96,9 +96,9 @@ rm -rf $RPM_BUILD_ROOT
 
 %files
 %defattr(-,root,root,0755)
-%{_bindir}/ovirt_create_db.sh
-%{_bindir}/ovirt_grant_admin_privileges.sh
-%{_bindir}/ovirt_reset_db.sh
+%{_bindir}/ovirt-wui-install
+%{_bindir}/ovirt-add-host
+%{_bindir}/ovirt-fix-ipa
 %{_initrddir}/%{name}
 %config(noreplace) %{_sysconfdir}/httpd/conf.d/%{name}.conf
 %doc
diff --git a/wui/scripts/ovirt-add-host b/wui/scripts/ovirt-add-host
new file mode 100755
index 0000000..700e2ac
--- /dev/null
+++ b/wui/scripts/ovirt-add-host
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+import krbV
+import os
+import socket
+import shutil
+import sys
+
+def kadmin_local(command):
+        ret = os.system("/usr/kerberos/sbin/kadmin.local -q '" + command + "'")
+        if ret != 0:
+                raise
+
+def get_ip(hostname):
+        return socket.gethostbyname(hostname)
+
+if len(sys.argv) < 2:
+        print "Usage: ovirt-add-host hostname [outfile]"
+        sys.exit(1)
+
+default_realm = krbV.Context().default_realm
+
+ipaddr = get_ip(sys.argv[1])
+
+libvirt_princ = 'libvirt/' + sys.argv[1] + '@' + default_realm
+if len(sys.argv) > 2:
+        outname = sys.argv[2]
+else:
+        outname = '/usr/share/ipa/html/' + ipaddr + '-libvirt.tab'
+
+# here, generate the libvirt/ principle for this machine, necessary
+# for taskomatic and host-browser
+kadmin_local('addprinc -randkey +requires_preauth ' + libvirt_princ)
+kadmin_local('ktadd -k ' + outname + ' ' + libvirt_princ)
+
+if len(sys.argv) <= 2:
+        # make sure it is readable by apache
+        os.chmod(outname, 0644)
diff --git a/wui/scripts/ovirt-fix-ipa b/wui/scripts/ovirt-fix-ipa
new file mode 100755
index 0000000..9e4aa14
--- /dev/null
+++ b/wui/scripts/ovirt-fix-ipa
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+import os, string, re
+
+ipaConfName = '/etc/httpd/conf.d/ipa.conf'
+ipaRewriteConfName = '/etc/httpd/conf.d/ipa-rewrite.conf'
+
+# make sure we skip this on subsequent runs of this script
+if string.find(file(ipaConfName, 'rb').read(), '<VirtualHost *:8089>') < 0:
+    ipaConf = open(ipaConfName, 'r')
+    ipaText = ipaConf.readlines()
+    ipaConf.close()
+
+    ipaConf2 = open(ipaConfName, 'w')
+    print >>ipaConf2, "Listen 8089"
+    print >>ipaConf2, "NameVirtualHost *:8089"
+    print >>ipaConf2, "<VirtualHost *:8089>"
+    for line in ipaText:
+        ipaConf2.write(line)
+    print >>ipaConf2, "</VirtualHost>"
+    ipaConf2.close()
+
+if os.path.isfile(ipaRewriteConfName):
+    os.remove(ipaRewriteConfName)
+    ipaRewriteConf = open(ipaRewriteConfName, 'w')
+    print >>ipaRewriteConf, ""
+    ipaRewriteConf.close()
+
diff --git a/wui/scripts/ovirt-wui-install b/wui/scripts/ovirt-wui-install
new file mode 100755
index 0000000..4462b6a
--- /dev/null
+++ b/wui/scripts/ovirt-wui-install
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+OVIRT_DIR=/usr/share/ovirt-wui
+OVIRT_CFG=/etc/ovirt-wui
+
+DATABASE=ovirt
+USERNAME=ovirt
+
+EXISTS_FILE=${OVIRT_CFG}/db/exists
+PW_FILE=${OVIRT_CFG}/db/dbaccess
+STEP_TICKER=0.fedora.pool.ntp.org
+STEP_FILE=/etc/ntp/step-tickers
+SASL_FILE=/etc/sasl2/libvirt.conf
+
+DISABLE_SVCS="libvirtd" 
+ENABLE_SVCS="ntpd httpd postgresql ovirt-wui"
+
+usage() {
+    echo "usage: $0 [-p password]"
+    echo "  -p : password to use for database connections, if omitted"
+    echo "       a random password will be generated"
+    exit 1
+} >&2
+
+PASSWD=
+for i ; do
+    case $1 in
+        -p)
+            [ $# -lt 2 ] && usage
+            PASSWD="$2"
+            shift; shift;;
+        -?|-*)
+            usage;;
+    esac
+done
+
+{
+for svc in $DISABLE_SVCS ; do
+    chkconfig $svc off
+    service $svc off
+done
+
+for svc in $ENABLE_SVCS ; do
+    chkconfig $svc on
+done
+} > /dev/null 2>&1
+
+# setup an NTP step-ticker
+if [ -f $STEP_FILE ]; then
+    if ! grep "^$${STEP_TICKER}$" $STEP_FILE > /dev/null 2>&1 ; then
+    echo $STEP_TICKER >> $STEP_FILE
+    fi
+fi
+
+# setup gssapi in the mech_list
+if [ `egrep -c '^mech_list: gssapi' $SASL_FILE` -eq 0 ]; then
+    sed -i -e 's/^\([[:space:]]*mech_list.*\)/#\1/' $SASL_FILE
+    echo "mech_list: gssapi" >> $SASL_FILE
+fi
+
+service postgresql stop > /dev/null 2>&1
+service postgresql initdb > /dev/null 2>&1
+echo "local all all trust" > /var/lib/pgsql/data/pg_hba.conf 
+echo "host all all 127.0.0.1 255.255.255.0 trust" >> /var/lib/pgsql/data/pg_hba.conf 
+service postgresql stop > /dev/null 2>&1
+service postgresql start
+[ $? != 0 ] && echo "Failed to start database" && exit 1
+
+if [ -z $PASSWD ]; then
+    # generate random pg user password
+    PASSWD=$(/usr/bin/pwgen -1 -n 8 -s)
+fi
+
+echo -e "${PASSWD}\n" > $PW_FILE
+
+# drop old db
+su - postgres -c "/usr/bin/dropdb $DATABASE > /dev/null 2>&1"
+
+# create new DB
+su - postgres -c "/usr/bin/createdb $DATABASE"
+[ $? != 0 ] && echo "Failed to create database $DATABASE" && exit 1
+
+su - postgres -c "psql --dbname $DATABASE <<EOF
+    DROP ROLE $USERNAME;
+EOF" > /dev/null 2>&1
+
+su - postgres -c "psql --dbname $DATABASE <<EOF
+    CREATE ROLE $USERNAME LOGIN PASSWORD '$PASSWD'
+    NOINHERIT
+    VALID UNTIL 'infinity';
+    GRANT ALL ON DATABASE $DATABASE TO $USERNAME;
+EOF"
+[ $? != 0 ] && echo "Failed to run database setup" && exit 1
+
+touch $EXISTS_FILE
+
+cd ${OVIRT_DIR}
+mkdir -p log
+rake db:migrate
+cd -
+
+${OVIRT_DIR}/script/grant_admin_privileges admin
+[ $? != 0 ] && echo "Failed to grant admin privileges" && exit 1
+
+if [ -f /usr/share/ovirt-wui/ovirtadmin.tab ]; then
+    ${OVIRT_DIR}/script/grant_admin_privileges ovirtadmin
+    [ $? != 0 ] && echo "Failed to grant ovirtadmin privileges" && exit 1
+fi
+
+/usr/bin/ovirt-add-host $(hostname) ${OVIRT_DIR}/ovirt.keytab
+
+# This is temporary until we get a version of FreeIPA that runs under /ipa
+# instead of as root
+if [ -f /etc/httpd/conf.d/ipa.conf ]; then
+    /usr/bin/ovirt-fix-ipa
+    service httpd restart
+    service ipa_webgui restart
+fi
+
+exit 0
+
diff --git a/wui/scripts/ovirt_create_db.sh b/wui/scripts/ovirt_create_db.sh
deleted file mode 100755
index 3a73e71..0000000
--- a/wui/scripts/ovirt_create_db.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/bash
-DATABASE="ovirt"
-PW_FILE="/etc/ovirt-wui/db/dbaccess"  
-USERNAME="ovirt"
-EXISTS_FILE="/etc/ovirt-wui/db/exists" 
-
-#generate pg user password
-PASSWD=$(/usr/bin/pwgen -1 -n 8 -s) # create random password
-echo $PASSWD\n > $PW_FILE
-
-#drop old db
-/usr/bin/dropdb $DATABASE
-
-#create new DB
-/usr/bin/createdb $DATABASE
-
-
-psql --dbname $DATABASE <<EOF
-    DROP ROLE $USERNAME;
-    CREATE ROLE $USERNAME LOGIN PASSWORD '$PASSWD'
-    NOINHERIT
-    VALID UNTIL 'infinity';
-    GRANT ALL ON DATABASE $DATABASE TO $USERNAME;
-EOF
-
-touch $EXISTS_FILE
diff --git a/wui/scripts/ovirt_grant_admin_privileges.sh b/wui/scripts/ovirt_grant_admin_privileges.sh
deleted file mode 100755
index 65e3c09..0000000
--- a/wui/scripts/ovirt_grant_admin_privileges.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-OVIRT_DIR=/usr/share/ovirt-wui
-
-$OVIRT_DIR/script/grant_admin_privileges $*
\ No newline at end of file
diff --git a/wui/scripts/ovirt_reset_db.sh b/wui/scripts/ovirt_reset_db.sh
deleted file mode 100755
index 5b132ce..0000000
--- a/wui/scripts/ovirt_reset_db.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-
-/usr/bin/dropdb -U postgres ovirt
-su - postgres -c "/usr/bin/psql -f /usr/share/ovirt-wui/psql.cmds"
-cd /usr/share/ovirt-wui
-rake db:migrate




More information about the ovirt-devel mailing list