# This is a POSIX shell fragment
#
+# User and HOME of metaproxy daemon
+SERVER_HOME=/var/metaproxy
+SERVER_USER=metaproxy
+SERVER_GROUP=metaproxy
+SERVER_NAME="Metaproxy user"
+
# Additional options that are passed to the Daemon.
-DAEMON_OPTS="-D -u nobody -p /var/run/metaproxy.pid -l /var/log/metaproxy.log -c /etc/metaproxy/metaproxy.xml"
+DAEMON_OPTS="-D -u ${SERVER_USER} -p /var/run/metaproxy.pid -l /var/log/metaproxy.log -c /etc/metaproxy/metaproxy.xml"
--- /dev/null
+#!/bin/sh
+
+set -e
+
+case "$1" in
+ configure)
+ [ -f /etc/default/metaproxy ] && . /etc/default/metaproxy
+
+ [ -z "$SERVER_HOME" ] && SERVER_HOME=/var/metaproxy
+ [ -z "$SERVER_USER" ] && SERVER_USER=metaproxy
+ [ -z "$SERVER_NAME" ] && SERVER_NAME="Metaproxy user"
+ [ -z "$SERVER_GROUP" ] && SERVER_GROUP=metaproxy
+
+ # 1. create group if not existing
+ if ! getent group | grep -q "^$SERVER_GROUP:" ; then
+ echo -n "Adding group $SERVER_GROUP.."
+ addgroup --quiet --system $SERVER_GROUP 2>/dev/null ||true
+ echo "..done"
+ fi
+ # 2. create homedir if not existing
+ test -d $SERVER_HOME || mkdir $SERVER_HOME
+
+ # 3. create user if not existing
+ if ! getent passwd | grep -q "^$SERVER_USER:"; then
+ echo -n "Adding system user $SERVER_USER.."
+ adduser --quiet \
+ --system \
+ --ingroup $SERVER_GROUP \
+ --no-create-home \
+ --disabled-password \
+ $SERVER_USER 2>/dev/null || true
+ echo "..done"
+ fi
+ # 4. adjust passwd entry
+ usermod -c "$SERVER_NAME" \
+ -d $SERVER_HOME \
+ -g $SERVER_GROUP \
+ $SERVER_USER
+
+ # 5. adjust file and directory permissions
+ if ! dpkg-statoverride --list $SERVER_HOME >/dev/null
+ then
+ chown -R $SERVER_USER:adm $SERVER_HOME
+ chmod u=rwx,g=rxs,o= $SERVER_HOME
+ fi
+
+ # 6. start service
+ if [ -x "/etc/init.d/metaproxy" ]; then
+ update-rc.d metaproxy defaults >/dev/null
+ invoke-rc.d metaproxy start || exit $?
+ fi
+ ;;
+esac
--- /dev/null
+#!/bin/sh
+
+set -e
+
+case "$1" in
+ purge)
+ update-rc.d metaproxy remove >/dev/null
+
+ [ -f /etc/default/metaproxy ] && . /etc/default/metaproxy
+
+ [ -z "$SERVER_HOME" ] && SERVER_HOME=/var/metaproxy
+ [ -z "$SERVER_USER" ] && SERVER_USER=metaproxy
+ [ -z "$SERVER_NAME" ] && SERVER_NAME="Metaproxy user"
+ [ -z "$SERVER_GROUP" ] && SERVER_GROUP=metaproxy
+
+ # find first and last SYSTEM_UID numbers
+ for LINE in `grep SYSTEM_UID /etc/adduser.conf | grep -v "^#"`; do
+ case $LINE in
+ FIRST_SYSTEM_UID*)
+ FIRST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
+ ;;
+ LAST_SYSTEM_UID*)
+ LAST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
+ ;;
+ *)
+ ;;
+ esac
+ done
+ # Remove system account if necessary
+ CREATEDUSER=$SERVER_USER
+ if [ -n "$FIRST_SYSTEM_UID" ] && [ -n "$LAST_SYSTEM_UID" ]; then
+ if USERID=`getent passwd $CREATEDUSER | cut -f 3 -d ':'`; then
+ if [ -n "$USERID" ]; then
+ if [ "$FIRST_SYSTEM_UID" -le "$USERID" ] && \
+ [ "$USERID" -le "$LAST_SYSTEM_UID" ]; then
+ echo -n "Removing $CREATEDUSER system user.."
+ deluser --quiet $CREATEDUSER || true
+ echo "..done"
+ fi
+ fi
+ fi
+ fi
+ # Remove system group if necessary
+ CREATEDGROUP=$SERVER_GROUP
+ FIRST_USER_GID=`grep ^USERS_GID /etc/adduser.conf | cut -f2 -d '='`
+ if [ -n "$FIRST_USER_GID" ]; then
+ if GROUPGID=`getent group $CREATEDGROUP | cut -f 3 -d ':'`; then
+ if [ -n "$GROUPGID" ]; then
+ if [ "$FIRST_USER_GID" -gt "$GROUPGID" ]; then
+ echo -n "Removing $CREATEDGROUP group.."
+ delgroup --only-if-empty $CREATEDGROUP || true
+ echo "..done"
+ fi
+ fi
+ fi
+ fi
+ ;;
+esac
--- /dev/null
+if [ -x "/etc/init.d/metaproxy" ]; then
+ invoke-rc.d metaproxy stop || exit $?
+fi