-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple-desktop.sh
executable file
·1668 lines (1408 loc) · 53 KB
/
simple-desktop.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
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
#!/bin/bash
#
# simple-desktop
# Opinionated, performant, and responsive experience to daily-users and developers on the Ubuntu 20+ desktop
#
# Copyright (C) 2021 Perlogix, Timothy Marcinowski
#
# 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/>.
PRIM_DISK=$(df -h / | grep dev | awk '{ print $1 }')
SETUP_LOG="/opt/simple-desktop/logs/setup.log"
SETUP_ERR_LOG="/opt/simple-desktop/logs/setup_err.log"
is_root() {
if [[ $(whoami) != "root" ]]; then
echo "run again with: sudo -E $0"
exit 1
fi
}
# Create GitHub issue submission
system_info() {
command -v inxi 1>/dev/null && inxi -Fxz || echo "Install inxi: sudo apt install -y inxi"
echo -e "\033[1mSystemD: \033[0m $(systemctl --failed --no-pager | grep -v UNIT)"
echo -e "\033[1mDmesg: \033[0m \n$(dmesg -tP --level=err,emerg,crit,alert | sed 's/^/ /')"
echo -e "\033[1mJournal: \033[0m \n$(journalctl -p "emerg..err" --no-pager -b | grep -v 'kernel\|Logs\|ssh' | sed 's/^/ /')"
echo -e "\033[1mSecureBoot: \033[0m \n$(mokutil --sb-state 2>/dev/null | sed 's/^/ /')"
if [[ -f /opt/simple-desktop/logs/setup.log ]]; then
echo -e "\033[1mSetupErrors: \033[0m \n$(sed 's/^/ /' /opt/simple-desktop/logs/setup_err.log)"
fi
if [[ -f /opt/simple-desktop/.first_run ]]; then
echo -e "\033[1mFirstRun: \033[0m \n$(sed 's/^/ /' /opt/simple-desktop/.first_run)"
fi
}
# Update components
update() {
case $1 in
hosts)
wget -c 'https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews/hosts'
sed -i "s/localhost$/localhost $(hostname)/g" hosts
mv -f hosts /etc/
;;
*)
echo "options: slack,discord,chrome,firefox,spotify,zoom,teams,overclock,developer,theme,docker,flatpak,cleanup_script,disable_spectre"
;;
esac
}
# Install common desktop apps
install() {
case $1 in
slack)
snap install slack --classic
;;
chrome)
wget -c 'https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb'
apt install -y ./google-chrome-stable_current_amd64.deb
rm -f ./google-chrome-stable_current_amd64.deb
;;
spotify)
snap install spotify
;;
zoom)
wget -c 'https://zoom.us/client/latest/zoom_amd64.deb'
apt install -y ./zoom_amd64.deb
rm -f ./zoom_amd64.deb
;;
teams)
curl -L 'https://packages.microsoft.com/keys/microsoft.asc' | sudo apt-key add -
echo 'deb [arch=amd64] https://packages.microsoft.com/repos/ms-teams stable main' >/etc/apt/sources.list.d/teams.list
apt update
apt install -y teams
;;
discord)
snap install discord
;;
firefox)
apt install firefox
;;
overclock)
echo 'arm_freq=1900' >>/boot/firmware/config.txt
echo 'over_voltage=4' >>/boot/firmware/config.txt
;;
docker)
curl -sSL https://get.docker.com/ | sh
;;
theme)
setup_theme
;;
cleanup_script)
setup_cleanup_script
;;
disable_spectre)
setup_disable_spectre
;;
flatpak)
apt update
apt install -y flatpak gnome-software-plugin-flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
;;
anbox)
# This does not work yet with zen-kernel 5.8
apt update
apt install -y android-tools-adb wget curl lzip tar unzip squashfs-tools
snap install --devmode --beta anbox
wget -c https://github.com/geeks-r-us/anbox-playstore-installer/raw/master/install-playstore.sh
chmod -f 0755 ./install-playstore.sh
./install-playstore.sh
/snap/anbox/current/bin/anbox-bridge.sh start
rm -rf ./install-playstore.sh ./anbox-work
;;
developer)
apt install -y jq zsh make git vim libsecret-1-0 libsecret-1-dev libglib2.0-dev libnss3-tools tmate cpulimit fzf
ZSH="$(command -v zsh || grep zsh /etc/shells | tail -n 1)"
sed -i "s|/bin/bash|$ZSH|g" /etc/passwd
# Create temp install directory
TEMPDIR="$HOME/.tmp98713245"
mkdir -p "$TEMPDIR"
cd "$TEMPDIR" || echo "Cannot make temp directory" >&2
# Install a better top/htop
wget -c https://github.com/ClementTsang/bottom/releases/latest/download/bottom_x86_64-unknown-linux-gnu.tar.gz
tar -zxvf bottom_x86_64-unknown-linux-gnu.tar.gz
cp -f ./btm /usr/bin/
# Install a better ls
wget -c https://github.com/Peltoche/lsd/releases/download/0.21.0/lsd-0.21.0-x86_64-unknown-linux-gnu.tar.gz
tar -zxvf lsd-0.21.0-x86_64-unknown-linux-gnu.tar.gz
cp -f ./lsd-*-x86_64-unknown-linux-gnu/lsd /usr/bin/
# Install a colorful cat
wget -c https://github.com/sharkdp/bat/releases/download/v0.20.0/bat-v0.20.0-x86_64-unknown-linux-gnu.tar.gz
tar -zxvf bat-v0.20.0-x86_64-unknown-linux-gnu.tar.gz
cp -f ./bat-v0.20.0-x86_64-unknown-linux-gnu/bat /usr/bin/
# Install lazydocker
wget -c https://github.com/jesseduffield/lazydocker/releases/download/v0.12/lazydocker_0.12_Linux_x86_64.tar.gz
tar -zxvf ./lazydocker_0.12_Linux_x86_64.tar.gz
chmod -f 0755 ./lazydocker
cp -f ./lazydocker /usr/bin/
# Install a better colorful diff
wget -c https://github.com/dandavison/delta/releases/download/0.12.1/delta-0.12.1-x86_64-unknown-linux-gnu.tar.gz
tar -zxvf ./delta-0.12.1-x86_64-unknown-linux-gnu.tar.gz
cp -f ./delta-0.12.1-x86_64-unknown-linux-gnu/delta /usr/bin/
# Install procs a colorful ps
wget -c https://github.com/dalance/procs/releases/download/v0.12.1/procs-v0.12.1-x86_64-lnx.zip
unzip procs-v0.12.1-x86_64-lnx.zip
cp -f ./procs /usr/bin/
# Install network utilization CLI bandwich
wget -c https://github.com/imsnif/bandwhich/releases/download/0.20.0/bandwhich-v0.20.0-x86_64-unknown-linux-musl.tar.gz
tar -zxvf ./bandwhich-v0.20.0-x86_64-unknown-linux-musl.tar.gz
cp -f ./bandwhich /usr/bin/
# Install git credential helper
make --directory=/usr/share/doc/git/contrib/credential/libsecret
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
# Install better vim defaults
git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
chsh -s "$ZSH" && "$ZSH" -i -c "omz update"
# Install powerlevel10k and oh-my-zsh plugins
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$HOME"/.oh-my-zsh/custom/themes/powerlevel10k
git clone https://github.com/zsh-users/zsh-autosuggestions "$HOME"/.oh-my-zsh/custom/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME"/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
rm -rf "$TEMPDIR"
# Create a better system monitor desktop icon
cat <<'EOF' >/usr/share/applications/sysmonitor.desktop
[Desktop Entry]
Version=1.0
Name=System Monitor
Type=Application
Comment=View System Performance
Terminal=true
Exec=btm -g --hide_time --hide_table_gap
Icon=org.gnome.SystemMonitor
Categories=ConsoleOnly;System;Monitor;Task;
GenericName=Process Viewer
Keywords=Monitor;System;Process;CPU;Memory;Network;History;Usage;Performance;Task;Manager;Activity;Performance;
EOF
# Install a better default zsh PS1
cp "$HOME"/.zshrc /opt/simple-desktop/backup_confs/
cat <<'EOF' >"$HOME"/.zshrc
export ZSH=$HOME/.oh-my-zsh
function prompt_my_cpu_temp() {
if [[ ! -f /sys/class/thermal/thermal_zone0/temp ]]; then
return
fi
integer cpu_temp="$(</sys/class/thermal/thermal_zone0/temp) / 1000"
if ((cpu_temp >= 80)); then
p10k segment -s HOT -f red -t "${cpu_temp}"$'\uE339' -i $'\uF737'
elif ((cpu_temp >= 60)); then
p10k segment -s WARM -f yellow -t "${cpu_temp}"$'\uE339' -i $'\uE350'
else
p10k segment -s COLD -f green -t "${cpu_temp}"$'\uE339' -i $'\uE350'
fi
}
function batppf() {
bat -ppf "$1"
}
function audit() {
echo -e "\033[1mSystemD: \033[0m $(sudo systemctl --failed --no-pager | grep -v UNIT)"
echo -e "\033[1mDmesg: \033[0m \n$(sudo dmesg -tP --level=err,emerg,crit,alert | sed 's/^/ /')"
echo -e "\033[1mJournal: \033[0m \n$(sudo journalctl -p "emerg..err" --no-pager -b | grep -v 'kernel\|Logs\|ssh'| sed 's/^/ /')"
echo -e "\033[1mSecureBoot: \033[0m \n$(mokutil --sb-state 2>/dev/null | sed 's/^/ /')"
echo -e "\033[1mVulnerabilities: \033[0m \n$(grep -r . /sys/devices/system/cpu/vulnerabilities/ 2>/dev/null | sed 's/^/ /')"
}
function keybindings() {
{
gsettings list-recursively org.gnome.settings-daemon.plugins.media-keys &
gsettings list-recursively org.gnome.desktop.wm.keybindings
} | awk '{sub($1 FS, "")}7' | sort
}
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
ZSH_THEME="powerlevel10k/powerlevel10k"
POWERLEVEL9K_MODE=nerdfont-complete
POWERLEVEL9K_SHORTEN_STRATEGY=truncate_beginning
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_RPROMPT_ON_NEWLINE=false
POWERLEVEL9K_DISABLE_GITSTATUS=true
POWERLEVEL9K_TIME_FORMAT='%D{%I:%M}'
POWERLEVEL9K_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL='\uE0B2'
POWERLEVEL9K_RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL='\uE0B0'
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX='%F{blue}╭─'
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX='%F{blue}╰%f '
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time my_cpu_temp ram load disk_usage)
plugins=(
fzf
git
zsh-autosuggestions
zsh-syntax-highlighting
colored-man-pages
)
source "$ZSH"/oh-my-zsh.sh
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias apt-get='sudo apt-get'
alias apt='sudo apt'
alias audit=audit
alias bat=batppf
alias c='clear'
alias cpr='rsync -ah --info=progress2'
alias crons='sudo find /var/spool/cron /etc/crontab /etc/anacrontab -type f -exec cat {} \; 2>/dev/null | grep -v "^#\|^[A-Z]"| sed -e "s/[[:space:]]\+/ /g" | awk NF'
alias df="df -hT"
alias diff="delta -s"
alias docker='sudo docker'
alias docker-compose='sudo docker-compose'
alias dpkg='sudo dpkg'
alias brew_update='brew update; brew upgrade; brew update --cask; brew upgrade --cask; brew cleanup -s; brew doctor; brew missing'
alias du='du -h'
alias egrep='egrep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox,.vscode,node_modules,vendor,.clangd,__pycache__,.npm,.cache,.composer}'
alias extract=extract
alias ff='find . -name'
alias flightoff='sudo rfkill unblock all'
alias flighton='sudo rfkill block all'
alias fgrep='fgrep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox,.vscode,node_modules,vendor,.clangd,__pycache__,.npm,.cache,.composer}'
alias grep='grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox,.vscode,node_modules,vendor,.clangd,__pycache__,.npm,.cache,.composer}'
alias halt='sudo sync && sudo systemctl halt'
alias h='history'
alias ls='lsd'
alias l='lsd -l'
alias la='lsd -a'
alias lla='lsd -la'
alias lt='lsd --tree'
alias ll='lsd -lh'
alias lsa='lsd -lah'
alias climit='cpulimit -l $((20 * $(nproc --all))) -b -z -q -e'
alias mkdir='mkdir -p'
alias mute='amixer set Master mute'
alias netfiles='sudo lsof -i 4 2>/dev/null'
alias netstat='sudo netstat -tulanp'
alias netreset='sudo systemd-resolve --flush-caches && sudo nmcli networking off && sudo nmcli networking on'
alias open='xdg-open'
alias old='lsd -lt | tail -n 10'
alias journalctl='sudo journalctl'
alias json='python3 -m json.tool'
alias keybindings=keybindings
alias more='less'
alias new='lsd -ltr | tail -n 10'
alias path='echo $PATH | tr -s ":" "\n"'
alias poweroff='sudo sync && systemctl poweroff'
alias pkill='sudo pkill -9 -f'
alias pubip='dig @1.1.1.1 ch txt whoami.cloudflare +short | cut -d\" -f 2'
alias reboot='sudo sync && sudo systemctl reboot'
alias restart='sudo systemctl --no-ask-password try-restart'
alias serve='python3 -m http.server'
alias service='sudo service'
alias services='sudo systemctl list-unit-files --no-legend --type=service --state=enabled --no-pager'
alias shutdown='sudo sync && systemctl poweroff'
alias scp='scp -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no"'
alias snap='sudo snap'
alias ssh='ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no"'
alias systemctl='sudo systemctl'
alias tb='nc termbin.com 9999'
alias top='btm -g --hide_time --hide_table_gap'
alias topcpu='sudo ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head'
alias topfiles='find . -type f -exec du -Sh {} + | sort -rh | head'
alias topmem='sudo ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'
alias topof='sudo lsof 2>/dev/null | cut -d" " -f1 | sort | uniq -c | sort -r -n | head'
alias timers='sudo systemctl list-timers --all --no-pager'
alias tmprm='for n in $(find $HOME -name ".*" -type d | grep "tmp$\|temp$\|cache$"); do find "$n" -type f -delete; done'
alias tree='lsd --tree'
alias root='sudo su -'
alias unmute='amixer set Master unmute && amixer set Headphone unmute'
alias vrm='vagrant box list | cut -f 1 -d " " | xargs -L 1 vagrant box remove -f'
alias vi='vim'
alias wflow='watch -n1 "sudo lsof -i TCP:80,443"'
alias q='exit'
alias quit='exit'
export VISUAL=vim
export EDITOR=$VISUAL
export PAGER=less
export HISTSIZE=3000
export HISTCONTROL=ignoredups:erasedups
export GIT_PAGER="delta -s"
export FZF_COMPLETION_TRIGGER='**'
export BAT_THEME="Sublime Snazzy"
export __GL_SHADER_DISK_CACHE_PATH=$HOME/.cache
export __GL_SHADER_DISK_CACHE=1
export __GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1
bindkey -s "^[OM" "^M" 2>/dev/null
EOF
chown -Rf "$SUDO_USER":"$SUDO_USER" "$HOME"
;;
*)
echo "options: slack,discord,chrome,firefox,spotify,zoom,teams,overclock,developer,theme,docker,flatpak,cleanup_script,disable_spectre"
;;
esac
}
# Remove common desktop apps
remove() {
case $1 in
slack)
snap remove slack
;;
chrome)
apt remove -y "google-chrome*"
;;
spotify)
snap remove spotify
;;
zoom)
apt remove -y "zoom*"
;;
teams)
apt remove -y teams
;;
discord)
snap remove discord
;;
firefox)
apt remove -y firefox
;;
bloat)
for p in gnome-todo thunderbird transmission-common shotwell byobu rhythmbox cheese totem aisleriot gnome-mahjongg gnome-mines gnome-sudoku remmina autofs beep pastebinit popularity-contest whoopsie xinetd yp-tools ypbind; do
apt purge -y $p
done
apt autoremove -y
;;
theme)
dconf load / </opt/simple-desktop/backup_confs/dconf-settings.ini
;;
*)
echo "slack,discord,chrome,firefox,spotify,zoom,teams,bloat,theme"
;;
esac
}
# Check if backup is present, if not delete current file
restore_delete() {
if [[ -f "$2" ]]; then
cp -f "$2" "$1"
else
rm -f "$1"
fi
}
# Detect internet connection
detect_internet() {
if [[ $(ping -c 1 1.1.1.1 | grep '100% packet loss') != "" ]]; then
echo "Internet seems to be down"
exit 1
fi
}
# rollback does it's best to reset the OS back to it's original state
rollback() {
cp -f /opt/simple-desktop/backup_confs/default-wifi-powersave-on.conf /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
cp -f /opt/simple-desktop/backup_confs/hosts /etc/hosts
restore_delete /opt/simple-desktop/backup_confs/99-limits.conf /etc/security/limits.d/99-limits.conf
restore_delete /opt/simple-desktop/backup_confs/99-sysctl.conf /etc/sysctl.d/99-sysctl.conf
cp -f /opt/simple-desktop/backup_confs/fstab /etc/fstab
restore_delete /opt/simple-desktop/backup_confs/rc.local /etc/rc.local
add-apt-repository --remove ppa:oibaf/graphics-drivers -y
add-apt-repository --remove ppa:damentz/liquorix -y
add-apt-repository --remove ppa:papirus/papirus -y
add-apt-repository --remove ppa:graphics-drivers/ppa -y
systemctl enable openvpn
systemctl enable sssd
systemctl enable NetworkManager-wait-online
systemctl enable motd-news.timer
systemctl enable fstrim.timer
systemctl enable irqbalance
systemctl enable apt-daily.service
systemctl enable apt-daily.timer
systemctl enable apt-daily-upgrade.timer
systemctl enable apt-daily-upgrade.service
systemctl enable fwupd-refresh.timer
systemctl enable ctrl-alt-del.target
systemctl enable debug-shell.service
systemctl mask simple-desktop-maintenance.timer
ufw logging on
ufw disable
gnome-extensions disable '[email protected]'
dconf load / </opt/simple-desktop/backup_confs/dconf-settings.ini
busctl --user call "org.gnome.Shell" "/org/gnome/Shell" "org.gnome.Shell" "Eval" "s" 'Meta.restart("Restarting…")'
snap remove --purge auto-cpufreq
apt remove -y tuned linux-image-liquorix-amd64 linux-headers-liquorix-amd64 papirus-icon-theme vim gnome-tweaks dconf-cli gnome-shell-extensions chrome-gnome-shell gnome-shell-extension-prefs bleachbit ubuntu-restricted-extras ubuntu-restricted-addons inxi dmidecode mokutil make gettext git
cp -f /opt/simple-desktop/backup_confs/grub /etc/default/grub
update-grub
}
# Setup cleanup systemd timers jobs for system maintenance
setup_cleanup_script() {
# Install update and cleanup script
cat <<'EOF' >/opt/simple-desktop/bin/simple-desktop-maintenance.sh
#!/bin/bash
# Sync time
if [ "$(systemctl status systemd-timesyncd.service | grep 'Active: active')" != "" ]; then
systemctl restart systemd-timesyncd.service
fi
# Update homebrew
if [ "$(command -v brew)" ]; then
brew update
brew upgrade
brew update --cask
brew upgrade --cask
brew cleanup -s
brew doctor
brew missing
fi
# Update flatpaks
command -v flatpak && flatpak update -y -v
# Update PI firmware
command -v rpi-eeprom-config && rpi-eeprom-config -a
# Update firmware
if [ "$(command -v fwupdmgr)" ]; then
fwupdmgr refresh --force
fwupdmgr update -y
fi
if [ "$(command -v swupd)" ]; then
# Update Clear Linux
swupd update -y
# Repair Clear Linux
swupd repair -y -x
# Clean Clear Linux Updates
swupd clean -y
fi
if [ "$(command -v dpkg)" ]; then
# Fix or clean any lock files
rm -f /var/lib/dpkg/updates/*
# Remove all linux kernels except the current one
dpkg --list | awk '{ print $2 }' | grep -e 'linux-\(headers\|image\)-.*[0-9]\($\|-generic\)' | grep -v "$(uname -r | sed 's/-generic//')" | xargs apt purge -y
# Remove old Linux source
dpkg --list | awk '{ print $2 }' | grep linux-source | xargs apt purge -y
# Purge old/removed packages
dpkg -l | awk '/^rc/{print $2}' | xargs apt-get purge -y
fi
if [ "$(command -v apt)" ]; then
# Fix or clean any lock files
rm -f /var/lib/apt/lists/lock
rm -f /var/cache/apt/archives/lock
# Upgrade packages
apt update -y
ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt upgrade -y
# Clean garbage
apt autoremove -y --purge
apt -y autoclean
apt -y clean
fi
if [ "$(command -v yum)" ]; then
yum update -y
yum clean all
rm -rf /var/cache/yum
fi
# Upgrade and remove old snaps
if [ "$(command -v snap)" ]; then
snap set system refresh.retain=2
snap refresh
snap list --all | awk '/disabled/{print $1, $3}' | while read -r snapname revision; do snap remove "$snapname" --revision="$revision"; done
fi
# Clean journal
if [ "$(command -v journalctl)" ]; then
journalctl --rotate
journalctl --vacuum-files=2
journalctl --vacuum-size=100M
fi
# BleachBit Cleaner
if [ "$(command -v bleachbit)" ]; then
bleachbit --clean adobe_reader.cache \
adobe_reader.mru \
adobe_reader.tmp \
apt.autoclean \
apt.autoremove \
apt.clean \
apt.package_lists \
deepscan.backup \
deepscan.ds_store \
deepscan.thumbs_db \
deepscan.tmp \
deepscan.vim_swap_root \
deepscan.vim_swap_user \
evolution.cache \
firefox.crash_reports \
flash.cache \
flash.cookies \
gedit.recent_documents \
gimp.tmp \
gnome.run \
gnome.search_history \
java.cache \
journald.clean \
libreoffice.cache \
libreoffice.history \
nautilus.history \
openofficeorg.cache \
openofficeorg.recent_documents \
screenlets.logs \
skype.chat_logs \
skype.installers \
slack.cache \
sqlite3.history \
system.cache \
system.localizations \
system.recent_documents \
system.rotated_logs \
system.tmp \
system.trash \
thumbnails.cache \
x11.debug_logs \
zoom.cache \
zoom.logs
# BleachBit for all users
grep home /etc/passwd | grep -v 'nologin\|false' | awk -F':' '{ print $ 1 }' | while IFS= read -r user; do
runuser -l "$user" -c "bleachbit --clean adobe_reader.cache \
adobe_reader.mru \
adobe_reader.tmp \
apt.autoclean \
apt.autoremove \
apt.clean \
apt.package_lists \
deepscan.backup \
deepscan.ds_store \
deepscan.thumbs_db \
deepscan.tmp \
deepscan.vim_swap_root \
deepscan.vim_swap_user \
evolution.cache \
firefox.crash_reports \
flash.cache \
flash.cookies \
gedit.recent_documents \
gimp.tmp \
gnome.run \
gnome.search_history \
java.cache \
journald.clean \
libreoffice.cache \
libreoffice.history \
nautilus.history \
openofficeorg.cache \
openofficeorg.recent_documents \
screenlets.logs \
skype.chat_logs \
skype.installers \
slack.cache \
sqlite3.history \
system.cache \
system.localizations \
system.recent_documents \
system.rotated_logs \
system.tmp \
system.trash \
thumbnails.cache \
x11.debug_logs \
zoom.cache \
zoom.logs"
done
fi
# Clean hidden temp and cache files
for n in $(find / -type d \( -name ".tmp" -o -name ".temp" -o -name ".cache" \) 2>/dev/null); do find "$n" -type f -delete; done
# Clean old logs
find /var/log -name '*.log' -type f -mtime +30 -delete
find /var/log -name '*.gz' -type f -delete
find /var/log -name '*.log.[0-9$]' -type f -delete
# Clear contents of log files bigger than 100M
for log in $(find / -type f -size +100M 2>/dev/null | grep '\.log$\|\.log.old$\|\.log.bk$\|\.log.backup$'); do
echo >"$log"
done
# Set 0600 to SSH files
for n in $(find / -type d -name ".ssh" 2>/dev/null); do find "$n" -type f -exec chmod -f 0600 {} +; done
# Set files and dirs without user to root
find / -nouser -exec chown -f root {} \; 2>/dev/null
# Set files and dirs without group to root
find / -nogroup -exec chown -f :root {} \; 2>/dev/null
# Remove other world writable permissions on all files
find / -xdev -perm +o=w ! \( -type d -perm +o=t \) ! -type l -ok chmod -v o-w {} \; 2>/dev/null
# Set home directories to 0750 permissions
find /home -maxdepth 1 -mindepth 1 -type d -exec chmod -f 0700 {} \;
# Remove group and other permissions on log files
chmod -Rf g-wx,o-rwx /var/log/*
# Trim SSD
command -v fstrim && fstrim -v /
EOF
chmod -f 0755 /opt/simple-desktop/bin/simple-desktop-maintenance.sh
cat <<'EOF' >/etc/systemd/system/simple-desktop-maintenance.service
[Unit]
Description=Run simple-desktop Update & Clean Up Script
After=network.target
[Service]
ExecStart=/opt/simple-desktop/bin/simple-desktop-maintenance.sh
StandardOutput=file:/var/log/simple-desktop-maintenance.log
StandardError=file:/var/log/simple-desktop-maintenance.log
[Install]
WantedBy=default.target
EOF
cat <<'EOF' >/etc/systemd/system/simple-desktop-maintenance.timer
[Unit]
Description=simple-desktop Update & Clean Up Timer
[Timer]
OnBootSec=30min
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
systemctl enable --now simple-desktop-maintenance.timer
}
# Setup /etc/rc.local startup script
setup_rclocal() {
# Better define the systemd rc-local service
cat <<'EOF' >/etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
EOF
# Create rc.local file that sets disk queue thresholds on-boot
cp -f /etc/rc.local /opt/simple-desktop/backup_confs/
cat <<'EOF' >/etc/rc.local
#!/bin/sh
for d in /sys/block/[m,s,n,x]*; do
printf 1024 > "$d"/queue/nr_requests
printf 1024 > "$d"/queue/read_ahead_kb
printf 1 > "$d"/queue/add_random
printf 2 > "$d"/queue/rq_affinity
printf 1 > "$d"/queue/iosched/low_latency
done
command -v tuned-adm && tuned-adm auto_profile
exit 0
EOF
chmod -f 0755 /etc/rc.local
systemctl daemon-reload
systemctl enable rc-local
}
# Setup mount points in /etc/fstab
setup_fstab() {
# Disable no access time on files and dirs. Increase commit to disk from 5
cp -f /etc/fstab /opt/simple-desktop/backup_confs/
if [[ $(mount | grep ext4 | grep ' / ') != "" ]]; then
sed -i 's| / .*| / ext4 rw,noatime,nodiratime,discard,commit=120,errors=remount-ro 0 1|g' /etc/fstab
fi
sed -i '/\/boot/ s/defaults.*/defaults,noatime,nodiratime,nosuid,nodev 0 2/g' /etc/fstab
}
# Setup additional kernel parameters
setup_sysctl() {
# TODO: Set different values based on RAM size
cp -f /etc/sysctl.d/99-sysctl.conf /opt/simple-desktop/backup_confs/
cat <<'EOF' >/etc/sysctl.d/99-sysctl.conf
dev.tty.ldisc_autoload=0
fs.epoll.max_user_watches=12616437
fs.file-max=9223372036854775807
fs.inotify.max_queued_events=524288
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=524288
fs.nr_open=1073741816
fs.protected_fifos=2
fs.protected_regular=2
fs.suid_dumpable=0
kernel.core_pattern=/bin/false
kernel.core_uses_pid=1
kernel.dmesg_restrict=1
kernel.kptr_restrict=2
kernel.panic=5
kernel.perf_event_paranoid=3
kernel.pid_max=65536
kernel.printk=3 3 3 3
kernel.sysrq=0
kernel.unprivileged_bpf_disabled=1
net.core.bpf_jit_harden=2
net.core.default_qdisc=fq
net.core.netdev_max_backlog=4096
net.core.rmem_max=16777216
net.core.somaxconn=65535
net.core.wmem_max=16777216
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.all.forwarding=0
net.ipv4.conf.all.log_martians=1
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.default.log_martians=1
net.ipv4.conf.default.rp_filter=1
net.ipv4.conf.default.secure_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.tcp_congestion_control=bbr
net.ipv4.tcp_early_retrans=1
net.ipv4.tcp_fin_timeout=15
net.ipv4.tcp_max_syn_backlog=8096
net.ipv4.tcp_max_tw_buckets=1440000
net.ipv4.tcp_moderate_rcvbuf=1
net.ipv4.tcp_no_metrics_save=1
net.ipv4.tcp_rmem=4096 12582912 16777216
net.ipv4.tcp_slow_start_after_idle=0
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_window_scaling=1
net.ipv4.tcp_wmem=4096 12582912 16777216
net.ipv6.conf.all.accept_redirects=0
net.ipv6.conf.all.forwarding=0
net.ipv6.conf.default.accept_redirects=0
net.ipv6.conf.default.accept_source_route=0
vm.dirty_background_ratio=5
vm.dirty_expire_centisecs=12000
vm.dirty_ratio=50
vm.dirty_writeback_centisecs=1500
vm.extfrag_threshold=100
vm.max_map_count=262144
vm.min_free_kbytes=80000
vm.mmap_min_addr=65536
vm.swappiness=10
vm.vfs_cache_pressure=50
EOF
sysctl -p /etc/sysctl.d/99-sysctl.conf
}
# Increase security file limits to max values
setup_limits() {
cp -f /etc/security/limits.d/99-limits.conf /opt/simple-desktop/backup_confs/ 2>/dev/null
cat <<'EOF' >/etc/security/limits.d/99-limits.conf
* soft nofile 999999
* hard nofile 999999
root soft nofile 999999
root hard nofile 999999
* soft stack unlimited
* hard stack unlimited
root soft stack unlimited
root hard stack unlimited
* hard core 0
* soft core 0
EOF
}
# Setup additional grub parameters
setup_grub() {
cp -f /etc/default/grub /opt/simple-desktop/backup_confs/
sed -i 's|GRUB_TIMEOUT=.*|GRUB_TIMEOUT=0|g' /etc/default/grub
sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT="quiet transparent_hugepage=madvise nowatchdog"|g' /etc/default/grub
update-grub
}
# Disable Spectre Mitigations
setup_disable_spectre() {
if [ ! -f "/opt/simple-desktop/backup_confs/grub" ]; then
cp -f /etc/default/grub /opt/simple-desktop/backup_confs/
fi
sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT="quiet transparent_hugepage=madvise mitigations=off nowatchdog"|g' /etc/default/grub
update-grub
}
# Setup various networking configurations
setup_network() {
# Block ads / trackers
cp -f /etc/hosts /opt/simple-desktop/backup_confs/
wget -c 'https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews/hosts'
sed -i "s/localhost$/localhost $(hostname)/g" hosts
mv -f hosts /etc/
# Turn off powersave on WiFi settings
cp -f /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf /opt/simple-desktop/backup_confs/
sed -i 's|wifi.powersave.*|wifi.powersave = 2|g' /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
}
# Setup advanced Gnome configurations including Tweaks
setup_theme() {
# Install MesloLGS Nerd font
mkdir -p "$HOME"/.local/share/fonts
cd "$HOME"/.local/share/fonts || echo "Cannot install MesloLGS fonts" >&2
wget -c https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
wget -c https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
wget -c https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
wget -c https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
# Install Vimix Material Design GNOME shell theme
curl -L https://github.com/vinceliuice/vimix-gtk-themes/archive/master.zip -o vimix.zip
unzip vimix.zip
./vimix-gtk-themes-master/install.sh
rm -rf vimix*
# Install Dock-to-Panel
git clone https://github.com/home-sweet-gnome/dash-to-panel.git -b gnome-3.38
cd dash-to-panel || echo "Cannot install Dock-to-Panel" >&2
make install
gnome-extensions enable '[email protected]'
cd .. && rm -rf dash-to-panel
# Install TopIcons-plus
git clone https://github.com/phocean/TopIcons-plus.git
cd TopIcons-plus || echo "Cannot install TopIcons-plus" >&2
make install
cd .. && rm -rf TopIcons-plus
# Install gnome-fuzzy-app-search
git clone https://gitlab.com/Czarlie/gnome-fuzzy-app-search.git
cd gnome-fuzzy-app-search || echo "Cannot install gnome-fuzzy-app-search" >&2
make install
cd .. && rm -rf gnome-fuzzy-app-search
busctl --user call "org.gnome.Shell" "/org/gnome/Shell" "org.gnome.Shell" "Eval" "s" 'Meta.restart("Restarting…")'
# Install Gnome Desktop UI settings
cat <<'EOF' >./dconf-settings.ini
[apps/update-manager]
first-run=false
launch-count=1
launch-time=int64 1598240380
[ca/desrt/dconf-editor]
saved-pathbar-path='favorit'
saved-view='/'
show-warning=false
window-height=500
window-is-maximized=true
window-width=540
[com/ubuntu/sound]
allow-amplified-volume=true
[com/ubuntu/touch/network]
gps=false
[com/ubuntu/update-notifier]
no-show-notifications=true
release-check-time=uint32 1598240370