-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobal.sh
75 lines (66 loc) · 1.55 KB
/
global.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
######
#
# Global functions & misc other stuff
# Matthew Davies, Dec 12th, 2013
#
######
#Missing message declarations
#Set a bunch of variables
name='BatterySaver'
osversion=$(system_profiler SPSoftwareDataType | grep 'System Version' | awk '{print($5)}')
os=$(echo $osversion | awk -F"." '{print $1}')
osDot=$(echo $osversion | awk -F"." '{print $2}')
charge=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%3.1f\n", $10/$5 * 100)}')
plugged=$(ioreg -n AppleSmartBattery | grep ExternalConnected | awk '{print($5)}')
notify=$(which terminal-notifer > /dev/null)
logfile='BatterySaver.log'
configfile='settings.conf'
LOGMESSAGE=''
##
# Logger, used for logging to the $LOGFILE, then exiting
##
die(){
echo $(date)': OS: '$version', Battery: '$charge', AC: '$plugged', '${LOGMESSAGE%,} >> $logfile
exit 1
}
##
# Creates an array of arguements
##
args=()
for i in "$@"; do
args+=("$i")
done
x=0
x2=0
argArray=()
for a in ${args[@]}; do
if [[ $a =~ ^- ]]; then
i=$(($x2+1))
argArray+=("$a ${args[$i]}")
let "x++"
fi
let "x2++"
done
arg(){
for a in "${argArray[@]}"; do
get="$@"
b=$(echo "$a" | awk '{ printf($1) }' | cut -d "-" -f 2)
if [ "$b" == "$get" ]; then
echo ${a/-${get}/}
fi
done
}
readSettings(){
i=0
while read line; do
if [[ "$line" =~ ^[^#]*= ]]; then
a=$(echo ${line%% =*} | sed 's/ /_/g' | awk '{print tolower($0)}')
eval $a="${line#*= }"
((i++))
fi
done < $configfile
}
setSetting(){
echo $1' = '$2 >> $configfile
LOGMESSAGE+="Set $1 = $2, "
}