-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·412 lines (353 loc) · 13.3 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·412 lines (353 loc) · 13.3 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
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
#!/usr/bin/env bash
clear
RED='\033[31m'
YELLOW='\033[33m'
CYAN='\033[36m'
GREEN='\033[32m'
NC='\033[0m'
print_message() {
local color="$1"
local message="$2"
printf "%b:: %s%b\n" "$color" "$message" "$NC"
}
confirm() {
while true; do
read -p "$(printf "%b:: %s%b" "$CYAN" "$1 [y/N]: " "$NC")" answer
case ${answer,,} in
y | yes) return 0 ;;
n | no | "") return 1 ;;
*) print_message "$YELLOW" "Please answer with y/yes or n/no." ;;
esac
done
}
detect_distro() {
if [ -x "$(command -v pacman)" ]; then
DISTRO="Arch"
elif [ -x "$(command -v dnf)" ]; then
DISTRO="Fedora"
elif [ -x "$(command -v zypper)" ]; then
DISTRO="openSUSE"
else
DISTRO="Unknown"
exit 1
fi
}
install_packages() {
case "$DISTRO" in
"Arch")
check_aur_helper
print_message "$CYAN" "Installing required packages using pacman and AUR..."
sudo pacman -S --needed git base-devel libx11 libxinerama libxft gnome-keyring ttf-cascadia-mono-nerd \
ttf-cascadia-code-nerd ttf-jetbrains-mono-nerd ttf-jetbrains-mono imlib2 libxcb git unzip lxappearance \
feh mate-polkit meson ninja xorg-xinit xorg-server network-manager-applet blueman pasystray bluez-utils \
thunar flameshot trash-cli tumbler fzf gvfs-mtp neovim slock nwg-look swappy kvantum \
gtk3 gtk4 qt5ct qt6ct man man-db pamixer pavucontrol pavucontrol-qt ffmpeg ffmpegthumbnailer yazi dunst \
picom || {
print_message "$RED" "Failed to install some packages via pacman."
exit 1
}
print_message "$CYAN" "Installing xautolock from AUR..."
$aur_helper -S --noconfirm xautolock || {
print_message "$RED" "Failed to install xautolock from AUR."
exit 1
}
;;
"Fedora")
print_message "$CYAN" "Installing required packages using dnf..."
print_message "$CYAN" "Enabling RPM Fusion repositories..."
sudo dnf install -y https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-42.noarch.rpm \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-42.noarch.rpm || {
print_message "$RED" "Failed to enable RPM Fusion repositories."
exit 1
}
print_message "$CYAN" "Enabling lihaohong/yazi COPR repository..."
sudo dnf copr enable -y lihaohong/yazi || {
print_message "$RED" "Failed to enable lihaohong/yazi COPR repository."
exit 1
}
sudo dnf install -y git libX11-devel libXinerama-devel libXft-devel imlib2-devel libxcb-devel \
gnome-keyring unzip lxappearance feh mate-polkit meson ninja-build jetbrains-mono-fonts-all \
google-noto-color-emoji-fonts network-manager-applet blueman pasystray google-noto-emoji-fonts thunar flameshot \
trash-cli tumbler fzf gvfs-mtp neovim slock nwg-look swappy kvantum gtk3 gtk4 qt5ct qt6ct man man-db pamixer \
pavucontrol pavucontrol-qt ffmpeg-devel ffmpegthumbnailer yazi xautolock dunst \
picom || {
print_message "$RED" "Failed to install some packages via dnf."
exit 1
}
;;
"openSUSE")
print_message "$CYAN" "Installing required packages using zypper..."
sudo zypper install -y libX11-devel libXinerama-devel libXft-devel imlib2-devel libxcb-devel \
gnome-keyring unzip lxappearance feh mate-polkit meson ninja jetbrains-mono-fonts \
google-noto-fonts noto-coloremoji-fonts NetworkManager-applet blueman pasystray thunar flameshot \
trash-cli tumbler mtp-tools fzf neovim i3lock nwg-look swappy kvantum-manager libgtk-3-0 libgtk-4-1 qt5ct qt6ct man man-pages pamixer \
pavucontrol pavucontrol-qt ffmpeg-7 ffmpegthumbnailer yazi xautolock dunst \
picom || {
print_message "${RED}" "Failed to install some packages via zypper."
exit 1
}
print_message "$YELLOW" "NOTE: openSUSE uses i3lock instead of slock (slock is not available in official repositories)."
print_message "$YELLOW" "To manually lock your screen, run: i3lock"
;;
esac
}
check_aur_helper() {
if command -v paru &> /dev/null; then
print_message "$GREEN" "AUR helper paru is already installed."
aur_helper="paru"
return 0
elif command -v yay &> /dev/null; then
print_message "$GREEN" "AUR helper yay is already installed."
aur_helper="yay"
return 0
fi
print_message "$CYAN" "No AUR helper found. Installing yay..."
sudo pacman -S --needed --noconfirm git base-devel
local temp_dir=$(mktemp -d)
cd "$temp_dir" || exit 1
if git clone https://aur.archlinux.org/yay.git; then
cd yay || exit 1
makepkg -si --noconfirm || {
print_message "$RED" "Failed to install yay."
cd "$HOME" || exit
rm -rf "$temp_dir"
exit 1
}
cd "$HOME" || exit
rm -rf "$temp_dir"
aur_helper="yay"
print_message "$GREEN" "Successfully installed yay as AUR helper."
return 0
else
print_message "$RED" "Failed to clone yay repository."
cd "$HOME" || exit
rm -rf "$temp_dir"
exit 1
fi
}
install_dwm() {
if [ -d "$HOME/dwm" ]; then
if confirm "DWM directory already exists. Do you want to overwrite it?"; then
rm -rf "$HOME/dwm"
else
print_message "$YELLOW" "Skipping DWM installation."
return
fi
fi
print_message "$CYAN" "Cloning DWM repository..."
git clone https://github.com/harilvfs/dwm.git "$HOME/dwm" || exit 1
cd "$HOME/dwm" || exit 1
sudo make clean install || exit 1
print_message "$GREEN" "DWM installed successfully!"
}
install_slstatus() {
print_message "$CYAN" "Installing slstatus..."
if confirm "Do you want to install slstatus (recommended)?"; then
cd "$HOME/dwm/slstatus" || exit 1
sudo make clean install || exit 1
print_message "$GREEN" "slstatus installed successfully!"
else
print_message "$CYAN" "Skipping slstatus installation."
fi
}
install_nerd_font() {
local FONT_DIR="$HOME/.fonts"
local FONT_NAME="MesloLGS NF Regular"
mkdir -p "$FONT_DIR"
if fc-list | grep -q "$FONT_NAME"; then
print_message "$GREEN" "Meslo Nerd Font is already installed. Skipping..."
return
fi
print_message "$CYAN" "Installing Meslo Nerd Font..."
case "$DISTRO" in
"Arch")
sudo pacman -S --needed ttf-meslo-nerd || exit 1
;;
"Fedora")
wget -P /tmp https://github.com/ryanoasis/nerd-fonts/releases/latest/download/Meslo.zip || exit 1
unzip /tmp/Meslo.zip -d /tmp/Meslo || exit 1
mv /tmp/Meslo/* "$FONT_DIR" || exit 1
;;
"openSUSE")
sudo zypper install -y meslo-lg-fonts || exit 1
;;
*)
exit 1
;;
esac
fc-cache -vf || exit 1
print_message "$GREEN" "Nerd Fonts installed successfully!"
}
configure_picom() {
local CONFIG_DIR="$HOME/.config"
local DESTINATION="$CONFIG_DIR/picom.conf"
local URL="https://raw.githubusercontent.com/harilvfs/dwm/refs/heads/main/config/picom/picom-no-animation/picom.conf"
mkdir -p "$CONFIG_DIR"
if [ -f "$DESTINATION" ]; then
if confirm "Existing picom.conf detected. Do you want to replace it?"; then
local backup_path="$DESTINATION.bak.$RANDOM"
mv "$DESTINATION" "$backup_path"
print_message "$GREEN" "Backup created: $backup_path"
else
return
fi
fi
print_message "$CYAN" "Downloading picom configuration..."
wget -q -O "$DESTINATION" "$URL" || exit 1
print_message "$GREEN" "Picom configuration installed."
}
configure_wallpapers() {
local BG_DIR="$HOME/Pictures/wallpapers"
mkdir -p "$HOME/Pictures"
if [ -d "$BG_DIR" ]; then
if confirm "Wallpapers directory already exists. Do you want to overwrite?"; then
rm -rf "$BG_DIR"
else
return
fi
fi
if confirm "Do you want to download wallpapers? (Note: The wallpaper collection is large in size but recommended)"; then
print_message "$CYAN" "Downloading wallpapers..."
git clone https://github.com/harilvfs/wallpapers "$BG_DIR" || exit 1
print_message "$GREEN" "Wallpapers downloaded successfully."
else
print_message "$YELLOW" "Skipping wallpaper download."
fi
}
setup_xinitrc() {
local XINITRC="$HOME/.xinitrc"
if [ -f "$XINITRC" ]; then
if confirm "Existing .xinitrc detected. Do you want to replace it?"; then
local backup_path="$XINITRC.bak.$RANDOM"
mv "$XINITRC" "$backup_path"
print_message "$GREEN" "Backup created: $backup_path"
else
return
fi
fi
print_message "$CYAN" "Creating .xinitrc file for DWM..."
case "$DISTRO" in
"openSUSE")
cat > "$XINITRC" << 'EOF'
#!/bin/sh
pgrep dunst >/dev/null || /usr/bin/dunst &
xautolock \
-time 10 \
-locker i3lock \
-notify 10 \
-notifier "/usr/bin/notify-send '🔒 Locking soon' 'The screen will lock in 10 seconds...'" &
exec dwm
EOF
;;
*)
cat > "$XINITRC" << 'EOF'
#!/bin/sh
pgrep dunst >/dev/null || /usr/bin/dunst &
xautolock \
-time 10 \
-locker slock \
-notify 10 \
-notifier "/usr/bin/notify-send '🔒 Locking soon' 'The screen will lock in 10 seconds...'" &
exec dwm
EOF
;;
esac
chmod +x "$XINITRC"
print_message "$GREEN" ".xinitrc configured successfully!"
}
setup_tty_login() {
if confirm "Do you want to use DWM from TTY using startx?"; then
setup_xinitrc
if confirm "Do you want to enable automatic login to TTY? (Not recommended for security reasons)"; then
local username=$(whoami)
print_message "$CYAN" "Setting up autologin for user: $username"
sudo mkdir -p /etc/systemd/system/getty@tty1.service.d/
sudo tee /etc/systemd/system/getty@tty1.service.d/autologin.conf > /dev/null << EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $username --noclear %I 38400 linux
EOF
sudo systemctl daemon-reexec
print_message "$GREEN" "Autologin configured for TTY1."
fi
fi
}
check_display_manager() {
local dm_found=false
local dm_name=""
for dm in sddm gdm lightdm lxdm xdm slim greetd; do
if systemctl is-enabled $dm.service &> /dev/null; then
dm_found=true
dm_name=$dm
break
fi
done
if $dm_found; then
print_message "$YELLOW" "Display manager $dm_name is detected."
if confirm "When using DWM from TTY, a display manager is not needed. Do you want to remove $dm_name?"; then
case "$DISTRO" in
"Arch")
sudo systemctl disable $dm_name.service
sudo systemctl stop $dm_name.service
sudo pacman -Rns $dm_name
;;
"Fedora")
sudo systemctl disable $dm_name.service
sudo systemctl stop $dm_name.service
sudo dnf remove -y $dm_name
;;
"openSUSE")
sudo systemctl disable $dm_name.service
sudo systemctl stop $dm_name.service
sudo zypper remove -y $dm_name
;;
esac
print_message "$GREEN" "Display manager $dm_name has been removed."
fi
else
print_message "$GREEN" "No display manager detected. You can start DWM using 'startx' from TTY."
fi
}
setup_numlock() {
print_message "$GREEN" "Setting up NumLock on login..."
sudo tee "/usr/local/bin/numlock" > /dev/null << 'EOF'
#!/bin/bash
for tty in /dev/tty{1..6}; do
/usr/bin/setleds -D +num < "$tty"
done
EOF
sudo chmod +x /usr/local/bin/numlock
sudo tee "/etc/systemd/system/numlock.service" > /dev/null << 'EOF'
[Unit]
Description=Enable NumLock on startup
[Service]
ExecStart=/usr/local/bin/numlock
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
if confirm "Enable NumLock on boot?"; then
sudo systemctl enable numlock.service
print_message "$GREEN" "NumLock will be enabled on boot."
else
print_message "$YELLOW" "NumLock setup skipped."
fi
}
main() {
detect_distro
print_message "$GREEN" "Detected distribution: $DISTRO"
install_packages
install_dwm
install_slstatus
install_nerd_font
configure_picom
configure_wallpapers
setup_tty_login
check_display_manager
setup_numlock
print_message "$GREEN" "DWM setup completed successfully!"
print_message "$YELLOW" "Notice: I am not including dotfiles in this script to avoid conflicts and potential data loss. If you need dotfiles, check out my repo:"
print_message "$CYAN" "https://github.com/harilvfs/dwm/blob/main/config"
}
main