922142c58c299071f847b82576f765cead493258
[metaproxy-moved-to-github.git] / debian / metaproxy.postrm
1 #!/bin/sh
2
3 set -e
4
5 case "$1" in
6     purge)
7         update-rc.d metaproxy remove >/dev/null
8
9         [ -f /etc/default/metaproxy ] && . /etc/default/metaproxy
10         
11         [ -z "$SERVER_HOME" ] && SERVER_HOME=/var/metaproxy
12         [ -z "$SERVER_USER" ] && SERVER_USER=metaproxy
13         [ -z "$SERVER_NAME" ] && SERVER_NAME="Metaproxy user"
14         [ -z "$SERVER_GROUP" ] && SERVER_GROUP=metaproxy
15
16         # find first and last SYSTEM_UID numbers
17         for LINE in `grep SYSTEM_UID /etc/adduser.conf | grep -v "^#"`; do
18             case $LINE in
19                 FIRST_SYSTEM_UID*)
20                     FIRST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
21                     ;;
22                 LAST_SYSTEM_UID*)
23                     LAST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
24                     ;;
25                 *)
26                     ;;
27             esac
28         done
29         # Remove system account if necessary
30         CREATEDUSER=$SERVER_USER
31         if [ -n "$FIRST_SYSTEM_UID" ] && [ -n "$LAST_SYSTEM_UID" ]; then
32             if USERID=`getent passwd $CREATEDUSER | cut -f 3 -d ':'`; then
33                 if [ -n "$USERID" ]; then
34                     if [ "$FIRST_SYSTEM_UID" -le "$USERID" ] && \
35                         [ "$USERID" -le "$LAST_SYSTEM_UID" ]; then
36                         echo -n "Removing $CREATEDUSER system user.."
37                         deluser --quiet $CREATEDUSER || true
38                         echo "..done"
39                     fi
40                 fi
41             fi
42         fi
43         # Remove system group if necessary
44         CREATEDGROUP=$SERVER_GROUP
45         FIRST_USER_GID=`grep ^USERS_GID /etc/adduser.conf | cut -f2 -d '='`
46         if [ -n "$FIRST_USER_GID" ]; then
47             if GROUPGID=`getent group $CREATEDGROUP | cut -f 3 -d ':'`; then
48                 if [ -n "$GROUPGID" ]; then
49                     if [ "$FIRST_USER_GID" -gt "$GROUPGID" ]; then
50                         echo -n "Removing $CREATEDGROUP group.."
51                         delgroup --only-if-empty $CREATEDGROUP || true
52                         echo "..done"
53                     fi
54                 fi
55             fi
56         fi
57         ;;
58 esac