-
Notifications
You must be signed in to change notification settings - Fork 0
/
habitat.sh
executable file
·214 lines (161 loc) · 3.33 KB
/
habitat.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
correct_usage () {
echo "Correct usage:"
echo "habitat (-c|--config) <configfile> [--no-web]"
}
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-c|--config)
CONFIG_FILE="$2"
shift
;;
*)
# unknown option
;;
esac
shift
done
if [ ! -n "$CONFIG_FILE" ]; then
echo "ERROR: no config file specified"
correct_usage
exit 1;
elif [ ! -f "$CONFIG_FILE" ]; then
echo "ERROR: $CONFIG_FILE does not exist"
echo "This should be a habitat config file"
correct_usage
exit 1;
else
# Source config file
echo "Sourcing config file: $CONFIG_FILE"
. $CONFIG_FILE
fi
main () {
if [ -n "$MUTE_SPEAKERS" ]; then
mute_speakers
fi
if [ -n "$PRIMARY_MONITOR" ]; then
select_primary_monitor
fi
if [ -n "$SECONDARY_MONITOR" ] && [ -n "$SECONDARY_MONITOR_RESOLUTION" ]; then
select_resolution $SECONDARY_MONITOR $SECONDARY_MONITOR_RESOLUTION
fi
if [ -n "$PROGRAMS" ]; then
start_programs
fi
if [ -n "$WEBPAGES" ]; then
start_chrome
fi
if [ "$BLUETOOTH" == "true" ]; then
start_bluetooth
fi
if [ -n "$TODO_LIST" ]; then
cat_todo_list
fi
# Show desktop / minimise all
wmctrl -k on
}
mute_speakers () {
MUTE_RESULT=$(amixer set Master mute | grep off)
if [[ $MUTE_RESULT == *"off"* ]]
then
tick "Audio muted"
else
fail "Audio muted"
fi
}
select_resolution () {
monitor=$1
resolution=$2
xrandr --output $monitor --mode $resolution
if [ $? -eq 0 ]
then
tick "$monitor set to $resolution"
else
fail "$monitor set to $resolution"
fi
}
select_primary_monitor () {
# Select Primary Monitor
MONITORS=$(xrandr --prop | grep "[^dis]connected" | cut --delimiter=" " -f1)
if [[ $MONITORS == *"$PRIMARY_MONITOR"* ]]
then
echo $PRIMARY_MONITOR | monitor-switcher.sh > /dev/null 2>&1;
MON_RESULT=$(xrandr --prop | grep "$PRIMARY_MONITOR")
if [[ $MON_RESULT == *"primary"* ]]
then
tick "$PRIMARY_MONITOR is now primary monitor"
else
fail "$PRIMARY_MONITOR is now primary monitor"
fi
if [ -n "$PRIMARY_MONITOR_RESOLUTION" ]; then
select_resolution $PRIMARY_MONITOR $PRIMARY_MONITOR_RESOLUTION
fi
else
echo -e "${RED}*** $PRIMARY_MONITOR is not connected ***${NC}"
fi
}
start_programs () {
# Start Programs
for i in "${PROGRAMS[@]}"
do
startme $i
done
}
start_chrome () {
# Start Chrome with profile & pages
google-chrome \
$WEBPAGES \
--profile-directory="$CHROME_PROFILE" \
> /dev/null 2>&1 &
if [ $? -eq 0 ]
then
tick "chrome"
else
fail "chrome"
fi
}
start_bluetooth () {
rfkill unblock bluetooth
if [ $? -eq 0 ]
then
tick $1
else
fail $1
fi
}
cat_todo_list () {
# cat todo list to screen
echo "------------------------------"
echo "*** Here is your todo list ***"
echo "$TODO_LIST"
echo "------------------------------"
eval cat $TODO_LIST
}
startme () {
pgrep $1 > /dev/null 2>&1
if [ $? -ne 0 ]
then
nohup $1 > /dev/null 2>&1 &
pgrep $1 > /dev/null 2>&1
if [ $? -eq 0 ]
then
tick $1
else
fail $1
fi
else
tick $1
fi
}
tick () {
echo -e "${GREEN}\xE2\x9c\x94${NC} $1"
}
fail () {
echo -e "${RED}\xE2\x9c\x98${NC} $1"
}
main "$@"