Skip to content

Commit 1f6f395

Browse files
authored
Merge pull request #73 from macadmins/bsb3fix
fix big sur b3 paths
2 parents 9b82f39 + 05f7dda commit 1f6f395

File tree

2 files changed

+63
-52
lines changed

2 files changed

+63
-52
lines changed

scripts/postinstall

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,41 @@ launch_daemon_plist_name='com.erikng.installapplications'
2222
launch_agent_base_path='Library/LaunchAgents/'
2323
launch_daemon_base_path='Library/LaunchDaemons/'
2424

25-
# Load agent if installing to a running system
25+
# Run the rest of this script only on a running OS
2626
if [[ $3 == "/" ]] ; then
27-
# Fail the install if the admin forgets to change their paths and they don't exist.
28-
if [ ! -e "$3${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ] || [ ! -e "$3${launch_agent_base_path}${launch_agent_plist_name}.plist" ]; then
29-
echo "LaunchAgent or Daemon missing, exiting"
30-
exit 1
31-
fi
32-
33-
# Attempt to unload the daemon if it's stuck in memory but gone from disk
34-
/bin/launchctl list | /usr/bin/grep 'installapplications'
35-
if [[ $? -eq 0 ]] && [[ ! -e "$3${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ]]; then
36-
/bin/launchctl remove "${launch_daemon_plist_name}"
37-
fi
38-
39-
# Enable the LaunchDaemon
40-
/bin/launchctl load "$3${launch_daemon_base_path}${launch_daemon_plist_name}.plist"
41-
42-
# Current console user information
43-
console_user=$(/usr/bin/stat -f "%Su" /dev/console)
44-
console_user_uid=$(/usr/bin/id -u "$console_user")
45-
46-
# Only enable the LaunchAgent if there is a user logged in, otherwise rely on built in LaunchAgent behavior
47-
if [[ -z "$console_user" ]]; then
48-
echo "Did not detect user"
49-
elif [[ "$console_user" == "loginwindow" ]]; then
50-
echo "Detected Loginwindow Environment"
51-
elif [[ "$console_user" == "_mbsetupuser" ]]; then
52-
echo "Detect SetupAssistant Environment"
53-
else
54-
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl load "$3${launch_agent_base_path}${launch_agent_plist_name}.plist"
55-
fi
27+
base_path=$3
28+
elif [[ $3 == "/System/Volumes/Data" ]] ; then
29+
base_path="$3/"
30+
else
31+
exit 0
32+
fi
33+
34+
# Fail the install if the admin forgets to change their paths and they don't exist.
35+
if [ ! -e "$base_path${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ] || [ ! -e "$base_path${launch_agent_base_path}${launch_agent_plist_name}.plist" ]; then
36+
echo "LaunchAgent or Daemon missing, exiting"
37+
exit 1
38+
fi
39+
40+
# Attempt to unload the daemon if it's stuck in memory but gone from disk
41+
/bin/launchctl list | /usr/bin/grep 'installapplications'
42+
if [[ $? -eq 0 ]] && [[ ! -e "$base_path${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ]]; then
43+
/bin/launchctl remove "${launch_daemon_plist_name}"
44+
fi
45+
46+
# Enable the LaunchDaemon
47+
/bin/launchctl load "$base_path${launch_daemon_base_path}${launch_daemon_plist_name}.plist"
48+
49+
# Current console user information
50+
console_user=$(/usr/bin/stat -f "%Su" /dev/console)
51+
console_user_uid=$(/usr/bin/id -u "$console_user")
52+
53+
# Only enable the LaunchAgent if there is a user logged in, otherwise rely on built in LaunchAgent behavior
54+
if [[ -z "$console_user" ]]; then
55+
echo "Did not detect user"
56+
elif [[ "$console_user" == "loginwindow" ]]; then
57+
echo "Detected Loginwindow Environment"
58+
elif [[ "$console_user" == "_mbsetupuser" ]]; then
59+
echo "Detect SetupAssistant Environment"
60+
else
61+
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl load "$base_path${launch_agent_base_path}${launch_agent_plist_name}.plist"
5662
fi

scripts/preinstall

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,35 @@ launch_daemon_plist_name='com.erikng.installapplications'
2222
launch_agent_base_path='Library/LaunchAgents/'
2323
launch_daemon_base_path='Library/LaunchDaemons/'
2424

25+
# Run the rest of this script only on a running OS
2526
if [[ $3 == "/" ]] ; then
26-
# Current console user information
27-
console_user=$(/usr/bin/stat -f "%Su" /dev/console)
28-
console_user_uid=$(/usr/bin/id -u "$console_user")
27+
base_path=$3
28+
elif [[ $3 == "/System/Volumes/Data" ]] ; then
29+
base_path="$3/"
30+
else
31+
exit 0
32+
fi
2933

30-
# Attempt to unload the daemon if it's stuck in memory but gone from disk
31-
/bin/launchctl list | /usr/bin/grep 'installapplications'
32-
if [[ $? -eq 0 ]] && [[ ! -e "$3${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ]]; then
33-
/bin/launchctl remove "${launch_daemon_plist_name}"
34-
fi
34+
# Current console user information
35+
console_user=$(/usr/bin/stat -f "%Su" /dev/console)
36+
console_user_uid=$(/usr/bin/id -u "$console_user")
3537

36-
if [[ -z "$console_user" ]]; then
37-
echo "Did not detect user"
38-
elif [[ "$console_user" == "loginwindow" ]]; then
39-
echo "Detected Loginwindow Environment"
40-
elif [[ "$console_user" == "_mbsetupuser" ]]; then
41-
echo "Detect SetupAssistant Environment"
42-
else
43-
# Attempt to unload the agent if it's stuck in memory but gone from disk
44-
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl list | /usr/bin/grep 'installapplications'
45-
if [[ $? -eq 0 ]] && [[ ! -e "$3${launch_agent_base_path}${launch_agent_plist_name}.plist" ]]; then
46-
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl remove "${launch_agent_plist_name}"
47-
fi
48-
fi
38+
# Attempt to unload the daemon if it's stuck in memory but gone from disk
39+
/bin/launchctl list | /usr/bin/grep 'installapplications'
40+
if [[ $? -eq 0 ]] && [[ ! -e "$base_path${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ]]; then
41+
/bin/launchctl remove "${launch_daemon_plist_name}"
4942
fi
5043

51-
exit 0
44+
if [[ -z "$console_user" ]]; then
45+
echo "Did not detect user"
46+
elif [[ "$console_user" == "loginwindow" ]]; then
47+
echo "Detected Loginwindow Environment"
48+
elif [[ "$console_user" == "_mbsetupuser" ]]; then
49+
echo "Detect SetupAssistant Environment"
50+
else
51+
# Attempt to unload the agent if it's stuck in memory but gone from disk
52+
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl list | /usr/bin/grep 'installapplications'
53+
if [[ $? -eq 0 ]] && [[ ! -e "$base_path${launch_agent_base_path}${launch_agent_plist_name}.plist" ]]; then
54+
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl remove "${launch_agent_plist_name}"
55+
fi
56+
fi

0 commit comments

Comments
 (0)