-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxbat.sh
More file actions
executable file
·92 lines (86 loc) · 2.01 KB
/
maxbat.sh
File metadata and controls
executable file
·92 lines (86 loc) · 2.01 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
#######################################################################
# maxbat.sh (Max)imize(Bat)tery
# arielvb - http://www.arielvb.com
# Turns on/off aplications, services or devices
# version: 0.2
# Changelog:
# 0.1 First relase
# 0.2 Added MySQL
# - Condition service return status changed to -ge, not == 0
#
# //TODO add dashboard
# //TODO easy way to add services, create function to add to each array
# //TODO profile management.
#######################################################################
DIC=( 'on' 'off' 'start' 'stop') # Arg dictionary
ONOFF=0 #Define for 'on off'
STST=2 #Define for 'start stop'
# APPS to kill
# The APP must be located inside /Applications
APPS=( 'Dropbox' 'DropboxAVB' 'Google Notifier' 'CapsSee' )
# Services to stop
COMM=( 'sudo apachectl' '/usr/local/mysql/support-files/mysql.server' 'networksetup -setairportpower Airport' 'blueutil')
COMM_NAM=( 'Apache' 'MySQL' 'Airport' 'Bluetooth')
COMM_ARG=( $STST $STST $ONOFF $ONOFF)
# Process name of each service for check if are running (unused)
COMM_PRC=( 'httpd' '' '' '' )
getDicStart(){
echo ${DIC[$1]};
}
getDicStop(){
echo ${DIC[`expr $1 + 1`]};
}
killproces(){
local a;
printf "Killing $1... "
a=`killall "$1"`
if [[ $? == 0 ]]; then
echo 'done'
fi
}
startproces(){
local a
printf "Opening $1..."
a=`open "/Applications/$1.app/" ` &
if [[ $? == 0 ]]; then
echo 'done'
fi
}
runcmd(){
printf "$1..."
$2 > /dev/null
if [[ $? -ge 0 ]]; then
echo 'done'
else
echo 'Return Code:' $?
echo 'error'
fi
}
############################
echo "START"
STOP=true
if [[ $BASH_ARGC > 0 ]]; then
if [[ $1 == 'on' ]]; then
STOP=true
fi
if [[ $1 == 'off' ]]; then
STOP=false
fi
fi
for (( i = 0 ; i < ${#APPS[@]}; i++ )) do
if ($STOP) then
killproces "${APPS[$i]}"
else
startproces "${APPS[$i]}"
fi
done
for (( i = 0 ; i < ${#COMM[@]}; i++ )) do
if ($STOP) then
args=`getDicStop ${COMM_ARG[$i]}`
else
args=`getDicStart ${COMM_ARG[$i]}`
fi
runcmd "${COMM_NAM[$i]}" "${COMM[$i]} $args"
done
echo "END"