Jeff Schroeder
2008-Oct-03 05:35 UTC
[Ovirt-devel] [PATCH] Add trivial error() function and change code to use it
Remove the multiple echo ... && exit 1 references and replace
them with a simple function. This makes the code a bit cleaner.
Signed-off-by: Jeff Schroeder <jeffschroeder at computer.org>
---
wui/scripts/ovirt-wui-install | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/wui/scripts/ovirt-wui-install b/wui/scripts/ovirt-wui-install
index 44798fc..1f5e1eb 100755
--- a/wui/scripts/ovirt-wui-install
+++ b/wui/scripts/ovirt-wui-install
@@ -31,6 +31,11 @@ usage() {
exit 1
} >&2
+error() {
+ echo $* >&2
+ exit 1
+}
+
find_srv() {
local dnsreply
@@ -112,7 +117,7 @@ find_srv ldap tcp
if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then
SRV_HOST=${SRV_HOST%.}
srv_base=$(find_ldap_base)
- [ $? != 0 ] && echo "Failed to determine base for ldap"
&& exit 1
+ [ $? != 0 ] && error "Failed to determine base for ldap"
sed -i -e "s/host: .*/host: $SRV_HOST/g" \
-e "s/port: .*/port: $SRV_PORT/g" \
@@ -121,7 +126,7 @@ if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ];
then
else
# FIXME: Eventually this script should prompt for things that can't
# be found in DNS SRV records.
- echo "Failed to get ldap host/port" && exit 1
+ error "Failed to get ldap host/port"
fi
# setup an NTP step-ticker
@@ -153,7 +158,7 @@ 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
+[ $? != 0 ] && error "Failed to start database"
wait_for_service 'psql -l -U postgres' 10 2 || exit 1
if [ -z $PASSWD ]; then
@@ -168,7 +173,7 @@ 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
+[ $? != 0 ] && error "Failed to create database $DATABASE"
su - postgres -c "psql --dbname $DATABASE <<EOF
DROP ROLE $USERNAME;
@@ -180,7 +185,7 @@ su - postgres -c "psql --dbname $DATABASE <<EOF
VALID UNTIL 'infinity';
GRANT ALL ON DATABASE $DATABASE TO $USERNAME;
EOF"
-[ $? != 0 ] && echo "Failed to run database setup" &&
exit 1
+[ $? != 0 ] && error "Failed to run database setup"
touch $EXISTS_FILE
@@ -190,7 +195,7 @@ rake db:migrate
cd -
${OVIRT_DIR}/script/grant_admin_privileges ovirtadmin
-[ $? != 0 ] && echo "Failed to grant ovirtadmin privileges"
&& exit 1
+[ $? != 0 ] && error "Failed to grant ovirtadmin privileges"
ovirt-add-host $(hostname) ${OVIRT_DIR}/ovirt.keytab
--
1.5.6.3
Perry N. Myers
2008-Oct-03 13:34 UTC
[Ovirt-devel] [PATCH] Add trivial error() function and change code to use it
Jeff Schroeder wrote:> Remove the multiple echo ... && exit 1 references and replace > them with a simple function. This makes the code a bit cleaner.No problem with this patch in concept, but this patch appears to be against the old repository. See the instructions on: http://ovirt.org/build-instructions.html for getting access to the new repositories. The file you're patching is now located in the ovirt-server repository and it's location is: scripts/ovirt-server-install Thanks! Perry> Signed-off-by: Jeff Schroeder <jeffschroeder at computer.org> > --- > wui/scripts/ovirt-wui-install | 17 +++++++++++------ > 1 files changed, 11 insertions(+), 6 deletions(-) > > diff --git a/wui/scripts/ovirt-wui-install b/wui/scripts/ovirt-wui-install > index 44798fc..1f5e1eb 100755 > --- a/wui/scripts/ovirt-wui-install > +++ b/wui/scripts/ovirt-wui-install > @@ -31,6 +31,11 @@ usage() { > exit 1 > } >&2 > > +error() { > + echo $* >&2 > + exit 1 > +} > + > find_srv() { > local dnsreply > > @@ -112,7 +117,7 @@ find_srv ldap tcp > if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then > SRV_HOST=${SRV_HOST%.} > srv_base=$(find_ldap_base) > - [ $? != 0 ] && echo "Failed to determine base for ldap" && exit 1 > + [ $? != 0 ] && error "Failed to determine base for ldap" > > sed -i -e "s/host: .*/host: $SRV_HOST/g" \ > -e "s/port: .*/port: $SRV_PORT/g" \ > @@ -121,7 +126,7 @@ if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then > else > # FIXME: Eventually this script should prompt for things that can't > # be found in DNS SRV records. > - echo "Failed to get ldap host/port" && exit 1 > + error "Failed to get ldap host/port" > fi > > # setup an NTP step-ticker > @@ -153,7 +158,7 @@ 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 > +[ $? != 0 ] && error "Failed to start database" > wait_for_service 'psql -l -U postgres' 10 2 || exit 1 > > if [ -z $PASSWD ]; then > @@ -168,7 +173,7 @@ 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 > +[ $? != 0 ] && error "Failed to create database $DATABASE" > > su - postgres -c "psql --dbname $DATABASE <<EOF > DROP ROLE $USERNAME; > @@ -180,7 +185,7 @@ su - postgres -c "psql --dbname $DATABASE <<EOF > VALID UNTIL 'infinity'; > GRANT ALL ON DATABASE $DATABASE TO $USERNAME; > EOF" > -[ $? != 0 ] && echo "Failed to run database setup" && exit 1 > +[ $? != 0 ] && error "Failed to run database setup" > > touch $EXISTS_FILE > > @@ -190,7 +195,7 @@ rake db:migrate > cd - > > ${OVIRT_DIR}/script/grant_admin_privileges ovirtadmin > -[ $? != 0 ] && echo "Failed to grant ovirtadmin privileges" && exit 1 > +[ $? != 0 ] && error "Failed to grant ovirtadmin privileges" > > ovirt-add-host $(hostname) ${OVIRT_DIR}/ovirt.keytab >-- |=- Red Hat, Engineering, Emerging Technologies, Boston -=| |=- Email: pmyers at redhat.com -=| |=- Office: +1 412 474 3552 Mobile: +1 703 362 9622 -=| |=- GnuPG: E65E4F3D 88F9 F1C9 C2F3 1303 01FE 817C C5D2 8B91 E65E 4F3D -=|