-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpostinstall
executable file
·52 lines (43 loc) · 1.41 KB
/
postinstall
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/zsh --no-rcs
##
## sets the desktop using `desktoppr`
##
# set the path to the desktop image file here
picturepath="/Library/Desktop Pictures/BoringBlueDesktop.png"
# only run when installing on System Volume
if [[ "$3" != "/" ]]; then
echo "Not installing on /, not setting desktop"
exit 0
fi
# verify the image exists
if [[ ! -f "$picturepath" ]]; then
echo "no file at $picturepath, exiting"
exit 1
fi
# path to current directory of the script
scriptdir=$(dirname "$0")
# try to locate desktoppr
if [[ -x "$scriptdir/desktoppr" ]]; then
desktoppr="$scriptdir/desktoppr"
elif [[ -x "/usr/local/bin/desktoppr" ]]; then
desktoppr="/usr/local/bin/desktoppr"
else
echo "cannot find desktoppr, exiting"
exit 1
fi
# get the current user
loggedInUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }')
uid=$(id -u "$loggedInUser")
if [[ "$loggedInUser" != "loginwindow" ]]; then
# set the desktop for the user
if [[ $(sw_vers -buildVersion) > "21" ]]; then
# behavior with sudo seems to be broken in Montery
# dropping the sudo will result in a warning that desktoprr seems to be
# running as root, but it will still work
launchctl asuser "$uid" "$desktoppr" "$picturepath"
else
sudo -u "$loggedInUser" launchctl asuser "$uid" "$desktoppr" "$picturepath"
fi
else
echo "no user logged in, no desktop set"
fi