Skip to content

Commit 63cecf1

Browse files
authored
Merge pull request #510 from vpodzime/master-fatal_scriptlets
Set -e in package scriptlets
2 parents 9115022 + c6def8a commit 63cecf1

File tree

7 files changed

+61
-40
lines changed

7 files changed

+61
-40
lines changed

packaging/common/cfengine-hub/postinstall.sh

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,14 @@ EOHIPPUS
187187
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "(echo '/cf_promises_*'; echo '.*.sw[po]'; echo '*~'; echo '\\#*#') >.gitignore")
188188
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT add .gitignore")
189189
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT commit -m 'Ignore cf_promise_*'")
190-
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT add *")
190+
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT add *") || true "Ignoring warning about ignored files not being added"
191191
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT commit -m 'Initial pristine masterfiles'")
192192

193193
(cd $DCWORKDIR/ && su $MP_APACHE_USER -c "$GIT clone --no-hardlinks --bare $DCWORKDIR/masterfiles_staging $DCWORKDIR/masterfiles.git")
194194
find "$DCWORKDIR/masterfiles.git" -type d -exec chmod 700 {} \;
195195
find "$DCWORKDIR/masterfiles.git" -type f -exec chmod 600 {} \;
196196

197197
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT branch CF_WORKING_BRANCH")
198-
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT remote rm origin")
199198
(cd $DCWORKDIR/masterfiles_staging && su $MP_APACHE_USER -c "$GIT remote add origin $DCWORKDIR/masterfiles.git")
200199

201200
if [ ! -f /usr/bin/curl ]; then
@@ -265,8 +264,7 @@ esac
265264

