-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
137 lines (119 loc) · 5.74 KB
/
setup.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
#!/bin/sh
# Script variables
NEWUSER="shyguy"
XKB_MODEL="pc105"
XKB_LAYOUT="latam"
XKB_VARIANT="deadtilde"
# https://wiki.archlinux.org/title/PC_speaker#Globally
# Remove beep sound
lsmod | grep -wq pcspkr && rmmod pcspkr
lsmod | grep -wq snd_pcsp && rmmod snd_pcsp
echo 'blacklist pcspkr' > /etc/modprobe.d/nobeep.conf
echo 'blacklist snd_pcsp' >> /etc/modprobe.d/nobeep.conf
# https://wiki.archlinux.org/title/Power_management#ACPI_events
# Ignore power/suspend/reboot/hibernate buttons
sed -i 's/^#*HandlePowerKey=.*/HandlePowerKey=ignore/' /etc/systemd/logind.conf
sed -i 's/^#*HandleRebootKey=.*/HandleRebootKey=ignore/' /etc/systemd/logind.conf
sed -i 's/^#*HandleSuspendKey=.*/HandleSuspendKey=ignore/' /etc/systemd/logind.conf
sed -i 's/^#*HandleHibernateKey=.*/HandleHibernateKey=ignore/' /etc/systemd/logind.conf
# https://wiki.archlinux.org/title/Sudo#Example_entries
# Allow wheel group to run sudo without password
sed -i 's/^# %wheel ALL=(ALL:ALL) NOPASSWD: ALL/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/' /etc/sudoers
sed -i 's/^%wheel ALL=(ALL:ALL) ALL/# %wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
# https://wiki.archlinux.org/title/Users_and_groups#User_management
# Add new user
id -u "$NEWUSER" > /dev/null 2>&1 || useradd -mk "" -G wheel "$NEWUSER"
# https://github.com/Jguer/yay#Installation
# Install yay from AUR
if ! pacman -Q yay > /dev/null 2>&1; then
curl -s --output-dir /tmp -L -O https://aur.archlinux.org/cgit/aur.git/snapshot/yay-bin.tar.gz
runuser -l "$NEWUSER" -c "cd /tmp && tar -C /tmp -xf /tmp/yay-bin.tar.gz && cd yay-bin && makepkg -si --needed --noconfirm" >> /yay-output.log 2>> /yay-error.log
fi
# Install packages inside csv file
curl -s -o /tmp/pkgs.csv.tmp https://raw.githubusercontent.com/shyguyCreate/setup/main/pkgs.csv
tail -n +2 /tmp/pkgs.csv.tmp | cut -d ',' -f -2 > /tmp/pkgs.csv
while IFS=, read -r tag program; do
case "$tag" in
"A") runuser -l "$NEWUSER" -c "yay -S --needed --noconfirm $program" >> /yay-output.log 2>> /yay-error.log ;;
*) pacman -S --needed --noconfirm "$program" >> /pacman-output.log 2>> /pacman-error.log ;;
esac
done < /tmp/pkgs.csv
# https://wiki.archlinux.org/title/Sudo#Example_entries
# Allow wheel to run sudo entering password
sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
sed -i 's/^%wheel ALL=(ALL:ALL) NOPASSWD: ALL/# %wheel ALL=(ALL:ALL) NOPASSWD: ALL/' /etc/sudoers
# https://wiki.archlinux.org/title/Sudo#Sudoers_default_file_permissions
# Reset sudoers file permissions in case of accidental change
chown -c root:root /etc/sudoers
chmod -c 0440 /etc/sudoers
# https://wiki.archlinux.org/title/Doas#Configuration
# Add config file to access root
echo 'permit setenv {PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin} :wheel' > /etc/doas.conf
chown -c root:root /etc/doas.conf
chmod -c 0400 /etc/doas.conf
# https://wiki.archlinux.org/title/Uncomplicated_Firewall#Installation
systemctl --quiet disable iptables.service
systemctl --quiet disable ip6tables.service
systemctl --quiet enable ufw.service
ufw enable
# https://wiki.archlinux.org/title/LightDM#Enabling_LightDM
# Enable lightdm
systemctl --quiet enable lightdm.service
# https://wiki.archlinux.org/title/CUPS#Installation
# Enable cups
systemctl --quiet enable cups.socket
# https://wiki.archlinux.org/title/CUPS#Printer_discovery
# Disable built-in mDNS service
systemctl --quiet disable systemd-resolved.service
# https://wiki.archlinux.org/title/Avahi#Hostname_resolution
# Enable avahi with hostname resolution
systemctl --quiet enable avahi-daemon.socket
sed -i 's/hosts: mymachines resolve/hosts: mymachines mdns_minimal [NOTFOUND=return] resolve/' /etc/nsswitch.conf
# https://wiki.archlinux.org/title/Libinput#Via_Xorg_configuration_file
# Add tap to click, natural scrolling, and increased mouse speed
mkdir -p /etc/X11/xorg.conf.d
cat > /etc/X11/xorg.conf.d/30-touchpad.conf << EOF
Section "InputClass"
Identifier "touchpad"
Driver "libinput"
MatchIsTouchpad "on"
Option "AccelSpeed" "0.25"
Option "NaturalScrolling" "on"
Option "Tapping" "on"
EndSection
EOF
# https://wiki.archlinux.org/title/Xorg/Keyboard_configuration#Using_X_configuration_files
# Change Xorg keyboard layout
mkdir -p /etc/X11/xorg.conf.d
cat > /etc/X11/xorg.conf.d/00-keyboard.conf << EOF
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbModel" "$XKB_MODEL"
Option "XkbLayout" "$XKB_LAYOUT"
Option "XkbVariant" "$XKB_VARIANT"
EndSection
EOF
# https://wiki.archlinux.org/title/File_manager_functionality#Use_PCManFM_to_get_thumbnails_for_other_file_types
# Get thumbnail preview for PDFs
mkdir -p /usr/share/thumbnailers
cat > /usr/share/thumbnailers/imagemagick-pdf.thumbnailer << EOF
[Thumbnailer Entry]
TryExec=convert
Exec=convert %i[0] -background "#FFFFFF" -flatten -thumbnail %s %o
MimeType=application/pdf;application/x-pdf;image/pdf;
EOF
# https://wiki.archlinux.org/title/Command-line_shell#Changing_your_default_shell
# Change new user default shell
[ "$(getent passwd "$NEWUSER" | awk -F: '{print $NF}')" = "/usr/bin/zsh" ] || chsh -s /usr/bin/zsh "$NEWUSER" > /dev/null
# https://wiki.archlinux.org/title/Dotfiles#Tracking_dotfiles_directly_with_Git
# Copy dotfiles from repo to HOME
runuser -l "$NEWUSER" << 'EOF'
git clone -q --bare https://github.com/shyguyCreate/dotfiles.git "$HOME/.dotfiles" --depth 1
dotfiles(){ git --git-dir="$HOME/.dotfiles/" --work-tree="$HOME" $@; }
dotfiles config --local status.showUntrackedFiles no
cd "$HOME" && mkdir -p .dotfiles-backup
dotfiles checkout 2>&1 | grep "\s\s*\." | awk '{print $1}' | sed 's|[^/]*$||' | sort -u | xargs -I {} mkdir -p ".dotfiles-backup/{}"
dotfiles checkout 2>&1 | grep "\s\s*\." | awk '{print $1}' | xargs -I {} mv {} ".dotfiles-backup/{}"
dotfiles checkout -f
EOF