aboutsummaryrefslogtreecommitdiffstats
path: root/net-mgmt/nav/pkg-install
blob: bd0dabfd2743d0c410a7be9115810f7825407daa (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
#! /bin/sh

pw="/usr/sbin/pw"
users="navcron:nav:${PKG_PREFIX}/nav"

setname() {
    # $1: username $2: real name
    $pw usermod "$1" -c "$2" 2>/dev/null
}

cruser() {
    username=`echo $1 | awk -F : '{print $1}'`
    group=`echo $1 | awk -F : '{print $2}'`
    homedir=`echo $1 | awk -F : '{print $3}'`
    name=`echo $1 | awk -F : '{print $4}'`
    shell="/bin/sh"
    
    if ($pw groupshow $group >/dev/null 2>&1)
    then
        echo "Group $group exists, so I will use it."
    else
        if ($pw groupadd $group)
        then
            echo "Added group $group."
        else
            echo "Could not add group $group. Aborting."
            exit 1
        fi
    fi

    if ($pw usershow $username >/dev/null 2>&1)
    then
        echo "User $username exists, so I will use it."
    else
        if ($pw useradd $username -g $group -d $homedir -s $shell -w no)
        then
            echo "Added user $username."
        else
            echo "Could not add user $username. Aborting."
            exit 1
        fi
    fi
}

deluser() {
    username=`echo $1 | awk -F : '{print $1}'`
    group=`echo $1 | awk -F : '{print $2}'`
    homedir=`echo $1 | awk -F : '{print $3}'`

    printf "Attempting to delete user $username: "
    if (printf "" | $pw userdel $username 2>/dev/null)
    then
        echo OK
    else
        echo FAIL
    fi
    printf "Attempting to delete group $group: "
    if ($pw groupdel $group 2>/dev/null)
    then
        echo OK
    else
        echo FAIL
    fi
}

case "$2" in
PRE-INSTALL)
    for user in $users; do cruser $user; done
    setname navcron "NAV User"
    ;;
DEINSTALL) for user in $users; do deluser $user; done;;
esac