-
Notifications
You must be signed in to change notification settings - Fork 12
/
iface
executable file
·1101 lines (975 loc) · 28.5 KB
/
iface
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:${PATH}"
################################################################################
#
# CUSTOM PLUGIN SECTION
#
################################################################################
############################################################
# Variables
############################################################
###
### Custom Defines
###
appname="iface"
if [ -n "${BLOCK_INSTANCE:-}" ]; then
iface="${BLOCK_INSTANCE}"
else
iface="$( ip route | awk '/^default/ { print $5 ; exit }' )"
fi
format=" {status_or_ip}"
###
### Thresholds
###
# Enable
has_threshold=1
# Depending on the conditions in your custom_action()
# you can force the output to be critical or warning
# Set these vars to 1 (in custom_action)
force_crit=0
force_warn=0
force_good=0
###
### Additional arguments
###
arg_params=(
"-i"
)
arg_vars=(
"iface"
)
arg_desc_val=(
"<iface>"
)
arg_desc_long=(
"Specify the network interface"
)
###
### Format placeholders
###
# bash variable names
format_vars=(
"ip"
"ip_nm"
"ip6"
"ip6_nm"
"mac"
"mtu"
"iface"
"status"
"status_or_ip"
"status_or_ip6"
)
# Format placeholders
format_nodes=(
"{ip}"
"{ip_nm}"
"{ip6}"
"{ip6_nm}"
"{mac}"
"{mtu}"
"{iface}"
"{status}"
"{status_or_ip}"
"{status_or_ip6}"
)
# Format description (for help display)
format_descs=(
"IPv4 address"
"IPv4 address including netmask"
"IPv6 address"
"IPv6 address including netmask"
"MAC address"
"MTU value"
"Network interface"
"Status (up, down, unknown, absent)"
"Status text if not up or IPv4 address"
"Status text if not up or IPv6 address"
)
# Format examples (for help display)
format_examples=(
"-f \" {status}: {ip6} {mtu}\""
"-f \" {iface}: {status_or_ip6} {mac}\""
)
############################################################
# custom_actio function
############################################################
###
### Evaluate disk space
###
custom_action() {
if ! command -v ip > /dev/null 2>&1; then
echo "Error, ip binary not found, but required"
exit 1
fi
local _output
ip=
ip_nm=
ip6=
ip6_nm=
mac=
mtu=
status="unknown"
status_or_ip="${status}"
status_or_ip6="${status}"
if [ ! -d "/sys/class/net/${iface}/" ] || [ ! -f "/sys/class/net/${iface}/operstate" ]; then
status="absent"
status_or_ip="${status}"
status_or_ip6="${status}"
force_crit=1
else
_output="$( ip addr show "${iface}" 2>/dev/null )"
ip="$( echo "${_output}" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1 )"
ip_nm="$( echo "${_output}" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]+' | head -1 )"
ip6="$( echo "${_output}" | grep -oE 'inet6' | grep -oE '[0-9a-fA-F]*::.*/[0-9]+' | sed 's/\/.*//g' )"
ip6_nm="$( echo "${_output}" | grep -oE 'inet6' | grep -oE '[0-9a-fA-F]*::.*/[0-9]+' || true )"
mac="$( echo "${_output}" | grep 'link/' | grep -oE '([0-9a-fA-F]{2}:)+[0-9a-fA-F]{2}' | head -1 )"
mtu="$( echo "${_output}" | grep -oE 'mtu\s*[0-9]+' | sed 's/mtu\s//g' )"
if [ "$( cat "/sys/class/net/${iface}/operstate" )" = "down" ]; then
status="down"
status_or_ip="${status}"
status_or_ip6="${status}"
force_crit=1
else
status="up"
status_or_ip="${ip}"
status_or_ip6="${ip6}"
force_good=1
fi
fi
}
###
###
###
### D O N O T E D I T A F T E R H E R E
###
###
###
################################################################################
#
# BUILT-IN VARIABLES
#
################################################################################
###
### General default values
###
color_def="#666666" # gray
color_good="#88b090" # green
color_warn="#ccdc90" # yellow
color_crit="#e89393" # red
color_info="#fce94f" # bright yellow
###
### Extended format arrays
###
fe_placeholder=()
fe_sign=()
fe_value=()
fe_format=()
###
### Threshold arrays
###
tg_placeholder=()
tg_sign=()
tg_value=()
ti_placeholder=()
ti_sign=()
ti_value=()
tw_placeholder=()
tw_sign=()
tw_value=()
tc_placeholder=()
tc_sign=()
tc_value=()
###
### Use of pango markup?
###
pango=1
###
### source configuration file if it exists
###
if [ -f "${HOME}/.config/i3blocks-modules/conf" ]; then
# shellcheck disable=SC1090
. "${HOME}/.config/i3blocks-modules/conf"
fi
###
### i3blocks vars info
### https://vivien.github.io/i3blocks/
###
# name= ${BLOCK_NAME}
# instace= ${BLOCK_INSTANCE}
# button= ${BLOCK_BUTTON}
# x-coor ${BLOCK_X}
# y-coor ${BLOCK_Y}
################################################################################
#
# BUILT-IN FUNCTIONS
#
################################################################################
###
### System functions
###
print_usage() {
custom_args=""
# program specific arguments
for (( i=0; i<${#arg_params[@]}; i++ )); do
custom_args="${custom_args}[${arg_params[$i]} ${arg_desc_val[$i]}] "
done
# Show/Hide threshold
if [ "${has_threshold}" = "1" ]; then
custom_args="${custom_args}[-tg|-ti|-tw|-tc <p> <s> <int|str>] "
fi
echo "Usage: ${appname} [-f <format>] [-fe <p> <s> <int|str> <f>] ${custom_args}[-np] [-cd|-cg|-cw|-cc|-ci <code>]"
echo " ${appname} -h"
echo " ${appname} -v"
echo
if [ "${#custom_args}" -gt "0" ]; then
echo "Optional variables:"
echo "--------------------------------------------------------------------------------"
for (( i=0; i<${#arg_params[@]}; i++ )); do
printf " %-13s%s\\n" "${arg_params[$i]} ${arg_desc_val[$i]}" "${arg_desc_long[$i]}"
done
echo
fi
if [ "${has_threshold}" = "1" ]; then
echo "Optional threshold arguments:"
echo "--------------------------------------------------------------------------------"
echo "You can optionally enable threshold checking against any placeholder value."
echo "This enables the colorizing of the final output depending on any met"
echo "conditions specified."
echo "Default is not to use any threshold"
echo "You can use unlimited number of threshold for each type."
echo
echo " -tg <p> <s> <int|str> Enable threshold for 'good status'"
echo " -ti <p> <s> <int|str> Enable threshold for 'info status'"
echo " -tw <p> <s> <int|str> Enable threshold for 'warn status'"
echo " -tc <p> <s> <int|str> Enable threshold for 'crit status'"
echo
echo " Explanation:"
echo " <p> is the placeholder value you want to check against."
printf " valid placeholders: "
for (( i=0; i<${#format_nodes[@]}; i++ )); do
printf "%s" "${format_nodes[$i]} "
done
printf "\\n"
echo " Note 1: placeholder values will be converted to integers"
echo " Any decimal places will simply be cut off."
echo " Note 2: In equal mode (<s> '=') is a string regex comparison and"
echo " no placeholder will be converted."
echo " Note 3: In unequal mode (<s> '!=') is a string comparison and"
echo " no placeholder will be converted."
echo " Note 3: In equal mode (<s> '=') regex is allowed :-)"
echo " <s> must either be '<', '>', '=' or '!=' depending on what direction"
echo " you want to check the threshold placeholder against."
echo " <int> The integer number you want to check against the placeholder."
echo " <str> The string you want to check against the placeholder."
echo " You can only use a string when in equal mode '='."
echo " You can also use regex here."
echo
echo " Examples:"
echo " 1. Check if value of ${format_nodes[0]} < 50, then format using the good color"
echo " -tg '${format_nodes[0]}' '<' 50"
echo
echo " 2. Check if value of ${format_nodes[0]} > 90, then format using the warn color"
echo " -tw '${format_nodes[0]}' '>' 90"
echo
echo " 3. Check if value of ${format_nodes[0]} equals the string 'foo', then format using the info color"
echo " -ti '${format_nodes[0]}' '=' 'foo'"
echo
echo " 4. Check if value of ${format_nodes[0]} equals the regex '^[0-9]+\$', then format using the info color"
echo " -ti '${format_nodes[0]}' '=' '^[0-9]+\$'"
echo
fi
echo "Optional markup (pango):"
echo "--------------------------------------------------------------------------------"
echo " -np Disable pango markup"
echo
echo "Optional color arguments:"
echo "--------------------------------------------------------------------------------"
echo "If not specified, script default colors are used"
echo "If config file with color codes is present in:"
echo "'${HOME}/.config/i3blocks-modules/conf', these colors will be used."
echo
echo " -cd <code> Default color (hexadecimal color code)"
echo " Default value is: ${color_def}"
echo " -cg <code> Good color (hexadecimal color code)"
echo " Default value is: ${color_good}"
echo " -cw <code> Warning color (hexadecimal color code)"
echo " Default value is: ${color_warn}"
echo " -cc <code> Critical color (hexadecimal color code)"
echo " Default value is: ${color_crit}"
echo " -ci <code> Info color (hexadecimal color code)"
echo " Default value is: ${color_info}"
echo
echo "Optional Format placeholders:"
echo "--------------------------------------------------------------------------------"
echo " Available color placeholders:"
echo " (Use with pango disabled for custom markup) building"
echo " {color} Current active color depending on thresholds"
echo " {color_def} Default color"
echo " {color_good} Good color"
echo " {color_warn} Warning color"
echo " {color_crit} Critical color"
echo " {color_info} Info color"
echo " Format example:"
echo " -np -f \"<span color='{color}'>Colored text</span>\""
echo
echo " Available specific placeholders:"
for (( i=0; i<${#format_nodes[@]}; i++ )); do
printf " %-15s%s\\n" "${format_nodes[$i]}" "${format_descs[$i]}"
done
echo " Format example:"
for (( i=0; i<${#format_examples[@]}; i++ )); do
printf " %s\\n" "${format_examples[$i]}"
done
echo " Default:"
echo " -f \"${format}\""
echo
echo "Optional extended Format output:"
echo "--------------------------------------------------------------------------------"
echo "You can conditionally set your output text depending on the value of any placeholder."
echo "For example, If you have a placeholder {status} that either is 'up' or 'down', you"
echo "can specify different outputs for 'up' and for 'down'."
echo "Usage"
echo " -fe <p> <s> <v> <f>"
echo
echo " Format example:"
echo " -fe '{status}' '=' 'up' 'It works ;-)' -fe '{status}' '!=' 'up' 'status is: {status}'"
echo " Explanation:"
echo " <p> is the placeholder value you want to check against."
printf " valid placeholders: "
for (( i=0; i<${#format_nodes[@]}; i++ )); do
printf "%s" "${format_nodes[$i]} "
done
printf "\\n"
echo " Note 1: placeholder values will be converted to integers"
echo " Any decimal places will simply be cut off."
echo " Note 2: In equal mode (<s> '=') is a string regex comparison and"
echo " no placeholder will be converted."
echo " Note 3: In unequal mode (<s> '!=') is a string comparison and"
echo " no placeholder will be converted."
echo " Note 3: In equal mode (<s> '=') regex is allowed :-)"
echo " <s> must either be '<', '>', '=' or '!=' depending on what direction"
echo " you want to check the threshold placeholder against."
echo " <int> The integer number you want to check against the placeholder."
echo " <str> The string you want to check against the placeholder."
echo " You can only use a string when in equal mode '='."
echo " You can also use regex here."
echo " <f> Is the format string that should be displayed under the above condition."
echo " Of course you can also use placeholders here ;-)."
}
print_version() {
echo "${appname} v1.8 by cytopia"
echo "https://github.com/cytopia/i3blocks-modules"
}
###
### Decide about final output color color
###
get_status_color() {
local _color_def="${1}"
local _color_good="${2}"
local _color_warn="${3}"
local _color_crit="${4}"
local _color_info="${5}"
# final color
local _color="${_color_def}"
local pval
# has custom critical color?
if [ "${force_crit}" = "1" ]; then
_color="${_color_crit}"
echo "${_color}"
return
fi
# has custom warning color?
if [ "${force_warn}" = "1" ]; then
_color="${_color_warn}"
echo "${_color}"
return
fi
# has custom good color?
if [ "${force_good}" = "1" ]; then
_color="${_color_good}"
fi
# has good color?
for (( i=0; i < ${#tg_placeholder[@]}; i++ )); do
if [ "${tg_sign[$i]}" = "=" ] || [ "${tg_sign[$i]}" = "!=" ]; then
pval="${!tg_placeholder[$i]}"
else
pval="$( echo "${!tg_placeholder[$i]}" | grep -oE '[0-9]*' | head -1 )"
fi
if [ "${tg_sign[$i]}" = "<" ]; then
if [ "${pval}" -lt "${tg_value[$i]}" ]; then
_color="${_color_good}"
fi
elif [ "${tg_sign[$i]}" = "=" ]; then
if [[ "${pval}" =~ ${tg_value[$i]} ]]; then
_color="${_color_good}"
fi
elif [ "${tg_sign[$i]}" = "!=" ]; then
if [[ "${pval}" != "${tg_value[$i]}" ]]; then
_color="${_color_good}"
fi
elif [ "${tg_sign[$i]}" = ">" ]; then
if [ "${pval}" -gt "${tg_value[$i]}" ]; then
_color="${_color_good}"
fi
fi
done
# has info color?
for (( i=0; i < ${#ti_placeholder[@]}; i++ )); do
if [ "${ti_sign[$i]}" = "=" ] || [ "${ti_sign[$i]}" = "!=" ]; then
pval="${!ti_placeholder[$i]}"
else
pval="$( echo "${!ti_placeholder[$i]}" | grep -oE '[0-9]*' | head -1 )"
fi
if [ "${ti_sign[$i]}" = "<" ]; then
if [ "${pval}" -lt "${ti_value[$i]}" ]; then
_color="${_color_info}"
fi
elif [ "${ti_sign[$i]}" = "=" ]; then
if [[ "${pval}" =~ ${ti_value[$i]} ]]; then
_color="${_color_info}"
fi
elif [ "${ti_sign[$i]}" = "!=" ]; then
if [[ "${pval}" != "${ti_value[$i]}" ]]; then
_color="${_color_info}"
fi
elif [ "${ti_sign[$i]}" = ">" ]; then
if [ "${pval}" -gt "${ti_value[$i]}" ]; then
_color="${_color_info}"
fi
fi
done
# has warning color?
for (( i=0; i < ${#tw_placeholder[@]}; i++ )); do
if [ "${tw_sign[$i]}" = "=" ] || [ "${tw_sign[$i]}" = "!=" ]; then
pval="${!tw_placeholder[$i]}"
else
pval="$( echo "${!tw_placeholder[$i]}" | grep -oE '[0-9]*' | head -1 )"
fi
if [ "${tw_sign[$i]}" = "<" ]; then
if [ "${pval}" -lt "${tw_value[$i]}" ]; then
_color="${color_warn}"
fi
elif [ "${tw_sign[$i]}" = "=" ]; then
if [[ "${pval}" =~ ${tw_value[$i]} ]]; then
_color="${_color_warn}"
fi
elif [ "${tw_sign[$i]}" = "!=" ]; then
if [[ "${pval}" != "${tw_value[$i]}" ]]; then
_color="${_color_warn}"
fi
elif [ "${tw_sign[$i]}" = ">" ]; then
if [ "${pval}" -gt "${tw_value[$i]}" ]; then
_color="${_color_warn}"
fi
fi
done
# has critical color?
for (( i=0; i < ${#tc_placeholder[@]}; i++ )); do
if [ "${tc_sign[$i]}" = "=" ] || [ "${tc_sign[$i]}" = "!=" ]; then
pval="${!tc_placeholder[$i]}"
else
pval="$( echo "${!tc_placeholder[$i]}" | grep -oE '[0-9]*' | head -1 )"
fi
if [ "${tc_sign[$i]}" = "<" ]; then
if [ "${pval}" -lt "${tc_value[$i]}" ]; then
_color="${_color_crit}"
fi
elif [ "${tc_sign[$i]}" = "=" ]; then
if [[ "${pval}" =~ ${tc_value[$i]} ]]; then
_color="${_color_crit}"
fi
elif [ "${tc_sign[$i]}" = "!=" ]; then
if [[ "${pval}" != "${tc_value[$i]}" ]]; then
_color="${_color_crit}"
fi
elif [ "${tc_sign[$i]}" = ">" ]; then
if [ "${pval}" -gt "${tc_value[$i]}" ]; then
_color="${_color_crit}"
fi
fi
done
echo "${_color}"
}
###
### Replace custom stuff in format string
###
replace_placeholders() {
local _format="${1}"
local _search
local _replace
# Select format based on extended placeholders
for (( i=0; i < ${#fe_placeholder[@]}; i++ )); do
if [ "${fe_sign[$i]}" = "=" ] || [ "${fe_sign[$i]}" = "!=" ]; then
pval="${!fe_placeholder[$i]}"
else
pval="$( echo "${!fe_placeholder[$i]}" | grep -oE '[0-9]*' | head -1 )"
fi
if [ "${fe_sign[$i]}" = "<" ]; then
if [ "${pval}" -lt "${fe_value[$i]}" ]; then
_format="${fe_format[$i]}"
fi
elif [ "${fe_sign[$i]}" = "=" ]; then
if [[ "${pval}" =~ ${fe_value[$i]} ]]; then
_format="${fe_format[$i]}"
fi
elif [ "${fe_sign[$i]}" = "!=" ]; then
if [[ "${pval}" != "${fe_value[$i]}" ]]; then
_format="${fe_format[$i]}"
fi
elif [ "${fe_sign[$i]}" = ">" ]; then
if [ "${pval}" -gt "${fe_value[$i]}" ]; then
_format="${fe_format[$i]}"
fi
fi
done
# Replace placeholders in $format
for (( i=0; i < ${#format_nodes[@]}; i++ )); do
_search="${format_nodes[$i]}"
_replace="${!format_vars[$i]}"
_format="${_format/${_search}/${_replace}}"
done
echo "${_format}"
}
###
### Replace colors in format string
###
replace_colors() {
local _format="${1}"
local _color="${2}"
local _color_def="${3}"
local _color_good="${4}"
local _color_warn="${5}"
local _color_crit="${6}"
local _color_info="${7}"
_format="${_format/'{color}'/${_color}}"
_format="${_format/'{color_def}'/${_color_def}}"
_format="${_format/'{color_good}'/${_color_good}}"
_format="${_format/'{color_warn}'/${_color_warn}}"
_format="${_format/'{color_crit}'/${_color_crit}}"
_format="${_format/'{color_info}'/${_color_info}}"
echo "${_format}"
}
################################################################################
#
# MAIN ENTRY POINT
#
################################################################################
# Enable/Disable threshold argument
if [ "${has_threshold}" = "1" ]; then
th_chk=""
else
th_chk="__THRESHOLD_DISABLED__"
fi
while [ $# -gt 0 ]; do
case "$1" in
###
### Extended formats
###
-fe)
# 1/4 Check placeholder
shift
if [ "${1}" = "" ]; then
echo "Error, -fe <p> - no placeholder specified."
echo "Type ${appname} -h for help"
exit 1
fi
f=0
for (( i=0; i < ${#format_nodes[@]}; i++ )); do
if [ "${format_nodes[$i]}" = "${1}" ]; then
f=1
break
fi
done
if [ "${f}" = "0" ]; then
echo "Error, -fe '${1}' no such placeholder."
echo "Type ${appname} -h for help"
exit 1
fi
fe_placeholder+=("${format_vars[$i]}")
# 2/4 Check sign
shift
if [ "${1}" = "" ]; then
echo "Error, -fe '{${fe_placeholder[${#fe_placeholder[@]}-1]}}' '${1}' - sign argyment is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${1}" != "<" ] && [ "${1}" != ">" ] && [ "${1}" != "=" ] && [ "${1}" != "!=" ]; then
echo "Error, -fe '{${fe_placeholder[${#fe_placeholder[@]}-1]}}' '${1}' - invalid sign: '${1}'."
echo "Type ${appname} -h for help"
exit 1
fi
fe_sign+=("${1}")
# 3/4 Check value
shift
if [ "${1}" = "" ]; then
echo "Error, -fe '{${fe_placeholder[${#fe_placeholder[@]}-1]}}' '${fe_sign[${#fe_sign[@]}-1]}' '${1}' - value argument is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${fe_sign[${#fe_sign[@]}-1]}" = ">" ] || [ "${fe_sign[${#fe_sign[@]}-1]}" = "<" ]; then
if ! printf "%d" "${1}" >/dev/null 2>&1; then
echo "Error, -fe '{${fe_placeholder[${#fe_placeholder[@]}-1]}}' '${fe_sign[${#fe_sign[@]}-1]}' '${1}' - value argument is not a number."
echo "Type ${appname} -h for help"
exit 1
fi
fi
fe_value+=("${1}")
# 4/4 Check placeholder string
shift
fe_format+=("${1}")
;;
###
### Threshold good
###
"-tg${th_chk}")
# 1/3 Check placeholder
shift
if [ "${1}" = "" ]; then
echo "Error, -tg <p> - no placeholder specified."
echo "Type ${appname} -h for help"
exit 1
fi
f=0
for (( i=0; i < ${#format_nodes[@]}; i++ )); do
if [ "${format_nodes[$i]}" = "${1}" ]; then
f=1
break
fi
done
if [ "${f}" = "0" ]; then
echo "Error, -tg '${1}' no such placeholder."
echo "Type ${appname} -h for help"
exit 1
fi
tg_placeholder+=("${format_vars[$i]}")
# 2/3 Check sign
shift
if [ "${1}" = "" ]; then
echo "Error, -tg '{${tg_placeholder[${#tg_placeholder[@]}-1]}}' '${1}' - sign argument is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${1}" != "<" ] && [ "${1}" != ">" ] && [ "${1}" != "=" ] && [ "${1}" != "!=" ]; then
echo "Error, -tg '{${tg_placeholder[${#tg_placeholder[@]}-1]}}' '${1}' - invalid sign: '${1}'."
echo "Type ${appname} -h for help"
exit 1
fi
tg_sign+=("${1}")
# 3/3 Check value
shift
if [ "${1}" = "" ]; then
echo "Error, -tg '{${tg_placeholder[${#tg_placeholder[@]}-1]}}' '${tg_sign[${#tg_sign[@]}-1]}' '${1}' - value argyment is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${tg_sign[${#tg_sign[@]}-1]}" = ">" ] || [ "${tg_sign[${#tg_sign[@]}-1]}" = "<" ]; then
if ! printf "%d" "${1}" >/dev/null 2>&1; then
echo "Error, -tg '{${tg_placeholder[${#tg_placeholder[@]}-1]}}' '${tg_sign[${#tg_sign[@]}-1]}' '${1}' - value argument is not a number."
echo "Type ${appname} -h for help"
exit 1
fi
fi
tg_value+=("${1}")
;;
###
### Threshold info
###
"-ti${th_chk}")
# 1/3 Check placeholder
shift
if [ "${1}" = "" ]; then
echo "Error, -ti <p> - no placeholder specified."
echo "Type ${appname} -h for help"
exit 1
fi
f=0
for (( i=0; i < ${#format_nodes[@]}; i++ )); do
if [ "${format_nodes[$i]}" = "${1}" ]; then
f=1
break
fi
done
if [ "${f}" = "0" ]; then
echo "Error, -ti '${1}' no such placeholder."
echo "Type ${appname} -h for help"
exit 1
fi
ti_placeholder+=("${format_vars[$i]}")
# 2/3 Check sign
shift
if [ "${1}" = "" ]; then
echo "Error, -ti '{${ti_placeholder[${#ti_placeholder[@]}-1]}}' '${1}' - sign argument is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${1}" != "<" ] && [ "${1}" != ">" ] && [ "${1}" != "=" ] && [ "${1}" != "!=" ]; then
echo "Error, -ti '{${ti_placeholder[${#ti_placeholder[@]}-1]}}' '${1}' - invalid sign: '${1}'."
echo "Type ${appname} -h for help"
exit 1
fi
ti_sign+=("${1}")
# 3/3 Check value
shift
if [ "${1}" = "" ]; then
echo "Error, -ti '{${ti_placeholder[${#ti_placeholder[@]}-1]}}' '${ti_sign[${#ti_sign[@]}-1]}' '${1}' - value argyment is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${ti_sign[${#ti_sign[@]}-1]}" = ">" ] || [ "${ti_sign[${#ti_sign[@]}-1]}" = "<" ]; then
if ! printf "%d" "${1}" >/dev/null 2>&1; then
echo "Error, -ti '{${ti_placeholder[${#ti_placeholder[@]}-1]}}' '${ti_sign[${#ti_sign[@]}-1]}' '${1}' - value argument is not a number."
echo "Type ${appname} -h for help"
exit 1
fi
fi
ti_value+=("${1}")
;;
###
### Threshold warning
###
"-tw${th_chk}")
# 1/3 Check placeholder
shift
if [ "${1}" = "" ]; then
echo "Error, -tw <p> - no placeholder specified."
echo "Type ${appname} -h for help"
exit 1
fi
f=0
for (( i=0; i < ${#format_nodes[@]}; i++ )); do
if [ "${format_nodes[$i]}" = "${1}" ]; then
f=1
break
fi
done
if [ "${f}" = "0" ]; then
echo "Error, -tw '${1}' no such placeholder."
echo "Type ${appname} -h for help"
exit 1
fi
tw_placeholder+=("${format_vars[$i]}")
# 2/3 Check sign
shift
if [ "${1}" = "" ]; then
echo "Error, -tw '{${tw_placeholder[${#tw_placeholder[@]}-1]}}' '${1}' - sign argument is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${1}" != "<" ] && [ "${1}" != ">" ] && [ "${1}" != "=" ] && [ "${1}" != "!=" ]; then
echo "Error, -tw '{${tw_placeholder[${#tw_placeholder[@]}-1]}}' '${1}' - invalid sign: '${1}'."
echo "Type ${appname} -h for help"
exit 1
fi
tw_sign+=("${1}")
# 3/3 Check value
shift
if [ "${1}" = "" ]; then
echo "Error, -tw '{${tw_placeholder[${#tw_placeholder[@]}-1]}}' '${tw_sign[${#tw_sign[@]}-1]}' '${1}' - value argyment is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${tw_sign[${#tw_sign[@]}-1]}" = ">" ] || [ "${tw_sign[${#tw_sign[@]}-1]}" = "<" ]; then
if ! printf "%d" "${1}" >/dev/null 2>&1; then
echo "Error, -tw '{${tw_placeholder[${#tw_placeholder[@]}-1]}}' '${tw_sign[${#tw_sign[@]}-1]}' '${1}' - value argument is not a number."
echo "Type ${appname} -h for help"
exit 1
fi
fi
tw_value+=("${1}")
;;
###
### Threshold critical
###
"-tc${th_chk}")
# 1/3 Check placeholder
shift
if [ "${1}" = "" ]; then
echo "Error, -tc <p> - no placeholder specified."
echo "Type ${appname} -h for help"
exit 1
fi
f=0
for (( i=0; i < ${#format_nodes[@]}; i++ )); do
if [ "${format_nodes[$i]}" = "${1}" ]; then
f=1
break
fi
done
if [ "${f}" = "0" ]; then
echo "Error, -tc '${1}' no such placeholder."
echo "Type ${appname} -h for help"
exit 1
fi
tc_placeholder+=("${format_vars[$i]}")
# 2/3 Check sign
shift
if [ "${1}" = "" ]; then
echo "Error, -tc '{${tc_placeholder[${#tc_placeholder[@]}-1]}}' '${1}' - sign argument is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${1}" != "<" ] && [ "${1}" != ">" ] && [ "${1}" != "=" ] && [ "${1}" != "!=" ]; then
echo "Error, -tc '{${tc_placeholder[${#tc_placeholder[@]}-1]}}' '${1}' - invalid sign: '${1}'."
echo "Type ${appname} -h for help"
exit 1
fi
tc_sign+=("${1}")
# 3/3 Check value
shift
if [ "${1}" = "" ]; then
echo "Error, -tc '{${tc_placeholder[${#tc_placeholder[@]}-1]}}' '${tc_sign[${#tc_sign[@]}-1]}' '${1}' - value argyment is empty."
echo "Type ${appname} -h for help"
exit 1
fi
if [ "${tc_sign[${#tc_sign[@]}-1]}" = ">" ] || [ "${tc_sign[${#tc_sign[@]}-1]}" = "<" ]; then
if ! printf "%d" "${1}" >/dev/null 2>&1; then
echo "Error, -tc '{${tc_placeholder[${#tc_placeholder[@]}-1]}}' '${tc_sign[${#tc_sign[@]}-1]}' '${1}' - value argument is not a number."
echo "Type ${appname} -h for help"
exit 1
fi
fi
tc_value+=("${1}")
;;
###
### Format overwrite
###
-f)
shift
if [ "${1}" = "" ]; then
echo "Error, -f requires a string"
echo "Type ${appname} -h for help"
exit 1
fi
format="${1}"
;;
###
### Disable pango markup output
###
-np)
pango=0
;;
###
### Color overwrites
###
-cd)
# default color
shift
if ! echo "${1}" | grep -qE '#[0-9a-fA-F]{6}' >/dev/null 2>&1; then
echo "Error, invalid color string: ${1}"
echo "Type ${appname} -h for help"
exit 1
fi
color_def="${1}"
;;
-cg)
# good color
shift
if ! echo "${1}" | grep -qE '#[0-9a-fA-F]{6}' >/dev/null 2>&1; then
echo "Error, invalid color string: ${1}"
echo "Type ${appname} -h for help"
exit 1
fi
color_good="${1}"
;;
-cw)
# warning color
shift
if ! echo "${1}" | grep -qE '#[0-9a-fA-F]{6}' >/dev/null 2>&1; then
echo "Error, invalid color string: ${1}"
echo "Type ${appname} -h for help"
exit 1
fi
color_warn="${1}"
;;
-cc)
# critical color