aboutsummaryrefslogtreecommitdiffstats
path: root/net-mgmt/bigsister/pkg-install
blob: fc53876aba6bd89c494af3ba355fd09e5ed2ec81 (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
#!/bin/sh

PATH=/bin:/usr/sbin

SANDBOX_DIR="${PKG_PREFIX}/bigsister"

if [ -z "${BS_USER}" ]; then
    BS_USER=bs
fi

if [ -z "${BS_GROUP}" ]; then
    BS_GROUP=bs
fi

case $2 in
    PRE-INSTALL)
    UID=220
    GID=${UID}
    if pw group show "${BS_GROUP}" 2>/dev/null; then
        echo "You already have a group \"${BS_GROUP}\", so I will use it."
    else
        if pw groupadd ${BS_GROUP} -g ${GID}; then
        echo "Added group \"${BS_GROUP}\."
        else
        echo "Adding group \"${BS_GROUP}\" failed."
        exit 1
        fi
    fi
    
    if pw user show "${BS_USER}" 2>/dev/null; then
        echo "You already have a user \"${BS_USER}\", so I will use it."
        if pw usermod ${BS_USER} -d ${SANDBOX_DIR}
        then
            echo "Changed home directory of \"${BS_USER}\" to \"${SANDBOX_DIR}\""
        else
            echo "Changing home directory of \"${BS_USER}\" to \"${SANDBOX_DIR}\" failed..."
            exit 1
        fi
    else
        if pw useradd ${BS_USER} -u ${UID} -g ${BS_GROUP} -h - \
            -d ${SANDBOX_DIR} -s /bin/sh -c "Big Sister"
        then
            echo "Added user \"${BS_USER}\"."
        else
            echo "Adding user \"${BS_USER}\" failed..."
            exit 1
        fi
    fi

    ;;
esac