266265
if [ -f "$MAN_CONFIG" ];
267266
then
268-
MAN=`cat "$MAN_CONFIG"| grep cfengine`
269-
if [ -z "$MAN" ]; then
267+
if grep cfengine "$MAN_CONFIG" >/dev/null; then
270268
echo "$MAN_PATH $PREFIX/share/man" >> "$MAN_CONFIG"
271269
fi
272270
fi
@@ -341,8 +339,7 @@ generate_new_postgres_conf() {
341339
# Otherwise, we use a shared_buffers equal to 25% of total memory
342340
total=`cat /proc/meminfo |grep "^MemTotal:.*[0-9]\+ kB"|awk '{print $2}'`
343341

344-
echo "$total" | grep -q '^[0-9]\+$'
345-
if [ $? -ne 0 ] ;then
342+
if ! echo "$total" | grep -q '^[0-9]\+$' >/dev/null; then
346343
cf_console echo "Error calculating total memory for setting postgresql shared_buffers";
347344
else
348345
upper=$(( 64 * 1024 * 1024 )) #in KB
@@ -573,6 +570,7 @@ migrate_db_using_dump_file() {
573570
}
574571

575572
if is_upgrade && [ -d "$BACKUP_DIR/data" ]; then
573+
set +e # this block has its own error detection/handling
576574
# DEBUG variable controls which of migration methods fail:
577575
# 0 - do nothing special (usually pg_upgrade, which is first method, succeeds)
578576
# 1 - fail first method (so we get a chance to run second method, migration via pipe)
@@ -657,6 +655,7 @@ if is_upgrade && [ -d "$BACKUP_DIR/data" ]; then
657655
cf_console echo "And now installation will proceed with clean (empty) database"
658656
(cd /tmp && su cfpostgres -c "$PREFIX/bin/initdb -D $PREFIX/state/pg/data")
659657
fi
658+
set -e
660659
fi
661660

662661
(cd /tmp && su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log start")
@@ -688,18 +687,23 @@ then
688687
cf_console echo "Database migration also failed for the above reason. Backups are in $PREFIX/state/pg/*.sql.gz"
689688
fi
690689
else
691-
(cd /tmp && su cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 cfdb")
692-
(cd /tmp && su cfpostgres -c "$PREFIX/bin/createuser -S -D -R -w $MP_APACHE_USER")
693-
(cd /tmp && su cfpostgres -c "$PREFIX/bin/createuser -d -a -w root")
694-
(cd /tmp && su cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 cfmp")
695-
(cd /tmp && su cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 cfsettings")
690+
(
691+
cd /tmp
692+
set +e
693+
su cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 cfdb"
694+
su cfpostgres -c "$PREFIX/bin/createuser -S -D -R -w $MP_APACHE_USER"
695+
su cfpostgres -c "$PREFIX/bin/createuser -d -a -w root"
696+
su cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 cfmp"
697+
su cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 cfsettings"
698+
exit 0
699+
)
696700

697701
# Create the cfengine mission portal postgres user
698702
(cd /tmp && su cfpostgres -c "$PREFIX/bin/psql cfmp" < $PREFIX/share/GUI/phpcfenginenova/create_cfmppostgres_user.sql)
699703

700704
# Ensure cfpostgres can read the sql files it will import. And that they are
701705
# restored to restrictive state after import ENT-2684
702-
(chown cfpostgres "$PREFIX/share/db/*.sql")
706+
chown cfpostgres $PREFIX/share/db/*.sql
703707
(cd /tmp && chown cfpostgres "$PREFIX/share/db/schema.sql" && su cfpostgres -c "$PREFIX/bin/psql cfdb -f $PREFIX/share/db/schema.sql" && chown root "$PREFIX/share/db/schema.sql")
704708

705709
#create database for MISSION PORTAL
@@ -708,9 +712,12 @@ else
708712

709713

710714
#create database for hub internal data
711-
(cd /tmp && chown cfpostgres "$PREFIX/share/db/schema_settings.sql" && su cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/schema_settings.sql" && chown root "$PREFIX/share/db/schema_settings.sql")
712-
(cd /tmp && chown cfpostgres "$PREFIX/share/db/ootb_settings.sql" && su cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/ootb_settings.sql" && chown root "$PREFIX/share/db/ootb_settings.sql")
713-
(cd /tmp && chown cfpostgres "$PREFIX/share/db/ootb_import.sql" && su cfpostgres -c "$PREFIX/bin/psql cfdb -f $PREFIX/share/db/ootb_import.sql" && chown root "$PREFIX/share/db/ootb_import.sql")
715+
(
716+
cd /tmp
717+
chown cfpostgres "$PREFIX/share/db/schema_settings.sql" && su cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/schema_settings.sql" && chown root "$PREFIX/share/db/schema_settings.sql"
718+
chown cfpostgres "$PREFIX/share/db/ootb_settings.sql" && su cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/ootb_settings.sql" && chown root "$PREFIX/share/db/ootb_settings.sql"
719+
chown cfpostgres "$PREFIX/share/db/ootb_import.sql" && su cfpostgres -c "$PREFIX/bin/psql cfdb -f $PREFIX/share/db/ootb_import.sql" && chown root "$PREFIX/share/db/ootb_import.sql"
720+
)
714721

715722
#revoke create permission on public schema for cfdb database
716723
(cd /tmp && su cfpostgres -c "$PREFIX/bin/psql cfdb") << EOF
@@ -763,9 +770,11 @@ find $PREFIX/httpd/htdocs/scripts/ -type f -exec chmod 0440 {} +
763770
find $PREFIX/httpd/htdocs/tmp/ -type f -exec chown -R root:$MP_APACHE_USER {} +
764771
find $PREFIX/httpd/htdocs/tmp/ -type f -exec chmod 0660 {} +
765772

766-
# logs
767-
find $PREFIX/httpd/htdocs/logs/ -type f -exec chown -R $MP_APACHE_USER:$MP_APACHE_USER {} +
768-
find $PREFIX/httpd/htdocs/logs/ -type f -exec chmod 0640 {} +
773+
# logs (if any)
774+
if [ -d $PREFIX/httpd/htdocs/logs/ ]; then
775+
find $PREFIX/httpd/htdocs/logs/ -type f -exec chown -R $MP_APACHE_USER:$MP_APACHE_USER {} +
776+
find $PREFIX/httpd/htdocs/logs/ -type f -exec chmod 0640 {} +
777+
fi
769778

770779
# application
771780
find $PREFIX/httpd/htdocs/application/ -type f -exec chown -R root:$MP_APACHE_USER {} +

packaging/common/cfengine-hub/preinstall.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ fi
114114
#stop the remaining services on upgrade
115115
if is_upgrade; then
116116
cf_console platform_service cfengine3 stop
117-
if [ -x /bin/systemctl ]; then
117+
# CFE-2278: Migrate to split units
118+
if [ -x /bin/systemctl ] && [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then
118119
# When using systemd, the services are split in two, and although both will
119120
# stop due to the command above, the web part may only do so after some
120121
# delay, which may cause problems in an upgrade situation, since this script
@@ -123,14 +124,6 @@ if is_upgrade; then
123124
fi
124125
fi
125126

126-
# CFE-2278: Migrate to split units
127-
if is_upgrade; then
128-
if [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then
129-
# It's functionality is replaced with multiple units.
130-
/bin/systemctl disable cfengine3-web.service
131-
fi
132-
fi
133-
134127
if migrating_postgres; then
135128
cf_console echo "Moving old data and copying old binaries to $BACKUP_DIR"
136129
# Now that PostgreSQL is shut down, move the old data out of the way.
@@ -164,18 +157,25 @@ if migrating_postgres; then
164157
cp -a "$BACKUP_DIR/data/postgresql.conf" "$BACKUP_DIR/data/postgresql.conf.modified"
165158
fi
166159
cp -al "$PREFIX/bin" "$BACKUP_DIR"
167-
cp -l "$PREFIX/lib"/* "$BACKUP_DIR/lib"
160+
for file in "$PREFIX/lib"/*; do
161+
if [ -f $file ]; then
162+
cp -l $file "$BACKUP_DIR/lib"
163+
fi
164+
done
168165
cp -al "$PREFIX/lib/postgresql/" "$BACKUP_DIR/lib"
169166
cp -al "$PREFIX/share/postgresql/" "$BACKUP_DIR/share"
170167
fi
171168

172169
filter_netstat_listen()
173170
{
171+
set +e
174172
if [ -x /usr/sbin/ss ]; then
175173
ss -natp | egrep "LISTEN.*($1)"
176174
else
177175
netstat -natp | egrep "($1).*LISTEN"
178176
fi
177+
set -e
178+
return 0
179179
}
180180

181181
#
@@ -326,7 +326,7 @@ if [ -d $PREFIX/httpd/htdocs ]; then
326326
cf_console echo "Using share/GUI as template"
327327
( cd $PREFIX/share/GUI
328328
# Make list of files in share/GUI and remove "them" from httpd/htdocs
329-
find -type f -print0 | ( cd ../../httpd/htdocs/ && xargs -0 rm )
329+
find -type f -print0 | ( cd ../../httpd/htdocs/ && xargs -0 rm -f )
330330
)
331331
else
332332
# Purge all files in httpd/htdocs with hardcoded exceptions:

packaging/common/cfengine-hub/preremove.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cf_console platform_service cfengine3 stop
2-
if [ -x /bin/systemctl ]; then
2+
if [ -x /bin/systemctl ] && [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then
33
# When using systemd, the services are split in two, and although both will
44
# stop due to the command above, the web part may only do so after some
55
# delay, which may cause problems later if the binaries are gone by the time
@@ -12,7 +12,7 @@ case "`os_type`" in
1212
chkconfig --del cfengine3
1313
;;
1414
debian)
15-
update-rc.d cfengine3 remove
15+
update-rc.d -f cfengine3 remove
1616
;;
1717
esac
1818

@@ -39,11 +39,8 @@ case "`package_type`" in
3939
;;
4040
esac
4141

42-
if [ -f "$MAN_CONFIG" ]; then
43-
grep -q cfengine "$MAN_CONFIG"
44-
if [ $? = "0" ]; then
45-
sed -i '/cfengine/d' "$MAN_CONFIG"
46-
fi
42+
if [ -f "$MAN_CONFIG" ] && grep -q cfengine "$MAN_CONFIG"; then
43+
sed -i '/cfengine/d' "$MAN_CONFIG"
4744
fi
4845

4946
#

packaging/common/cfengine-non-hub/postremove.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ case `os_type` in
33
#
44
# Unregister CFEngine initscript.
55
#
6-
/usr/sbin/update-rc.d cfengine3 remove
6+
/usr/sbin/update-rc.d -f cfengine3 remove
77
;;
88
esac
99

packaging/common/cfengine-non-hub/preinstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ esac
3535
case `os_type` in
3636
debian)
3737
if [ -x /etc/init.d/cfengine3 ]; then
38-
/usr/sbin/update-rc.d cfengine3 remove
38+
/usr/sbin/update-rc.d -f cfengine3 remove
3939
fi
4040
;;
4141
esac

packaging/common/produce-script

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ include_script()
3535

3636
include_script "$TEMPLATEDIR/$PKG_TYPE-script-common.sh"
3737

38+
case "$PKG_TYPE" in
39+
deb|rpm)
40+
echo "set -e"
41+
;;
42+
esac
43+
3844
echo "PKG_TYPE=$PKG_TYPE"
3945
echo "SCRIPT_TYPE=$SCRIPT_TYPE"
4046
echo "PROJECT_TYPE=$PROJECT_TYPE"

packaging/common/script-templates/script-common.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ restore_cfengine_state() {
5353
# $1 -- file where the state to restore is saved (see get_cfengine_state())
5454

5555
if type systemctl >/dev/null 2>&1; then
56-
xargs -n1 -a "$1" systemctl start
56+
for service in `cat "$1"`; do
57+
definition=`systemctl cat "$service"` || continue
58+
# only try to start service that are defined/exist (some may be gone
59+
# in the new version)
60+
if [ -n "$definition" ]; then
61+
systemctl start "$service"
62+
fi
63+
done
5764
else
5865
CALLED_FROM_STATE_RESTORE=1
5966
if [ -f ${PREFIX}/bin/cfengine3-nova-hub-init-d.sh ]; then
@@ -67,7 +74,9 @@ restore_cfengine_state() {
6774
fi
6875

6976
for d in `grep 'cf-' "$1"`; do
70-
${PREFIX}/bin/${d}
77+
if [ -f ${PREFIX}/bin/${d} ]; then
78+
${PREFIX}/bin/${d}
79+
fi
7180
done
7281
fi
7382
}

0 commit comments

Comments
 (0)