-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathadduser
More file actions
executable file
·35 lines (30 loc) · 949 Bytes
/
Copy pathadduser
File metadata and controls
executable file
·35 lines (30 loc) · 949 Bytes
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
#!/bin/bash -e
if [[ -x /usr/sbin/adduser ]]; then
exec /usr/sbin/adduser "$@"
fi
NEW_USERNAME="$1"
if [ -z "$NEW_USERNAME" ]
then
echo "Usage: $(basename "$0") [username]" >&2
exit 1
fi
if id "$NEW_USERNAME" 2> /dev/null
then
echo "$(basename "$0"): User \"$NEW_USERNAME\" already exists." >&2
exit 1
fi
NEW_UID=$(( $(dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1) + 1 ))
if ! [ $NEW_UID -gt 500 ]
then
echo "$(basename "$0"): Could not determine new UID." >&2
exit 1
fi
dscl . create "/Users/$NEW_USERNAME"
dscl . create "/Users/$NEW_USERNAME" UniqueID $NEW_UID
dscl . create "/Users/$NEW_USERNAME" PrimaryGroupID 20
dscl . delete "/Users/$NEW_USERNAME" AuthenticationAuthority
dscl . create "/Users/$NEW_USERNAME" Password '*'
dscl . create "/Users/$NEW_USERNAME" UserShell /bin/bash
dscl . create "/Users/$NEW_USERNAME" NFSHomeDirectory "/Users/$NEW_USERNAME"
cd /tmp
createhomedir -c -u "$NEW_USERNAME"