Commit | Line | Data |
---|---|---|
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 |
22 | set -e |
23 | ||
24 | group=${group:-secnet} | |
25 | user=${user:-secnet} | |
26 | ||
27 | # pick ID1 ID2 ... IDn | |
28 | # Echoes an ID matching none of ID1..IDn | |
29 | pick() { | |
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 | ||
48 | if dscl . -read /Groups/$group >/dev/null 2>&1; then | |
49 | : | |
50 | else | |
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 \* | |
56 | fi | |
57 | ||
58 | if dscl . -read /Users/$user >/dev/null 2>&1; then | |
59 | : | |
60 | else | |
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 \* | |
71 | fi | |
72 | ||
73 | cp uk.org.greenend.secnet.plist /Library/LaunchDaemons/. | |
74 | launchctl load /Library/LaunchDaemons | |
75 | echo "To start secnet:" | |
76 | echo " sudo launchctl start uk.org.greenend.secnet" | |
77 | echo | |
78 | echo "To stop secnet:" | |
79 | echo " sudo launchctl stop uk.org.greenend.secnet" | |
80 | echo | |
81 | echo "To uninstall:" | |
b953af83 | 82 | echo " sudo launchctl unload /Library/LaunchDaemons/uk.org.greenend.secnet.plist" |
19a171f1 | 83 | echo " sudo rm -f /Library/LaunchDaemons/uk.org.greenend.secnet.plist" |