@@ -22,35 +22,41 @@ launch_daemon_plist_name='com.erikng.installapplications'
2222launch_agent_base_path=' Library/LaunchAgents/'
2323launch_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
2626if [[ $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"
5662fi
0 commit comments