Skip to content

Commit

Permalink
Merge pull request #73 from macadmins/bsb3fix
Browse files Browse the repository at this point in the history
fix big sur b3 paths
  • Loading branch information
natewalck authored Sep 3, 2020
2 parents 9b82f39 + 05f7dda commit 1f6f395
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 52 deletions.
66 changes: 36 additions & 30 deletions scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,41 @@ launch_daemon_plist_name='com.erikng.installapplications'
launch_agent_base_path='Library/LaunchAgents/'
launch_daemon_base_path='Library/LaunchDaemons/'

# Load agent if installing to a running system
# Run the rest of this script only on a running OS
if [[ $3 == "/" ]] ; then
# Fail the install if the admin forgets to change their paths and they don't exist.
if [ ! -e "$3${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ] || [ ! -e "$3${launch_agent_base_path}${launch_agent_plist_name}.plist" ]; then
echo "LaunchAgent or Daemon missing, exiting"
exit 1
fi

# Attempt to unload the daemon if it's stuck in memory but gone from disk
/bin/launchctl list | /usr/bin/grep 'installapplications'
if [[ $? -eq 0 ]] && [[ ! -e "$3${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ]]; then
/bin/launchctl remove "${launch_daemon_plist_name}"
fi

# Enable the LaunchDaemon
/bin/launchctl load "$3${launch_daemon_base_path}${launch_daemon_plist_name}.plist"

# Current console user information
console_user=$(/usr/bin/stat -f "%Su" /dev/console)
console_user_uid=$(/usr/bin/id -u "$console_user")

# Only enable the LaunchAgent if there is a user logged in, otherwise rely on built in LaunchAgent behavior
if [[ -z "$console_user" ]]; then
echo "Did not detect user"
elif [[ "$console_user" == "loginwindow" ]]; then
echo "Detected Loginwindow Environment"
elif [[ "$console_user" == "_mbsetupuser" ]]; then
echo "Detect SetupAssistant Environment"
else
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl load "$3${launch_agent_base_path}${launch_agent_plist_name}.plist"
fi
base_path=$3
elif [[ $3 == "/System/Volumes/Data" ]] ; then
base_path="$3/"
else
exit 0
fi

# Fail the install if the admin forgets to change their paths and they don't exist.
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
echo "LaunchAgent or Daemon missing, exiting"
exit 1
fi

# Attempt to unload the daemon if it's stuck in memory but gone from disk
/bin/launchctl list | /usr/bin/grep 'installapplications'
if [[ $? -eq 0 ]] && [[ ! -e "$base_path${launch_daemon_base_path}${launch_daemon_plist_name}.plist" ]]; then
/bin/launchctl remove "${launch_daemon_plist_name}"
fi

# Enable the LaunchDaemon
/bin/launchctl load "$base_path${launch_daemon_base_path}${launch_daemon_plist_name}.plist"

# Current console user information
console_user=$(/usr/bin/stat -f "%Su" /dev/console)
console_user_uid=$(/usr/bin/id -u "$console_user")

# Only enable the LaunchAgent if there is a user logged in, otherwise rely on built in LaunchAgent behavior
if [[ -z "$console_user" ]]; then
echo "Did not detect user"
elif [[ "$console_user" == "loginwindow" ]]; then
echo "Detected Loginwindow Environment"
elif [[ "$console_user" == "_mbsetupuser" ]]; then
echo "Detect SetupAssistant Environment"
else
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl load "$base_path${launch_agent_base_path}${launch_agent_plist_name}.plist"
fi
49 changes: 27 additions & 22 deletions scripts/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@ launch_daemon_plist_name='com.erikng.installapplications'
launch_agent_base_path='Library/LaunchAgents/'
launch_daemon_base_path='Library/LaunchDaemons/'

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

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

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

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

0 comments on commit 1f6f395

Please sign in to comment.