File: enable-units

package info (click to toggle)
bdebstrap 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 312 kB
  • sloc: python: 1,736; sh: 125; makefile: 4
file content (32 lines) | stat: -rwxr-xr-x 1,237 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
set -eu

# Copyright (C) 2021-2022, Benjamin Drung <bdrung@posteo.de>
# SPDX-License-Identifier: ISC

# Enable services / systemd units in a chroot environment.

if test "$#" = 0; then
    echo "${0##*/}: Called without required CHROOT_DIR argument." >&2
    echo "usage: ${0##*/} CHROOT_DIR service/systemd_unit [service/system_unit...]" >&2
    exit 1
fi

chroot_directory="$1"
shift

for unit in "$@"; do
    if test -e "${chroot_directory}/etc/systemd/system/${unit}" || \
       test -e "${chroot_directory}/lib/systemd/system/${unit}" || \
       test -e "${chroot_directory}/usr/lib/systemd/system/${unit}" || \
       test -e "${chroot_directory}/etc/systemd/system/${unit}.service" || \
       test -e "${chroot_directory}/lib/systemd/system/${unit}.service" || \
       test -e "${chroot_directory}/usr/lib/systemd/system/${unit}.service" || \
       test -e "${chroot_directory}/etc/init.d/$unit"; then
        echo "${0##*/}: Enabling unit $unit..." >&2
        echo "${0##*/}: Calling chroot \"${chroot_directory}\" /bin/systemctl enable \"$unit\"" >&2
        chroot "${chroot_directory}" /bin/systemctl enable "$unit"
    else
        echo "${0##*/}: Unit $unit not found. Skipping enabling it." >&2
    fi
done