-
Notifications
You must be signed in to change notification settings - Fork 0
/
MacHUD.sh
51 lines (40 loc) · 1.75 KB
/
MacHUD.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
#functions
cd "$(dirname $0)"
printBars() {
num=$1
retVal=$(printf "%-${num}s" "|")
echo "${retVal// /|}"
}
#Insert find line number function to find line number of element.
#Disk Space Calculations
usedSpace=$(df -hl | grep '/dev/disk1' | awk '{sub("%","");print $5}')
sed -i'' -e "9s/.*/$usedSpace%/" MacHUD.html
numUsedBars=$(($usedSpace/5))
usedBars="$(printBars $numUsedBars)"
numFreeBars=$((20-$numUsedBars))
freeBars="$(printBars $numFreeBars)"
sed -i '' -e "11s/.*/<barsUsed>$usedBars<\/barsUsed><barsFree>$freeBars<\/barsFree>/" MacHUD.html
#Find External IP
#Print IP and provider
extAddyJson="$(curl -s http://ip-api.com/json)"
isp="$(echo $extAddyJson | awk 'BEGIN { FS = ":" } ; { print $6 }' | sed 's/\"//g' | sed 's/,lat//g')"
extAddy="$(echo $extAddyJson | awk 'BEGIN { FS = ":" } ; { print $10 }' | sed 's/\"//g' | sed 's/,region//g')"
sed -i'' -e "16s/.*/$extAddy/" MacHUD.html
sed -i'' -e "18s/.*/$isp/" MacHUD.html
#FUTURE: Find Active Network Adapter(s)
#Print IP, subnet mask, gateway, DNS servers, and domain suffix
wiFiAddy="$(ifconfig en0 | awk '{ print $2}' | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")"
#Get hexadecimal value of subnet mask
hexMask="$(ifconfig en0 | awk '{ print $4}' | grep 0x)"
#Generate Array of Mask Octets
maskArray=$(echo $hexMask | sed 's/../0x& /g' | tr ' ' '\n')
#Trim first OxOx entry
maskArray=${maskArray[@]:5}
#Convert hex Octets to dotted decimal notation
netMask=$(printf "%d." $maskArray | sed 's/.$//')
#find gateway address
gateway=$(netstat -nr | grep default | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
resolvers=$(scutil --dns)
dnsServer=$(echo $resovlers | awk 'BEGIN { FS = "\n" } ; { print $3 }')
sed -i'' -e "22s/.*/<br>IP: $wiFiAddy<br>Mask: $netMask<br>Gateway: $gateway<br>/" MacHUD.html