-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch_tmux.sh
executable file
·395 lines (328 loc) · 14 KB
/
launch_tmux.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/bin/bash
# launch_tmux.sh - launch my tmux dev env on different machines
# author : Chad Mayfield (chad@chd.my)
# license : gplv3
# date : 02/12/2019
# ADDITIONAL INFO:
# INFO: to identify panes easily;
# Ctrl+B + Q (within tmux)
# --- or ---
# tmux display -pt "${TMUX_PANE:?}" '#{pane_index}'
# view panes: #{session_name}:#{window_index}.#{pane_index}
if [[ $OSTYPE =~ "linux" ]]; then
# get current IP address, to make sure we're on the correct network
IP="$(ip -br -4 addr | grep UP | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")"
# check hostnames and apply create env for each machine
if [[ "$(hostname)" =~ "phobos" ]] && [[ "$IP" =~ "73.196" ]]; then
# start a new 'main' session detached
tmux new-session -s "main" -d -n "dev1"
# set the status bar for this session
#tmux set status-bg default
#tmux set status-fg white
#tmux set status-left '#[fg=green]#S'
tmux set status-right '#[fg=red,bold]w#{window_index}.p#{pane_index} #[fg=default,nobold](#(whoami)@#h) %H:%M:%S %d-%b-%y'
#tmux set status-right '#{session_name}:#{window_index}.#{pane_index} (#(ehoami)@#h) %H:%M:%S %d-%b-%y'
#tmux set status-left-length 20
tmux set status-right-length 80
######## create a new window: dev1 (dev1 environment)
#tmux new-window -t main:0 -n "dev1"
#tmux rename-window dev
# split windows into panes
tmux split-window -h
tmux split-window -h
#tmux select-layout even-horizontal
tmux select-pane -t 1
tmux split-window -v -p 50
tmux select-pane -t 3
tmux split-window -v -p 50
tmux select-pane -t 3
tmux split-window -v -p 20
# run these commands in created panes
tmux send-keys -t 0 C-z 'cd ~/Code/' Enter
tmux send-keys -t 1 C-z 'ssh file' Enter
tmux send-keys -t 2 C-z 'ssh file' Enter
tmux send-keys -t 3 C-z 'top' Enter
tmux clock-mode -t 4
tmux send-keys -t 5 C-z 'ssh file' Enter
tmux select-pane -t main:0
######## create a new window: dev2 (dev2 environment)
tmux new-window -t main:1 -n "dev2"
# split windows into panes
tmux split-window -h
tmux split-window -h
#tmux select-layout even-horizontal
tmux select-pane -t 1
tmux split-window -v -p 50
tmux select-pane -t 3
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'cd ~/Code/ && ls' Enter
tmux select-pane -t main:1
######## create a new window: k8s1 (work with k8s cluster)
tmux new-window -t main:2 -n "k8s"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
######## create a new window: admin (for sysadmin-y things)
tmux new-window -t main:3 -n "admin"
# split windows into panes
tmux split-window -h
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
tmux select-pane -t 4
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'top' Enter
tmux send-keys -t 1 C-z 'last' Enter
tmux send-keys -t 2 C-z 'who' Enter
tmux send-keys -t 3 C-z 'ssh file' Enter
tmux select-pane -t 0
######## create a new window: misc
tmux new-window -t main:4 -n "misc"
# split windows into panes
tmux split-window -h
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
tmux select-pane -t 4
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'echo command goes here' Enter
tmux send-keys -t 1 C-z 'ssh file' Enter
tmux select-pane -t 0
# switch focus back to main window, pane 0
tmux select-window -t 0
tmux select-pane -t 0
# attach to main session
tmux -2 attach-session -t main
# check hostnames and apply create env for each machine
elif [[ "$(hostname)" =~ (deimos|ISFL) ]] && [[ "$IP" =~ "76.133" ]]; then
# start a new 'main' session detached
tmux new-session -s "main" -d -n "dev"
# set the status bar for this session
tmux set status-right '#[fg=red,bold]w#{window_index}.p#{pane_index} #[fg=default,nobold](#(whoami)@#h) %H:%M:%S %d-%b-%y'
tmux set status-right-length 80
######## create a new window: dev (dev environment)
# split windows into panes
tmux split-window -h
#tmux select-layout even-horizontal
tmux select-pane -t 1
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'cd ~/Code/' Enter
tmux send-keys -t 1 C-z 'ssh file' Enter
# dont forget to add user to sudoers like this;
# username ALL=(ALL) NOPASSWD: /usr/local/bin/sysinfo.sh
tmux send-keys -t 2 'if ! /usr/local/bin/sysinfo.sh; then curl -sSL https://git.io/fhQAQ | sudo bash; fi' Enter
tmux select-pane -t main:0
######## create a new window: admin (for sysadmin-y things)
tmux new-window -t main:1 -n "admin"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'ssh file' Enter
tmux send-keys -t 1 C-z 'who' Enter
tmux send-keys -t 2 C-z 'last' Enter
tmux send-keys -t 3 'if ! /usr/local/bin/sysinfo.sh; then curl -sSL https://git.io/fhQAQ | sudo bash; fi' Enter
tmux select-pane -t 0
######## create a new window: k8s1 (work with k8s cluster 1)
tmux new-window -t main:2 -n "k8s1"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
# run these commands in created panes
#tmux send-keys -t 0 C-z 'ssh k8s-node1' Enter
#tmux send-keys -t 1 C-z 'ssh k8s-node2' Enter
#tmux send-keys -t 2 C-z 'ssh k8s-node3' Enter
#tmux send-keys -t 3 C-z 'ssh k8s-node4' Enter
#tmux select-pane -t 0
######## create a new window: k8s2 (work with k8s cluster 2)
tmux new-window -t main:3 -n "k8s2"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
# run these commands in created panes
#tmux send-keys -t 0 C-z 'ssh n1' Enter
#tmux send-keys -t 1 C-z 'ssh n2' Enter
#tmux send-keys -t 2 C-z 'ssh n3' Enter
#tmux send-keys -t 3 C-z 'ssh n4' Enter
#tmux select-pane -t 0
######## create a new window: misc
tmux new-window -t main:4 -n "misc"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'ssh file' Enter
tmux select-pane -t 0
# switch focus back to main window, pane 0
tmux select-window -t 0
tmux select-pane -t 0
# attach to main session
tmux -2 attach-session -t main
else
echo "ERROR: Not implemented (UNKNOWN HOST/NETWORK)!"
exit 1
fi
elif [[ $OSTYPE =~ "darwin" ]]; then
# grab internal IPv4 address and check it
IP="$(ifconfig en0 | grep 'inet ' | awk '{print $2}')"
if [[ "$(hostname -s)" =~ "MBP" ]] && [[ "$IP" =~ "7.10" ]]; then
# start a new 'main' session detached
tmux new-session -s "main" -d -n "dev"
# set the status bar for this session
#pmset -g batt | egrep "([0-9]+\%).*" -o | cut -f1 -d';'
tmux set status-right '#[fg=red,bold]w#{window_index}/p#{pane_index} #[fg=default,nobold](#(whoami)@#h) %H:%M:%S %d-%b-%y'
tmux set status-right-length 80
######## create a new window: dev1 (dev1 environment)
# split windows into panes
tmux split-window -h
#tmux select-layout even-horizontal
tmux select-pane -t 1
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'cd ~/Code/' Enter
tmux send-keys -t 0 'if ! /usr/local/bin/sysinfo.sh; then curl -sSL https://git.io/fhQAQ | bash; fi; ls' Enter
tmux send-keys -t 1 C-z 'ssh file' Enter
tmux send-keys -t 1 "ls" C-m
tmux send-keys -t 2 C-z 'ssh file' Enter
tmux send-keys -t 2 "uptime" C-m
tmux select-pane -t main:0
######## create a new window: plex (plex environment)
tmux new-window -t main:1 -n "plex"
# split windows into panes
tmux split-window -h
#tmux select-layout even-horizontal
tmux select-pane -t 1
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'ssh plex' Enter
tmux send-keys -t 0 "cd /mnt/plex/ && ls -l" C-m
tmux send-keys -t 1 C-z 'ssh plex' Enter
tmux send-keys -t 1 "dfh" C-m
tmux send-keys -t 2 C-z 'ssh plex' Enter
tmux send-keys -t 2 "docker logs plex" C-m
tmux select-pane -t main:1
######## create a new window: transmission (transmission environment)
tmux new-window -t main:2 -n "transmission"
# split windows into panes
tmux split-window -h
#tmux select-layout even-horizontal
tmux select-pane -t 1
tmux split-window -v -p 50
# run these commands in created panes
tmux send-keys -t 0 C-z 'ssh transmission' Enter
tmux send-keys -t 0 "cd ~/completed/ && ls" C-m
tmux send-keys -t 1 C-z 'ssh transmission' Enter
tmux send-keys -t 1 "cd ~/completed/" C-m
tmux send-keys -t 2 C-z 'ssh transmission' Enter
tmux send-keys -t 2 "dfh" C-m
tmux select-pane -t main:2
######## create a new window: k8s-prod (work with production k8s cluster)
tmux new-window -t main:3 -n "k8s-prod"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
tmux select-pane -t main:3
# run these commands in created panes
tmux send-keys -t 0 C-z 'ssh k8s-node1' Enter
tmux send-keys -t 0 "kubectl get nodes && kubectl get po --all-namespaces" C-m
tmux send-keys -t 1 C-z 'ssh k8s-node2' Enter
tmux send-keys -t 2 C-z 'ssh k8s-node3' Enter
tmux send-keys -t 3 C-z 'ssh k8s-node4' Enter
######## create a new window: k8s-prod (work with production k8s cluster)
tmux new-window -t main:4 -n "k8s-test"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
tmux select-pane -t main:4
# run these commands in created panes
tmux send-keys -t 0 C-z 'ssh k8s-test-node1' Enter
tmux send-keys -t 0 "kubectl get nodes && kubectl get po --all-namespaces" C-m
tmux send-keys -t 1 C-z 'ssh k8s-test-node2' Enter
tmux send-keys -t 2 C-z 'ssh k8s-test-node3' Enter
tmux send-keys -t 3 C-z 'ssh k8s-test-node4' Enter
######## create a new window: admin (server/network administration)
tmux new-window -t main:5 -n "admin"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 0
tmux split-window -v -p 50
tmux select-pane -t 2
tmux split-window -v -p 50
tmux select-pane -t main:5
# run these commands in created panes
tmux send-keys -t 0 C-z 'ssh file' Enter
# tmux send-keys -t 0 "awk '/^md/ {printf \"%s: \", $1}; /blocks/ {print $NF}' /proc/mdstat;" C-m
tmux send-keys -t 1 C-z 'ssh nuc1' Enter
tmux send-keys -t 1 "df -h && uptime && ls" C-m
tmux send-keys -t 2 C-z 'ssh ns1' Enter
tmux send-keys -t 2 "tail -n 30 /var/log/dnsmasq/dnsmasq.log" C-m
tmux send-keys -t 3 C-z 'ssh ns2' Enter
tmux send-keys -t 3 "pihole -c -e" C-m "curl -s http://${PIHOLE}/admin/api.php?summaryRaw | jq '.' | grep -E 'dns_queries_today|ads_blocked|percent'" C-m
tmux select-pane -t main:5
######## create a new window: misc
tmux new-window -t main:6 -n "misc"
# split windows into panes
tmux split-window -h
tmux select-layout even-horizontal
tmux select-pane -t 1
tmux split-window -v -p 50
tmux select-pane -t main:6
# run these commands in created panes
tmux send-keys -t 0 C-z 'cd ~' Enter
tmux send-keys -t 1 C-z 'cd ~' Enter
tmux send-keys -t 2 C-z 'cd ~' Enter
tmux send-keys -t 3 C-z 'cd ~' Enter
# switch focus back to main window, pane 0
tmux select-window -t 0
tmux select-pane -t 0
# attach to main session
tmux -2 attach-session -t main
else
echo "ERROR: Not implemented (UNKNOWN HOST/NETWORK)!"
exit 1
fi
else
# TODO: Add cygwin?
echo "ERROR: Unknown \$OSTYPE, bailing out now!"
exit 1
fi
#EOF