-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
executable file
·338 lines (291 loc) · 11.5 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
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
#!/usr/bin/env bash
# Quickly sets up the Dwm window manager with a single-click script, using my customized configuration.
clear
RC='\033[0m'
RED='\033[31m'
YELLOW='\033[33m'
CYAN='\033[36m'
GREEN='\033[32m'
BLUE='\033[34m'
RESET="\033[0m"
print_message() {
local color="$1"
local message="$2"
printf "%b%s%b\n" "$color" "$message" "$RC"
}
echo -e "${BLUE}"
if command -v figlet &>/dev/null; then
figlet -f slant "Dwm"
else
echo "========== Dwm Setup =========="
fi
echo -e "${RESET}"
FZF_COMMON="--layout=reverse \
--border=bold \
--border=rounded \
--margin=5% \
--color=dark \
--info=inline \
--header-first \
--bind change:top"
fzf_confirm() {
local prompt="$1"
local options=("Yes" "No")
local selected=$(printf "%s\n" "${options[@]}" | fzf ${FZF_COMMON} \
--height=40% \
--prompt="$prompt " \
--header="Confirm" \
--pointer="➤" \
--color='fg:white,fg+:green,bg+:black,pointer:green')
if [[ "$selected" == "Yes" ]]; then
return 0
else
return 1
fi
}
detect_distro() {
if command -v pacman &>/dev/null; then
distro="arch"
print_message "$GREEN" "Detected distribution: Arch Linux"
elif command -v dnf &>/dev/null; then
distro="fedora"
print_message "$YELLOW" "Detected distribution: Fedora"
else
print_message "$RED" "Unsupported distribution. Exiting..."
exit 1
fi
}
install_packages() {
if [ "$distro" == "arch" ]; then
print_message "$CYAN" ":: Installing required packages using pacman..."
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 gvfs-mtp fzf vim neovim slock nwg-look swappy kvantum gtk3 gtk4 qt5ct qt6ct man man-db pamixer pavucontrol pavucontrol-qt || {
print_message "$RED" "Failed to install some packages."
exit 1
}
elif [ "$distro" == "fedora" ]; then
print_message "$CYAN" ":: Installing required packages using dnf..."
print_message "$CYAN" ":: Enabling solopasha/hyprland COPR repository..."
sudo dnf copr enable -y solopasha/hyprland || {
print_message "$RED" "Failed to enable solopasha/hyprland 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 gnome-keyring jetbrains-mono-fonts-all google-noto-color-emoji-fonts network-manager-applet blueman pasystray google-noto-emoji-fonts thunar flameshot trash-cli tumbler gvfs-mtp fzf vim neovim slock nwg-look swappy kvantum gtk3 gtk4 qt5ct qt6ct man man-db pamixer pavucontrol pavucontrol-qt || {
print_message "$RED" "Failed to install some packages."
exit 1
}
fi
}
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 fzf_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 fzf_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..."
if command -v dnf &>/dev/null; then
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
else
sudo pacman -S --needed ttf-meslo-nerd || exit 1
fi
fc-cache -vf || exit 1
print_message "$GREEN" "Nerd Fonts installed successfully!"
}
install_picom() {
if [ "$distro" == "arch" ]; then
check_aur_helper
print_message "$CYAN" ":: Installing Picom with $aur_helper..."
$aur_helper -S --noconfirm picom-ftlabs-git || {
print_message "$RED" "Failed to install Picom."
print_message "$YELLOW" "Trying alternative installation method..."
local temp_dir=$(mktemp -d)
cd "$temp_dir" || exit 1
git clone https://github.com/FT-Labs/picom.git
cd picom || exit 1
meson setup --buildtype=release build
ninja -C build
sudo ninja -C build install
cd "$HOME" || exit
rm -rf "$temp_dir"
}
elif [ "$distro" == "fedora" ]; then
print_message "$CYAN" ":: Installing Picom manually on Fedora..."
sudo dnf install -y dbus-devel gcc git libconfig-devel libdrm-devel libev-devel libX11-devel libX11-xcb libXext-devel libxcb-devel libGL-devel libEGL-devel libepoxy-devel meson pcre2-devel pixman-devel uthash-devel xcb-util-image-devel xcb-util-renderutil-devel xorg-x11-proto-devel xcb-util-devel
git clone https://github.com/FT-Labs/picom.git "$HOME/picom"
cd "$HOME/picom" || exit 1
meson setup --buildtype=release build
ninja -C build
sudo cp build/src/picom /usr/bin/
fi
configure_picom
}
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.conf"
mkdir -p "$CONFIG_DIR"
if [ -f "$DESTINATION" ]; then
if fzf_confirm "Existing picom.conf detected. Do you want to replace it?"; then
mv "$DESTINATION" "$DESTINATION.bak"
else
return
fi
fi
wget -q -O "$DESTINATION" "$URL" || exit 1
print_message "$GREEN" "Picom configuration updated."
}
configure_wallpapers() {
local BG_DIR="$HOME/Pictures/wallpapers"
mkdir -p "$HOME/Pictures"
if [ -d "$BG_DIR" ]; then
if fzf_confirm "Wallpapers directory already exists. Do you want to overwrite?"; then
rm -rf "$BG_DIR"
else
return
fi
fi
if fzf_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 fzf_confirm "Existing .xinitrc detected. Do you want to replace it?"; then
mv "$XINITRC" "$XINITRC.bak"
else
return
fi
fi
print_message "$CYAN" ":: Creating .xinitrc file for DWM..."
cat > "$XINITRC" << 'EOF'
#!/bin/sh
exec dwm
EOF
chmod +x "$XINITRC"
print_message "$GREEN" ".xinitrc configured successfully!"
}
setup_tty_login() {
if fzf_confirm "Do you want to use DWM from TTY using startx?"; then
setup_xinitrc
if fzf_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/[email protected]/
sudo tee /etc/systemd/system/[email protected]/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 fzf_confirm "When using DWM from TTY, a display manager is not needed. Do you want to remove $dm_name?"; then
if [ "$distro" == "arch" ]; then
sudo systemctl disable $dm_name.service
sudo systemctl stop $dm_name.service
sudo pacman -Rns $dm_name
elif [ "$distro" == "fedora" ]; then
sudo systemctl disable $dm_name.service
sudo systemctl stop $dm_name.service
sudo dnf remove -y $dm_name
fi
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
}
detect_distro
install_packages
install_dwm
install_slstatus
install_nerd_font
install_picom
configure_wallpapers
setup_xinitrc
setup_tty_login
check_display_manager
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"