woodpecker/packaging/scripts/postinst.deb
2014-10-12 23:51:51 +04:00

91 lines
No EOL
1.9 KiB
Bash

#!/bin/sh
set -e
case "$1" in
abort-upgrade|abort-remove|abort-deconfigure|configure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
if [ -f /etc/drone/drone.toml ]; then
chmod 600 /etc/drone/drone.toml
fi
dist() {
lsb_release -i | awk '{print tolower($3)}' | sed -e 's/^ *//' -e 's/ *$//'
}
version() {
lsb_release -r | awk '{print $2}' | sed -e 's/^ *//' -e 's/ *$//'
}
upstart() {
if [ -d /etc/init ]; then
if [ -f /usr/local/bin/droned ]; then
if pidof /usr/local/bin/droned >/dev/null; then
initctl stop drone || :
fi
fi
echo "You have $(dist) $(version): using upstart to control Drone"
cp -r /usr/share/drone/init/drone.conf /etc/init/drone.conf
initctl start drone || :
else
echo "Couldn't find upstart to control Drone, cannot proceed."
echo "Open an issue and tell us about your system."
exit 1
fi
}
systemd() {
if which systemctl > /dev/null; then
echo "Your system $(dist) $(version): using systemd to control Drone"
cp /usr/share/drone/systemd/drone.service /lib/systemd/system/drone.service
systemctl daemon-reload || :
if [ "$1" = 1 ] ; then
# first time install
systemctl enable drone || :
systemctl start drone || :
else
echo "Upgrading drone"
systemctl restart drone
fi
else
echo "Couldn't find systemd to control Drone, cannot proceed."
echo "Open an issue and tell us about your system."
exit 1
fi
}
validate_ver() {
echo "$(version) < $1" | bc
}
case "$(dist)" in
debian)
if [ $(validate_ver "8.0") -eq 1 ]; then
upstart
else
systemd $1
fi
;;
ubuntu)
if [ $(validate_ver "14.10") -eq 1 ]; then
upstart
else
systemd $1
fi
;;
*)
echo "\033[33m Your system $(dist) $(version) \033[0m"
echo "\033[33m This system is not supported, you can install service manually \033[0m"
;;
esac
exit 0