Make Sebastian's bug1831 branch build with --enable-gcc-warnings
[tor.git] / contrib / osx / addsysuser
blob50797f1ab0cf51a67c4e09e369c7ece7e289c4ff
1 #!/bin/sh
3 # Original adduser 05 Feb 2002 by Jon L. Gardner
5 # Modified for Tor installer by Nick Mathewson
6 # 2007-06-12 Modified for leopard by Andrew Lewman
7 # Copyright (c) 2007 Andrew Lewman
11 ROOTPROP=/
13 if [ "`whoami`" != "root" ]; then
14 echo "You must be root to execute this script."
15 exit
17 if [ "x$3" = "x" ]; then
18 echo 'Usage: addsysuser <username> "<full name>" <homedir>'
19 exit 0
22 username=$1
23 realname=$2
24 homedir=$3
26 if [ -x /usr/bin/dscl ]; then
27 # Determine the gid of the daemon group
28 gid=`dscl . -read /groups/daemon gid`
29 if [ "x`dscl . -list /users|cut -f2 -d' '|grep $username`" != "x" ]; then
30 echo The account $username already exists.
31 exit 0
33 if [ -x /usr/bin/nidump ]; then
34 uiddef=`nidump passwd / | cut -d: -f3 | sort -n | grep -v '^[56789]..' |grep -v '^....$' | tail -n 1`
35 else
36 _tmp=/tmp/_dsexport_tmp.txt.$$
37 rm -f $_tmp
38 dsexport $_tmp '/Local/Default' 'dsRecTypeStandard:Users' > /dev/null 2>&1
39 uiddef=`cat $_tmp | sed 's/\\\://g' | cut -d: -f6 | grep '^[0-9]' | sort -n | grep -v '^[56789]..' | grep -v '^....$' | tail -n 1`
40 rm -f $_tmp
42 uiddef=`echo $uiddef + 1 | bc`
43 dscl . -create /users/$username uid $uiddef
44 # home is the local path to the home directory
45 home=/Users/$username
46 echo Creating account for $username...
47 dscl . -create /users/$username
48 dscl . -create /users/$username _writers_tim_passwd $username
49 dscl . -create /users/$username realname $realname
50 dscl . -create /users/$username _writers_passwd $username
51 dscl . -create /users/$username gid $gid
52 dscl . -create /users/$username home $homedir
53 dscl . -create /users/$username name $username
54 dscl . -create /users/$username passwd '*'
55 dscl . -create /users/$username shell /dev/null
56 else
57 # Determine the gid of the daemon group
58 gid=`niutil -readprop $ROOTPROP /groups/daemon gid`
59 if [ "x`niutil -list $ROOTPROP /users|cut -f2 -d' '|grep $username`" != "x" ]; then
60 echo The account $username already exists.
61 exit 0
63 # home is the local path to the home directory
64 home=/Users/$username
65 # defhome is what goes into NetInfo
66 defhome="/Network/Servers/MyServer/Users"
67 #echo "Determining next available system uid (please be patient)..."
68 # Uids over 500 are for system users.
69 uiddef=`nidump passwd / | cut -d: -f3 | sort -n | grep -v '^[56789]..' |grep -v '^....$' | tail -n 1`
70 uiddef=`echo $uiddef + 1 |bc`
71 echo Creating account for $username...
72 niutil -create $ROOTPROP /users/$username
73 niutil -createprop $ROOTPROP /users/$username _writers_tim_passwd $username
74 niutil -createprop $ROOTPROP /users/$username realname $realname
75 niutil -createprop $ROOTPROP /users/$username _writers_passwd $username
76 niutil -createprop $ROOTPROP /users/$username uid $uiddef
77 #niutil -createprop $ROOTPROP /users/$username home_loc "<home_dir><url>afp://afp.server.com/Users/</url><path>$username</path></home_dir>"
78 niutil -createprop $ROOTPROP /users/$username gid $gid
79 niutil -createprop $ROOTPROP /users/$username home $homedir
80 niutil -createprop $ROOTPROP /users/$username name $username
81 niutil -createprop $ROOTPROP /users/$username passwd '*'
82 niutil -createprop $ROOTPROP /users/$username shell /dev/null