From 6cb71b84b2e6be147594015c4942891ee9e021e0 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 28 Feb 2022 09:32:51 +0100 Subject: DEBIAN Signed-off-by: Daniel Baumann --- .../open-infrastructure-container-tools.postinst | 188 +++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100755 debian/open-infrastructure-container-tools.postinst (limited to 'debian/open-infrastructure-container-tools.postinst') diff --git a/debian/open-infrastructure-container-tools.postinst b/debian/open-infrastructure-container-tools.postinst new file mode 100755 index 0000000..af0137f --- /dev/null +++ b/debian/open-infrastructure-container-tools.postinst @@ -0,0 +1,188 @@ +#!/bin/sh + +set -e + +CONFFILE="/etc/compute-tools/container.conf" + +Install () +{ + DEFAULT="${1}" + TARGET="${2}" + + mkdir -p "${DEFAULT}" > /dev/null 2>&1 || true + mkdir -p "${TARGET}" > /dev/null 2>&1 || true + + if [ "${TARGET}" != "${DEFAULT}" ] + then + if [ -h "${DEFAULT}" ] + then + rm -f "${DEFAULT}" + ln -s "${TARGET}" "${DEFAULT}" + else + if [ -e "${DEFAULT}" ] && [ -z "$(ls -A ${DEFAULT})" ] + then + rmdir "${DEFAULT}" + ln -s "${TARGET}" "${DEFAULT}" + fi + fi + fi + + if ! dpkg-statoverride --list "${DEFAULT}" > /dev/null 2>&1 && + ! dpkg-statoverride --list "${TARGET}" > /dev/null 2>&1 + then + chmod 0700 "${TARGET}" + chown root:root "${TARGET}" + + chmod 0700 "${DEFAULT}" + chown root:root "${DEFAULT}" + fi +} + +Upgrade () +{ + # upgrade from buster: conffile + if [ -e /etc/open-infrastructure/container.conf ] && [ ! -e "${CONFFILE}" ] + then + mv /etc/open-infrastructure/container.conf "${CONFFILE}" + rmdir /etc/open-infrastructure > /dev/null 2>&1 || true + fi + + # upgrade from buster: hooks + for HOOK in ${HOOKS}/* + do + NAME="$(basename ${HOOK})" + TARGET="$(readlink -m ${HOOK})" + + case "${TARGET}" in + /usr/share/open-infrastructure/container/hooks/pre-create.git-pull.sh) + rm -f "${HOOKS}/${NAME}" + ln -sf /usr/share/compute-tools/hooks/pre-get.git-pull.sh "${HOOKS}/pre-get.git-pull.sh" + ln -sf /usr/share/compute-tools/hooks/pre-build.git-pull.sh "${HOOKS}/pre-build.git-pull.sh" + ;; + + /usr/share/open-infrastructure/container/hooks/*) + ln -sf "$(echo ${TARGET} | sed -e 's|/usr/share/open-infrastructure/container/hooks/|/usr/share/compute-tools/hooks/|')" "${HOOKS}/${NAME}" + ;; + + *) + if [ -e "/usr/share/compute-tools/hooks/${NAME}" ] + then + rm -f "${HOOKS}/${NAME}" + ln -sf "/usr/share/compute-tools/hooks/${NAME}" "${HOOKS}/${NAME}" + fi + ;; + esac + done + + # upgrade from buster: keys + if [ -e /etc/open-infrastructure/container/keys ] + then + mv /etc/open-infrastructure/container/keys/* "${KEYS}" > /dev/null 2>&1 || true + rmdir /etc/open-infrastructure/container/keys > /dev/null 2>&1 || true + rm -f /etc/open-infrastructure/container/keys > /dev/null 2>&1 || true + rmdir -p /etc/open-infrastructure/container > /dev/null 2>&1 || true + fi + + # upgrade from buster: logfiles + if ls /var/log/open-infrastructure/container.log* > /dev/null 2>&1 + then + if [ -e /var/log/compute-tools ] + then + mv /var/log/open-infrastructure/* /var/log/compute-tools 2>&1 || true + rmdir /var/log/open-infrastructure > /dev/null 2>&1 || true + else + mv /var/log/open-infrastructure /var/log/compute-tools + fi + fi +} + +case "${1}" in + configure) + . /usr/share/debconf/confmodule + + db_get open-infrastructure-container-tools/machines + MACHINES="${RET:-/var/lib/machines}" # string (w/o empty) + + db_get open-infrastructure-container-tools/config + CONFIG="${RET:-/etc/compute-tools/config}" # string (w/o empty) + + db_get open-infrastructure-container-tools/debconf + DEBCONF="${RET:-/etc/compute-tools/debconf}" # string (w/o empty) + + db_get open-infrastructure-container-tools/hooks + HOOKS="${RET:-/etc/compute-tools/hooks}" # string (w/o empty) + + db_get open-infrastructure-container-tools/keys + KEYS="${RET:-/etc/compute-tools/keys}" # string (w/o empty) + + db_get open-infrastructure-container-tools/cache + CACHE="${RET:-/var/cache/container}" # string (w/o empty) + + db_get open-infrastructure-container-tools/build-script + SCRIPT="${RET:-debian}" # string (w/o empty) + + db_get open-infrastructure-container-tools/irc + IRK_TARGETS="${RET}" # string (w/ empty) + + db_stop + + Install "/var/lib/machines" "${MACHINES}" + Install "/etc/compute-tools/config" "${CONFIG}" + Install "/etc/compute-tools/debconf" "${DEBCONF}" + Install "/etc/compute-tools/hooks" "${HOOKS}" + Install "/etc/compute-tools/keys" "${KEYS}" + Install "/var/cache/container" "${CACHE}" + + Upgrade + + if [ ! -e "${CONFFILE}" ] + then + +cat > "${CONFFILE}" << EOF +# ${CONFFILE} + +IRK_TARGETS="${IRK_TARGETS}" +EOF + + fi + + cp -a -f "${CONFFILE}" "${CONFFILE}.tmp" + + # If the admin deleted or commented some variables but then set + # them via debconf, (re-)add them to the config file. + + test -z "${IRK_TARGETS}" || \ + grep -Eq '^ *IRK_TARGETS=' "${CONFFILE}" || \ + echo "IRK_TARGETS=" >> "${CONFFILE}" + + sed -e "s|^ *IRK_TARGETS=.*|IRK_TARGETS=\"${IRK_TARGETS}\"|" \ + < "${CONFFILE}" > "${CONFFILE}.tmp" + + mv -f "${CONFFILE}.tmp" "${CONFFILE}" + + if command -v sysctl > /dev/null 2>&1 + then + sysctl -q -p /etc/sysctl.d/zz-container.conf + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + + ;; + + *) + echo "postinst called with unknown argument \`${1}'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +case "${1}" in + configure) + # run after debhelper update-alternative scripts + update-alternatives --quiet --set container_build-script "/usr/share/compute-tools/build-scripts/${SCRIPT}" + ;; +esac + +exit 0 -- cgit v1.2.3