ce720c141bd0bb46592210db4915042b7ff64afc
[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         # copy of metaproxy.user, which is gone at this point
10         SERVER_HOME=/var/metaproxy
11         SERVER_USER=metaproxy
12         SERVER_NAME="Metaproxy user"
13         SERVER_GROUP=metaproxy
14
15         # find first and last SYSTEM_UID numbers
16         for LINE in `grep SYSTEM_UID /etc/adduser.conf | grep -v "^#"`; do
17             case $LINE in
18                 FIRST_SYSTEM_UID*)
19                     FIRST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
20                     ;;
21                 LAST_SYSTEM_UID*)
22                     LAST_SYSTEM_UID=`echo $LINE | cut -f2 -d '='`
23                     ;;
24                 *)
25                     ;;
26             esac
27         done
28         # Remove system account if necessary
29         CREATEDUSER=$SERVER_USER
30         if [ -n "$FIRST_SYSTEM_UID" ] && [ -n "$LAST_SYSTEM_UID" ]; then
31             if USERID=`getent passwd $CREATEDUSER | cut -f 3 -d ':'`; then
32                 if [ -n "$USERID" ]; then
33                     if [ "$FIRST_SYSTEM_UID" -le "$USERID" ] && \
34                         [ "$USERID" -le "$LAST_SYSTEM_UID" ]; then
35                         echo -n "Removing $CREATEDUSER system user.."
36                         deluser --quiet $CREATEDUSER || true
37                         echo "..done"
38                     fi
39                 fi
40             fi
41         fi
42         # Remove system group if necessary
43         CREATEDGROUP=$SERVER_GROUP
44         FIRST_USER_GID=`grep ^USERS_GID /etc/adduser.conf | cut -f2 -d '='`
45         if [ -n "$FIRST_USER_GID" ]; then
46             if GROUPGID=`getent group $CREATEDGROUP | cut -f 3 -d ':'`; then
47                 if [ -n "$GROUPGID" ]; then
48                     if [ "$FIRST_USER_GID" -gt "$GROUPGID" ]; then
49                         echo -n "Removing $CREATEDGROUP group.."
50                         delgroup --only-if-empty $CREATEDGROUP || true
51                         echo "..done"
52                     fi
53                 fi
54             fi
55         fi
56         ;;
57 esac