~smoser/ubuntu/maverick/cloud-init/lp942961-apt-pipeline

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/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
}

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
esac