forked from shigeno143/OCSPanelCentos6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenfetch
4916 lines (4674 loc) · 190 KB
/
screenfetch
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-2016 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.7.0"
######################
# 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.
#display="distro host kernel uptime pkgs shell res de wm wmtheme gtk disk cpu gpu mem"
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 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"
# WM & DE process names
# 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 )
denames=( gnome-session xfce-mcs-manage xfce4-session xfconfd ksmserver lxsession lxqt-session gnome-settings-daemon mate-session mate-settings-daemon Finder deepin )
# 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-`date +'%Y-%m-%d_%H-%M-%S'`.png")
# Verbose Setting - Set to 1 for verbose output.
verbosity=
#############################################
#### CODE No need to edit past here CODE ####
#############################################
#########################################
# 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[38;5;$1m"
}
getColor() {
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
'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';;
'light grey') color_ret='\033[0m\033[37m';;
'dark grey') 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';;
'yellow') color_ret='\033[0m\033[1;33m';;
'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';;
'white') color_ret='\033[0m\033[1;37m';;
# Some 256 colors
'orange') color_ret="$(colorize '202')";;
# HaikuOS
'black_haiku') color_ret="$(colorize '7')";;
esac
[[ -n "${color_ret}" ]] && echo "${color_ret}"
else
:
fi
}
verboseOut() {
if [[ "$verbosity" -eq "1" ]]; then
printf "\033[1;31m:: \033[0m$1\n"
fi
}
errorOut() {
printf "\033[1;37m[[ \033[1;31m! \033[1;37m]] \033[0m$1\n"
}
stderrOut() {
while IFS='' read -r line; do printf "\033[1;37m[[ \033[1;31m! \033[1;37m]] \033[0m${line}\n"; done
}
####################
# Color Defines
####################
colorNumberToCode() {
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="Alpine Linux, Antergos, Arch Linux (Old and Current Logos), BLAG, BunsenLabs, CentOS, Chakra, Chapeau, Chrome OS, Chromium OS, CrunchBang, CRUX, Debian, Deepin, Devuan, Dragora, elementary OS, Evolve OS, Exherbo, Fedora, Frugalware, Fuduntu, Funtoo, Gentoo, gNewSense, Jiyuu Linux, Kali Linux, KaOS, KDE neon, Kogaion, Korora, LinuxDeepin, Linux Mint, LMDE, Logos, Mageia, Mandriva/Mandrake, Manjaro, Mer, Netrunner, NixOS, openSUSE, Oracle Linux, Parabola GNU/Linux-libre, PCLinuxOS, PeppermintOS, Qubes OS, Raspbian, Red Hat Enterprise Linux, Sabayon, SailfishOS, Scientific Linux, Slackware, Solus, SparkyLinux, SteamOS, SUSE Linux Enterprise, TinyCore, Trisquel, Ubuntu, Viperr and Void."
supported_other="Dragonfly/Free/Open/Net BSD, Haiku, Mac OS X, Windows+Cygwin and Windows+MSYS."
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() {
printf "${underline}Usage${c0}:\n"
printf " ${0} [OPTIONAL FLAGS]\n\n"
printf "screenFetch - a CLI Bash script to show system/theme info in screenshots.\n\n"
printf "${underline}Supported GNU/Linux Distributions${c0}:\n"
printf "${supported_distros}" | fold -s | sed 's/^/\t/g'
printf "\n\n"
printf "${underline}Other Supported Systems${c0}:\n"
printf "${supported_other}" | fold -s | sed 's/^/\t/g'
printf "\n\n"
printf "${underline}Supported Desktop Managers${c0}:\n"
printf "${supported_dms}" | fold -s | sed 's/^/\t/g'
printf "\n\n"
printf "${underline}Supported Window Managers${c0}:\n"
printf "${supported_wms}" | fold -s | sed 's/^/\t/g'
printf "\n\n"
printf "${underline}Options${c0}:\n"
printf " ${bold}-v${c0} Verbose output.\n"
printf " ${bold}-o 'OPTIONS'${c0} Allows for setting script variables on the\n"
printf " command line. Must be in the following format...\n"
printf " 'OPTION1=\"OPTIONARG1\";OPTION2=\"OPTIONARG2\"'\n"
printf " ${bold}-d '+var;-var;var'${c0} Allows for setting what information is displayed\n"
printf " on the command line. You can add displays with +var,var. You\n"
printf " can delete displays with -var,var. Setting without + or - will\n"
printf " set display to that explicit combination. Add and delete statements\n"
printf " may be used in conjunction by placing a ; between them as so:\n"
printf " +var,var,var;-var,var.\n"
printf " ${bold}-n${c0} Do not display ASCII distribution logo.\n"
printf " ${bold}-L${c0} Display ASCII distribution logo only.\n"
printf " ${bold}-N${c0} Strip all color from output.\n"
printf " ${bold}-t${c0} Truncate output based on terminal width (Experimental!).\n"
printf " ${bold}-p${c0} Portrait output.\n"
printf " ${bold}-s [-u IMGHOST]${c0} Using this flag tells the script that you want it\n"
printf " to take a screenshot. Use the -u flag if you would like\n"
printf " to upload the screenshots to one of the pre-configured\n"
printf " locations. These include: teknik, imgur, mediacrush and hmp.\n"
printf " ${bold}-c string${c0} You may change the outputted colors with -c. The format is\n"
printf " as follows: [0-9][0-9],[0-9][0-9]. The first argument controls the\n"
printf " ASCII logo colors and the label colors. The second argument\n"
printf " controls the colors of the information found. One argument may be\n"
printf " used without the other.\n"
printf " ${bold}-a 'PATH'${c0} You can specify a custom ASCII art by passing the path\n"
printf " to a Bash script, defining \`startline\` and \`fulloutput\`\n"
printf " variables, and optionally \`labelcolor\` and \`textcolor\`.\n"
printf " See the \`asciiText\` function in the source code for more\n"
printf " informations on the variables format.\n"
printf " ${bold}-S 'COMMAND'${c0} Here you can specify a custom screenshot command for\n"
printf " the script to execute. Surrounding quotes are required.\n"
printf " ${bold}-D 'DISTRO'${c0} Here you can specify your distribution for the script\n"
printf " to use. Surrounding quotes are required.\n"
printf " ${bold}-A 'DISTRO'${c0} Here you can specify the distribution art that you want\n"
printf " displayed. This is for when you want your distro\n"
printf " detected but want to display a different logo.\n"
printf " ${bold}-E${c0} Suppress output of errors.\n"
printf " ${bold}-V, --version${c0} Display current script version.\n"
printf " ${bold}-h, --help${c0} Display this help.\n"
}
displayVersion() {
printf ${underline}"screenFetch"${c0}" - Version ${scriptVersion}\n"
printf "Created by and licensed to Brett Bohnenkamper <[email protected]>\n"
printf "OS X porting done almost solely by shrx (https://github.com/shrx) and John D. Duncan, III (https://github.com/JohnDDuncanIII).\n\n"
printf "This is free software; see the source for copying conditions. There is NO warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
}
#####################
# Begin Flags Phase
#####################
case $1 in
--help) displayHelp; exit 0;;
--version) displayVersion; exit 0;;
esac
while getopts ":hsu:evVEnLNtlS:A:D:o:Bc:d:pa:" 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}" ;;
:) 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..."
OLD_IFS="$IFS"
IFS=";"
for overopt in "${overrideOpts}"; do
eval "${overrideOpts}"
done
IFS="$OLD_IFS"
fi
#########################
# Begin Detection Phase
#########################
# Distro Detection - Begin
detectdistro () {
if [[ -z "${distro}" ]]; then
distro="Unknown"
# LSB Release Check
if type -p lsb_release >/dev/null 2>&1; then
# read distro_detect distro_release distro_codename <<< $(lsb_release -sirc)
distro_detect=( $(lsb_release -sirc) )
if [[ ${#distro_detect[@]} -eq 3 ]]; then
distro_codename=${distro_detect[2]}
distro_release=${distro_detect[1]}
distro_detect=${distro_detect[0]}
else
for ((i=0; i<${#distro_detect[@]}; i++)); do
if [[ ${distro_detect[$i]} =~ ^[[:digit:]]+((.[[:digit:]]+|[[:digit:]]+|)+)$ ]]; then
distro_release=${distro_detect[$i]}
distro_codename=${distro_detect[@]:$(($i+1)):${#distro_detect[@]}+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[@]}+1}
distro_detect=${distro_detect[@]:0:${i}}
break 1
fi
done
fi
case "${distro_detect}" in
"CentOS"|"Chapeau"|"Deepin"|"Devuan"|"Fedora"|"gNewSense"|"Jiyuu Linux"|"Kogaion"|"Korora"|"Mageia"|"Netrunner"|"NixOS"|"Raspbian"|"Sabayon"|"Solus"|"SteamOS"|"Trisquel"|"Ubuntu")
# no need to fix $distro/$distro_codename/$distro_release
distro="${distro_detect}"
;;
"archlinux"|"Arch Linux"|"arch"|"Arch"|"archarm")
distro="Arch Linux"
distro_release="n/a"
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
;;
"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/os-release ]]; then
if [[ "$(cat /etc/os-release)" =~ "Raspbian" ]]; then
distro="Raspbian"
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"
;;
"KaOS"|"kaos")
distro="KaOS"
;;
"frugalware")
distro="Frugalware"
distro_codename=null
distro_release=null
;;
"Fuduntu")
distro="Fuduntu"
distro_codename=null
;;
"Gentoo")
if [[ "$(lsb_release -sd)" =~ "Funtoo" ]]; then
distro="Funtoo"
else
distro="Gentoo"
fi
;;
"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"
fi
;;
"openSUSE"|"openSUSE project"|"SUSE LINUX")
distro="openSUSE"
if [ -f /etc/os-release ]; then
if [[ "$(cat /etc/os-release)" =~ "SUSE Linux Enterprise" ]]; 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"
;;
"PCLinuxOS")
distro="PCLinuxOS"
distro_codename="n/a"
distro_release="n/a"
;;
"Peppermint")
distro="Peppermint"
distro_codename=null
;;
"rhel")
distro="Red Hat Enterprise Linux"
;;
"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"
;;
"Viperr")
distro="Viperr"
distro_codename=null
;;
*)
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')
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
case "$(uname -o)" in
"Cygwin")
distro="Cygwin"
fake_distro="${distro}"
;;
"Msys")
distro="Msys"
fake_distro="${distro}"
distro_more="${distro} $(uname -r | head -c 1)"
;;
"Haiku")
distro="Haiku"
distro_more="$(uname -v | tr ' ' '\n' | grep 'hrev')"
;;
"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
;;
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 -o '^\(6\.[23]\|10\)')" ]; then
fake_distro="Windows - Modern"
fi
fi
if [[ "${distro}" == "Unknown" ]]; then
if [ -f /etc/os-release ]; then
distrib_id=$(</etc/os-release);
for l in $(echo $distrib_id); do
if [[ ${l} =~ ^ID= ]]; then
distrib_id=${l//*=}
distrib_id=${distrib_id//\"/}
break 1
fi
done
if [[ -n ${distrib_id} ]]; then
if [[ -n ${BASH_VERSINFO} && ${BASH_VERSINFO} -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}" == "void" ]] && distro="Void"
[[ "${distro}" == "evolveos" ]] && distro="Evolve OS"
[[ "${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
[[ "${distro}" == "rhel" ]] && distro="Red Hat Enterprise Linux"
[[ "${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
fi
fi
if [[ "${distro}" == "Unknown" ]]; then
if [[ "${OSTYPE}" == "linux-gnu" || "${OSTYPE}" == "linux" ]]; then
if [ -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
fi
fi
if [[ "${distro}" == "Unknown" ]]; then
if [[ "${OSTYPE}" == "linux-gnu" || "${OSTYPE}" == "linux" || "${OSTYPE}" == "gnu" ]]; then
if [ -f /etc/arch-release ]; then distro="Arch Linux"
elif [ -f /etc/chakra-release ]; then distro="Chakra"
elif [ -f /etc/crunchbang-lsb-release ]; then distro="CrunchBang"
elif [ -f /etc/debian_version ]; then
if [ -f /etc/issue ]; then
if grep -q "gNewSense" /etc/issue ; then
distro="gNewSense"
elif grep -q "^KDE neon" /etc/issue ; then
distro="KDE neon"
distro_more="$(cut -d ' ' -f3 /etc/issue)"
else
distro="Debian"
fi
fi
if grep -q "Kali" /etc/debian_version ; then
distro="Kali Linux"
fi
elif [ -f /etc/dragora-version ]; then distro="Dragora" && distro_more="$(cut -d, -f1 /etc/dragora-version)"
elif [ -f /etc/evolveos-release ]; then distro="Evolve OS"
elif [ -f /etc/exherbo-release ]; then distro="Exherbo"
elif [ -f /etc/fedora-release ]; then
if grep -q "Korora" /etc/fedora-release; then
distro="Korora"
elif grep -q "BLAG" /etc/fedora-release; then
distro="BLAG"
distro_more="$(head -n1 /etc/fedora-release)"
else
distro="Fedora"
fi
elif [ -f /etc/frugalware-release ]; then distro="Frugalware"
elif [ -f /etc/gentoo-release ]; then
if grep -q "Funtoo" /etc/gentoo-release ; then
distro="Funtoo"
else
distro="Gentoo"
fi
elif [ -f /etc/kogaion-release ]; then distro="Kogaion"
elif [ -f /etc/mageia-release ]; then distro="Mageia"
elif [ -f /etc/mandrake-release ]; then
if grep -q "PCLinuxOS" /etc/mandrake-release ; then
distro="PCLinuxOS"
else
distro="Mandrake"
fi
elif [ -f /etc/mandriva-release ]; then
if grep -q "PCLinuxOS" /etc/mandriva-release ; then
distro="PCLinuxOS"
else
distro="Mandriva"
fi
elif [ -f /etc/NIXOS ]; then distro="NixOS"
elif [ -f /etc/obarun-release ]; then distro="Obarun"
elif [ -f /etc/oracle-release ]; then
distro="Oracle Linux"
distro_more="$(sed 's/Oracle Linux //' /etc/oracle-release)"
elif [ -f /etc/SuSE-release ]; then
distro="openSUSE"
if [ -f /etc/os-release ]; then
if [[ "$(cat /etc/os-release)" =~ "SUSE Linux Enterprise" ]]; then
distro="SUSE Linux Enterprise"
distro_more=$(awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release | tr -d '"')
fi
fi
if [[ "${distro_more}" =~ "Tumbleweed" ]]; then distro_more="Tumbleweed"; fi
elif [ -f /etc/pclinuxos-release ]; then distro="PCLinuxOS"
elif [ -f /etc/redstar-release ]; then
distro="Red Star OS"
distro_more=$(grep -o '[0-9.]' /etc/redstar-release | tr -d '\n')
elif [ -f /etc/redhat-release ]; then
if grep -q "CentOS" /etc/redhat-release; then
distro="CentOS"
elif grep -q "PCLinuxOS" /etc/redhat-release; then
distro="PCLinuxOS"
elif [ "x$(od -t x1 /etc/redhat-release | sed -e 's/^\w*\ *//' | tr '\n' ' ' | grep 'eb b6 89 ec 9d 80 eb b3 84 ')" != "x" ]; then
distro="Red Star OS"
distro_more=$(grep -o '[0-9.]' /etc/redhat-release | tr -d '\n')
else
distro="Red Hat Enterprise Linux"
fi
elif [ -f /etc/slackware-version ]; then distro="Slackware"
elif [ -f /usr/share/doc/tc/release.txt ]; then
distro="TinyCore"
distro_more="$(cat /usr/share/doc/tc/release.txt)"
elif [ -f /etc/sabayon-edition ]; then distro="Sabayon"; fi
else
if [[ -x /usr/bin/sw_vers ]] && /usr/bin/sw_vers | grep -i "Mac OS X" >/dev/null; then
distro="Mac OS X"
elif [[ -f /var/run/dmesg.boot ]]; then
distro=$(awk 'BEGIN {
distro = "Unknown"
}
{
if ($0 ~ /DragonFly/) {
distro = "DragonFlyBSD"
exit
}
else if ($0 ~ /FreeBSD/) {
distro = "FreeBSD"
exit
}
else if ($0 ~ /NetBSD/) {
distro = "NetBSD"
exit
}
else if ($0 ~ /OpenBSD/) {
distro = "OpenBSD"
exit
}
} END {
print distro
}' /var/run/dmesg.boot)
fi
fi
fi
if [[ "${distro}" == "Unknown" ]] && [[ "${OSTYPE}" == "linux-gnu" || "${OSTYPE}" == "linux" || "${OSTYPE}" == "gnu" ]]; then
if [[ -f /etc/issue ]]; then
distro=$(awk 'BEGIN {
distro = "Unknown"
}
{
if ($0 ~ /"LinuxDeepin"/) {
distro = "LinuxDeepin"
exit
}
else if ($0 ~ /"Obarun"/) {
distro = "Obarun"
exit
}
else if ($0 ~ /"Parabola GNU\/Linux-libre"/) {
distro = "Parabola GNU/Linux-libre"
exit
}
else if ($0 ~ /"Solus"/) {
distro = "Solus"
exit
}
} END {
print distro
}' /etc/issue)
fi
fi
if [[ "${distro}" == "Unknown" ]] && [[ "${OSTYPE}" == "linux-gnu" || "${OSTYPE}" == "linux" || "${OSTYPE}" == "gnu" ]]; then
if [[ -f /etc/system-release ]]; then
if grep -q "Scientific Linux" /etc/system-release; then
distro="Scientific Linux"
elif grep -q "Oracle Linux" /etc/system-release; then
distro="Oracle Linux"
fi
elif [[ -f /etc/lsb-release ]]; then
if grep -q "CHROMEOS_RELEASE_NAME" /etc/lsb-release; then
distro="$(awk -F'=' '/^CHROMEOS_RELEASE_NAME=/ {print $2}' /etc/lsb-release)"
distro_more="$(awk -F'=' '/^CHROMEOS_RELEASE_VERSION=/ {print $2}' /etc/lsb-release)"
fi
fi
fi
fi
fi
if [[ -n ${distro_more} ]]; then
distro_more="${distro} ${distro_more}"
fi
if [[ "${distro}" != "Haiku" ]]; 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
distro=${distro,,}
else
distro="$(tr '[:upper:]' '[:lower:]' <<< ${distro})"
fi
else
distro="$(tr '[:upper:]' '[:lower:]' <<< ${distro})"
fi
fi
case $distro in
alpine) distro="Alpine Linux" ;;
antergos) distro="Antergos" ;;
arch*linux*old) distro="Arch Linux - Old" ;;
arch|arch*linux) distro="Arch Linux" ;;
blag) distro="BLAG" ;;
bunsenlabs) distro="BunsenLabs" ;;
centos) distro="CentOS" ;;
chakra) distro="Chakra" ;;
chapeau) distro="Chapeau" ;;
chrome*|chromium*) distro="Chrome OS" ;;
crunchbang) distro="CrunchBang" ;;
crux) distro="CRUX" ;;
cygwin) distro="Cygwin" ;;
debian) distro="Debian" ;;
devuan) distro="Devuan" ;;
deepin) distro="Deepin" ;;
dragonflybsd) distro="DragonFlyBSD" ;;
dragora) distro="Dragora" ;;
elementary|'elementary os') distro="elementary OS";;
evolveos) distro="Evolve OS" ;;
exherbo|exherbo*linux) distro="Exherbo" ;;
fedora) distro="Fedora" ;;
freebsd) distro="FreeBSD" ;;
freebsd*old) distro="FreeBSD - Old" ;;
frugalware) distro="Frugalware" ;;
fuduntu) distro="Fuduntu" ;;
funtoo) distro="Funtoo" ;;
gentoo) distro="Gentoo" ;;
gnewsense) distro="gNewSense" ;;
haiku) distro="Haiku" ;;
kali*linux) distro="Kali Linux" ;;
kaos) distro="KaOS";;
kde*neon|neon) distro="KDE neon" ;;
kogaion) distro="Kogaion" ;;
korora) distro="Korora" ;;
linuxdeepin) distro="LinuxDeepin" ;;
lmde) distro="LMDE" ;;
logos) distro="Logos" ;;
lunar|lunar*linux) distro="Lunar Linux";;
mac*os*x|os*x) distro="Mac OS X" ;;
manjaro) distro="Manjaro" ;;
mageia) distro="Mageia" ;;
mandrake) distro="Mandrake" ;;
mandriva) distro="Mandriva" ;;
mer) distro="Mer" ;;
mint|linux*mint) distro="Mint" ;;
msys|msys2) distro="Msys" ;;
netbsd) distro="NetBSD" ;;
netrunner) distro="Netrunner" ;;
nix|nix*os) distro="NixOS" ;;
obarun) distro="Obarun" ;;
ol|oracle*linux) distro="Oracle Linux" ;;
openbsd) distro="OpenBSD" ;;
opensuse) distro="openSUSE" ;;
parabolagnu|parabolagnu/linux-libre|'parabola gnu/linux-libre'|parabola) distro="Parabola GNU/Linux-libre" ;;
pclinuxos|pclos) distro="PCLinuxOS" ;;
peppermint) distro="Peppermint" ;;
qubes) distro="Qubes OS" ;;
raspbian) distro="Raspbian" ;;
red*hat*|rhel) distro="Red Hat Enterprise Linux" ;;
red*star|red*star*os) distro="Red Star OS" ;;
sabayon) distro="Sabayon" ;;
sailfish|sailfish*os) distro="SailfishOS" ;;
slackware) distro="Slackware" ;;
solus) distro="Solus" ;;
steam|steam*os) distro="SteamOS" ;;
suse*linux*enterprise) distro="SUSE Linux Enterprise" ;;
tinycore|tinycore*linux) distro="TinyCore" ;;
trisquel) distro="Trisquel";;
ubuntu)
distro="Ubuntu"
if grep -q 'Microsoft' /proc/version 2>/dev/null || \
grep -q 'Microsoft' /proc/sys/kernel/osrelease 2>/dev/null
then
uow=$(echo -e "$(getColor 'yellow') [Ubuntu on Windows 10]")
fi
;;
viperr) distro="Viperr" ;;
void) distro="Void" ;;
esac
verboseOut "Finding distro...found as '${distro} ${distro_release}'"
}
# Distro Detection - End
# Host and User detection - Begin
detecthost () {
myUser=${USER}
myHost=${HOSTNAME}
if [[ "${distro}" == "Mac OS X" ]]; then myHost=${myHost/.local}; fi
verboseOut "Finding hostname and user...found as '${myUser}@${myHost}'"
}
# Find Number of Running Processes
# processnum="$(( $( ps aux | wc -l ) - 1 ))"
# Kernel Version Detection - Begin
detectkernel () {
# compatibility for older versions of OS X:
kernel=$(uname -m && uname -sr)
kernel=${kernel//$'\n'/ }
#kernel=( $(uname -srm) )
#kernel="${kernel[${#kernel[@]}-1]} ${kernel[@]:0:${#kernel[@]}-1}"
verboseOut "Finding kernel version...found as '${kernel}'"
}
# Kernel Version Detection - End
# Uptime Detection - Begin
detectuptime () {
unset uptime
if [[ "${distro}" == "Mac OS X" || "${distro}" == "FreeBSD" || "${distro}" == "DragonFlyBSD" ]]; then
boot=$(sysctl -n kern.boottime | cut -d "=" -f 2 | cut -d "," -f 1)
now=$(date +%s)
uptime=$(($now-$boot))
elif [[ "${distro}" == "OpenBSD" ]]; then
boot=$(sysctl -n kern.boottime)
now=$(date +%s)
uptime=$((${now} - ${boot}))
elif [[ "${distro}" == "Haiku" ]]; then
uptime=$(uptime | cut -d ',' -f2,3 | sed 's/ up //; s/ hour,/h/; s/ minutes/m/;')
else
if [[ -f /proc/uptime ]]; then
uptime=$(</proc/uptime)
uptime=${uptime//.*}
fi
fi
if [[ -n ${uptime} ]] && [[ "${distro}" != "Haiku" ]]; then
secs=$((${uptime}%60))
mins=$((${uptime}/60%60))
hours=$((${uptime}/3600%24))
days=$((${uptime}/86400))
uptime="${mins}m"
if [ "${hours}" -ne "0" ]; then
uptime="${hours}h ${uptime}"
fi
if [ "${days}" -ne "0" ]; then
uptime="${days}d ${uptime}"
fi
else
if [[ "$distro" =~ "NetBSD" ]]; then uptime=$(awk -F. '{print $1}' /proc/uptime); fi
if [[ "$distro" =~ "BSD" ]]; then uptime=$(uptime | awk '{$1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; sub(" days","d");sub(",","");sub(":","h ");sub(",","m"); print}'); fi
fi
verboseOut "Finding current uptime...found as '${uptime}'"
}
# Uptime Detection - End
# Package Count - Begin
detectpkgs () {
pkgs="Unknown"
case "${distro}" in
'Alpine Linux') pkgs=$(apk info | wc -l) ;;
'Arch Linux'|'Parabola GNU/Linux-libre'|'Chakra'|'Manjaro'|'Antergos'|'Netrunner'|'KaOS'|'Obarun') pkgs=$(pacman -Qq | wc -l) ;;
'Dragora') pkgs=$(ls -1 /var/db/pkg | wc -l) ;;
'Frugalware') pkgs=$(pacman-g2 -Q | wc -l) ;;
'Fuduntu'|'Ubuntu'|'Mint'|'KDE neon'|'Debian'|'Devuan'|'Raspbian'|'LMDE'|'CrunchBang'|'Peppermint'|'LinuxDeepin'|'Deepin'|'Kali Linux'|'Trisquel'|'elementary OS'|'gNewSense'|'BunsenLabs'|'SteamOS') pkgs=$(dpkg -l | grep -c ^i) ;;
'Slackware') pkgs=$(ls -1 /var/log/packages | wc -l) ;;
'Gentoo'|'Sabayon'|'Funtoo'|'Chrome OS'|'Kogaion') pkgs=$(ls -d /var/db/pkg/*/* | wc -l) ;;
'NixOS') pkgs=$(ls -d -1 /nix/store/*/ | wc -l) ;;
'Fedora'|'Korora'|'BLAG'|'Chapeau'|'openSUSE'|'SUSE Linux Enterprise'|'Red Hat Enterprise Linux'|'Oracle Linux'|'CentOS'|'Mandriva'|'Mandrake'|'Mageia'|'Mer'|'SailfishOS'|'PCLinuxOS'|'Viperr'|'Qubes OS'|'Red Star OS') pkgs=$(rpm -qa | wc -l) ;;
'Void') pkgs=$(xbps-query -l | wc -l) ;;
'Evolve OS'|'Solus') pkgs=$(pisi list-installed | wc -l) ;;
'CRUX') pkgs=$(pkginfo -i | wc -l) ;;
'Lunar Linux') pkgs=$(lvu installed | wc -l) ;;
'TinyCore') pkgs=$(tce-status -i | wc -l) ;;
'Exherbo')
xpkgs=$(ls -d -1 /var/db/paludis/repositories/cross-installed/*/data/* | wc -l)
pkgs=$(ls -d -1 /var/db/paludis/repositories/installed/data/* | wc -l)
pkgs=$((${pkgs} + ${xpkgs}))
;;
'Mac OS X')
if [ -d "/usr/local/bin" ]; then
loc_pkgs=$(ls -l /usr/local/bin/ | grep -v "\(../Cellar/\|brew\)" | wc -l)
pkgs=$((${loc_pkgs} -1));
fi
if type -p port >/dev/null 2>&1; then
port_pkgs=$(port installed 2>/dev/null | wc -l)