#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later set -ex # Silence warning from running_in_chroot_or_offline() export SYSTEMD_IGNORE_CHROOT=1 systemctl=${1:-systemctl} systemd_id128=${2:-systemd-id128} unset root cleanup() { [ -n "$root" ] && rm -rf "$root" } trap cleanup exit root=$(mktemp -d --tmpdir systemctl-test.XXXXXX) islink() { test -h "$1" || return 1 test "$(readlink "$1")" = "$2" || return 2 } : '------enable nonexistent------------------------------------' ( ! "$systemctl" --root="$root" enable test1.service ) : '------basic enablement--------------------------------------' mkdir -p "$root/etc/systemd/system" cat >"$root/etc/systemd/system/test1.service" <>"$root/etc/systemd/system/test1.service" <"$root/etc/systemd/system/test1a.service" <"$root/etc/systemd/system/test2.socket" <"$root/etc/systemd/system/test2.service" <"$root/link1.path" <"$root/link-instance@.service" <"$root/link3.suffix" <"$root/etc/systemd/system/link5-also.service" <"$root/etc/systemd/system/myown.d/link5.service" <"$root/etc/systemd/system/templ1@.service" <"$root/etc/systemd/system/templ1@.service" <"$root/etc/systemd/system/templ2@.service" <"$root/etc/systemd/system/link4.service" <"$root/etc/systemd/system/link4.service" <"$root/etc/systemd/system/link5.service" <"$root/link5copy.service" <"$root/etc/systemd/system/link5@.path" <"$root/etc/systemd/system/multilink.mount" <"$root/etc/systemd/system/some-some-link6@.socket" <"$root/etc/os-release" <"$root/etc/os-release" <"$root/etc/machine-id" check_alias m "$(cat "$root/etc/machine-id")" check_alias n 'some-some-link6@.socket' check_alias N 'some-some-link6@' check_alias p 'some-some-link6' uname -r | grep -q '[^a-zA-Z0-9_.\\-]' || \ check_alias v "$(uname -r)" # % is not legal in unit name ( ! check_alias % '%' ) # %z is not defined ( ! check_alias z 'z' ) : '-------specifiers in WantedBy-------------------------------' # We don't need to repeat all the tests. Let's do a basic check that specifier # expansion is performed. cat >"$root/etc/systemd/system/some-some-link7.socket" <"$root/etc/os-release2" <