Skip to content

Commit

Permalink
test: use quotes where necessary
Browse files Browse the repository at this point in the history
to avoid possible word splitting.

[dtardon: Dropped changes to other files.]

(cherry picked from commit 3882526)

Related: #2156620
  • Loading branch information
mrc0mmand authored and dtardon committed Jul 13, 2023
1 parent 7c9f16f commit 0548d91
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions test/TEST-15-DROPIN/test-dropin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,53 @@ set -e
set -x

_clear_service () {
systemctl stop $1.service 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/$1.service
rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.{wants,requires}
if [[ $1 == *@ ]]; then
systemctl stop $1*.service 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/$1*.service
rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.{wants,requires}
local SERVICE_NAME="${1:?_clear_service: missing argument}"
systemctl stop "$SERVICE_NAME.service" 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{wants,requires}
if [[ $SERVICE_NAME == *@ ]]; then
systemctl stop "$SERVICE_NAME"*.service 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.{wants,requires}
fi
}

clear_services () {
for u in $*; do
_clear_service $u
for u in "$@"; do
_clear_service "$u"
done
systemctl daemon-reload
}

create_service () {
clear_services $1
local SERVICE_NAME="${1:?create_service: missing argument}"
clear_services "$SERVICE_NAME"

cat >/etc/systemd/system/$1.service<<EOF
cat >/etc/systemd/system/"$SERVICE_NAME".service <<EOF
[Unit]
Description=$1 unit
Description=$SERVICE_NAME unit
[Service]
ExecStart=/bin/sleep 100000
EOF
mkdir -p /{etc,run,usr/lib}/systemd/system/$1.service.d
mkdir -p /etc/systemd/system/$1.service.{wants,requires}
mkdir -p /run/systemd/system/$1.service.{wants,requires}
mkdir -p /usr/lib/systemd/system/$1.service.{wants,requires}
mkdir -p /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d
mkdir -p /etc/systemd/system/"$SERVICE_NAME".service.{wants,requires}
mkdir -p /run/systemd/system/"$SERVICE_NAME".service.{wants,requires}
mkdir -p /usr/lib/systemd/system/"$SERVICE_NAME".service.{wants,requires}
}

create_services () {
for u in $*; do
create_service $u
for u in "$@"; do
create_service "$u"
done
}

check_ok () {
[ $# -eq 3 ] || return

x="$(systemctl show --value -p $2 $1)"
x="$(systemctl show --value -p "$2" "$1")"
case "$x" in
*$3*) return 0 ;;
*) return 1
Expand Down

0 comments on commit 0548d91

Please sign in to comment.