Assorted shell and Python scripts
1#!/usr/bin/env zsh 2 3# Check for dependencies 4if ! test -x "$(command -v curl)"; then 5 echo "Missing dependency: curl" 6 exit 1 7fi 8 9if ! test -x "$(command -v gum)"; then 10 echo "Missing dependency: gum" 11 echo "See github.com/charmbracelet/gum" 12 exit 1 13fi 14 15if ! test -x "$(command -v jq)"; then 16 echo "Missing dependency: jq" 17 exit 1 18fi 19 20MV_API=$(curl -sSL https://am.i.mullvad.net/json) 21IP=$(echo $MV_API | jq ."ip" | tr -d '"') 22CITY=$(echo $MV_API | jq ."city" | tr -d '"') 23COUNTRY=$(echo $MV_API | jq ."country" | tr -d '"') 24MV_EXIT_IP_HN=$(echo $MV_API | jq ."mullvad_exit_ip_hostname" | tr -d '"') 25MV_SERVER_TYPE=$(echo $MV_API | jq ."mullvad_server_type" | tr -d '"') 26BLACKLISTED=$(echo $MV_API | jq ."blacklisted"."blacklisted") 27 28LEFT_COL=$(printf "%s\n%s\n%s\n%s\n%s\n%s\n" "IP Address" "City" "Country" "Exit IP Hostname" "Server Type" "Blacklisted") 29RIGHT_COL=$(printf "%s\n%s\n%s\n%s\n%s\n%s\n" "$IP" "$CITY" "$COUNTRY" "$MV_EXIT_IP_HN" "$MV_SERVER_TYPE" "$BLACKLISTED") 30GUM_LEFT=$(gum style --foreground "#73F59F" --border-foreground 57 --border none --width 20 --margin "1 2" --padding "0 1" --align right "$LEFT_COL") 31GUM_RIGHT=$(gum style --foreground "#F1F1F1" --border-foreground 57 --border none --width 20 --margin "1 0" --align left "$RIGHT_COL") 32 33GUM_TOP=$(gum style --bold --foreground 212 --border-foreground 57 --border rounded --width 50 --align center --padding "0 1" "Am I Mullvad?") 34GUM_BOTTOM=$(gum join --horizontal --align right "$GUM_LEFT" "$GUM_RIGHT") 35BOTTOM=$(gum style --border-foreground 57 --border rounded --width 50 --align center --padding "0 1" $GUM_BOTTOM) 36gum join --vertical "$GUM_TOP" "$BOTTOM"