#!/usr/bin/env bash usage() { cat << EOF usage: ${0##*/} [command] -h Print this help message. -l Start (load) agent or daemon. -u Stop (unload) agent or daemon. EOF } getPath() { case "$1" in cisco) echo '/Library/LaunchDaemons/com.cisco.anyconnect.vpnagentd.plist /Library/LaunchDaemons/com.cisco.anyconnect.ciscod64.plist /Library/LaunchAgents/com.cisco.anyconnect.notification.plist /Library/LaunchAgents/com.cisco.anyconnect.aciseposture.plist /Library/LaunchAgents/com.cisco.anyconnect.gui.plist' ;; postgresql) echo '/Users/slococo/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist' ;; zerotier) echo '/Library/LaunchDaemons/com.zerotier.one.plist' ;; wireshark) echo '/Library/LaunchDaemons/org.wireshark.ChmodBPF.plist' ;; openvpn) echo '/Library/LaunchDaemons/org.openvpn.helper.plist /Library/LaunchDaemons/org.openvpn.client.plist' ;; citrix) echo '/Library/LaunchDaemons/com.citrix.CtxWorkspaceHelperDaemon.plist /Library/LaunchDaemons/com.citrix.ctxusbd.plist /Library/LaunchDaemons/com.citrix.ctxworkspaceupdater.plist /Library/LaunchAgents/com.citrix.ServiceRecords.plist /Library/LaunchAgents/com.citrix.safariadapter.plist /Library/LaunchAgents/com.citrix.AuthManager_Mac.plist /Library/LaunchAgents/com.citrix.ReceiverHelper.plist' ;; microsoft) echo '/Library/LaunchDaemons/com.microsoft.autoupdate.helper.plist /Library/LaunchAgents/com.microsoft.update.agent.plist' ;; zoom) echo '/Library/LaunchDaemons/us.zoom.ZoomDaemon.plist' ;; ?) printf '%s: invalid program -''%s'\\n "$OPTARG" exit 1 ;; esac } runScript() { while getopts ':hl:u:' flag; do case $flag in h) usage exit 0 ;; l) programs=($(getPath $2)) for value in "${programs[@]}"; do if [[ $value == *"LaunchAgent"* ]]; then service.sh -e "$value" -u else owner="$(stat -f '%Su' $value)" if [[ "$owner" == "root" ]]; then service.sh -e "$value" else service.sh -e "$value" -u fi fi done ;; u) programs=($(getPath $2)) for value in "${programs[@]}"; do if [[ $value == *"LaunchAgent"* ]]; then service.sh -d "$value" -u else owner="$(stat -f '%Su' $value)" if [[ "$owner" == "root" ]]; then service.sh -d "$value" else service.sh -d "$value" -u fi fi done ;; ?) printf '%s: invalid option -''%s'\\n "${0##*/}" "$OPTARG" exit 1 ;; esac done } runScript "$@"