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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
#! /bin/sh
# postinst script for smokeping
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#
# quoting from the policy:
# Any necessary prompting should almost always be confined to the
# post-installation script, and should be protected with a conditional
# so that unnecessary prompting doesn't happen if a package's
# installation fails and the `postinst' is called with `abort-upgrade',
# `abort-remove' or `abort-deconfigure'.
split_config () {
version="$1"
echo "splitting the old monolithic config into separate sections..." 1>&2
local found
local stop
local DIR
local sec
DIR=/etc/smokeping/config.d
[ -d $DIR ] || mkdir -p $DIR
for sec in General Alerts Database Presentation Probes Slaves Targets
do
if [ ! -f ${DIR}/$sec ]; then
# seed ucf with the default configuration from the version we're upgrading from
found=""
stop=false
for oldvers in 2.0.9-2 2.1.1-1 2.2.4-1 2.2.6-1 2.2.7-1 2.2.7-2 2.3.0-1 2.3.2-1
do
if ! $stop && dpkg --compare-versions "$oldvers" gt "$version"; then
stop=true
fi
if ! $stop && [ -e /usr/share/smokeping/oldconfigs/$oldvers/$sec ]; then
found=/usr/share/smokeping/oldconfigs/$oldvers/$sec
fi
done
if [ -n "$found" ]; then
ucf --three-way $found ${DIR}/$sec
fi
sed -n "1,/^\*\*\* $sec \*\*\*/{h;d}; \${g;p;q}; /^\*\*\*/{g;p;q}; H" \
< /etc/smokeping/config > ${DIR}/$sec
fi
done
}
migrate_cgi_directory () {
echo "migrating CGI files into /var/lib/smokeping/__cgi..." 1>&2
# move any old .adr files under __cgi
(cd /var/lib/smokeping; find . -name __cgi -prune -o -name '*.adr' -print0 | \
cpio --quiet -pdm0 /var/lib/smokeping/__cgi)
(cd /var/lib/smokeping; find . -name __cgi -prune -o -name '*.adr' -print0 | \
xargs -0 --no-run-if-empty rm)
# make sure the permissions are right
find /var/lib/smokeping/__cgi -name '*.adr' -print0 | \
xargs -0 --no-run-if-empty chown www-data
find /var/lib/smokeping/__cgi -type d -print0 | \
xargs -0 --no-run-if-empty chown smokeping:www-data
find /var/lib/smokeping/__cgi -type d -print0 | \
xargs -0 --no-run-if-empty chmod 2775
}
setup_permissions() {
# Smokeping.cgi is run as user www-data, so we need it to be able
# to write in /var/cache/smokeping/images and in /var/lib/smokeping/__cgi
chown smokeping:smokeping /var/lib/smokeping
chown www-data /var/cache/smokeping/images
chown smokeping:www-data /var/lib/smokeping/__cgi
chmod 2775 /var/lib/smokeping/__cgi
}
setup_apache() {
# note that this is only done on initial installations
if [ -d /etc/apache2/conf.d ] && \
[ ! -e /etc/apache2/conf.d/smokeping ] && \
which apache2ctl >/dev/null 2>&1
then
if apache2ctl configtest 2>/dev/null; then
echo "enabling Apache configuration in /etc/apache2/conf.d/smokeping" 1>&2
ln -s /etc/smokeping/apache2.conf /etc/apache2/conf.d/smokeping
if apache2ctl configtest 2>/dev/null; then
invoke-rc.d apache2 force-reload || true
fi
else
echo "broken Apache configuration detected, not enabling /etc/smokeping/apache2.conf" 1>&2
fi
else
echo "non-standard Apache configuration or missing apache2ctl, not enabling /etc/smokeping/apache2.conf" 1>&2
fi
}
var_www_migration() {
# until the lenny release (2.3.6-3), the CGI wrote the images in /var/www
if [ -d /var/www/smokeping ]
then
for d in images javascript
do
if [ ! -e /var/www/smokeping/$d ]
then
ln -s /usr/share/smokeping/www/$d /var/www/smokeping/$d
fi
done
fi
}
do_ucf() {
# install the configuration files and register them with ucfr
[ -d /etc/smokeping ] || mkdir -p /etc/smokeping
for f in basepage.html smokemail tmail
do
ucf --debconf-ok --three-way /usr/share/smokeping/etc/${f}.dist /etc/smokeping/$f
ucfr smokeping /etc/smokeping/$f
done
[ -d /etc/smokeping/config.d ] || mkdir -p /etc/smokeping/config.d
for f in /usr/share/smokeping/etc/config.d/*
do
ucf --debconf-ok --three-way --src-dir /usr/share/smokeping/etc/config.d.md5sums/ \
$f /etc/smokeping/config.d/$(basename $f)
ucfr smokeping /etc/smokeping/config.d/$(basename $f)
done
# do the main config last so the admin won't be quite so surprised
ucf --debconf-ok --three-way /usr/share/smokeping/etc/default-config /etc/smokeping/config
ucfr smokeping /etc/smokeping/config
}
# OK, let's go
case "$1" in
configure|reconfigure)
getent passwd smokeping > /dev/null || \
adduser --system --group --home /var/lib/smokeping --no-create-home --gecos "SmokePing daemon" smokeping
if [ -n "$2" ] && dpkg --compare-versions "$2" lt "2.3.5-1"
then
split_config "$2"
migrate_cgi_directory
fi
if [ -n "$2" ] && dpkg --compare-versions "$2" le "2.3.6-3"
then
var_www_migration
fi
if [ -z "$2" ]
then
setup_apache
fi
setup_permissions
do_ucf
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
|