torch-agent/torch-agent-0.0.1/debian/torch-agent/DEBIAN/postinst

105 lines
3.0 KiB
Bash
Executable File

#!/bin/sh
# postinst script for torch-agent
#
# 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>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package
USER="torch"
GROUP="debian-tor"
TORRC="/etc/tor/torrc"
configure_tor_controller() {
TORRC_CHANGED=0
if ! grep -q "^ControlPort [0-9]\+" $TORRC; then
sed -i '/^#ControlPort 9051/s/^#//' $TORRC
TORRC_CHANGED=1
fi
if ! grep -q "^CookieAuthentication 1" $TORRC; then
sed -i '/^#CookieAuthentication 1/s/^#//' $TORRC
TORRC_CHANGED=1
fi
if ! grep -q "^CookieAuthFileGroupReadable 1" $TORRC; then
echo "CookieAuthFileGroupReadable 1" >> $TORRC
TORRC_CHANGED=1
fi
if [ $TORRC_CHANGED -eq 1 ]; then
systemctl reload tor
fi
}
case "$1" in
configure)
if ! getent passwd $USER >/dev/null ; then
useradd -r -g $GROUP $USER
fi
chown $USER /etc/torch
chown $USER /etc/torch/torch.conf
chown $USER /usr/share/torch-agent/torch-agent.py
configure_tor_controller
;;
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.
# Automatically added by dh_installsystemd/12.10ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if deb-systemd-helper debian-installed 'torch-agent.service'; then
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask 'torch-agent.service' >/dev/null || true
if deb-systemd-helper --quiet was-enabled 'torch-agent.service'; then
# Create new symlinks, if any.
deb-systemd-helper enable 'torch-agent.service' >/dev/null || true
fi
fi
# Update the statefile to add new symlinks (if any), which need to be cleaned
# up on purge. Also remove old symlinks.
deb-systemd-helper update-state 'torch-agent.service' >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installsystemd/12.10ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -n "$2" ]; then
deb-systemd-invoke try-restart 'torch-agent.service' >/dev/null || true
fi
fi
fi
# End automatically added section
exit 0