#!/bin/sh set -e CONFFILE="/etc/compute-tools/container.conf" Install () { DEFAULT="${1}" TARGET="${2}" mkdir -p "${DEFAULT}" mkdir -p "${TARGET}" 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 } case "${1}" in configure) # build-scripts update-alternatives --quiet --install /usr/share/compute-tools/build-scripts/default container_build-script /usr/share/compute-tools/build-scripts/mmdebstrap 1000 update-alternatives --quiet --install /usr/share/compute-tools/build-scripts/default container_build-script /usr/share/compute-tools/build-scripts/debootstrap 2000 update-alternatives --quiet --install /usr/share/compute-tools/build-scripts/default container_build-script /usr/share/compute-tools/build-scripts/progress-linux 3000 update-alternatives --quiet --install /usr/share/compute-tools/build-scripts/default container_build-script /usr/share/compute-tools/build-scripts/debian 4000 # get-scripts update-alternatives --quiet --install /usr/share/compute-tools/get-scripts/default container_get-script /usr/share/compute-tools/get-scripts/curl 1000 . /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) # fencing user db_get open-infrastructure-container-tools/user FENCING_USER="${RET:-fence}" db_get open-infrastructure-container-tools/key FENCING_KEY_PATH="${RET:-/home/${MONITOR_USER}/.ssh}" 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}" update-alternatives --quiet --set container_build-script "/usr/share/compute-tools/build-scripts/${SCRIPT}" 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. # creating user if ! getent passwd ${FENCING_USER} > /dev/null 2>&1 then useradd -c "fence,,," -M -s /bin/bash ${FENCING_USER} if getent passwd ${FENCING_USER} > /dev/null 2>&1 then gpasswd -a ${FENCING_USER} ${FENCING_USER} fi fi cat > "/etc/sudoers.d/${FENCING_USER}" << EOF ${FENCING_USER} ALL=NOPASSWD: ALL EOF chmod 0440 "/etc/sudoers.d/${FENCING_USER}" mkdir -p "/home/${FENCING_USER}/.ssh" 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 [ -x "$(which sysctl)" ] 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# exit 0