File: preinst

package info (click to toggle)
nut 0.45.5-rel-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,984 kB
  • ctags: 2,146
  • sloc: ansic: 22,216; sh: 1,138; makefile: 405
file content (61 lines) | stat: -rw-r--r-- 1,584 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

# source the debconf library
. /usr/share/debconf/confmodule

case "$1" in

  install)
    # create the nut system account
    if [ `id -u $1 >/dev/null 2>&1` ] ; then
      # the account already exists! check that it's a system account
      if ! [ `id -u $1 >/dev/null 2>&1` -lt 1000 ] ; then
        # the account is a user account! abort!
	echo "error: a \"nut\" account already exists on your system"
	exit 1
      fi
    else
      # the account doesn't exist... time to create it
      adduser --quiet --system --group --home /var/lib/nut nut
      chown nut.nut /var/lib/nut
    fi
    ;;

  upgrade)
    # remove the obsolete config file (upgrading from nut < 0.44.0)
    db_get nut/remove_debian_conf
    if [ "$RET" = "true" ] ; then
      rm -f /etc/nut/debian.conf
    fi

    # modify the nut user's home dir (upgrading from nut < 0.44.0)
    if dpkg --compare-versions "$2" lt-nl "0.44.0" ; then
      usermod -d /var/lib/nut -m nut
    fi

    # modify the nut user again (upgrading from nut < 0.44.1-3)
    if dpkg --compare-versions "$2" lt-nl "0.44.1-3" ; then
      # remove the nut user for the dialout group
      usermod -G "" nut
      # try to make a nut group with gid equal to uid of the nut user
      if ! [ `addgroup --gid \`id -u nut\` nut` ] ; then
        # oh well, gid and uid will not be the same
        addgroup nut
      fi
      # change the nut user's primary grou
      usermod -g nut nut
    fi
    ;;

  abort-upgrade)
    # do nothing
    ;;

  *)
    echo "$0: incorrect arguments: $*" >&2
    exit 1
    ;;
esac

#DEBHELPER#