From 265b31e6b5c3d1d89d0d57fcfa5df8771f9fc26c Mon Sep 17 00:00:00 2001 From: Matthew Thode Date: Thu, 28 Jan 2016 15:53:13 -0600 Subject: [PATCH] Add support for OpenRC to dib-init-system Adds a post-install function that enables installed initscripts, as that is not done by default in gentoo. Change-Id: I04e8d506ddcbefa8a983dd31ad16df5e13cb26e7 Closes-Bug: 1539276 --- elements/dib-init-system/dib-init-system | 14 +++++++--- .../install.d/20-install-init-scripts | 3 ++- .../post-install.d/10-enable-init-scripts | 27 +++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100755 elements/dib-init-system/post-install.d/10-enable-init-scripts diff --git a/elements/dib-init-system/dib-init-system b/elements/dib-init-system/dib-init-system index 1596fe71..6953c935 100755 --- a/elements/dib-init-system/dib-init-system +++ b/elements/dib-init-system/dib-init-system @@ -6,12 +6,18 @@ fi set -eu set -o pipefail -if [ -f /sbin/initctl ]; then +if [[ -f /sbin/initctl ]]; then echo "upstart" -elif [ -f /usr/bin/systemctl ]; then +elif [[ -f /etc/gentoo-release ]]; then + if [[ "${GENTOO_PROFILE}" =~ systemd ]]; then + echo "systemd" + else + echo "openrc" + fi +elif [[ -f /usr/bin/systemctl ]]; then echo "systemd" -elif [ -f /sbin/init ]; then - if [ -f /bin/systemd ]; then +elif [[ -f /sbin/init ]]; then + if [[ -f /bin/systemd ]]; then echo "systemd" else echo "sysv" diff --git a/elements/dib-init-system/install.d/20-install-init-scripts b/elements/dib-init-system/install.d/20-install-init-scripts index 49099614..f474b6ed 100755 --- a/elements/dib-init-system/install.d/20-install-init-scripts +++ b/elements/dib-init-system/install.d/20-install-init-scripts @@ -14,12 +14,13 @@ if [ -d "$scripts_dir" ]; then dest= case $DIB_INIT_SYSTEM in upstart) dest=/etc/init/ ;; + openrc) dest=/etc/init.d/ ;; systemd) dest=/usr/lib/systemd/system/ ;; sysv) dest=/etc/init.d/ ;; esac if [ -z "$dest" ]; then - echo "ERROR: DIB_INIT_SYSTEM ($DIB_INIT_SYSTEM) is not an unknown type" + echo "ERROR: DIB_INIT_SYSTEM ($DIB_INIT_SYSTEM) is not a known type" exit 1 fi cp -RP $scripts_dir. $dest || true diff --git a/elements/dib-init-system/post-install.d/10-enable-init-scripts b/elements/dib-init-system/post-install.d/10-enable-init-scripts new file mode 100755 index 00000000..dc7e872d --- /dev/null +++ b/elements/dib-init-system/post-install.d/10-enable-init-scripts @@ -0,0 +1,27 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +SCRIPTS_DIR="$(dirname $0)/../init-scripts/${DIB_INIT_SYSTEM}/" +if [[ -d "${SCRIPTS_DIR}" ]]; then + # figure out init prefix + case "${DIB_INIT_SYSTEM}" in + upstart) ;; + openrc) + # only gentoo needs manual runlevel adding + for INIT_SCRIPT in "${SCRIPTS_DIR}"*; do + rc-update add $(basename "${INIT_SCRIPT}") default + done + ;; + systemd) ;; + sysv) ;; + *) + echo "ERROR: DIB_INIT_SYSTEM (${DIB_INIT_SYSTEM}) is not a known type" + exit 1 + ;; + esac +fi