diff --git a/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash b/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash index acaa6f334..62f95fe9a 100644 --- a/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash +++ b/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash @@ -1,5 +1,6 @@ export DISTRO_NAME=debian export DIB_RELEASE=${DIB_RELEASE:-stable} +export DIB_INIT_SYSTEM=systemd if [ -n "${DIB_DEBIAN_DISTRIBUTION_MIRROR:-}" ]; then DIB_DISTRIBUTION_MIRROR=$DIB_DEBIAN_DISTRIBUTION_MIRROR diff --git a/diskimage_builder/elements/dib-init-system/README.rst b/diskimage_builder/elements/dib-init-system/README.rst index b2c343830..b7d3423bb 100644 --- a/diskimage_builder/elements/dib-init-system/README.rst +++ b/diskimage_builder/elements/dib-init-system/README.rst @@ -2,9 +2,7 @@ dib-init-system =============== -Installs a script (dib-init-system) which outputs the type of init system in -use on the target image. Also sets an environment variable ``DIB_INIT_SYSTEM`` -to this value. +Element that handles aspects of the used target's init system. Any files placed in a ``init-scripts/INIT_SYSTEM`` directory inside the element will be copied into the appropriate directory if ``INIT_SYSTEM`` @@ -14,5 +12,6 @@ Environment Variables --------------------- DIB_INIT_SYSTEM - :Description: One of upstart, systemd, or sysv depending on the init system - in use for the target image. + :Description: One of ``upstart``, ``systemd``, ``openrc`` or + ``sysv`` depending on the init system in use for the target image. + This should be set automatically by your platform elements. diff --git a/diskimage_builder/elements/dib-init-system/dib-init-system b/diskimage_builder/elements/dib-init-system/dib-init-system deleted file mode 100755 index 48164d3d9..000000000 --- a/diskimage_builder/elements/dib-init-system/dib-init-system +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -# Debian Jessie and Debian Stretch use /bin/systemctl. -# (/sbin/init is only available if systemd-sysv is installed.) - -if [ -f /usr/bin/systemctl -o -f /bin/systemctl ]; then - echo "systemd" -elif [[ -f /sbin/initctl ]]; then - echo "upstart" -elif [[ -f /etc/gentoo-release ]]; then - if [[ -z GENTOO_PROFILE ]]; then - if [[ "${GENTOO_PROFILE}" =~ systemd ]]; then - echo "systemd" - fi - else - echo "openrc" - fi -elif [[ -f /sbin/init ]]; then - if [[ -f /bin/systemd ]]; then - echo "systemd" - else - echo "sysv" - fi -else - echo "Unknown init system" - exit 1 -fi diff --git a/diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash b/diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash deleted file mode 100644 index d683ce894..000000000 --- a/diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash +++ /dev/null @@ -1,2 +0,0 @@ -DIB_INIT_SYSTEM=$(PATH="$PATH:$(dirname $BASH_SOURCE)/.." dib-init-system) -export DIB_INIT_SYSTEM diff --git a/diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system b/diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system new file mode 100644 index 000000000..958a6e905 --- /dev/null +++ b/diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system @@ -0,0 +1,30 @@ +# +# This runs last in the environment to ensure DIB_INIT_SYSTEM is set. +# We expect the base environments to set this variable particular to +# their platform. Note we used to try and guess this automatically +# inside the chroot, but there's a chicken-and-egg issue when you're +# building from scratch and you're guessing before you've even +# installed the init system. +# + +if [ -z "${DIB_INIT_SYSTEM:-}" ]; then + echo "DIB_INIT_SYSTEM is not set! Can not continue" + exit 1 +fi + +# whitelist known systems +case $DIB_INIT_SYSTEM in + upstart) ;; + openrc) ;; + systemd) ;; + sysv) ;; + *) + echo "Unrecognised init system: ${DIB_INIT_SYSTEM}!" + echo "Can not continue" + exit 1 +esac + +# Tell emacs to use shell-mode +# Local variables: +# mode: sh +# End: diff --git a/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system b/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system index 8e63fcd26..36f5bd794 100755 --- a/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system +++ b/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system @@ -6,4 +6,16 @@ fi set -eu set -o pipefail -install -m 0755 -o root -g root $(dirname $0)/../dib-init-system /usr/bin/ +FILE=/usr/local/bin/dib-init-system + +# This is a dummy script that simply echos the output of +# ${DIB_INIT_SYSTEM}. This script used to try and guess the init +# system, but that doesn't work. This script is deprecated. + +cat > ${FILE} <