Auto-update: Tue Aug 6 15:07:59 PDT 2024

This commit is contained in:
sanj 2024-08-06 15:07:59 -07:00
parent ebaf22c08b
commit ad2a10b1c7

74
vitals
View file

@ -6,7 +6,16 @@ adguard_home_ip='100.64.64.15'
if [[ "$(uname)" == "Darwin" ]]; then if [[ "$(uname)" == "Darwin" ]]; then
# macOS # macOS
local_ip=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -n1) local_ip=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -n1)
uptime=$(uptime | awk '{print $3}' | sed 's/,//') uptime_seconds=$(sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//')
current_time=$(date +%s)
uptime_seconds=$((current_time - uptime_seconds))
days=$((uptime_seconds / 86400))
hours=$(( (uptime_seconds % 86400) / 3600 ))
minutes=$(( (uptime_seconds % 3600) / 60 ))
uptime="up "
[[ $days -gt 0 ]] && uptime+="$days days, "
[[ $hours -gt 0 ]] && uptime+="$hours hours, "
uptime+="$minutes minutes"
else else
# Linux # Linux
local_ip=$(hostname -I | awk '{print $1}') local_ip=$(hostname -I | awk '{print $1}')
@ -22,8 +31,11 @@ if [ ! -z "$wan_info" ]; then
blacklisted=$(echo "$wan_info" | jq '.blacklisted.blacklisted') blacklisted=$(echo "$wan_info" | jq '.blacklisted.blacklisted')
else else
wan_ip="Unavailable" wan_ip="Unavailable"
mullvad_exit_ip=false
blacklisted=false
fi fi
# Check if Tailscale is installed and get IP # Check if Tailscale is installed and get IP
if command -v tailscale &> /dev/null; then if command -v tailscale &> /dev/null; then
has_tailscale=true has_tailscale=true
@ -33,8 +45,8 @@ if command -v tailscale &> /dev/null; then
# Parse exit node hostname # Parse exit node hostname
if echo "$ts_exitnode_output" | grep -q 'selected'; then if echo "$ts_exitnode_output" | grep -q 'selected'; then
mullvad_exitnode=true mullvad_exitnode=true
# Extract the hostname of the selected exit node # Extract the hostname of the selected exit node, remove any newline characters, and take only the first occurrence
mullvad_hostname=$(echo "$ts_exitnode_output" | grep 'selected' | awk '{print $2}') mullvad_hostname=$(echo "$ts_exitnode_output" | grep 'selected' | awk '{print $2}' | tr -d '\n' | awk -F'.' '{print $1"."$2"."$3"."$4}')
else else
mullvad_exitnode=false mullvad_exitnode=false
mullvad_hostname="" mullvad_hostname=""
@ -77,24 +89,40 @@ else
adguard_client="" adguard_client=""
fi fi
cat <<EOF # Output JSON using jq for proper formatting and escaping
{ jq -n \
"local_ip": "$local_ip", --arg local_ip "$local_ip" \
"wan_connected": $wan_connected, --argjson wan_connected "$wan_connected" \
"wan_ip": "$wan_ip", --arg wan_ip "$wan_ip" \
"has_tailscale": $has_tailscale, --argjson has_tailscale "$has_tailscale" \
"tailscale_ip": "$tailscale_ip", --arg tailscale_ip "$tailscale_ip" \
"mullvad_exitnode": $mullvad_exitnode, --argjson mullvad_exitnode "$mullvad_exitnode" \
"mullvad_hostname": "$mullvad_hostname", --arg mullvad_hostname "$mullvad_hostname" \
"mullvad_exit_ip": $mullvad_exit_ip, --argjson mullvad_exit_ip "$mullvad_exit_ip" \
"blacklisted": $blacklisted, --argjson blacklisted "$blacklisted" \
"nextdns_connected": $nextdns_connected, --argjson nextdns_connected "$nextdns_connected" \
"nextdns_protocol": "$nextdns_protocol", --arg nextdns_protocol "$nextdns_protocol" \
"nextdns_client": "$nextdns_client", --arg nextdns_client "$nextdns_client" \
"adguard_connected": $adguard_connected, --argjson adguard_connected "$adguard_connected" \
"adguard_protocol": "$adguard_protocol", --arg adguard_protocol "$adguard_protocol" \
"adguard_client": "$adguard_client", --arg adguard_client "$adguard_client" \
"uptime": "$uptime" --arg uptime "$uptime" \
} '{
EOF local_ip: $local_ip,
wan_connected: $wan_connected,
wan_ip: $wan_ip,
has_tailscale: $has_tailscale,
tailscale_ip: $tailscale_ip,
mullvad_exitnode: $mullvad_exitnode,
mullvad_hostname: $mullvad_hostname,
mullvad_exit_ip: $mullvad_exit_ip,
blacklisted: $blacklisted,
nextdns_connected: $nextdns_connected,
nextdns_protocol: $nextdns_protocol,
nextdns_client: $nextdns_client,
adguard_connected: $adguard_connected,
adguard_protocol: $adguard_protocol,
adguard_client: $adguard_client,
uptime: $uptime
}'