| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
CONFFILE="/etc/compute-tools/container.conf" |
| 6 |
|
| 7 |
Install () |
| 8 |
{ |
| 9 |
DEFAULT="${1}" |
| 10 |
TARGET="${2}" |
| 11 |
|
| 12 |
mkdir -p "${DEFAULT}" > /dev/null 2>&1 || true |
| 13 |
mkdir -p "${TARGET}" > /dev/null 2>&1 || true |
| 14 |
|
| 15 |
if [ "${TARGET}" != "${DEFAULT}" ] |
| 16 |
then |
| 17 |
if [ -h "${DEFAULT}" ] |
| 18 |
then |
| 19 |
rm -f "${DEFAULT}" |
| 20 |
ln -s "${TARGET}" "${DEFAULT}" |
| 21 |
else |
| 22 |
if [ -e "${DEFAULT}" ] && [ -z "$(ls -A ${DEFAULT})" ] |
| 23 |
then |
| 24 |
rmdir "${DEFAULT}" |
| 25 |
ln -s "${TARGET}" "${DEFAULT}" |
| 26 |
fi |
| 27 |
fi |
| 28 |
fi |
| 29 |
|
| 30 |
if ! dpkg-statoverride --list "${DEFAULT}" > /dev/null 2>&1 && |
| 31 |
! dpkg-statoverride --list "${TARGET}" > /dev/null 2>&1 |
| 32 |
then |
| 33 |
chmod ${DIRECTORY_PERMISSIONS} "${TARGET}" |
| 34 |
chown root:root "${TARGET}" |
| 35 |
|
| 36 |
chmod ${DIRECTORY_PERMISSIONS} "${DEFAULT}" |
| 37 |
chown root:root "${DEFAULT}" |
| 38 |
fi |
| 39 |
} |
| 40 |
|
| 41 |
case "${1}" in |
| 42 |
configure) |
| 43 |
. /usr/share/debconf/confmodule |
| 44 |
|
| 45 |
db_get open-infrastructure-compute-tools/machines-directory |
| 46 |
MACHINES_DIRECTORY="${RET:-/var/lib/machines}" # string (w/o empty) |
| 47 |
|
| 48 |
db_get open-infrastructure-compute-tools/config-directory |
| 49 |
CONFIG_DIRECTORY="${RET:-/etc/compute-tools/config}" # string (w/o empty) |
| 50 |
|
| 51 |
db_get open-infrastructure-compute-tools/debconf-directory |
| 52 |
DEBCONF_DIRECTORY="${RET:-/etc/compute-tools/debconf}" # string (w/o empty) |
| 53 |
|
| 54 |
db_get open-infrastructure-compute-tools/hooks-directory |
| 55 |
HOOKS_DIRECTORY="${RET:-/etc/compute-tools/hooks}" # string (w/o empty) |
| 56 |
|
| 57 |
db_get open-infrastructure-compute-tools/keys-directory |
| 58 |
KEYS_DIRECTORY="${RET:-/etc/compute-tools/keys}" # string (w/o empty) |
| 59 |
|
| 60 |
db_get open-infrastructure-compute-tools/cache-directory |
| 61 |
CACHE_DIRECTORY="${RET:-/var/cache/container}" # string (w/o empty) |
| 62 |
|
| 63 |
db_get open-infrastructure-compute-tools/directory-permissions |
| 64 |
DIRECTORY_PERMISSIONS="${RET}" # select (w/o empty) |
| 65 |
|
| 66 |
db_get open-infrastructure-compute-tools/build-script |
| 67 |
SCRIPT="${RET:-debian}" # string (w/o empty) |
| 68 |
|
| 69 |
db_get open-infrastructure-compute-tools/irc |
| 70 |
IRK_TARGETS="${RET}" # string (w/ empty) |
| 71 |
|
| 72 |
db_stop |
| 73 |
|
| 74 |
Install "/var/lib/machines" "${MACHINES_DIRECTORY}" |
| 75 |
Install "/etc/compute-tools/config" "${CONFIG_DIRECTORY}" |
| 76 |
Install "/etc/compute-tools/debconf" "${DEBCONF_DIRECTORY}" |
| 77 |
Install "/etc/compute-tools/hooks" "${HOOKS_DIRECTORY}" |
| 78 |
Install "/etc/compute-tools/keys" "${KEYS_DIRECTORY}" |
| 79 |
Install "/var/cache/container" "${CACHE_DIRECTORY}" |
| 80 |
|
| 81 |
if [ ! -e "${CONFFILE}" ] |
| 82 |
then |
| 83 |
|
| 84 |
cat > "${CONFFILE}" << EOF |
| 85 |
# ${CONFFILE} |
| 86 |
|
| 87 |
IRK_TARGETS="${IRK_TARGETS}" |
| 88 |
EOF |
| 89 |
|
| 90 |
fi |
| 91 |
|
| 92 |
cp -a -f "${CONFFILE}" "${CONFFILE}.tmp" |
| 93 |
|
| 94 |
# If the admin deleted or commented some variables but then set |
| 95 |
# them via debconf, (re-)add them to the config file. |
| 96 |
|
| 97 |
test -z "${IRK_TARGETS}" || \ |
| 98 |
grep -Eq '^ *IRK_TARGETS=' "${CONFFILE}" || \ |
| 99 |
echo "IRK_TARGETS=" >> "${CONFFILE}" |
| 100 |
|
| 101 |
sed -e "s|^ *IRK_TARGETS=.*|IRK_TARGETS=\"${IRK_TARGETS}\"|" \ |
| 102 |
< "${CONFFILE}" > "${CONFFILE}.tmp" |
| 103 |
|
| 104 |
mv -f "${CONFFILE}.tmp" "${CONFFILE}" |
| 105 |
|
| 106 |
if command -v sysctl > /dev/null 2>&1 |
| 107 |
then |
| 108 |
sysctl -q -p /etc/sysctl.d/zz-container.conf |
| 109 |
fi |
| 110 |
;; |
| 111 |
|
| 112 |
abort-upgrade|abort-remove|abort-deconfigure) |
| 113 |
|
| 114 |
;; |
| 115 |
|
| 116 |
*) |
| 117 |
echo "postinst called with unknown argument \`${1}'" >&2 |
| 118 |
exit 1 |
| 119 |
;; |
| 120 |
esac |
| 121 |
|
| 122 |
#DEBHELPER# |
| 123 |
|
| 124 |
case "${1}" in |
| 125 |
configure) |
| 126 |
# run after debhelper update-alternative scripts |
| 127 |
update-alternatives --quiet --set container_build-script "/usr/share/compute-tools/build-scripts/${SCRIPT}" |
| 128 |
;; |
| 129 |
esac |
| 130 |
|
| 131 |
exit 0 |