forked from KittyKatt/screenFetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenfetch-dev
executable file
·6471 lines (6199 loc) · 238 KB
/
screenfetch-dev
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
# screenFetch - a CLI Bash script to show system/theme info in screenshots
# Copyright (c) 2010-2019 Brett Bohnenkamper <[email protected]>
# 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 <http://www.gnu.org/licenses/>.
# Yes, I do realize some of this is horribly ugly coding. Any ideas/suggestions would be
# appreciated by emailing me or by stopping by http://github.com/KittyKatt/screenFetch. You
# could also drop in on the IRC channel at irc://irc.rizon.net/screenFetch.
# to put forth suggestions/ideas. Thank you.
# Requires: bash 4.0+
# Optional dependencies: xorg-xdpyinfo (resoluton detection)
# scrot (screenshot taking)
# curl (screenshot uploading)
#LANG=C
#LANGUAGE=C
#LC_ALL=C
scriptVersion="3.9.1"
######################
# Settings for fetcher
######################
# This setting controls what ASCII logo is displayed.
# distro="Linux"
# This sets the information to be displayed. Available: distro, Kernel, DE, WM, Win_theme, Theme, Icons, Font, Background, ASCII.
# To get just the information, and not a text-art logo, you would take "ASCII" out of the below variable.
valid_display=(
'distro'
'host'
'kernel'
'uptime'
'pkgs'
'shell'
'res'
'de'
'wm'
'wmtheme'
'gtk'
'disk'
'cpu'
'gpu'
'mem'
)
display=(
'distro'
'host'
'kernel'
'uptime'
'pkgs'
'shell'
'res'
'de'
'wm'
'wmtheme'
'gtk'
'cpu'
'disk'
'gpu'
'mem'
)
# Display Type: ASCII or Text
display_type="ASCII"
# Plain logo
display_logo="no"
# Colors to use for the information found. These are set below according to distribution.
# If you would like to set your OWN color scheme for these, uncomment the lines below and edit them to your heart's content.
# textcolor="\e[0m"
# labelcolor="\e[1;34m"
# Array: WM Process Names
# Order matters!
# Removed WM's: compiz
wmnames=(
'fluxbox'
'openbox'
'blackbox'
'xfwm4'
'metacity'
'kwin'
'twin'
'icewm'
'pekwm'
'flwm'
'flwm_topside'
'fvwm'
'dwm'
'awesome'
'wmaker'
'stumpwm'
'musca'
'xmonad.*'
'i3'
'ratpoison'
'scrotwm'
'spectrwm'
'wmfs'
'wmii'
'beryl'
'subtle'
'e16'
'enlightenment'
'sawfish'
'emerald'
'monsterwm'
'dminiwm'
'compiz'
'Finder'
'herbstluftwm'
'howm'
'notion'
'bspwm'
'cinnamon'
'2bwm'
'echinus'
'swm'
'budgie-wm'
'dtwm'
'9wm'
'chromeos-wm'
'deepin-wm'
'sway'
'mwm'
)
# Array with full Ubuntu release codenames, used so that the script will display
# i.e. "Ubuntu 18.04 LTS (Bionic Beaver)" instead of "Ubuntu 18.04 bionic"
ubuntu_codenames=(
'(Warty Warthog)' # 4.10
'(Hoary Hedgehog)' # 5.04
'(Breezy Badger)' # 5.10
'LTS (Dapper Drake)' # 6.06
'(Edgy Eft)' # 6.10
'(Feisty Fawn)' # 7.04
'(Gutsy Gibbon)' # 7.10
'LTS (Hardy Heron)' # 8.04
'(Intrepid Ibex)' # 8.10
'(Jaunty Jackalope)' # 9.04
'(Karmic Koala)' # 9.10
'LTS (Lucid Lynx)' # 10.04
'(Maverick Meerkat)' # 10.10
'(Natty Narwhal)' # 11.04
'(Oneiric Ocelot)' # 11.10
'LTS (Precise Pangolin)'# 12.04
'(Quantal Quetzal)' # 12.10
'(Raring Ringtail)' # 13.04
'(Saucy Salamander)' # 13.10
'LTS (Trusty Tahr)' # 14.04
'(Utopic Unicorn)' # 14.10
'(Vivid Vervet)' # 15.04
'(Wily Werewolf)' # 15.10
'LTS (Xenial Xerus)' # 16.04
'(Yakkety Yak)' # 16.10
'(Zesty Zapus)' # 17.04
'(Artful Aardvark)' # 17.10
'LTS (Bionic Beaver)' # 18.04
'(Cosmic Cuttlefish)' # 18.10
'(Disco Dingo)' # 19.04
'(Eoan Ermine)' # 19.10
)
# Screenshot Settings
# This setting lets the script know if you want to take a screenshot or not. 1=Yes 0=No
screenshot=
# This setting lets the script know if you want to upload the screenshot to a filehost. 1=Yes 0=No
upload=
# This setting lets the script know where you would like to upload the file to.
# Valid hosts are: teknik, mediacrush, imgur, hmp, and a configurable local.
uploadLoc=
# You can specify a custom screenshot command here. Just uncomment and edit.
# Otherwise, we'll be using the default command: scrot -cd3.
# screenCommand="scrot -cd5"
shotfile=$(printf "screenFetch-%s.png" "$(date +'%Y-%m-%d_%H-%M-%S')")
# Verbose Setting - Set to 1 for verbose output.
verbosity=
# The below function will allow you to add custom lines of text to the screenfetch output.
# It will automatically be executed at the right moment if use_customlines is set to 1.
use_customlines=
customlines () {
# The following line can serve as an example.
# feel free to let the computer generate the output: e. g. using $(cat /etc/motd) or $(upower -d | grep THISORTHAT)
# In the example custom0 line replace <YOUR LABEL> and <your text> with options specified by you.
# Also make sure the $custom0 variable in out_array=... matches the one at the beginning of the line
#
custom0=$(echo -e "$labelcolor YOUR LABEL:$textcolor your text"); out_array=( "${out_array[@]}" "$custom0" ); ((display_index++));
# Battery percentage and time to full/empty:
# (uncomment lines below to use)
#
#custom1=$(echo -e "$labelcolor Battery:$textcolor $(upower -d | grep percentage | head -n1 | cut -d ' ' -f 15-)"); out_array=( "${out_array[@]}" "$custom1" ); ((display_index++));
#if [ "$(upower -d | grep time)" ]; then
# battery_time="$(upower -d | grep time | head -n1 | cut -d ' ' -f 14-) $(upower -d | grep time | head -n1 | cut -d ' ' -f 6-7 | cut -d ':' -f1)"
#else
# battery_time="power supply plugged in"
#fi
#custom2=$(echo -e "$labelcolor $(echo ' `->')$textcolor $battery_time"); out_array=( "${out_array[@]}" "$custom2" ); ((display_index++));
# Display public IP:
#custom3=$(echo -e "$labelcolor Public IP:$textcolor $(curl -s ipinfo.io/ip)"); out_array=( "${out_array[@]}" "$custom3" ); ((display_index++));
###########################################
## MY CUSTOM LINES
###########################################
#custom4=...
}
#############################################
#### CODE No need to edit past here CODE ####
#############################################
# https://github.com/KittyKatt/screenFetch/issues/549
if [[ "${OSTYPE}" =~ "linux" || "${OSTYPE}" == "gnu" ]]; then
# issue seems to affect Ubuntu; add LSB directories if it appears on other distros too
export GIO_EXTRA_MODULES="/usr/lib/x86_64-linux-gnu/gio/modules:/usr/lib/i686-linux-gnu/gio/modules:$GIO_EXTRA_MODULES"
fi
#########################################
# Static Variables and Common Functions #
#########################################
c0=$'\033[0m' # Reset Text
bold=$'\033[1m' # Bold Text
underline=$'\033[4m' # Underline Text
display_index=0
# User options
gtk_2line="no"
# Static Color Definitions
colorize () {
printf $'\033[0m\033[38;5;%sm' "$1"
}
getColor () {
local tmp_color=""
if [[ -n "$1" ]]; then
if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
if [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -gt 1 ]] || [[ ${BASH_VERSINFO[0]} -gt 4 ]]; then
tmp_color=${1,,}
else
tmp_color="$(tr '[:upper:]' '[:lower:]' <<< "${1}")"
fi
else
tmp_color="$(tr '[:upper:]' '[:lower:]' <<< "${1}")"
fi
case "${tmp_color}" in
# Standards
'black') color_ret='\033[0m\033[30m';;
'red') color_ret='\033[0m\033[31m';;
'green') color_ret='\033[0m\033[32m';;
'brown') color_ret='\033[0m\033[33m';;
'blue') color_ret='\033[0m\033[34m';;
'purple') color_ret='\033[0m\033[35m';;
'cyan') color_ret='\033[0m\033[36m';;
'yellow') color_ret='\033[0m\033[1;33m';;
'white') color_ret='\033[0m\033[1;37m';;
# Bolds
'dark grey'|'dark gray') color_ret='\033[0m\033[1;30m';;
'light red') color_ret='\033[0m\033[1;31m';;
'light green') color_ret='\033[0m\033[1;32m';;
'light blue') color_ret='\033[0m\033[1;34m';;
'light purple') color_ret='\033[0m\033[1;35m';;
'light cyan') color_ret='\033[0m\033[1;36m';;
'light grey'|'light gray') color_ret='\033[0m\033[37m';;
# Some 256 colors
'orange') color_ret="$(colorize '202')";; #DarkOrange
'light orange') color_ret="$(colorize '214')";; #Orange1
# HaikuOS
'black_haiku') color_ret="$(colorize '7')";;
#ROSA color
'rosa_blue') color_ret='\033[01;38;05;25m';;
# ArcoLinux
'arco_blue') color_ret='\033[1;38;05;111m';;
esac
[[ -n "${color_ret}" ]] && echo "${color_ret}"
fi
}
verboseOut () {
if [[ "$verbosity" -eq "1" ]]; then
printf '\033[1;31m:: \033[0m%s\n' "$1"
fi
}
errorOut () {
printf '\033[1;37m[[ \033[1;31m! \033[1;37m]] \033[0m%s\n' "$1"
}
stderrOut () {
while IFS='' read -r line; do
printf '\033[1;37m[[ \033[1;31m! \033[1;37m]] \033[0m%s\n' "$line"
done
}
####################
# Color Defines
####################
colorNumberToCode () {
local number="$1"
if [[ "${number}" == "na" ]]; then
unset code
elif [[ $(tput colors) -eq "256" ]]; then
code=$(colorize "${number}")
else
case "$number" in
0|00) code=$(getColor 'black');;
1|01) code=$(getColor 'red');;
2|02) code=$(getColor 'green');;
3|03) code=$(getColor 'brown');;
4|04) code=$(getColor 'blue');;
5|05) code=$(getColor 'purple');;
6|06) code=$(getColor 'cyan');;
7|07) code=$(getColor 'light grey');;
8|08) code=$(getColor 'dark grey');;
9|09) code=$(getColor 'light red');;
10) code=$(getColor 'light green');;
11) code=$(getColor 'yellow');;
12) code=$(getColor 'light blue');;
13) code=$(getColor 'light purple');;
14) code=$(getColor 'light cyan');;
15) code=$(getColor 'white');;
*) unset code;;
esac
fi
echo -n "${code}"
}
detectColors () {
my_colors=$(sed 's/^,/na,/;s/,$/,na/;s/,/ /' <<< "${OPTARG}")
my_lcolor=$(awk -F' ' '{print $1}' <<< "${my_colors}")
my_lcolor=$(colorNumberToCode "${my_lcolor}")
my_hcolor=$(awk -F' ' '{print $2}' <<< "${my_colors}")
my_hcolor=$(colorNumberToCode "${my_hcolor}")
}
supported_distros="ALDOS, Alpine Linux, Amazon Linux, Antergos, Arch Linux (Old and Current Logos), ArcoLinux, Artix Linux, \
blackPanther OS, BLAG, BunsenLabs, CentOS, Chakra, Chapeau, Chrome OS, Chromium OS, CrunchBang, CRUX, \
Debian, Deepin, DesaOS,Devuan, Dragora, elementary OS, EuroLinux, Evolve OS, Sulin, Exherbo, Fedora, Frugalware, Fuduntu, Funtoo, \
Fux, Gentoo, gNewSense, Guix System, Hyperbola GNU/Linux-libre, januslinux, Jiyuu Linux, Kali Linux, KaOS, KDE neon, Kogaion, Korora, \
LinuxDeepin, Linux Mint, LMDE, Logos, Mageia, Mandriva/Mandrake, Manjaro, Mer, Netrunner, NixOS, OBRevenge, openSUSE, \
OS Elbrus, Oracle Linux, Parabola GNU/Linux-libre, Pardus, Parrot Security, PCLinuxOS, PeppermintOS, Proxmox VE, PureOS, Qubes OS, \
Raspbian, Red Hat Enterprise Linux, ROSA, Sabayon, SailfishOS, Scientific Linux, Siduction, Slackware, Solus, Source Mage GNU/Linux, \
SparkyLinux, SteamOS, SUSE Linux Enterprise, SwagArch, TinyCore, Trisquel, Ubuntu, Viperr, Void and Zorin OS and EndeavourOS"
supported_other="Dragonfly/Free/Open/Net BSD, Haiku, Mac OS X, Windows+Cygwin and Windows+MSYS2."
supported_dms="KDE, GNOME, Unity, Xfce, LXDE, Cinnamon, MATE, Deepin, CDE, RazorQt and Trinity."
supported_wms="2bwm, 9wm, Awesome, Beryl, Blackbox, Cinnamon, chromeos-wm, Compiz, deepin-wm, \
dminiwm, dwm, dtwm, E16, E17, echinus, Emerald, FluxBox, FLWM, FVWM, herbstluftwm, howm, IceWM, KWin, \
Metacity, monsterwm, Musca, Gala, Mutter, Muffin, Notion, OpenBox, PekWM, Ratpoison, Sawfish, ScrotWM, SpectrWM, \
StumpWM, subtle, sway, TWin, WindowMaker, WMFS, wmii, Xfwm4, XMonad and i3."
displayHelp () {
echo "${underline}Usage${c0}:"
echo " ${0} [OPTIONAL FLAGS]"
echo
echo "screenFetch - a CLI Bash script to show system/theme info in screenshots."
echo
echo "${underline}Supported GNU/Linux Distributions${c0}:"
echo "${supported_distros}" | fold -s | sed 's/^/\t/g'
echo
echo "${underline}Other Supported Systems${c0}:"
echo "${supported_other}" | fold -s | sed 's/^/\t/g'
echo
echo "${underline}Supported Desktop Managers${c0}:"
echo "${supported_dms}" | fold -s | sed 's/^/\t/g'
echo
echo "${underline}Supported Window Managers${c0}:"
echo "${supported_wms}" | fold -s | sed 's/^/\t/g'
echo
echo "${underline}Supported Information Displays${c0}:"
echo "${valid_display[@]}" | fold -s | sed 's/^/\t/g'
echo
echo "${underline}Options${c0}:"
echo " ${bold}-v${c0} Verbose output."
echo " ${bold}-o 'OPTIONS'${c0} Allows for setting script variables on the"
echo " command line. Must be in the following format..."
echo " 'OPTION1=\"OPTIONARG1\";OPTION2=\"OPTIONARG2\"'"
echo " ${bold}-d '+var;-var;var'${c0} Allows for setting what information is displayed"
echo " on the command line. You can add displays with +var,var. You"
echo " can delete displays with -var,var. Setting without + or - will"
echo " set display to that explicit combination. Add and delete statements"
echo " may be used in conjunction by placing a ; between them as so:"
echo " +var,var,var;-var,var. See above to find supported display names."
echo " ${bold}-n${c0} Do not display ASCII distribution logo."
echo " ${bold}-L${c0} Display ASCII distribution logo only."
echo " ${bold}-N${c0} Strip all color from output."
echo " ${bold}-w${c0} Wrap long lines."
echo " ${bold}-t${c0} Truncate output based on terminal width (Experimental!)."
echo " ${bold}-p${c0} Portrait output."
echo " ${bold}-s [-u IMGHOST]${c0} Using this flag tells the script that you want it"
echo " to take a screenshot. Use the -u flag if you would like"
echo " to upload the screenshots to one of the pre-configured"
echo " locations. These include: teknik, imgur, mediacrush and hmp."
echo " ${bold}-c string${c0} You may change the outputted colors with -c. The format is"
echo " as follows: [0-9][0-9],[0-9][0-9]. The first argument controls the"
echo " ASCII logo colors and the label colors. The second argument"
echo " controls the colors of the information found. One argument may be"
echo " used without the other. For terminals supporting 256 colors argument"
echo " may also contain other terminal control codes for bold, underline etc."
echo " separated by semicolon. For example -c \"4;1,1;2\" will produce bold"
echo " blue and dim red."
echo " ${bold}-a 'PATH'${c0} You can specify a custom ASCII art by passing the path"
echo " to a Bash script, defining \`startline\` and \`fulloutput\`"
echo " variables, and optionally \`labelcolor\` and \`textcolor\`."
echo " See the \`asciiText\` function in the source code for more"
echo " information on the variables format."
echo " ${bold}-S 'COMMAND'${c0} Here you can specify a custom screenshot command for"
echo " the script to execute. Surrounding quotes are required."
echo " ${bold}-D 'DISTRO'${c0} Here you can specify your distribution for the script"
echo " to use. Surrounding quotes are required."
echo " ${bold}-A 'DISTRO'${c0} Here you can specify the distribution art that you want"
echo " displayed. This is for when you want your distro"
echo " detected but want to display a different logo."
echo " ${bold}-E${c0} Suppress output of errors."
echo " ${bold}-V, --version${c0} Display current script version."
echo " ${bold}-h, --help${c0} Display this help."
}
displayVersion () {
echo "${underline}screenFetch${c0} - Version ${scriptVersion}"
echo "Created by and licensed to Brett Bohnenkamper <[email protected]>"
echo "OS X porting done almost solely by shrx (https://github.com/shrx) and John D. Duncan, III (https://github.com/JohnDDuncanIII)."
echo
echo "This is free software; see the source for copying conditions. There is NO warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
}
#####################
# Begin Flags Phase
#####################
case $1 in
--help) displayHelp; exit 0;;
--version) displayVersion; exit 0;;
esac
while getopts ":hsu:evVEnLNtlS:A:D:o:c:d:pa:w" flags; do
case $flags in
h) displayHelp; exit 0 ;;
s) screenshot='1' ;;
S) screenCommand="${OPTARG}" ;;
u) upload='1'; uploadLoc="${OPTARG}" ;;
v) verbosity=1 ;;
V) displayVersion; exit 0 ;;
E) errorSuppress='1' ;;
D) distro="${OPTARG}" ;;
A) asc_distro="${OPTARG}" ;;
t) truncateSet='Yes' ;;
n) display_type='Text' ;;
L) display_type='ASCII'; display_logo='Yes' ;;
o) overrideOpts="${OPTARG}" ;;
c) detectColors "${OPTARGS}" ;;
d) overrideDisplay="${OPTARG}" ;;
N) no_color='1' ;;
p) portraitSet='Yes' ;;
a) art="${OPTARG}" ;;
w) lineWrap='Yes' ;;
:) errorOut "Error: You're missing an argument somewhere. Exiting."; exit 1 ;;
?) errorOut "Error: Invalid flag somewhere. Exiting."; exit 1 ;;
*) errorOut "Error"; exit 1 ;;
esac
done
###################
# End Flags Phase
###################
############################
# Override Options/Display
############################
if [[ "$overrideOpts" ]]; then
verboseOut "Found 'o' flag in syntax. Overriding some script variables..."
eval "${overrideOpts}"
fi
#########################
# Begin Detection Phase
#########################
# Distro Detection - Begin
detectdistro () {
local distro_detect=""
if [[ -z "${distro}" ]]; then
distro="Unknown"
# LSB Release or MCST Version Check
if [[ -e "/etc/mcst_version" ]]; then
distro="OS Elbrus"
distro_release="$(tail -n 1 /etc/mcst_version)"
if [[ -n ${distro_release} ]]; then
distro_more="$distro_release"
fi
elif type -p lsb_release >/dev/null 2>&1; then
# read distro_detect distro_release distro_codename <<< $(lsb_release -sirc)
#OLD_IFS=$IFS
#IFS=" "
#read -r -a distro_detect <<< "$(lsb_release -sirc)"
#IFS=$OLD_IFS
#if [[ ${#distro_detect[@]} -eq 3 ]]; then
# distro_codename=${distro_detect[2]}
# distro_release=${distro_detect[1]}
# distro_detect=${distro_detect[0]}
#else
# for i in "${!distro_detect[@]}"; do
# if [[ ${distro_detect[$i]} =~ ^[[:digit:]]+((.[[:digit:]]+|[[:digit:]]+|)+)$ ]]; then
# distro_release=${distro_detect[$i]}
# distro_codename=${distro_detect[*]:$((i+1))}
# distro_detect=${distro_detect[*]:0:${i}}
# break 1
# elif [[ ${distro_detect[$i]} =~ [Nn]/[Aa] || ${distro_detect[$i]} == "rolling" ]]; then
# distro_release=${distro_detect[$i]}
# distro_codename=${distro_detect[*]:$((i+1))}
# distro_detect=${distro_detect[*]:0:${i}}
# break 1
# fi
# done
#fi
distro_detect="$(lsb_release -si)"
distro_release="$(lsb_release -sr)"
distro_codename="$(lsb_release -sc)"
case "${distro_detect}" in
"archlinux"|"Arch Linux"|"arch"|"Arch"|"archarm")
distro="Arch Linux"
distro_release="n/a"
if [ -f /etc/os-release ]; then
os_release="/etc/os-release";
elif [ -f /usr/lib/os-release ]; then
os_release="/usr/lib/os-release";
fi
if [[ -n ${os_release} ]]; then
if grep -q 'antergos' /etc/os-release; then
distro="Antergos"
distro_release="n/a"
fi
if grep -q -i 'logos' /etc/os-release; then
distro="Logos"
distro_release="n/a"
fi
if grep -q -i 'swagarch' /etc/os-release; then
distro="SwagArch"
distro_release="n/a"
fi
if grep -q -i 'obrevenge' /etc/os-release; then
distro="OBRevenge"
distro_release="n/a"
fi
fi
;;
"ALDOS"|"Aldos")
distro="ALDOS"
;;
"ArcoLinux")
distro="ArcoLinux"
distro_release="n/a"
;;
"artixlinux"|"Artix Linux"|"artix"|"Artix"|"Artix release")
distro="Artix"
;;
"blackPantherOS"|"blackPanther"|"blackpanther"|"blackpantheros")
distro=$(source /etc/lsb-release; echo "$DISTRIB_ID")
distro_release=$(source /etc/lsb-release; echo "$DISTRIB_RELEASE")
distro_codename=$(source /etc/lsb-release; echo "$DISTRIB_CODENAME")
;;
"BLAG")
distro="BLAG"
distro_more="$(head -n1 /etc/fedora-release)"
;;
"Chakra")
distro="Chakra"
distro_release=""
;;
"BunsenLabs")
distro=$(source /etc/lsb-release; echo "$DISTRIB_ID")
distro_release=$(source /etc/lsb-release; echo "$DISTRIB_RELEASE")
distro_codename=$(source /etc/lsb-release; echo "$DISTRIB_CODENAME")
;;
"Debian")
if [[ -f /etc/crunchbang-lsb-release || -f /etc/lsb-release-crunchbang ]]; then
distro="CrunchBang"
distro_release=$(awk -F'=' '/^DISTRIB_RELEASE=/ {print $2}' /etc/lsb-release-crunchbang)
distro_codename=$(awk -F'=' '/^DISTRIB_DESCRIPTION=/ {print $2}' /etc/lsb-release-crunchbang)
elif [[ -f /etc/siduction-version ]]; then
distro="Siduction"
distro_release="(Debian Sid)"
distro_codename=""
elif [[ -f /usr/bin/pveversion ]]; then
distro="Proxmox VE"
distro_codename="n/a"
distro_release="$(/usr/bin/pveversion | grep -oP 'pve-manager\/\K\d+\.\d+')"
elif [[ -f /etc/os-release ]]; then
if grep -q -i 'Raspbian' /etc/os-release ; then
distro="Raspbian"
distro_release=$(awk -F'=' '/^PRETTY_NAME=/ {print $2}' /etc/os-release)
elif grep -q -i 'BlankOn' /etc/os-release ; then
distro='BlankOn'
distro_release=$(awk -F'=' '/^PRETTY_NAME=/ {print $2}' /etc/os-release)
else
distro="Debian"
fi
else
distro="Debian"
fi
;;
"elementary"|"elementary OS")
distro="elementary OS"
;;
"EvolveOS")
distro="Evolve OS"
;;
"Sulin")
distro="Sulin"
distro_release=$(awk -F'=' '/^ID_LIKE=/ {print $2}' /etc/os-release)
distro_codename="Roolling donkey" # this is not wrong :D
;;
"KaOS"|"kaos")
distro="KaOS"
;;
"frugalware")
distro="Frugalware"
distro_codename=null
distro_release=null
;;
"Fuduntu")
distro="Fuduntu"
distro_codename=null
;;
"Fux")
distro="Fux"
distro_codename=null
;;
"Gentoo")
if [[ "$(lsb_release -sd)" =~ "Funtoo" ]]; then
distro="Funtoo"
else
distro="Gentoo"
fi
#detecting release stable/testing/experimental
if [[ -f /etc/portage/make.conf ]]; then
source /etc/portage/make.conf
elif [[ -d /etc/portage/make.conf ]]; then
source /etc/portage/make.conf/*
fi
case $ACCEPT_KEYWORDS in
[a-z]*) distro_release=stable ;;
~*) distro_release=testing ;;
'**') distro_release=experimental ;; #experimental usually includes git-versions.
esac
;;
"Hyperbola GNU/Linux-libre"|"Hyperbola")
distro="Hyperbola GNU/Linux-libre"
distro_codename="n/a"
distro_release="n/a"
;;
"januslinux"|"janus")
distro="januslinux"
;;
"LinuxDeepin")
distro="LinuxDeepin"
distro_codename=null
;;
"Kali"|"Debian Kali Linux")
distro="Kali Linux"
if [[ "${distro_codename}" =~ "kali-rolling" ]]; then
distro_codename="n/a"
distro_release="n/a"
fi
;;
"Lunar Linux"|"lunar")
distro="Lunar Linux"
;;
"MandrivaLinux")
distro="Mandriva"
case "${distro_codename}" in
"turtle"|"Henry_Farman"|"Farman"|"Adelie"|"pauillac")
distro="Mandriva-${distro_release}"
distro_codename=null
;;
esac
;;
"ManjaroLinux")
distro="Manjaro"
;;
"Mer")
distro="Mer"
if [[ -f /etc/os-release ]]; then
if grep -q 'SailfishOS' /etc/os-release; then
distro="SailfishOS"
distro_codename="$(grep 'VERSION=' /etc/os-release | cut -d '(' -f2 | cut -d ')' -f1)"
distro_release="$(awk -F'=' '/^VERSION=/ {print $2}' /etc/os-release)"
fi
fi
;;
"neon"|"KDE neon")
distro="KDE neon"
distro_codename="n/a"
distro_release="n/a"
if [[ -f /etc/issue ]]; then
if grep -q '^KDE neon' /etc/issue ; then
distro_release="$(grep '^KDE neon' /etc/issue | cut -d ' ' -f3)"
fi
fi
;;
"Ol"|"ol"|"Oracle Linux")
distro="Oracle Linux"
[ -f /etc/oracle-release ] && distro_release="$(sed 's/Oracle Linux //' /etc/oracle-release)"
;;
"LinuxMint")
distro="Mint"
if [[ "${distro_codename}" == "debian" ]]; then
distro="LMDE"
distro_codename="n/a"
distro_release="n/a"
#adding support for LMDE 3
elif [[ "$(lsb_release -sd)" =~ "LMDE" ]]; then
distro="LMDE"
fi
;;
"openSUSE"|"openSUSE project"|"SUSE LINUX" | "SUSE")
distro="openSUSE"
if [ -f /etc/os-release ]; then
if grep -q -i 'SUSE Linux Enterprise' /etc/os-release ; then
distro="SUSE Linux Enterprise"
distro_codename="n/a"
distro_release=$(awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release | tr -d '"')
fi
fi
if [[ "${distro_codename}" == "Tumbleweed" ]]; then
distro_release="n/a"
fi
;;
"Parabola GNU/Linux-libre"|"Parabola")
distro="Parabola GNU/Linux-libre"
distro_codename="n/a"
distro_release="n/a"
;;
"Parrot"|"Parrot Security")
distro="Parrot Security"
;;
"PCLinuxOS")
distro="PCLinuxOS"
distro_codename="n/a"
distro_release="n/a"
;;
"Peppermint")
distro="Peppermint"
distro_codename=null
;;
"rhel")
distro="Red Hat Enterprise Linux"
;;
"RosaDesktopFresh")
distro="ROSA"
distro_release=$(grep 'VERSION=' /etc/os-release | cut -d ' ' -f3 | cut -d "\"" -f1)
distro_codename=$(grep 'PRETTY_NAME=' /etc/os-release | cut -d ' ' -f4,4)
;;
"SailfishOS")
distro="SailfishOS"
if [[ -f /etc/os-release ]]; then
distro_codename="$(grep 'VERSION=' /etc/os-release | cut -d '(' -f2 | cut -d ')' -f1)"
distro_release="$(awk -F'=' '/^VERSION=/ {print $2}' /etc/os-release)"
fi
;;
"Sparky"|"SparkyLinux")
distro="SparkyLinux"
;;
"Ubuntu")
for each in "${ubuntu_codenames[@]}"; do
if [[ "${each,,}" =~ "${distro_codename,,}" ]]; then
distro_codename="$each"
fi
done
;;
"Viperr")
distro="Viperr"
distro_codename=null
;;
"Void"|"VoidLinux")
distro="Void Linux"
distro_codename=""
distro_release=""
;;
"Zorin")
distro="Zorin OS"
distro_codename=""
;;
*)
if [ "x$(printf "${distro_detect}" | od -t x1 | sed -e 's/^\w*\ *//' | tr '\n' ' ' | grep 'eb b6 89 ec 9d 80 eb b3 84 ')" != "x" ]; then
distro="Red Star OS"
distro_codename="n/a"
distro_release=$(printf "${distro_release}" | grep -o '[0-9.]' | tr -d '\n')
else
distro="${distro_detect}"
fi
;;
esac
if [[ "${distro_detect}" =~ "RedHatEnterprise" ]]; then
distro="Red Hat Enterprise Linux"
fi
if [[ "${distro_detect}" =~ "SUSELinuxEnterprise" ]]; then
distro="SUSE Linux Enterprise"
fi
if [[ -n ${distro_release} && ${distro_release} != "n/a" ]]; then
distro_more="$distro_release"
fi
if [[ -n ${distro_codename} && ${distro_codename} != "n/a" ]]; then
distro_more="$distro_more $distro_codename"
fi
fi
# Existing File Check
if [ "$distro" == "Unknown" ]; then
if [ "$(uname -o 2>/dev/null)" ]; then
os="$(uname -o)"
case "$os" in
"Cygwin"|"FreeBSD"|"OpenBSD"|"NetBSD")
distro="$os"
fake_distro="${distro}"
;;
"DragonFly")
distro="DragonFlyBSD"
fake_distro="${distro}"
;;
"EndeavourOS")
distro="EndeavourOS"
fake_distro="${distro}"
;;
"Msys")
distro="Msys"
fake_distro="${distro}"
distro_more="${distro} $(uname -r | head -c 1)"
;;
"Haiku")
distro="Haiku"
distro_more="$(uname -v | awk '/^hrev/ {print $1}')"
;;
"GNU/Linux")
if type -p crux >/dev/null 2>&1; then
distro="CRUX"
distro_more="$(crux | awk '{print $3}')"
fi
if type -p nixos-version >/dev/null 2>&1; then
distro="NixOS"
distro_more="$(nixos-version)"
fi
if type -p sorcery >/dev/null 2>&1; then
distro="SMGL"
fi
if (type -p guix && type -p herd) >/dev/null 2>&1; then
distro="Guix System"
fi
;;
esac
fi
if [[ "${distro}" == "Cygwin" || "${distro}" == "Msys" ]]; then
# https://msdn.microsoft.com/en-us/library/ms724832%28VS.85%29.aspx
if wmic os get version | grep -q '^\(6\.[23]\|10\)'; then
fake_distro="Windows - Modern"
fi
fi
if [[ "${distro}" == "Unknown" ]]; then
if [ -f /etc/os-release ]; then
os_release="/etc/os-release";
elif [ -f /usr/lib/os-release ]; then
os_release="/usr/lib/os-release";
fi
if [[ -n ${os_release} ]]; then
distrib_id=$(<${os_release});
for l in $distrib_id; do
if [[ ${l} =~ ^ID= ]]; then
distrib_id=${l//*=}
distrib_id=${distrib_id//\"/}
break 1
fi
done
if [[ -n ${distrib_id} ]]; then
if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
distrib_id=$(for i in ${distrib_id}; do echo -n "${i^} "; done)
distro=${distrib_id% }
unset distrib_id
else
distrib_id=$(for i in ${distrib_id}; do FIRST_LETTER=$(echo -n "${i:0:1}" | tr "[:lower:]" "[:upper:]"); echo -n "${FIRST_LETTER}${i:1} "; done)
distro=${distrib_id% }
unset distrib_id
fi
fi
# Hotfixes
[[ "${distro}" == "Opensuse-tumbleweed" ]] && distro="openSUSE" && distro_more="Tumbleweed"
[[ "${distro}" == "Opensuse-leap" ]] && distro="openSUSE"
[[ "${distro}" == "void" ]] && distro="Void Linux"
[[ "${distro}" == "evolveos" ]] && distro="Evolve OS"
[[ "${distro}" == "Sulin" ]] && distro="Sulin"
[[ "${distro}" == "antergos" ]] && distro="Antergos"
[[ "${distro}" == "logos" ]] && distro="Logos"
[[ "${distro}" == "Arch" || "${distro}" == "Archarm" || "${distro}" == "archarm" ]] && distro="Arch Linux"
[[ "${distro}" == "elementary" ]] && distro="elementary OS"
[[ "${distro}" == "Fedora" && -d /etc/qubes-rpc ]] && distro="qubes" # Inner VM
[[ "${distro}" == "Ol" || "${distro}" == "ol" ]] && distro="Oracle Linux"
if [[ "${distro}" == "Oracle Linux" && -f /etc/oracle-release ]]; then
distro_more="$(sed 's/Oracle Linux //' /etc/oracle-release)"
fi
# Upstream problem, SL and so EL is using rhel ID in os-release
if [[ "${distro}" == "rhel" ]] || [[ "${distro}" == "Rhel" ]]; then
distro="Red Hat Enterprise Linux"
if grep -q 'Scientific' /etc/os-release; then
distro="Scientific Linux"
elif grep -q 'EuroLinux' /etc/os-release; then
distro="EuroLinux"
fi
fi
[[ "${distro}" == "Neon" ]] && distro="KDE neon"
[[ "${distro}" == "SLED" || "${distro}" == "sled" || "${distro}" == "SLES" || "${distro}" == "sles" ]] && distro="SUSE Linux Enterprise"
if [[ "${distro}" == "SUSE Linux Enterprise" && -f /etc/os-release ]]; then
distro_more="$(awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release | tr -d '"')"
fi
if [[ "${distro}" == "Debian" && -f /usr/bin/pveversion ]]; then
distro="Proxmox VE"
distro_codename="n/a"
distro_release="$(/usr/bin/pveversion | grep -oP 'pve-manager\/\K\d+\.\d+')"
fi
fi
fi
if [[ "${distro}" == "Unknown" && "${OSTYPE}" =~ "linux" && -f /etc/lsb-release ]]; then
LSB_RELEASE=$(</etc/lsb-release)
distro=$(echo "${LSB_RELEASE}" | awk 'BEGIN {
distro = "Unknown"
}
{
if ($0 ~ /[Uu][Bb][Uu][Nn][Tt][Uu]/) {
distro = "Ubuntu"
exit
}
else if ($0 ~ /[Mm][Ii][Nn][Tt]/ && $0 ~ /[Dd][Ee][Bb][Ii][Aa][Nn]/) {
distro = "LMDE"
exit
}
else if ($0 ~ /[Mm][Ii][Nn][Tt]/) {
distro = "Mint"
exit
}
} END {
print distro
}')
fi
if [[ "${distro}" == "Unknown" ]] && [[ "${OSTYPE}" =~ "linux" || "${OSTYPE}" == "gnu" ]]; then
for di in arch chakra crunchbang-lsb evolveos exherbo fedora \
frugalware fux gentoo kogaion mageia obarun oracle \
pardus pclinuxos redhat redstar rosa SuSe; do
if [ -f /etc/$di-release ]; then
distro=$di
break
fi
done
if [[ "${distro}" == "crunchbang-lsb" ]]; then
distro="Crunchbang"
elif [[ "${distro}" == "gentoo" ]]; then
grep -q -i 'Funtoo' /etc/gentoo-release && distro="Funtoo"
elif [[ "${distro}" == "mandrake" ]] || [[ "${distro}" == "mandriva" ]]; then
grep -q -i 'PCLinuxOS' /etc/${distro}-release && distro="PCLinuxOS"
elif [[ "${distro}" == "fedora" ]]; then
grep -q -i 'Korora' /etc/fedora-release && distro="Korora"
grep -q -i 'BLAG' /etc/fedora-release && distro="BLAG" && distro_more="$(head -n1 /etc/fedora-release)"
elif [[ "${distro}" == "oracle" ]]; then
distro_more="$(sed 's/Oracle Linux //' /etc/oracle-release)"