-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtermux-wifi-map
More file actions
executable file
·2209 lines (2069 loc) · 65.8 KB
/
termux-wifi-map
File metadata and controls
executable file
·2209 lines (2069 loc) · 65.8 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
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
#!/data/data/com.termux/files/usr/bin/bash
# shellcheck disable=1090,2015,2001,2009,2034,2006,2048,2086,2046,2269,1010,2068
# + merge
# + rerurn codes
# + update
# + oui/vendor search
# Debugging
export PS4='$(if [[ $? -eq 0 ]]; then echo -e "\e[0;32m TRUE/DONE\n\n\e[0m"; else echo -e "\e[1;5;31m FALSE/ERROR\n\n\e[0m"; fi) '
# Set shell
set -eo pipefail
# Termux-WiFi-map v3.0
# Copyright (C) 2025 Kamil "BuriXon" Burek (https://burixon.dev)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Variables
SCRIPT_NAME="Termux-WiFi-map"
SCRIPT_COMMAND_O="termux-wifi-map"
SCRIPT_COMMAND="$(basename "$0")"
SCRIPT_AUTHOR="Kamil BuriXon Burek"
SCRIPT_AUTHOR_ALIAS="BuriXon-code"
SCRIPT_VERSION="3.0-pre.1"
SCRIPT_V_R_DATE="2026"
SCRIPT_PAGE="https://burixon.dev/projects/$SCRIPT_NAME/"
SCRIPT_DONATE="https://burixon.dev/donate/"
SCRIPT_REPORT="https://burixon.dev/bugreport/#$SCRIPT_NAME"
SHOW_BANNER=true
ASCI_RETURN="\e[0m"
CACHE_DIR="$HOME/.cache/BuriXon-code/Termux-WiFi-map"
CACHE_FILE="$CACHE_DIR/wifi_scan_cache.jsonl"
LOCATION_FILE="$CACHE_DIR/wifi_scan_last_loc.env"
OUI_FILE="$CACHE_DIR/oui.lst"
PROVIDER="network"
DELAY=10
ZERO_DELAY=false
DO_VIBRATE=true
EXIT_ON_FAIL=false
TRY_PREV_LOC=false
CONTINUOUS=false
AP_COUNT=0
GPS_TIMEOUT=10
H_ENGINE="TERMUX"
H_ENGINE_SET=false
FROM_ALIAS=false
SAVE_OVERRIDE=false
DO_SAVE=false
SAVE_FILE=""
SAVE_FMT=""
SAVE_EXT=""
SAVE_KML_NAME="$SCRIPT_NAME v$SCRIPT_VERSION (c) by $SCRIPT_AUTHOR_ALIAS"
CACHE_LIST=false
CACHE_PURGE=false
CACHE_COUNT=false
JSON_LIST=false
CACHE_SEARCH=false
SEARCH_PATTERN=""
OUI_SEARCH=false
SEARCH_VENDOR=""
DO_VALID=false
VALID_FILE=""
DO_MERGE=false
MERGE_1=""
MERGE_2=""
CHECK_UPDATE=false
FOUND_VERSION=""
GREEN="\e[38;5;120m"
RED="\e[38;5;203m"
YELLOW="\e[38;5;229m"
RESET="\e[0m"
# Messages
error() {
echo -e "\r\e[1;31m[ERR!]\e[0m $*\e[K" >&2
}
success() {
echo -e "\r\e[1;32m[DONE]\e[0m $*\e[K"
}
info() {
echo -e "\r\e[1;33m[INFO]\e[0m $*\e[K"
}
placeholder() {
info "Not implemented yet..."
}
show_help() {
version_info
#TODO
echo -e "
\e[1;36m[Usage]\e[0m $SCRIPT_COMMAND [D] [mode] [options]
\e[1;36m[Modes]\e[0m
R|-R|--run Start scanning and saving scanned WiFi networks to cache.
S|-S|--save Save collected data to the chosen format (JSON, CSV, KML etc.).
C|-C|--cache Manage data in cache (list of known networks).
V|-V|--check Check the correctness of the given file structure.
M|-M|--merge Merge two KML files into one.
A|-A|--alias Manage fast-access command aliases.
D|-D|--debug Enable debugging info (outputs).
N|-N|--nobanner Disable banner display on startup.
-v|--version Display short info about the script version and exit.
-i|--version-info Displays detailed info about the script and exit.
--report Open bug-report page.
--update Check for script version updates.
-h|--help Displays information about options and script usage and exit.
[alias name] Run the selected alias (if exists).\n
\e[1;36m[Options]\e[0m
\e[36m[RUN]\e[0m
-p|--provider [option] Set GPS provider [gps|network|passive] (default: gps)
-d|--delay [value] Set delay between scans in seconds [int. 0-3600] (default: 10)
-c|--countinuous Set working mode to continuous (default: false)
-q|--quiet Disable vibration/outputs during scanning (default: false)
-v|--haptic-engine [option] Set up the haptic engine [bell|termux] (default: termux-vibrate)
-l|--last-location Use last known location in case of Termux:API error.
-t|--timeout [value] Set the timeout for location retrieval [1-3600] (default: 10)
-e|--exit-on-fail Exit on Termux:API error (default: false)\n
\e[36m[SAVE]\e[0m
-n|--name [filename] Declare filename to save
-f|--format [option] Declare chosen output format [json|pjson|jsonl|csv|kml]
-o|--override Allow overwriting an existing file
-k|--kml-name [name] Allow to set the name of the kml document\n
\e[36m[CACHE]\e[0m
-l|--list List all known APs (pretty but slow)
-j|--json List all known APs as JSON (fast)
-c|--count Display the number of all known APs
-s|--search [pattern] Search the given (comma-separated) phrases in the AP data
-p|--purge Clear the list of all known APs\n
\e[36m[ALIAS]\e[0m
-a|--add [name] [options] Add a new command alias/shortcut by specifying the name and target parameters
-l|--list [name] List the created aliases/shortcuts along with their contents (specified or all)
-e|--edit [name] Edit the selected alias. The editing is done in the default text editor
-d|--delete [name] Delete the selected alias/shortcut. This operation cannot be undone
-r|--run [name] Run the selected alias
-b|--bin [name] Create exec symlink in \$PATH directory
-u|--unbin [name] Remove existing scripts symlink
[name] Run the selected alias.\n
\e[36m[CHECK]\e[0m
/path/to/file Path to the file to check\n
\e[36m[MERGE]\e[0m
file1.kml file2.kml Paths to (2) files to merge\n
\e[1;36m[Examples]\e[0m
Scan once:
$SCRIPT_COMMAND -R\n
Continous scanning with 5s delay:
$SCRIPT_COMMAND --run -d 5 -c\n
Save DB to file.kml file:
$SCRIPT_COMMAND -S -n file -f kml\n
Override existing file.json file:
$SCRIPT_COMMAND S -n file -f json -o\n
List all cached APs:
$SCRIPT_COMMAND -C -l\n
Search for phrases 'WiFi' and 'AP':
$SCRIPT_COMMAND -C -s \"WiFi,AP\"\n
Check file.json integrity:
$SCRIPT_COMMAND V file.json\n
Merge 'map1.kml' with 'map2.kml':
$SCRIPT_COMMAND M map1.kml map2.kml\n
Create new loop-scan alias \"run\":
$SCRIPT_COMMAND A -a run R -c -d 5 -t 5 -q\n
Run created \"run\" alias:
$SCRIPT_COMMAND run
$SCRIPT_COMMAND A run\n
Show informations about script:
$SCRIPT_COMMAND --version-info\n
\e[1;36m[File formats]\e[0m
JSON Classic single-line (compact) JSON
PJSON Pretty formatted JSON
JSONL Newline-delimited JSON
CSV Comma-separated values
KML Format for representing points on maps\n
\e[1;36m[Return codes]\e[0m
Code 1 - invalid input/option/value - the provided parameter or parameter value is invalid;
Code 2 - dependency error - required dependencies are missing;
Code 3 - cache error - error while creating the cache/database directory or cache empty/unreadable;
Code 4 - termux-api error - Termux API error, error retrieving location, scanning networks, enabling Wi-Fi, or restarting the API;
Code 5 - input/outout file error - file read or write error, error exporting data.
Code 6 - invalid input pattern - no results match the selected pattern;
Code 7 - processing error - error while pricessing raw data;
Code 8 - empty cache - attempted operation on non-existent data;
Code 9 - problem with alias file - something went wrong with the alias configuration file;
"
exit 0
}
banner() {
$SHOW_BANNER || return 0
stty -echo
CWIFI="\e[38;5;9m"
CBLU="\e[1;38;5;75m"
CRED="\e[1;38;5;9m"
CLINK="\e[1;4;36m"
CRESET="\e[0m"
print_logo_gt65() {
echo -e "\e[?7l\e[?25l
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⣀⣤⣶⣿⠷⠾⠛⠛⠛⠛⠷⠶⢶⣶⣤⣄⡀⠀⠀⠀⠀⠀⠀
${CWIFI}⠀⠀⠀⠀⣀⣴⡾⠛⠉⠁⠀ ⠀⠉⠛⠿⣷⣄⡀⠀⠀⠀${CBLU} _____ \e[K
${CWIFI}⠀⠀⣠⣾⠟⠁⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠈⠛⢿⣦⡀ ${CBLU}⠀|_ _|___ ___ _____ _ _ _ _ \e[K
${CWIFI}⢠⣼⠟⠁⠀⠀⠀⠀⣠⣴⣶⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⠀⠀⠀⠀⠀⠙⣧⡀${CBLU} | | | -_| _| | | |_'_| \e[K
${CWIFI}⣿⡇⠀⠀⠀⢀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⢈⣷${CBLU} |_| |___|_| |_|_|_|___|_,_| \e[K
${CWIFI}⣿⣿⣦⡀⣠⣾⣿⣿⣿⡿⠟⠛⠁⠁⠁⠁⠁⠁⠛⠻⢿⣿⣿⣿⣿⣆⣀⣠⣾⣿${CBLU} \e[K
${CWIFI}⠉⠻⣿⣿⣿⣿⣽⡿⠋⠀⠀ ⠀⠀⠉⠻⣿⣿⣿⣿⣿⠟⠁${CRED} _ _ _ _ _____ _ \e[K
${CWIFI}⠀⠀⠈⠙⠛⣿⣿⠀⠀⠀⠀ ⠀⠀⠀⠀ ⠀⣹⣿⡟⠋⠁⠀⠀${CRED} | | | |_| __|_|${CBLU}___ _____ ___ ___ \e[K
${CWIFI}⠀⠀⠀⠀⠀⢿⣿⣷⣄⣀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣷⣀⣀⣾⣿⣿⠇⠀⠀⠀⠀${CRED} | | | | | __| |${CBLU}___| | .'| . |\e[K
${CWIFI}⠀⠀⠀⠀⠀⠈⠻⢿⣿⣿⣿⣿⣿⠟⠛⠛⠻⣿⣿⣿⣿⣿⡿⠛⠉⠀⠀⠀⠀⠀${CRED} |_____|_|__| |_|${CBLU} |_|_|_|__,| _|\e[K
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠁⣿⡇⠀⠀⠀⠀⢸⣿⡏⠙⠋⠁⠀⠀⠀⠀⠀⠀⠀${CRED} ${CBLU} |_| \e[K
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⣄⠀⠀⣀⣾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⠀⠀ ${ANIM1}\e[K
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀ ${ANIM2}\e[K\e[?7h
\e[16A"
}
print_logo_lt65() {
echo -e "\e[?7l\e[?25l
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⣀⣤⣶⣿⠷⠾⠛⠛⠛⠛⠷⠶⢶⣶⣤⣄⡀⠀⠀⠀⠀⠀⠀
${CWIFI}⠀⠀⠀⠀⣀⣴⡾⠛⠉⠁⠀ ⠀⠉⠛⠿⣷⣄⡀⠀⠀⠀
${CWIFI}⠀⠀⣠⣾⠟⠁⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠈⠛⢿⣦⡀
${CWIFI}⢠⣼⠟⠁⠀⠀⠀⠀⣠⣴⣶⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⠀⠀⠀⠀⠀⠙⣧⡀
${CWIFI}⣿⡇⠀⠀⠀⢀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⢈⣷
${CWIFI}⣿⣿⣦⡀⣠⣾⣿⣿⣿⡿⠟⠛⠁⠁⠁⠁⠁⠁⠛⠻⢿⣿⣿⣿⣿⣆⣀⣠⣾⣿
${CWIFI}⠉⠻⣿⣿⣿⣿⣽⡿⠋⠀⠀ ⠀⠀⠉⠻⣿⣿⣿⣿⣿⠟⠁
${CWIFI}⠀⠀⠈⠙⠛⣿⣿⠀⠀⠀⠀ ⠀⠀⠀⠀ ⠀⣹⣿⡟⠋⠁⠀⠀
${CWIFI}⠀⠀⠀⠀⠀⢿⣿⣷⣄⣀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣷⣀⣀⣾⣿⣿⠇⠀⠀⠀⠀
${CWIFI}⠀⠀⠀⠀⠀⠈⠻⢿⣿⣿⣿⣿⣿⠟⠛⠛⠻⣿⣿⣿⣿⣿⡿⠛⠉⠀⠀⠀⠀⠀
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠁⣿⡇⠀⠀⠀⠀⢸⣿⡏⠙⠋⠁⠀⠀⠀⠀⠀⠀⠀
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⣄⠀⠀⣀⣾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀
${CWIFI}⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⠀⠀
${CBLU} _____ \e[K
${CBLU}⠀|_ _|___ ___ _____ _ _ _ _ \e[K
${CBLU} | | | -_| _| | | |_'_| \e[K
${CBLU} |_| |___|_| |_|_|_|___|_,_| \e[K
${CBLU} \e[K
${CRED} _ _ _ _ _____ _ \e[K
${CRED} | | | |_| __|_|${CBLU}___ _____ ___ ___ \e[K
${CRED} | | | | | __| |${CBLU}___| | .'| . |\e[K
${CRED} |_____|_|__| |_|${CBLU} |_|_|_|__,| _|\e[K
${CRED} ${CBLU} |_| \e[K\n
⠀ ${ANIM1}\e[K
${ANIM2}\e[K\e[?7h
\e[28A"
}
ANIM1_FULL=" >>> Made by BuriXon-code <<<"
ANIM2_FULL=" >>> https://burixon.dev/ <<< "
for ((i=1; i<=${#ANIM1_FULL}+${#ANIM2_FULL}; i++)); do
ANIM1=""
ANIM2=""
for ((j=0; j<${#ANIM1_FULL}; j++)); do
c="${ANIM1_FULL:j:1}"
if (( j == i-1 )); then
ANIM1+="\e[1;38;5;228m${c}${CRESET}"
elif (( j < i-1 )); then
if (( j >= 14 && j <= 27 )); then
ANIM1+="${CWIFI}${c}${CRESET}"
else
ANIM1+="${CBLU}${c}${CRESET}"
fi
else
ANIM1+=" "
fi
done
if (( i > ${#ANIM1_FULL} )); then
k=$((i-${#ANIM1_FULL}-1))
for ((j=0; j<${#ANIM2_FULL}; j++)); do
c="${ANIM2_FULL:j:1}"
if (( j == k )); then
ANIM2+="\e[1;38;5;228m${c}${CRESET}"
elif (( j < k )); then
if (( j >= 7 && j <= 26 )); then
ANIM2+="${CLINK}${c}${CRESET}"
else
ANIM2+="${CBLU}${c}${CRESET}"
fi
else
ANIM2+=" "
fi
done
fi
if [ `tput cols` -lt 65 ]; then
ASCI_RETURN="\e[29B"
print_logo_lt65 >&2
else
ASCI_RETURN="\e[17B"
print_logo_gt65 >&2
fi
#sleep 0 # zero for minimal delay
done
stty echo
}
version_info() {
banner
echo -e "${ASCI_RETURN}"
info "$SCRIPT_NAME v$SCRIPT_VERSION (c) $SCRIPT_V_R_DATE $SCRIPT_AUTHOR"
}
about_info() {
#TODO
version_info
echo -e "
\e[1;36m[About]\e[0m The script \e[1m$SCRIPT_COMMAND_O\e[0m, which is the main executable component of the Termux-WiFi-map project, is a tool that allows you to build a database of WiFi networks in your surroundings directly in Termux.\n
\e[1;36m[Options]\e[0m Among the available options, you can find:
+ scanning with various options
+ saving collected data to JSON, CSV, KML files
+ combining multiple KML files into one
+ validating files created by the script
+ automatic updates
+ clear return codes
\e[1;36m[Changelog]\e[0m:
[1.0] - Initial Release
This is the very first official release of Termux-WiFi-map.
It marks the initial version of the tool, providing basic WiFi scanning, data saving, and validation features.
Future updates will expand functionality and improve usability.
[2.0] - Major functionality update
This is the second release of the script which, due to the number of introduced changes, received a separate major release.
This version introduces many improvements, fixes errors and imperfections detected in the previous version and adds a range of new options and functionalities.
The most important implementations in this version include:
+ Fixing errors during data parsing by jq - in some Termux and termux-api installations the termux-api command incorrectly intercepted standard streams which caused corrupted JSON to be sent to jq;
+ Ability to choose a haptic engine - the user can select the vibration engine (termux-api or system bell) through appropriate CLI parameters;
+ Ability to list saved Access Points in raw JSON form - the previous formatted output generated for a very long time for large AP databases;
+ Ability to search the collected database - the user can search for specific phrases or strings in the database;
+ Ability to export specific searches - the user can export to one of the available formats those APs that were previously found.
[2.1] - Funcionality update
This update adds an option to use the previously known location if a location update fails. Useful, among others, when scanning inside buildings.
[2.2] - Functionality update
This version introduces many improvements and simplifications for the user. The most important ones include:
+ An option to interactively select the operating mode without the need to enter long CLI parameters;
+ An option to create dynamic aliases/shortcuts for options, allowing you to avoid typing long CLI parameters;
+ The ability to set a custom timeout for location retrieval from termux-api (useful when GPS signal is unstable);
+ Added debugging options (first parameter: \"D\").
[2.3] - Fixed one minor bug:
+ Slight line shifting during interactive export to KML.
[2.4] - Fixed two reported bugs:
+ Problem parsing args $(basename $0) -A <aliasname> for non-existent aliasname.
+ -v --version option started an infinite loop.
+ Additionally: Checking if the alias aliasname is readable.
[2.5] - Added \'nobanner\' option:
+ An option has been added to disable the banner display on startup.
[2.6] - Fix banner:
+ Removed the delay between banner animation frames. The banner now renders faster.
[2.6.1] - Fix URL open:
+ Minor change for opening project page.
[2.7] - Fix KML exporting:
+ Fixed a user-noted bug where ANSI cleanup sequences were being written to the file during resize during export. A file descriptor change was necessary.
[3.0] - A huge dose of improvements [not released yet]:
+ New option to merge KML files;
+ New script auto-update option;
+ New unified return codes:
++ sorted 10..50 by category/type;
++ precise, punctual;
\e[1;36m[License]\e[0m The script is released under the GPLv3 license.\n
This license allows you to freely use, modify, and distribute the script, even for commercial purposes, as long as any distributed versions also remain under GPLv3. \n
It does not allow you to take the script and release it under a different proprietary license, nor does it remove the requirement to share the source code of any modified versions.\n
Visit \e[1;4;36mhttps://www.gnu.org/licenses/gpl-3.0.html\e[0m\e[K for more info.\n
\e[1;36m[URL]\e[0m If you appreciate my work, consider making a donation at: \e[1;4;36m$SCRIPT_DONATE\e[0m\e[K\n
\e[1;36m[URL]\e[0m To report an error visit the page: \e[1;4;36m$SCRIPT_REPORT\e[0m\e[K\n
\e[1;36m[URL]\e[0m More information about the script's functionality, version changes, usage, and tips can be found at: \e[1;4;36m$SCRIPT_PAGE\e[0m\e[K\n
"
# Webpage
info "Open page now? [y/N] "
read -rn1 answer
case "$answer" in
y)
echo -en "\e[1A\e[K"
info "Selecting browser..."
open_page $SCRIPT_PAGE
success "Done."
;;
*)
info "Selected: $answer"
info "Aborting."
;;
esac
SHOW_BANNER=false
show_help
}
by_termux() {
if command -v termux-open-url &>/dev/null; then
termux-open-url "${1}?FROM_CLI"
else
error "Cannot open link."
exit 1
fi
}
open_page() {
local page="$1"
local vnc_proc vnc_pid browser
for b in firefox firefox-esr chromium brave google-chrome midori qutebrowser netsurf; do
if command -v "$b" >/dev/null 2>&1; then
browser="$b"
break
fi
done
if ps -e | grep -iE 'vnc|tigervnc|vncserver' | grep -v grep &>/dev/null; then
if ls "$HOME/.vnc/"*.pid &>/dev/null; then
if [ -n "$browser" ] && [ -n "${DISPLAY:-}" ]; then
"$browser" "$page" &>/dev/null & disown
else
by_termux "$page"
fi
else
by_termux "$page"
fi
else
by_termux "$page"
fi
}
# Traps
on_exit() {
code=$?
echo -en "\e[0m\e[?25h\e[?7h"
if $FROM_ALIAS && [ $code -eq 1 ]; then
info "Some of alias parameters may be incorrect. Use -h|--help to find out."
fi
if [ $code -ne 0 ]; then
info "Return code: $code\e[J"
fi
stty echo
echo
}
trap on_exit EXIT
on_abort() {
code=$?
if [[ $code -eq 0 ]]; then
code=$2
fi
error "Operation aborted by $1 signal."
exit "$code"
}
trap "on_abort SIGINT 130" SIGINT
trap "on_abort SIGTERM 143" SIGTERM
trap "on_abort SIGHUP 129" SIGHUP
trap "on_abort SIGHUP 131" SIGQUIT
# Parse args
parse_args() {
if [ $# -lt 1 ]; then
banner
echo -e "${ASCI_RETURN}"
info "Select work mode:"
menu_select MODE "RUN - scan mode" "SAVE - export mode" "CACHE - DB management" "ABORT"
success "Selected work mode: $MODE"
case "$MODE" in
RUN*)
local ASK_HAPTIC=false
local ASK_DELAY=false
local ASK_ERROR=false
info "Run in loop?"
menu_select LOOP YES NO ABORT
case $LOOP in
YES) CONTINUOUS=true; success "Work in loop"; ASK_DELAY=true; ASK_ERROR=true ;;
NO) CONTINUOUS=false; success "Scan once" ;;
ABORT) info Aborting.; exit 0 ;;
*) error Invalid option $LOOP. How did you do that?; exit 1 ;;
esac
if $ASK_DELAY; then
echo -en "\e[?25h\r\e[1;33m[INFO]\e[0m Enter delay value [0-3600]s: \e[K"
IFS=" " read -r DELAY GARBAGE
if [[ ! "$DELAY" =~ ^[0-9]+$ ]] || [ $DELAY -gt 3600 ]; then
error "Delay value must be 0-3600s."
exit 1
fi
echo -e "\e[2A\e[?25l"
success "Delay value: ${DELAY}s"
fi
echo -en "\e[?25h\r\e[1;33m[INFO]\e[0m Enter location fetching timeout [1-3600]s: \e[K"
IFS=" " read -r GPS_TIMEOUT GARBAGE
if ! [[ "$GPS_TIMEOUT" =~ ^[0-9]+$ ]] || \
[ "$GPS_TIMEOUT" -lt 1 ] || \
[ "$GPS_TIMEOUT" -gt 3600 ]; then
error "Timeout value must be 1-3600."
exit 1
fi
echo -e "\e[2A\e[?25l"
success "Timeout value: ${GPS_TIMEOUT}s"
if $ASK_ERROR; then
info "What to do on timeout?"
menu_select ON_TIMEOUT "EXIT ON TIMEOUT" "USE PREVIOUS LOCATION" "NONE OF ABOVE" "ABORT"
case "$ON_TIMEOUT" in
EXIT*) EXIT_ON_FAIL=true; success "Exit on timeout" ;;
USE*) TRY_PREV_LOC=true; success "Use previous location" ;;
NONE*) success "Run w/o error handler" ;;
ABORT) info Aborting.; exit 0 ;;
*) error Invalid option $ASK_ERROR. How did you do that?; exit 1 ;;
esac
fi
info "Run in quiet mode?"
menu_select QUIET "YES" "NO" "ABORT"
case $QUIET in
YES) DO_VIBRATE=false; AP_COUNT=0; success "Quiet run" ;;
NO) DO_VIBRATE=true; success "Full output run"; ASK_HAPTIC=true ;;
ABORT) info Aborting.; exit 0 ;;
*) error Invalid option $QUIET. How did you do that?; exit 1 ;;
esac
if $ASK_HAPTIC; then
info "Choose vibrations engine:"
menu_select H_ENGINE "TERMUX" "BELL" "EXIT"
if [[ "$H_ENGINE" == "EXIT" ]]; then
info Aborting.
exit 0
fi
success "Vibrations engine: $H_ENGINE"
fi
info "Select location provider:"
menu_select LOCATION_PROVIDER GPS NETWORK PASSIVE ABORT
case $LOCATION_PROVIDER in
GPS) PROVIDER="gps" ;;
NETWORK) PROVIDER="network" ;;
PASSIVE) PROVIDER="passive" ;;
ABORT) info Aborting.; exit 0 ;;
*) error Invalid option $LOCATION_PROVIDER. How did you do that?; exit 1 ;;
esac
success "Location provider: $LOCATION_PROVIDER\n"
info "Configuration ready."
info "Press any key to continue or CTRL+C to abort...\n"
read -rsn1 any_key
info Starting...
while :; do
scan_once || error "Scan error."
$CONTINUOUS || break
if ! $ZERO_DELAY; then
sleep "$DELAY"
fi
done
;;
SAVE*)
local ASK_KML=false
DO_SAVE=true
info "Select target file format:"
menu_select FORMAT JSON "PRETTY JSON" JSONL CSV KML ABORT
case "$FORMAT" in
KML) ASK_KML=true; SAVE_FMT=kml; EXT="$SAVE_FMT" ;;
CSV) SAVE_FMT=csv; EXT="$SAVE_FMT" ;;
JSON) SAVE_FMT=json; EXT="$SAVE_FMT" ;;
JSONL) SAVE_FMT=jsonl; EXT="$SAVE_FMT" ;;
PRETTY*) SAVE_FMT=pjson; EXT=json ;;
ABORT) info Aborting.; exit 0 ;;
*) error Invalid option $FORMAT. How did you do that?; exit 1 ;;
esac
success "Format: $FORMAT [#.$EXT]"
echo -en "\e[?25h\r\e[1;33m[INFO]\e[0m Enter target filename [w/o extension]: \e[K"
IFS= read -r SAVE_FILE
echo -e "\e[2A\e[?25l"
success "Filename: ${SAVE_FILE}.${EXT}"
if $ASK_KML; then
info "Select KML Document name:"
menu_select KMLNAME DEFAULT CUSTOM ABORT
case $KMLNAME in
DEFAULT) SAVE_KML_NAME="$SAVE_KML_NAME" ;;
CUSTOM)
success "Selected name: $KMLNAME"
echo -en "\e[?25h\r\e[1;33m[INFO]\e[0m Enter KML Document name: \e[K"
IFS= read -r NEW_SAVE_KML_NAME
echo -e "\e[2A\e[?25l"
if [ -z "$NEW_SAVE_KML_NAME" ]; then
error Using default KML Document name.
SAVE_KML_NAME="$SAVE_KML_NAME"
else
SAVE_KML_NAME="$NEW_SAVE_KML_NAME"
fi
;;
ABORT) info Aborting.; exit 0 ;;
*) error Invalid option $KMLNAME. How did you do that?; exit 1 ;;
esac
success "KML Document name: $SAVE_KML_NAME"
fi
if [ -f "${SAVE_FILE}.${EXT}" ]; then
info "File exists. Override?:"
menu_select OVERRIDE YES NO
case $OVERRIDE in
YES) success Writing new data to file.; SAVE_OVERRIDE=true ;;
NO) error File exists. Aborting.; exit 1 ;;
*) error Invalid option $OVERRIDE. How did you do that?; exit 1 ;;
esac
else
success Writing new data to file.; SAVE_OVERRIDE=true
fi
do_save
exit 0
;;
CACHE*)
JSON_LIST=false
info "Select operation:"
menu_select CACHE_OP "List in pretty format [slow]" "List in JSON [fast]" "Count data records" "Search for patterns" "Purge all database contents" ABORT
case "$CACHE_OP" in
List\ in\ pretty*) success "Listing..."; list_cache; exit 0 ;;
List\ in\ JSON*) success "Listing..."; JSON_LIST=true; list_cache; exit 0 ;;
Count*) success "Counting..."; count_cache; exit 0 ;;
Search*)
info "Enter search patterns one-by-one bellow."
info "Enter empty to finish."
PATTERNS=""
CYCLE=1
until [ "$CYCLE" -gt 10 ]; do
ERROR=false
echo -en "\e[?25h\r\e[1;33m[INFO]\e[0m Enter phrase to find: \e[K"
IFS=" " read -r PHRASE GARBAGE
echo -en ,"\e[1A\e[?25l"
if [ -n "$GARBAGE" ] || [[ "$PHRASE" =~ [,] ]]; then
error "Need 1 phrase without spaces or commas."
ERROR=true
elif [ -z "$PHRASE" ]; then
success "Empty. Finishing."
break
else
success "Pattern $CYCLE: $PHRASE"
PHRASE="$PHRASE,"
PATTERNS="${PHRASE}${PATTERNS}"
fi
if ! $ERROR; then ((CYCLE++)); fi
done
success "Got $((CYCLE-1)) patterns: $PATTERNS"
if [ -z "$PATTERNS" ]; then
error "Empty..."
exit 1
fi
DO_SAVE=true
SEARCH_PATTERN="$PATTERNS"
search_cache
;;
#TODO VENDOR
Purge*) success "Selected: ${CACHE_OP}..."; purge_cache ;;
ABORT) info Aborting.; exit 0 ;;
*) error Invalid option $CACHE_OP. How did you do that?; exit 1 ;;
esac
;;
ABORT) info Aborting.; exit 0 ;;
*) error "Invalid option $MODE"; exit 1 ;;
esac
exit 0
fi
until [ $# -eq 0 ]; do
case $1 in
D|-D|--debug) set -x; shift; echo $@ ;;
N|-N|--nobanner) SHOW_BANNER=false; shift ;;
R|-R|--run)
shift
if [ $# -gt 10 ]; then
error "Too many parameters."
info "Try to use -h|--help for more info."
exit 1
fi
until [ $# -eq 0 ]; do
case $1 in
-p|--provider)
PROVIDER="$2"
[[ "$PROVIDER" =~ ^(gps|network|passive)$ ]] || {
error "Provider must be gps|network|passive"
exit 1
}
shift 2
;;
-c|--countinuous)
CONTINUOUS=true
shift
;;
-d|--delay)
DELAY="$2"
if [[ "$DELAY" == "0" ]]; then
ZERO_DELAY=true
fi
if ! $ZERO_DELAY; then
if ! [[ "$DELAY" =~ ^[0-9]+$ ]] || \
[ "$DELAY" -lt 1 ] || \
[ "$DELAY" -gt 3600 ]; then
error "Delay value must be 0-3600s."
exit 1
fi
fi
shift 2
;;
-t|--timeout)
GPS_TIMEOUT="$2"
if ! [[ "$GPS_TIMEOUT" =~ ^[0-9]+$ ]] || \
[ "$GPS_TIMEOUT" -lt 1 ] || \
[ "$GPS_TIMEOUT" -gt 3600 ]; then
error "Timeout value must be 1-3600."
exit 1
fi
shift 2
;;
-q|--quiet)
if $H_ENGINE_SET; then error "Cannot set haptic engine if running quiet run."; exit 1; fi
echo -e "\e[2A"; info "Quiet run..."; echo
DO_VIBRATE=false
shift
;;
-v|--haptic-engine)
H_ENGINE_SET=true
if ! $DO_VIBRATE; then error "Cannot set haptic engine if running quiet run."; exit 1; fi
case $2 in
bell) H_ENGINE="BELL" ;;
termux) H_ENGINE="TERMUX" ;;
*) error "Invalid haptic engine: $2"; exit 1 ;;
esac
shift 2
;;
-e|--exit-on-fail)
$TRY_PREV_LOC && {
error Cannot combine -e and -l.
exit 1
}
EXIT_ON_FAIL=true
shift
;;
-l|--prev-location)
$EXIT_ON_FAIL && {
error Cannot combine -e and -l.
exit 1
}
TRY_PREV_LOC=true
shift
;;
*)
error "Invalid parameter: $1"
info "Try to use -h|--help for more info."
exit 1
;;
esac
done
;;
C|-C|--cache)
shift
if [ $# -gt 2 ]; then
error "Too many parameters."
info "Try to use -h|--help for more info."
exit 1
elif [ $# -lt 1 ]; then
error "The required parameter is missing."
info "Try to use -h|--help for more info."
exit 1
fi
until [ $# -eq 0 ]; do
case $1 in
-l|--list)
CACHE_LIST=true
shift
;;
-j|--json)
CACHE_LIST=true
JSON_LIST=true
shift
;;
-p|--purge)
CACHE_PURGE=true
shift
;;
-c|--count)
CACHE_COUNT=true
shift
;;
-s|--search)
CACHE_SEARCH=true
SEARCH_PATTERN="$2"
shift 2
;;
-v|--vendor)
OUI_SEARCH=true
SEARCH_VENDOR="$2"
shift 2
;;
*)
error "Invalid parameter: $1"
info "Try to use -h|--help for more info."
exit 1
;;
esac
done
;;
S|-S|--save)
shift
if [ $# -gt 7 ]; then
error "Too many parameters."
info "Try to use -h|--help for more info."
exit 1
elif [ $# -lt 2 ]; then
error "The required parameter is missing."
info "Try to use -h|--help for more info."
exit 1
fi
DO_SAVE=true
until [ $# -eq 0 ]; do
case $1 in
-n|--name)
SAVE_FILE="$2"
shift 2
;;
-f|--format)
SAVE_FMT="$2"
shift 2
;;
-o|--override)
SAVE_OVERRIDE=true
shift
;;
-k|--kml-name)
SAVE_KML_NAME="$2"
shift 2
;;
*)
error "Invalid parameter: $1"
info "Try to use -h|--help for more info."
exit 1
;;
esac
done
if $DO_SAVE; then
if [ -z "$SAVE_FILE" ] || [ -z "$SAVE_FMT" ]; then
error "The required parameter is missing."
info "Try to use -h|--help for more info."
exit 1
fi
fi
;;
A|-A|--alias)
shift
if [ $# -lt 1 ]; then error Must specify alias-mode; exit 1; fi
case $1 in
-a|--add) shift; alias_mod add $* ;;
-l|--list) shift; alias_mod list $* ;;
-e|--edit) shift; alias_mod edit $* ;;
-d|--delete) shift; alias_mod delete $* ;;
-r|--run) shift; alias_run $* ;;
-b|--bin)
shift
TARGET_BIN="$1"
if [ $# -ne 1 ] || [ -z "$1" ]; then
error Must specify target linkname.
exit 1
fi
if [ -e "$PREFIX/bin/$TARGET_BIN" ] || command -v "$1" &>/dev/null; then
error Executable/command $1 already exits. Use another name.
exit 1
fi
if [[ `dirname $0` != "$PREFIX/bin" ]]; then
error Command must be located in $PATH to create bin alias.
fi
ln -s "$0" "$PREFIX/bin/$TARGET_BIN" &>/dev/null || {
error Cannot create symlink $TARGET_BIN.
exit 5
}
success Link created. Try to run \"$TARGET_BIN\".
echo "$TARGET_BIN" >> "$CACHE_DIR/alias/bin.lst"
exit 0
;;
-u|--unbin)
shift
if [ $# -lt 1 ]; then
error Must specify link name to remove.
exit 1
fi
if [ $# -gt 1 ]; then
error Can remove one symlink at once.
exit 1
fi
if [ ! -f "$CACHE_DIR/alias/bin.lst" ]; then
error Linkname cache file does not exists.
exit 3
fi
if ! grep -Fxq "$1" "$CACHE_DIR/alias/bin.lst"; then
error No such symlink $1.
exit 6
else
LINK_TARGET=`readlink -f "$PREFIX/bin/$1"`
if [[ "$LINK_TARGET" != "$0" ]] || [[ "$LINK_TARGET" != "$PREFIX/bin/$SCRIPT_COMMAND_O" ]]; then
error Script can remove only own symlinks.
exit 5
fi
esc=$(printf '%s\n' "$1" | sed 's/[][\/.^$*]/\\&/g')
if ! sed -i "/^$esc$/d" "$CACHE_DIR/alias/bin.lst"; then
error Cannot update linknames cache.
exit 5
fi
if [ -f "$PREFIX/bin/$1" ]; then
if ! rm "$PREFIX/bin/$1"; then
error Cannot remove symlink $PREFIX/bin/$1.
exit 5
fi
fi
fi
success Symlink removed.
exit 0
;;
-*) error "Invalid parameter: $1"; info "Try to use -h|--help for more info."; exit 1 ;;
*)
if [ -f "$CACHE_DIR/alias/$1.alias" ]; then
alias_run $*
else
error "Invalid parameter: $1"
info "Try to use -h|--help for more info."
exit 1
fi
;;
esac
;;
V|-V|--check)
shift
if [ $# -gt 1 ]; then
error "Too many parameters."
info "Try to use -h|--help for more info."
exit 1
elif [ $# -lt 1 ]; then
error "The required parameter is missing."
info "Try to use -h|--help for more info."
exit 1
fi
until [ $# -eq 0 ]; do
case $1 in
-*)
error "Invalid parameter: $1"
info "Try to use -h|--help for more info."
exit 1
;;
*)
VALID_FILE="$1"
shift
DO_VALID=true
;;
esac
done
;;
M|-M|--merge)
shift
if [ $# -gt 2 ]; then
error "Too many parameters."
info "Try to use -h|--help for more info."
exit 1
elif [ $# -lt 2 ]; then
error "The required parameter is missing."
info "Try to use -h|--help for more info."
exit 1
fi
for arg in "$@"; do
case "$arg" in
-*)
error "Invalid parameter: $1"
info "Try to use -h|--help for more info."
exit 1
;;
esac
done
MERGE_1="$1"
MERGE_2="$2"
shift 2
DO_MERGE=true
;;
-h|--help)
show_help
;;
-v|--version)
version_info
exit 0
;;
-i|--version-info)
about_info
;;
--report)
info "Selecting browser..."
open_page $SCRIPT_REPORT
success "Done."
exit 0
;;
--update)
shift
CHECK_UPDATE=true
;;
*)
if [ $# -eq 1 ]; then
if [ -f "$CACHE_DIR/alias/$1.alias" ]; then
alias_run $1
else