diff --git a/Nudge/Scripts/postinstall-launchagent b/Nudge/Scripts/postinstall-launchagent index 17deaa57..25888280 100755 --- a/Nudge/Scripts/postinstall-launchagent +++ b/Nudge/Scripts/postinstall-launchagent @@ -17,35 +17,32 @@ launch_agent_plist_name='com.github.macadmins.Nudge.plist' # Base paths -launch_agent_base_path='Library/LaunchAgents/' +launch_agent_base_path='/Library/LaunchAgents' -# Load agent if installing to a running system -if [[ $3 == "/" ]] ; then - # Fail the install if the admin forgets to change their paths and they don't exist. - if [ ! -e "$3/${launch_agent_base_path}${launch_agent_plist_name}" ]; then - echo "LaunchAgent missing, exiting" - exit 1 - fi +# Fail the install if the admin forgets to change their paths and they don't exist. +if [[ ! -e "${launch_agent_base_path}/${launch_agent_plist_name}" ]]; then + echo "LaunchAgent missing, exiting" + exit 1 +fi - # Current console user information - console_user=$(/usr/bin/stat -f "%Su" /dev/console) - console_user_uid=$(/usr/bin/id -u "$console_user") +# 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" - elif [[ "$console_user" == "root" ]]; then - echo "Detect root as currently logged-in user" - else - # Unload the agent so it can be triggered on re-install - /bin/launchctl asuser "${console_user_uid}" /bin/launchctl unload -w "$3${launch_agent_base_path}${launch_agent_plist_name}" - # Kill Nudge just in case (say someone manually opens it and not launched via launchagent - /usr/bin/killall Nudge - # Load the launch agent - /bin/launchctl asuser "${console_user_uid}" /bin/launchctl load -w "$3${launch_agent_base_path}${launch_agent_plist_name}" - fi +# 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" +elif [[ "$console_user" == "root" ]]; then + echo "Detect root as currently logged-in user" +else + # Unload the agent so it can be triggered on re-install + /bin/launchctl asuser "${console_user_uid}" /bin/launchctl unload -w "${launch_agent_base_path}/${launch_agent_plist_name}" + # Kill Nudge just in case (say someone manually opens it and not launched via launchagent + /usr/bin/killall Nudge + # Load the launch agent + /bin/launchctl asuser "${console_user_uid}" /bin/launchctl load -w "${launch_agent_base_path}/${launch_agent_plist_name}" fi diff --git a/Nudge/Scripts/postinstall-logger b/Nudge/Scripts/postinstall-logger index 66813978..25d0389a 100755 --- a/Nudge/Scripts/postinstall-logger +++ b/Nudge/Scripts/postinstall-logger @@ -17,18 +17,15 @@ launch_daemon_plist_name='com.github.macadmins.Nudge.logger.plist' # Base paths -launch_daemon_base_path='Library/LaunchDaemons/' +launch_daemon_base_path='/Library/LaunchDaemons' -# Load agent if installing to a running system -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}" ]; then - echo "LaunchDaemon missing, exiting" - exit 1 - fi - - # Unload the agent so it can be triggered on re-install - /bin/launchctl unload -w "$3${launch_daemon_base_path}${launch_daemon_plist_name}" - # Load the launch agent - /bin/launchctl load -w "$3${launch_daemon_base_path}${launch_daemon_plist_name}" +# Fail the install if the admin forgets to change their paths and they don't exist. +if [[ ! -e "${launch_daemon_base_path}/${launch_daemon_plist_name}" ]]; then + echo "LaunchDaemon missing, exiting" + exit 1 fi + +# Unload the agent so it can be triggered on re-install +/bin/launchctl unload -w "${launch_daemon_base_path}/${launch_daemon_plist_name}" +# Load the launch agent +/bin/launchctl load -w "${launch_daemon_base_path}/${launch_daemon_plist_name}" diff --git a/Nudge/Scripts/postinstall-nudge b/Nudge/Scripts/postinstall-nudge index 9cea8714..5ae7a975 100755 --- a/Nudge/Scripts/postinstall-nudge +++ b/Nudge/Scripts/postinstall-nudge @@ -13,22 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Only run if on a running system -if [[ $3 == "/" ]] ; then - # Current console user information - console_user=$(/usr/bin/stat -f "%Su" /dev/console) +# Current console user information +console_user=$(/usr/bin/stat -f "%Su" /dev/console) - # Only run if there is a user logged in, otherwise do nothing - 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" - elif [[ "$console_user" == "root" ]]; then - echo "Detect root as currently logged-in user" - else - # Kill Nudge is running - /usr/bin/pgrep -i Nudge | /usr/bin/xargs kill - fi +# Only run if there is a user logged in, otherwise do nothing +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" +elif [[ "$console_user" == "root" ]]; then + echo "Detect root as currently logged-in user" +else + # Kill Nudge is running + /usr/bin/pgrep -i Nudge | /usr/bin/xargs kill fi