summaryrefslogtreecommitdiff
path: root/debian/cloud-init.preinst
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2016-08-23 16:48:37 -0400
committerScott Moser <smoser@brickies.net>2016-08-23 16:48:37 -0400
commit7b0efb97c3667d4d1335e384433877a13e065380 (patch)
treee854ffa174128a5539af979707f1c5f850437d58 /debian/cloud-init.preinst
parent74fe2d2c661d70e5ec93ebde036d927c0f9ed15c (diff)
downloadvyos-cloud-init-7b0efb97c3667d4d1335e384433877a13e065380.tar.gz
vyos-cloud-init-7b0efb97c3667d4d1335e384433877a13e065380.zip
Import version 0.7.7~bzr1154-0ubuntu1
Imported using git-dsc-commit.
Diffstat (limited to 'debian/cloud-init.preinst')
-rw-r--r--debian/cloud-init.preinst170
1 files changed, 170 insertions, 0 deletions
diff --git a/debian/cloud-init.preinst b/debian/cloud-init.preinst
new file mode 100644
index 00000000..e5c7755f
--- /dev/null
+++ b/debian/cloud-init.preinst
@@ -0,0 +1,170 @@
+#!/bin/sh
+set -e
+
+#DEBHELPER#
+# Remove a no-longer used conffile
+rm_conffile() {
+ local PKGNAME="$1"
+ local CONFFILE="$2"
+
+ [ -e "$CONFFILE" ] || return 0
+
+ local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')"
+ local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PKGNAME | \
+ sed -n -e "\' $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
+ if [ "$md5sum" != "$old_md5sum" ]; then
+ echo "Obsolete conffile $CONFFILE has been modified by you."
+ echo "Saving as $CONFFILE.dpkg-bak ..."
+ mv -f "$CONFFILE" "$CONFFILE".dpkg-bak
+ else
+ echo "Removing obsolete conffile $CONFFILE ..."
+ rm -f "$CONFFILE"
+ fi
+}
+
+# move_sem(src,targets)
+# rename sem/* items named $src to $targets
+# (with hard links if more than one)
+move_sem() {
+ local src=$1 f="" targ="" freqid="" dir=/var/lib/cloud/sem
+ shift
+ # link the remaining targets to src, if it exists
+ for f in "${dir}/${src}."*; do
+ # if there were no src entries, nothing to do
+ [ -f "${f}" ] || return 0
+ freqid=${f#${dir}/${src}.} # 'i-abcdefg' or 'always'
+ for targ in "$@"; do
+ [ -e "${dir}/${targ}.${freqid}" ] && continue
+ ln -f "${f}" "${dir}/${targ}.${freqid}"
+ done
+ rm "${f}"
+ done
+ return 0
+}
+
+fix_ephemeral0_micro() {
+ # make ephemeral0 entries in /etc/fstab written by cloudconfig
+ # 'nobootwait', so they do not block subsequent boots (LP: #634102)
+ local out="" oldver=$1 dev="" adop="nobootwait"
+ local s="[[:space:]]" ns="[^[:space:]]" # space and "not space"
+ local remain="${s}\+.*" first4=""
+ for dev in /dev/sda2 /dev/sdb; do
+ first4="${dev}$s\+$ns\+$s\+$ns\+$s\+$ns\+"
+ out=$(awk '$1 == dev && $4 ~ /cloudconfig/ && $4 !~ op { print $1 ; }' \
+ dev="${dev}" "op=${adop}" /etc/fstab) || return 0
+ [ -n "${out}" ] || continue
+ echo "making ephemeral ${dev} in /etc/fstab ${adop} (LP: #634102)" 1>&2
+ sed -i "s|^\(${first4}\)\(${remain}\)|\1,${adop}\2|" /etc/fstab
+ done
+}
+
+convert_varlib_05x_06x() {
+ local url="http://169.254.169.254/2009-04-04/meta-data/instance-id"
+ local tout="--connect-timeout .5 --read-timeout .5"
+ local iid="" f="" uptime="" bn=""
+ iid=$(wget "${url}" ${tout} --tries 1 -O - 2>/dev/null) || iid=""
+
+ [ -n "${iid}" -a -d /var/lib/cloud ] || return 0
+ cd /var/lib/cloud
+ mkdir -p "instances/${iid}" "instances/${iid}/sem"
+ [ -e instance ] || ln -sf "instances/${iid}" instance
+ for f in data/*; do
+ [ -f "$f" ] || continue
+ case "${f#*/}" in
+ user-data.txt.i|user-data.txt|cloud-config.txt)
+ mv "${f}" instance/
+ ;;
+ esac
+ done
+ [ -f data/cache/obj.pkl ] && mv data/cache/obj.pkl instance/
+ for f in sem/*.${iid}; do
+ [ -f "${f}" ] || continue
+ bn=${f#*/}; bn=${bn%.${iid}}
+ case "${bn}" in
+ set_defaults) mv "${f}" "instance/sem/config-locale";;
+ set_hostname) mv "${f}" "instance/sem/config-set_hostname";;
+ *) mv "${f}" "instance/sem/${bn}";;
+ esac
+ done
+ [ ! -f sem/update_hostname.always ] ||
+ mv sem/update_hostname.always sem/config-update_hostname.always
+ rmdir data/cache 2>/dev/null || :
+ rm -f data/available.build
+
+ mkdir -p instance/scripts
+ if [ -d data/scripts ]; then
+ mv data/scripts/* instance/scripts || :
+ rmdir data/scripts || :
+ fi
+ [ -d data/scripts/* ] && mv data/scripts instance/
+
+ [ ! -e instance/boot-finished ] &&
+ [ -f /proc/uptime ] && read uptime other </proc/uptime &&
+ echo "${uptime}" > instance/boot-finished || :
+
+ return 0
+}
+
+case "$1" in
+ install|upgrade)
+ # removing obsolete conffiles from the 'ec2-init' package
+ if dpkg --compare-versions "$2" le "0.5.1"; then
+ rm_conffile ec2-init "/etc/init/cloud-ssh-keygen.conf"
+ fi
+ if dpkg --compare-versions "$2" lt "0.5.3"; then
+ rm_conffile ec2-init "/etc/init/ec2init.conf"
+ fi
+ if [ "$2" = "0.5.7-0ubuntu1" ]; then
+ bad_d=/etc/update-motd.d/92-ec2-upgrade-available
+ rm_conffile cloud-init "${bad_d}/motd-hook"
+ # the dir for this file is almost certainly empty, but
+ # if the file above was only moved, or other files there
+ # then leave it be
+ rmdir "${bad_d}" 2>/dev/null || true
+ fi
+
+ if dpkg --compare-versions "$2" le "0.5.10-0ubuntu2"; then
+ old_confs="cloud-apt-update-upgrade cloud-config-misc
+ cloud-config-mounts cloud-config-puppet
+ cloud-config-ssh cloud-disable-ec2-metadata"
+ for f in ${old_confs}; do
+ rm_conffile cloud-init "/etc/init/${f}.conf"
+ done
+ fi
+
+ if dpkg --compare-versions "$2" le "0.5.11-0ubuntu1"; then
+ # rename the config entries in sem/ so they're not run again
+
+ # transition names in 0.5.11 had only short name (no config- prefix)
+ # so create config- entries for each
+ for name in apt-update-upgrade disable-ec2-metadata mounts \
+ puppet runcmd ssh updates-check; do
+ move_sem ${name} config-${name}
+ done
+
+ # 0.5.11 split 'config-misc' into 'updates-check' and 'runcmd'
+ move_sem config-misc config-updates-check config-runcmd
+ fi
+
+ if dpkg --compare-versions "$2" le "0.5.14-0ubuntu5"; then
+ fix_ephemeral0_micro
+ fi
+
+ if dpkg --compare-versions "$2" le 0.6.0-0ubuntu1; then
+ # convert /var/lib/cloud from 0.5.x layout to 0.6.x
+ convert_varlib_05x_06x
+ fi
+
+ # 0.6.0 changed 'user-scripts' to config-scripts-user (LP: #1049146)
+ if [ -e /var/lib/cloud/instance/sem/user-scripts ]; then
+ ln -sf user-scripts /var/lib/cloud/instance/sem/config-scripts-user
+ fi
+
+
+ d=/etc/cloud/
+ if [ -f "$d/distro.cfg" ] && [ ! -f "$d/cloud.cfg.d/90_dpkg.cfg" ]; then
+ echo "moving $d/distro.cfg -> $d/cloud.cfg.d/90_dpkg.cfg"
+ [ -d "${d}/cloud.cfg.d" ] || mkdir "${d}/cloud.cfg.d"
+ mv "$d/distro.cfg" "$d/cloud.cfg.d/90_dpkg.cfg"
+ fi
+esac