From 8f218141f4633bf8f5c4aa2d266fabf7b2dc58b1 Mon Sep 17 00:00:00 2001 From: hagen Date: Wed, 16 Dec 2015 13:22:55 +0000 Subject: [PATCH] * add 'i2pd' user (#313) --- debian/control | 1 + debian/i2pd.init | 16 ++++++++++------ debian/postinst | 36 ++++++++++++++++++++++++++++++++++++ debian/postrm | 12 ++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100755 debian/postinst create mode 100755 debian/postrm diff --git a/debian/control b/debian/control index add1060f..e76f9c7b 100644 --- a/debian/control +++ b/debian/control @@ -17,6 +17,7 @@ Vcs-Browser: https://github.com/PurpleI2P/i2pd.git Package: i2pd Architecture: any +Pre-Depends: adduser Depends: ${shlibs:Depends}, ${misc:Depends} Recommends: privoxy Suggests: tor diff --git a/debian/i2pd.init b/debian/i2pd.init index ed061b04..609a3407 100644 --- a/debian/i2pd.init +++ b/debian/i2pd.init @@ -16,9 +16,9 @@ NAME=i2pd # Introduce the short server's name here DAEMON=/usr/sbin/$NAME # Introduce the server's location here DAEMON_OPTS="" # Arguments to run the daemon with PIDFILE=/var/run/$NAME.pid -SCRIPTNAME=/etc/init.d/$NAME I2PCONF=/etc/$NAME/i2pd.conf TUNCONF=/etc/$NAME/tunnels.conf +USER="i2pd" # Exit if the package is not installed [ -x $DAEMON ] || exit 0 @@ -36,16 +36,20 @@ do_start() # 2 if daemon could not be started if [ "x$I2PD_ENABLED" != "xyes" ]; then - log_warning_msg "disabled in config" + log_warning_msg "$NAME disabled in config" return 2 fi - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + touch "$PIDFILE" + chown -f $USER:adm "$PIDFILE" + + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid "$USER" --test > /dev/null \ || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid "$USER" -- \ --service=1 --daemon=1 --log=1 --conf=$I2PCONF --tunnelscfg=$TUNCONF \ - --port=$I2PD_PORT $DAEMON_OPTS \ + --port=$I2PD_PORT $DAEMON_OPTS > /dev/null 2>&1 \ || return 2 + return $? } # Function that stops the daemon/service @@ -115,7 +119,7 @@ case "$1" in esac ;; *) - echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 00000000..ddb5ef7c --- /dev/null +++ b/debian/postinst @@ -0,0 +1,36 @@ +#!/bin/sh + +I2PDHOME='/var/lib/i2pd' +I2PDUSER='i2pd' + +case "$1" in + configure|reconfigure) + # Older versions of adduser created the home directory. + # The version of adduser in Debian unstable does not. + # Create user and group as a system user. + getent passwd ${I2PDUSER} > /dev/null 2>&1 + if [ $? -eq 2 ]; then + adduser --system --quiet --group --home $I2PDHOME $I2PDUSER + else + groupadd -f $I2PDUSER || true + usermod -s "/bin/false" -e 1 $I2PDUSER > /dev/null || true + fi + + touch /var/log/i2pd.log + chown -f ${I2PDUSER}:adm /var/log/i2pd.log + mkdir -p -m0750 $I2PDHOME + chown -f -R ${I2PDUSER}:${I2PDUSER} ${I2PDHOME} + ;; + abort-upgrade|abort-remove|abort-deconfigure) + echo "Aborting upgrade" + exit 0 + ;; + *) + echo "postinst called with unknown argument '$1'" >&2 + exit 0 + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/debian/postrm b/debian/postrm new file mode 100755 index 00000000..7015e547 --- /dev/null +++ b/debian/postrm @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +if [ "$1" = "purge" ]; then + rm -f /etc/default/i2pd /var/log/i2pd.log + rm -rf /var/lib/i2pd +fi + +#DEBHELPER# + +exit 0