aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Vitters <olav@vitters.nl>2020-07-25 20:49:02 +0200
committerOlav Vitters <olav@vitters.nl>2020-07-25 20:49:02 +0200
commit73b82d1b4d3cd40287c6a0b36f2c5404d09bb4d8 (patch)
tree8f0a3aed288726ba715add37fd8ec8ca2e785ea7
parent0a25ba446c1cb47a21b3f6056a10c90fea630c6f (diff)
downloadrpm-helper-73b82d1b4d3cd40287c6a0b36f2c5404d09bb4d8.tar
rpm-helper-73b82d1b4d3cd40287c6a0b36f2c5404d09bb4d8.tar.gz
rpm-helper-73b82d1b4d3cd40287c6a0b36f2c5404d09bb4d8.tar.bz2
rpm-helper-73b82d1b4d3cd40287c6a0b36f2c5404d09bb4d8.tar.xz
rpm-helper-73b82d1b4d3cd40287c6a0b36f2c5404d09bb4d8.zip
add-service: ShellCheck: fix loads of shellcheck warnings
-rwxr-xr-xadd-service80
1 files changed, 40 insertions, 40 deletions
diff --git a/add-service b/add-service
index 571a54c..3763fca 100755
--- a/add-service
+++ b/add-service
@@ -10,7 +10,7 @@
# service.
#---------------------------------------------------------------
-if [ x$1 = x--no-sysv ]; then
+if [ "x$1" = x--no-sysv ]; then
do_sysv=no
shift
else
@@ -48,7 +48,7 @@ RUNTIMEUNITDIR=/run/systemd/system
SYSTEMUNITDIR=/lib/systemd/system
find_unit() {
- unit=$(basename $1)
+ unit=$(basename "$1")
# We need to normalise the systemd unit name as the native unit may not have
# the same filename (sans it's .service suffix) as sysvinit script.
@@ -70,7 +70,7 @@ find_unit() {
searchunit="$SYSTEMUNITDIR/$unit"
fi
if [ -n "$searchunit" ]; then
- echo -n $searchunit
+ echo -n "$searchunit"
fi
}
@@ -78,11 +78,11 @@ find_unit() {
# If only a sysvinit service is given, then deal with a systemd unit of the same
# name. Specific specs can enable specific unit names as needed but this should
# catch the most common usage.
-if [ -z "$units" -a -n "$srv" -a ! -f /etc/xinetd.d/$srv ]; then
+if [ -z "$units" ] && [ -n "$srv" ] && [ ! -f "/etc/xinetd.d/$srv" ]; then
units="$srv.service"
searchunit=$(find_unit $units)
if [ -n "$searchunit" ]; then
- units=$(basename $searchunit)
+ units=$(basename "$searchunit")
fi
fi
@@ -97,7 +97,7 @@ add_service() {
# during the install the symlink isn't done so find the right file
# by ourselves
- if [ -n "$DURING_INSTALL" -a ! -f $LIST ]; then
+ if [ -n "$DURING_INSTALL" ] && [ ! -f $LIST ]; then
LIST=/etc/security/msec/server.$SECURE_LEVEL
fi
@@ -107,18 +107,18 @@ add_service() {
# If SysV name was supplied, we assume units are equivalent and do
# not need to be checked.
# TODO should msec support full unit name?
- if [ -f $LIST ]; then
+ if [ -f "$LIST" ]; then
if [ -n "$srv" ]; then
- if fgrep -qx "${srv}" $LIST; then
+ if grep -Fqx "${srv}" "$LIST"; then
units_to_enable="$units"
else
srv=
fi
elif [ -n "$units" ]; then
for i in $units; do
- [ $i != ${i%.service} ] && ! fgrep -qx ${i%.service} $LIST && continue
- [ $i != ${i%.socket} ] && ! fgrep -qx ${i%.socket} $LIST && continue
- [ $i != ${i%.path} ] && ! fgrep -qx ${i%.path} $LIST && continue
+ [ "$i" != "${i%.service}" ] && ! grep -Fqx "${i%.service}" "$LIST" && continue
+ [ "$i" != "${i%.socket}" ] && ! grep -Fqx "${i%.socket}" "$LIST" && continue
+ [ "$i" != "${i%.path}" ] && ! grep -Fqx "${i%.path}" "$LIST" && continue
units_to_enable="$units_to_enable $i"
done
fi
@@ -135,7 +135,7 @@ add_service() {
echo " Please check and enable manually if necessary." >&2
echo " Service units affected: $units_to_enable" >&2
fi
- if [ -n "$srv" -a ! -f "${systemd_migration_dir}/$srv" ]; then
+ if [ -n "$srv" ] && [ ! -f "${systemd_migration_dir}/$srv" ]; then
touch "${systemd_migration_dir}/$srv"
fi
fi
@@ -146,7 +146,7 @@ add_service() {
# In order to enable switching back ot sysvinit, we should enable the
# sysvinit scripts too.
if [ -n "$srv" ]; then
- if [ -f /etc/rc.d/init.d/$srv -o -f /etc/xinetd.d/$srv ]; then
+ if [ -f /etc/rc.d/init.d/$srv ] || [ -f /etc/xinetd.d/$srv ]; then
/sbin/chkconfig --add $srv
if [ -r /etc/sysconfig/system ]; then
@@ -158,7 +158,7 @@ add_service() {
# add the service to all the profiles at once
if [ -d /etc/netprofile/profiles/default/services ]; then
for dir in /etc/netprofile/profiles/*/services; do
- touch $dir/$srv
+ touch "$dir/$srv"
done
fi
fi
@@ -175,9 +175,9 @@ check_sysvinit_service() {
echo 1>&2 "add-service: Error: $srv appears multiple times at runlevel $rl: $*"
fi
- echo -n $1
+ echo -n "$1"
}
-if [ $num = 1 ]; then
+if [ "$num" = 1 ]; then
# First install mode
if [ "null" != "$units" ]; then
add_service
@@ -190,7 +190,7 @@ else
# If a previously installed package only had a sysvinit script, but an
# updated package has a native systemd unit, we need to make sure we migrate
# any service enablement for various targets (née runlevels)
- if [ -n "$srv" -a -n "$units" ]; then
+ if [ -n "$srv" ] && [ -n "$units" ]; then
if [ ! -f "${systemd_migration_dir}/$srv" ]; then
full_path_units=
for unit in $units; do
@@ -200,7 +200,7 @@ else
# a sysvinit script and thus we'll not have anything native.
# We only consider a "migration" to have taken place when
# we genuinely have a native systemd unit.
- unit=$(find_unit $unit)
+ unit=$(find_unit "$unit")
if [ -n "$unit" ]; then
full_path_units="$full_path_units $unit"
fi
@@ -211,7 +211,7 @@ else
# We have not yet migrated this service
# First we check in which runlevels the legacy service is enabled
# Only bother checking runlevels 1 3 and 5
- script=$(check_sysvinit_service 1 $srv)
+ script=$(check_sysvinit_service 1 "$srv")
# NB We only check that the link exists as the old sysvinit
# script may have been removed during migration to systemd
@@ -220,13 +220,13 @@ else
enable_targets="$enable_targets rescue.target"
fi
- script=$(check_sysvinit_service 3 $srv)
+ script=$(check_sysvinit_service 3 "$srv")
if [ -L "$script" ]; then
enable_targets="$enable_targets multi-user.target"
else
# As graphical.target includes everything in multi-user.target,
# we only need to check 5 when 3 does NOT give us a result.
- script=$(check_sysvinit_service 5 $srv)
+ script=$(check_sysvinit_service 5 "$srv")
if [ -L "$script" ]; then
enable_targets="$enable_targets graphical.target"
fi
@@ -234,23 +234,23 @@ else
if [ -n "$enable_targets" ]; then
for unit in $full_path_units; do
- bn_unit="$(basename $unit)"
- if grep -qE "^(WantedBy|Alias)=" $unit; then
- if [ x$init = xsystemd -a x$reloaded = xno ]; then
+ bn_unit="$(basename "$unit")"
+ if grep -qE "^(WantedBy|Alias)=" "$unit"; then
+ if [ x$init = xsystemd ] && [ x$reloaded = xno ]; then
/bin/systemctl --system daemon-reload
reloaded=yes
fi
echo 1>&2 "Migrating sysvinit service '$srv' to systemd native unit '$bn_unit' via systemd install rules."
- /bin/systemctl enable $bn_unit
- elif [[ "$bn_unit" =~ "@.service" ]]; then
+ /bin/systemctl enable "$bn_unit"
+ elif [[ "$bn_unit" =~ @.service ]]; then
echo 1>&2 "Migrating sysvinit service '$srv' to systemd native template unit '$bn_unit': Failed - no install rules"
else
for enable_target in $enable_targets; do
- wantsdir=$USERUNITDIR/${enable_target}.wants
- mkdir -p $wantsdir
- if [ ! -f $wantsdir/$bn_unit ]; then
+ wantsdir="$USERUNITDIR/${enable_target}.wants"
+ mkdir -p "$wantsdir"
+ if [ ! -f "$wantsdir/$bn_unit" ]; then
echo 1>&2 "Migrating sysvinit service '$srv' to systemd native unit '$bn_unit' for target '${enable_target}'"
- ln -s $unit $wantsdir/$bn_unit
+ ln -s "$unit" "$wantsdir/$bn_unit"
reloaded=no
fi
done
@@ -270,35 +270,35 @@ else
fi
fi
- if [ x$init = xsystemd ]; then
+ if [ "x$init" = xsystemd ]; then
# Package install may have changed the unit file, so reload the daemon
# before trying to restart anything
- if [ x$reloaded = xno ]; then
+ if [ "x$reloaded" = xno ]; then
/bin/systemctl --system daemon-reload
fi
# There may be template units, so attempt to find all instances and
# restart them.
for unit in $units; do
- if [[ "$unit" =~ "@.service" ]]; then
+ if [[ "$unit" =~ @.service ]]; then
instances=$(/bin/systemctl -a --full list-units | grep -E "${unit%@.service}@[^ ]+.service" | awk '{ print $1 }')
if [ -n "$instances" ]; then
for iunit in $instances; do
- /bin/systemctl --quiet try-restart $iunit
+ /bin/systemctl --quiet try-restart "$iunit"
done
fi
elif [ "null" != "$unit" ]; then
- /bin/systemctl --quiet try-restart $unit
+ /bin/systemctl --quiet try-restart "$unit"
fi
done
- elif [ -f /etc/rc.d/init.d/$srv ]; then
- script=$(check_sysvinit_service 3 $srv);
+ elif [ -f "/etc/rc.d/init.d/$srv" ]; then
+ script=$(check_sysvinit_service 3 "$srv");
if [ -f "$script" ]; then
- /sbin/chkconfig --add $srv
+ /sbin/chkconfig --add "$srv"
fi
# restart the service if already running
- if [ -f /var/lock/subsys/$srv ]; then
- /sbin/service $srv restart > /dev/null || :
+ if [ -f "/var/lock/subsys/$srv" ]; then
+ /sbin/service "$srv" restart > /dev/null || :
fi
fi
fi