Merge remote-tracking branch 'mdw/mdw/powm-sec'
[secnet] / setup.mac
CommitLineData
19a171f1
RK
1#!/bin/bash
2#
3# Richard Kettlewell 2011-06-18
4#
c215a4bc
IJ
5# This file is part of secnet.
6# See README for full list of copyright holders.
7#
8# secnet is free software; you can redistribute it and/or modify it
9# under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version d of the License, or
11# (at your option) any later version.
12#
13# secnet is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# version 3 along with secnet; if not, see
20# https://www.gnu.org/licenses/gpl.html.
21#
19a171f1
RK
22set -e
23
24group=${group:-secnet}
25user=${user:-secnet}
26
27# pick ID1 ID2 ... IDn
28# Echoes an ID matching none of ID1..IDn
29pick() {
30 local n
31 n=250 # better not choose 0!
32 while :; do
33 ok=true
34 for k in "$@"; do
35 if [ $n = $k ]; then
36 ok=false
37 break
38 fi
39 done
40 if $ok; then
41 echo $n
42 return
43 fi
44 n=$((1+$n))
45 done
46}
47
48if dscl . -read /Groups/$group >/dev/null 2>&1; then
49 :
50else
51 gids=$(dscl . -list /Groups PrimaryGroupID|awk '{print $2}')
52 gid=$(pick $gids)
53 dscl . -create /Groups/$group
54 dscl . -create /Groups/$group PrimaryGroupID $gid
55 dscl . -create /Groups/$group Password \*
56fi
57
58if dscl . -read /Users/$user >/dev/null 2>&1; then
59 :
60else
61 uids=$(dscl . -list /Users UniqueID|awk '{print $2}')
62 uid=$(pick $uids)
63 gid=$(dscl . -read /Groups/$group PrimaryGroupID | awk '{print $2}')
64 dscl . -create /Users/$user
65 dscl . -create /Users/$user UniqueID $uid
66 dscl . -create /Users/$user UserShell /usr/bin/false
67 dscl . -create /Users/$user RealName 'secnet'
e247763d 68 dscl . -create /Users/$user NFSHomeDirectory /var/empty
19a171f1
RK
69 dscl . -create /Users/$user PrimaryGroupID $gid
70 dscl . -create /Users/$user Password \*
71fi
72
73cp uk.org.greenend.secnet.plist /Library/LaunchDaemons/.
74launchctl load /Library/LaunchDaemons
75echo "To start secnet:"
76echo " sudo launchctl start uk.org.greenend.secnet"
77echo
78echo "To stop secnet:"
79echo " sudo launchctl stop uk.org.greenend.secnet"
80echo
81echo "To uninstall:"
b953af83 82echo " sudo launchctl unload /Library/LaunchDaemons/uk.org.greenend.secnet.plist"
19a171f1 83echo " sudo rm -f /Library/LaunchDaemons/uk.org.greenend.secnet.plist"