Created
July 13, 2026 15:42
-
-
Save bencevans/4c5b51139c7985489341c1d046a7ac58 to your computer and use it in GitHub Desktop.
GlobalProtect Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -u | |
| DOMAIN="gui/$(id -u)" | |
| PANGPS_LABEL="com.paloaltonetworks.gp.pangps" | |
| PANGPA_LABEL="com.paloaltonetworks.gp.pangpa" | |
| PANGPS_PLIST="/Library/LaunchAgents/${PANGPS_LABEL}.plist" | |
| PANGPA_PLIST="/Library/LaunchAgents/${PANGPA_LABEL}.plist" | |
| usage() { | |
| echo "Usage: work_vpn {on|off|restart|status}" | |
| exit 1 | |
| } | |
| is_loaded() { | |
| launchctl print "${DOMAIN}/$1" >/dev/null 2>&1 | |
| } | |
| start_agent() { | |
| local label="$1" | |
| local plist="$2" | |
| local name="$3" | |
| if is_loaded "$label"; then | |
| echo "$name is already loaded." | |
| else | |
| echo "Loading $name..." | |
| launchctl bootstrap "$DOMAIN" "$plist" | |
| fi | |
| echo "Starting $name..." | |
| launchctl kickstart -k "${DOMAIN}/${label}" | |
| } | |
| stop_agent() { | |
| local label="$1" | |
| local name="$2" | |
| if is_loaded "$label"; then | |
| echo "Stopping $name..." | |
| launchctl bootout "${DOMAIN}/${label}" | |
| else | |
| echo "$name is not loaded." | |
| fi | |
| } | |
| show_status() { | |
| echo | |
| echo "GlobalProtect status:" | |
| for entry in \ | |
| "$PANGPS_LABEL:PanGPS" \ | |
| "$PANGPA_LABEL:GlobalProtect (PanGPA)" | |
| do | |
| label="${entry%%:*}" | |
| name="${entry#*:}" | |
| if is_loaded "$label"; then | |
| pid="$( | |
| launchctl print "${DOMAIN}/${label}" 2>/dev/null | | |
| awk '/^[[:space:]]*pid =/ { print $3; exit }' | |
| )" | |
| if [[ -n "$pid" ]]; then | |
| printf " %-24s running (PID %s)\n" "$name" "$pid" | |
| else | |
| printf " %-24s loaded, but not currently running\n" "$name" | |
| fi | |
| else | |
| printf " %-24s stopped\n" "$name" | |
| fi | |
| done | |
| echo | |
| launchctl list | grep -i palo || true | |
| } | |
| case "${1:-}" in | |
| on) | |
| start_agent "$PANGPS_LABEL" "$PANGPS_PLIST" "PanGPS" | |
| start_agent "$PANGPA_LABEL" "$PANGPA_PLIST" "GlobalProtect (PanGPA)" | |
| sleep 1 | |
| show_status | |
| ;; | |
| off) | |
| stop_agent "$PANGPA_LABEL" "GlobalProtect (PanGPA)" | |
| stop_agent "$PANGPS_LABEL" "PanGPS" | |
| sleep 1 | |
| show_status | |
| ;; | |
| restart) | |
| stop_agent "$PANGPA_LABEL" "GlobalProtect (PanGPA)" | |
| stop_agent "$PANGPS_LABEL" "PanGPS" | |
| sleep 1 | |
| start_agent "$PANGPS_LABEL" "$PANGPS_PLIST" "PanGPS" | |
| start_agent "$PANGPA_LABEL" "$PANGPA_PLIST" "GlobalProtect (PanGPA)" | |
| sleep 1 | |
| show_status | |
| ;; | |
| status) | |
| show_status | |
| ;; | |
| *) | |
| usage | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment