Skip to content

Commit

Permalink
Removing check for running system (#564)
Browse files Browse the repository at this point in the history
* Removing check for running system
If these scripts are executed, the running system check has already been satisfied by the package postinstall.

* Removing $3 variables that are no longer present
  • Loading branch information
smithjw authored Mar 14, 2024
1 parent edbcd5b commit ea34aba
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 58 deletions.
53 changes: 25 additions & 28 deletions Nudge/Scripts/postinstall-launchagent
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 10 additions & 13 deletions Nudge/Scripts/postinstall-logger
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
31 changes: 14 additions & 17 deletions Nudge/Scripts/postinstall-nudge
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ea34aba

Please sign in to comment.