Created
December 24, 2017 02:43
-
-
Save rtrouton/ad0d1df26ab351534265845801216bfa to your computer and use it in GitHub Desktop.
Postinstall script for username user account created with pycreateuserpkg
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" && \ | |
PlistArrayAdd "$3/private/var/db/dslocal/nodes/Default/groups/admin.plist" groupmembers "CB18DA2D-D70A-429D-9E76-413C5D0A54A2" | |
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