Created
August 24, 2016 00:19
-
-
Save rtrouton/d5879304e2763caf20646696e4e5e3f2 to your computer and use it in GitHub Desktop.
CreateUserPkg postinstall script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# postinstall for local account install | |
PlistArrayAdd() { | |
# Add $value to $array_name in $plist_path, creating if necessary | |
local plist_path="$1" | |
local array_name="$2" | |
local value="$3" | |
local old_values | |
local item | |
old_values=$(/usr/libexec/PlistBuddy -c "Print :$array_name" "$plist_path" 2>/dev/null) | |
if [[ $? == 1 ]]; then | |
# Array doesn't exist, create it | |
/usr/libexec/PlistBuddy -c "Add :$array_name array" "$plist_path" | |
else | |
# Array already exists, check if array already contains value | |
IFS=$'\012' | |
for item in $old_values; do | |
unset IFS | |
if [[ "$item" =~ ^\ *$value$ ]]; then | |
# Array already contains value | |
return 0 | |
fi | |
done | |
unset IFS | |
fi | |
# Add item to array | |
/usr/libexec/PlistBuddy -c "Add :$array_name: string \"$value\"" "$plist_path" | |
} | |
ACCOUNT_TYPE=ADMIN # Used by read_package.py. | |
PlistArrayAdd "$3/private/var/db/dslocal/nodes/Default/groups/admin.plist" users "username_goes_here" && \ | |
PlistArrayAdd "$3/private/var/db/dslocal/nodes/Default/groups/admin.plist" groupmembers "96DC0604-5AFA-4970-A404-380BBA399BFD" | |
if [ "$3" == "/" ]; then | |
# we're operating on the boot volume | |
# kill local directory service so it will see our local | |
# file changes -- it will automatically restart | |
/usr/bin/killall DirectoryService 2>/dev/null || /usr/bin/killall opendirectoryd 2>/dev/null | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment