| 1 |
#!/bin/sh |
| 2 |
set -eu |
| 3 |
|
| 4 |
# Copyright (C) 2021-2022, Benjamin Drung <[email protected]> |
| 5 |
# SPDX-License-Identifier: ISC |
| 6 |
|
| 7 |
# Enable services / systemd units in a chroot environment. |
| 8 |
|
| 9 |
if test "$#" = 0; then |
| 10 |
echo "${0##*/}: Called without required CHROOT_DIR argument." >&2 |
| 11 |
echo "usage: ${0##*/} CHROOT_DIR service/systemd_unit [service/system_unit...]" >&2 |
| 12 |
exit 1 |
| 13 |
fi |
| 14 |
|
| 15 |
chroot_directory="$1" |
| 16 |
shift |
| 17 |
|
| 18 |
for unit in "$@"; do |
| 19 |
if test -e "${chroot_directory}/etc/systemd/system/${unit}" \ |
| 20 |
|| test -e "${chroot_directory}/lib/systemd/system/${unit}" \ |
| 21 |
|| test -e "${chroot_directory}/usr/lib/systemd/system/${unit}" \ |
| 22 |
|| test -e "${chroot_directory}/etc/systemd/system/${unit}.service" \ |
| 23 |
|| test -e "${chroot_directory}/lib/systemd/system/${unit}.service" \ |
| 24 |
|| test -e "${chroot_directory}/usr/lib/systemd/system/${unit}.service" \ |
| 25 |
|| test -e "${chroot_directory}/etc/init.d/$unit"; then |
| 26 |
echo "${0##*/}: Enabling unit $unit..." >&2 |
| 27 |
echo "${0##*/}: Calling chroot \"${chroot_directory}\" /bin/systemctl enable \"$unit\"" >&2 |
| 28 |
chroot "${chroot_directory}" /bin/systemctl enable "$unit" |
| 29 |
else |
| 30 |
echo "${0##*/}: Unit $unit not found. Skipping enabling it." >&2 |
| 31 |
fi |
| 32 |
done |