aboutsummaryrefslogtreecommitdiffstats
path: root/comms/aprsd/pkg-install
blob: 2d0dee30332e3ad56a833c83352365c9cd98086c (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh

UID=240
GID=${UID}
DAEMON_NAME="aprsd"
UID_NAME=${DAEMON_NAME}
GID_NAME=${DAEMON_NAME}

TNC_UID=241
TNC_GID=${TNC_UID}
TNC_UID_NAME="tnc"
TNC_GID_NAME="tnc"

if [ "x$2" != "xPRE-INSTALL" ]; then
    exit 0;
fi

ask() {
    local question default answer

    question=$1
    default=$2
    if [ -z "${PACKAGE_BUILDING}" ]; then
        read -p "${question} [${default}]? " answer
    fi
    if [ x${answer} = x ]; then
        answer=${default}
    fi
    echo ${answer}
}

yesno() {
    local dflt question answer

    question=$1
    dflt=$2
    while :; do
        answer=$(ask "${question}" "${dflt}")
        case "${answer}" in
        [Yy]*)          return 0;;
        [Nn]*)          return 1;;
        esac
        echo "Please answer yes or no."
    done
}

adduser() {
    local uid gid uid_name gid_name daemon_name

    uid=$1
    gid=$2
    uid_name=$3
    gid_name=$4
    daemon_name=$5
    if which -s pw ; then
        :
    else
        cat <<EOF
Your system does not include the "pw" utility.  You should upgrade
to a newer version of FreeBSD.  Without "pw" this script will not
run.
EOF
        exit 1
    fi

    echo ""
    if pw groupshow ${gid_name} 2> /dev/null ; then
        echo "You already have a group \"${gid_name}\", so I will use it."
    else
        if pw groupshow ${gid} 2> /dev/null ; then
            echo "You already have a gid \"${gid}\".  Please create a user ${gid_name}"
            echo "with a default group of \"${gid_name}\"."
            exit 1
        fi
        echo "You need a group \"${gid_name}\"."
        if which -s pw && yesno "Would you like me to create it" y; then
            pw groupadd ${gid_name} -g ${gid} || exit
            echo "Done."
        else
            echo "Please create it, and try again."
            if ! pw usershow ${uid_name} 2> /dev/null ; then
                echo "While you're at it, please create a user \"${uid_name}\""
                echo 'too, with a default group of "${gid_name}".'
            fi
            exit 1
        fi
    fi

    if pw usershow ${uid_name} 2> /dev/null ; then
        echo "You already have a user \"${uid_name}\", so I will use it."
    else
            if pw usershow ${uid} 2> /dev/null ; then
                    echo "You already have a uid \"${uid}\".  Please create a user \"${uid_name}\""
                    echo "with a default group of \"${gid_name}\"."
                    exit 1
        fi
        echo "You need a user \"${uid_name}\"."
        if which -s pw && yesno "Would you like me to create it" y; then
            pw useradd ${uid_name} -g ${gid_name} -u ${uid} -h - -d /nonexistent \
                -s /bin/sh -c "${daemon_name}" || exit
            echo "Done."
        else
            echo "Please create it, and try again."
            exit 1
        fi
    fi
}

(adduser ${UID} ${GID} ${UID_NAME} ${GID_NAME} ${DAEMON_NAME})

echo `pw groupshow dialer`|grep -q ${UID_NAME}
if [ $? -eq 0 ]; then
    echo "You already have \"${UID_NAME}\" in the dialer group, so I will use this."
else
cat<<EOF
${DAEMON_NAME} needs access to serial ports to talk to an
external tnc. You will be asked if you wish to add ${DAEMON_NAME}
to the dialer group for that purpose.
EOF
    if pw usershow ${UID_NAME} 2> /dev/null ; then
        if which -s pw && yesno "Would you like to add \"${UID_NAME}\" to the dialer group?" y; then
            pw groupmod -n "dialer" -m ${UID_NAME} || exit
            echo "Done."
        fi
    fi
fi

if ! pw usershow ${TNC_UID_NAME} 2> /dev/null ; then
cat<<EOF
"${DAEMON_NAME}" has an optional login "${TNC_UID_NAME}",
(This is described in the aprsd docs.) if you
wish to allow remote logins. "${DAEMON_NAME}" needs to run as
root for this to work, if you do not plan to run
"${DAEMON_NAME}" ever as root, you can skip this step.
You can always add it manually later if you change your mind.
EOF
        if which -s pw && yesno "Would you like to add a ${TNC_UID_NAME} login" y; then
        (adduser ${TNC_UID} ${TNC_GID} ${TNC_UID_NAME} ${TNC_GID_NAME} ${DAEMON_NAME})
        fi
else
    echo "You already have an user \"${TNC_UID_NAME}\" so I will use it."
fi