-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux.sh
More file actions
executable file
·140 lines (108 loc) · 4.78 KB
/
linux.sh
File metadata and controls
executable file
·140 lines (108 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
set -euo pipefail
. src/linux/apk.sh
. src/linux/gui.sh
. src/linux/gui_apps.sh
. src/linux/machines.sh
provision_setup_linux() {
if [ "$IS_LINUX" != "1" ]; then
return
fi
cat >>~/.shellrc <<"EOF"
export PATH="$PATH:/usr/sbin"
EOF
install_system_package "lshw"
install_system_package "dmidecode"
cat >>~/.shell_aliases <<"EOF"
alias systemctl='systemctl --user'
alias LinuxLsHardwareMemory='sudo dmidecode --type 17'
alias JournalctlDiskUsage='sudo journalctl --disk-usage'
alias JournalctlKernel='sudo journalctl -k'
alias JournalctlLsBoots='sudo journalctl --list-boots'
alias JournalctlSystemErrors='sudo journalctl -p 3 -x'
alias JournalctlUnit='sudo journalctl -u' # e.g. JournalctlUnit ufw -b
alias JournalctlUser='sudo journalctl _UID=' # find with `id USER_NAME`
alias LinuxLsCPU='lscpu'
alias LinuxLsHardware='sudo lshw'
alias LinuxLsHardwarePCI='lspci'
alias LinuxLsKernelModules='lsmod'
alias SystemFailed='systemctl --failed ; sudo systemctl --failed'
alias SystemFailedReset='systemctl reset-failed ; sudo systemctl reset-failed'
alias SystemAnalyzeCriticalChain='systemd-analyze critical-chain'
alias SystemAnalyzePlot='systemd-analyze plot > /tmp/plot.svg && echo "/tmp/plot.svg generated"'
alias SystemAnalyzeTimes='systemd-analyze blame'
FACLRemoveGroupForFile() { sudo setfacl -x g:$1 $2 ; }
alias LsBlkNoLoop='lsblk -e7' # Excludes loop devices, which can accumulate when using snaps: https://askubuntu.com/a/1142405
alias LsInitRAMFS='lsinitcpio /boot/initramfs-linux.img'
alias LabelEXTPartition='sudo e2label' # For example: LabelEXTPartition /dev/sda2 FOO_NAME
alias LabelFAT='sudo fatlabel' # For example: LabelFAT /dev/sda2 FOO_NAME
LuksAddKeyInPartitionForSlot() { sudo cryptsetup --key-slot $2 luksAddKey $1; } # 當佢只有一個密鑰嗰陣,個插槽號碼係0
LuksLabelPartition() { sudo cryptsetup config $1 --label $2; } # 例如: LabelLuksPartition /dev/sda2 FOO_NAME
LuksPrintDump() { sudo cryptsetup luksDump $1; }
LuksRemoveKeyByPassword() { sudo cryptsetup luksRemoveKey $1; } # 例如: LuksRemoveKeyByPassword /dev/sda2
SystemdFindReference() { sudo grep -r "$1" /usr/lib/systemd/system/; }
# Example: TOTP ~/foo-topt.gpg
TOTP() {
KEY=$(sudo gpg -q -d --pinentry-mode=loopback --no-symkey-cache $1)
if [ -z "$KEY" ]; then echo "Invalid key"; return; fi
VALUE=$(oathtool --totp -b "$KEY");
echo "$VALUE" ; echo "$VALUE" | tr -d '\n' | xclip -selection clipboard
}
alias HongKongTimezone='sudo timedatectl set-timezone Asia/Hong_Kong'
alias MadridTimezone='sudo timedatectl set-timezone Europe/Madrid'
alias TimeSyncRestart='sudo systemctl restart systemd-timesyncd.service'
alias TimeSyncShow='timedatectl show-timesync --all'
alias TimeSyncStatus='timedatectl timesync-status'
alias TimezoneShow='timedatectl status'
alias TokyoTimezone='sudo timedatectl set-timezone Asia/Tokyo'
GrubHideSetupTimeout() {
sudo sed -i 's|^GRUB_TIMEOUT=.*|GRUB_TIMEOUT=1|' /etc/default/grub
sudo sed -i 's|^GRUB_TIMEOUT_STYLE=.*|GRUB_TIMEOUT_STYLE=hidden|' /etc/default/grub
}
LinuxSwappinessUpdate() {
echo 'vm.swappiness=10' > /tmp/99-swappiness.conf
echo 'vm.vfs_cache_pressure=50' >> /tmp/99-swappiness.conf
echo 'vm.dirty_ratio=3' >> /tmp/99-swappiness.conf
sudo mv /tmp/99-swappiness.conf /etc/sysctl.d/
}
alias SOInspectSymbols='nm -gDC'
alias SODumpSymbols='objdump -tT'
EOF
# https://www.geeksforgeeks.org/iotop-command-in-linux-with-examples
# sudo iotop -o -n 2 -t -b
install_system_package "iotop"
# LVM
# Creation: lvcreate --size 10G -n home ubuntu-vg # use mkfs.ext4 and mount (for fstab) after
# For extending: lvextend -L +8G /dev/mapper/lv-foo ; resize2fs /dev/mapper/lv-foo
# lvdisplay
# Performance
if [ ! -f ~/.check-files/noatime ]; then
if [ -f /etc/fstab ] && [ -n "$(grep relatime /etc/fstab || true)" ]; then
echo "[~/.check-files/noatime]: Replace relatime with noatime in fstab and hide this message"
fi
fi
install_system_package "strace"
mkdir -p ~/.gnupg
echo "pinentry-program /usr/bin/pinentry-tty" >~/.gnupg/gpg-agent.conf
# Disable the PC loud beep
if [ ! -f /etc/modprobe.d/nobeep.conf ]; then
sudo mkdir -p /etc/modprobe.d
echo 'blacklist pcspkr' | sudo tee /etc/modprobe.d/nobeep.conf
fi
if [ "$IS_NIXOS" != "1" ]; then
if [ -f "$PROVISION_CONFIG"/tailscale ] && [ ! -f ~/.check-files/tailscale ]; then
curl -fsSL https://tailscale.com/install.sh | sh
if [ -n "$(sudo systemctl list-units | grep tailscaled || true)" ]; then
sudo systemctl enable --now tailscaled
else
sudo systemctl enable --now tailscale
fi
touch ~/.check-files/tailscale
fi
fi
echo 'export XDG_RUNTIME_DIR="/run/user/$(id -u)"' >>~/.zshrc
provision_setup_linux_apk
provision_setup_linux_gui
provision_setup_linux_gui_apps
provision_setup_linux_machines
}