-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
398 lines (324 loc) · 12.1 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
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
#!/bin/bash
# Advanced Hyprland Installation Script by Shell Ninja ( https://github.com/shell-ninja )
# color defination
red="\e[1;31m"
green="\e[1;32m"
yellow="\e[1;33m"
blue="\e[1;34m"
megenta="\e[1;1;35m"
cyan="\e[1;36m"
orange="\x1b[38;5;214m"
end="\e[1;0m"
if command -v gum &> /dev/null; then
display_text() {
gum style \
--border rounded \
--align center \
--width 60 \
--margin "1" \
--padding "1" \
'
__ __ ___
/ // /_ _____ ___________ ___ / _/
/ _ / // / _ \/ __/ __/ _ \/ _ \/ _/
/_//_/\_, / .__/_/ \__/\___/_//_/_/
/___/_/
'
}
else
display_text() {
cat << "EOF"
__ __ ___
/ // /_ _____ ___________ ___ / _/
/ _ / // / _ \/ __/ __/ _ \/ _ \/ _/
/_//_/\_, / .__/_/ \__/\___/_//_/_/
/___/_/
EOF
}
fi
clear && display_text
printf " \n \n"
###------ Startup ------###
# finding the presend directory and log file
dir="$(dirname "$(realpath "$0")")"
# log directory
log_dir="$dir/Logs"
log="$log_dir"/dotfiles.log
mkdir -p "$log_dir"
touch "$log"
# message prompts
msg() {
local actn=$1
local msg=$2
case $actn in
act)
printf "${green}=>${end} $msg\n"
;;
ask)
printf "${orange}??${end} $msg\n"
;;
dn)
printf "${cyan}::${end} $msg\n\n"
;;
att)
printf "${yellow}!!${end} $msg\n"
;;
nt)
printf "${blue}\$\$${end} $msg\n"
;;
skp)
printf "${magenta}[ SKIP ]${end} $msg\n"
;;
err)
printf "${red}>< Ohh sheet! an error..${end}\n $msg\n"
sleep 1
;;
*)
printf "$msg\n"
;;
esac
}
# Directories ----------------------------
hypr_dir="$HOME/.config/hypr"
scripts_dir="$hypr_dir/scripts"
fonts_dir="$HOME/.local/share/fonts"
msg act "Now setting up the pre installed Hyprland configuration..."sleep 1
mkdir -p ~/.config
# ========= checking the distro ========= #
check_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
arch)
distro="arch"
;;
fedora)
distro="fedora"
;;
opensuse*)
distro="opensuse"
;;
esac
fi
}
dirs=(
btop
dunst
fastfetch
fish
gtk-3.0
gtk-4.0
hypr
kitty
Kvantum
nvim
nwg-look
qt5ct
qt6ct
rofi
waybar
xsettingsd
yazi
)
# Paths
backup_dir="$HOME/.temp-back"
keybinds_backup="$backup_dir/keybinds.conf"
wrules_backup="$backup_dir/wrules.conf"
wallpapers_backup="$backup_dir/Wallpaper"
hypr_cache_backup="$backup_dir/.cache"
keybinds="$HOME/.config/hypr/configs/keybinds.conf"
wrules="$HOME/.config/hypr/configs/wrules.conf"
wallpapers="$HOME/.config/hypr/Wallpaper"
hypr_cache="$HOME/.config/hypr/.cache"
# Ensure backup directory exists
mkdir -p "$backup_dir"
# Function to handle backup/restore
backup_or_restore() {
local file_path="$1"
local file_type="$2"
if [[ -e "$file_path" ]]; then
msg att "A $file_type has been found."
if command -v gum &> /dev/null; then
gum confirm "Would you Restore it or put it into the Backup?" \
--affirmative "Restore it.." \
--negative "Backup it..."
echo
if [[ $? -eq 0 ]]; then
action="r"
else
action="b"
fi
else
msg ask "Would you Restore it or put it into the Backup? [ r/b ]"
read -r -p "$(echo -e '\e[1;32mSelect: \e[0m')" action
fi
if [[ "$action" =~ ^[rR] ]]; then
cp -r "$file_path" "$backup_dir/"
else
msg att "$file_type will be backed up..."
fi
fi
}
# Backing up keybinds, wrules, and wallpapers
backup_or_restore "$keybinds" "keybinds config file"
backup_or_restore "$wrules" "window rules config file"
backup_or_restore "$wallpapers" "wallpaper directory"
[[ -e "$hypr_cache" ]] && cp -r "$hypr_cache" "$backup_dir/"
# if some main directories exists, backing them up.
if [[ -d "$HOME/.config/HyprBackup-${USER}" ]]; then
msg att "a HyprBackup directory was there. Archiving it..."
cd "$HOME/.config"
mkdir -p "HyprArchive-${USER}"
zip -r -1 "HyprArchive-${USER}/HyprBackup-$(date +%d-%m-%Y_%I-%M-%p)-${USER}.zip" "HyprBackup-${USER}" &> /dev/null
# mv "HyprBackup-${USER}.zip" "HyprArchive-${USER}/"
rm -rf "HyprBackup-${USER}"
msg dn "HyprBackup-${USER} was zipped and backed up inside HyprArchive-${USER} directory..." && sleep 1
fi
for confs in "${dirs[@]}"; do
mkdir -p "$HOME/.config/HyprBackup-${USER}"
dir_path="$HOME/.config/$confs"
if [[ -d "$dir_path" ]]; then
mv "$dir_path" "$HOME/.config/HyprBackup-${USER}/" 2>&1 | tee -a "$log"
fi
done
[[ -d "$HOME/.config/HyprBackup-${USER}" ]] && msg dn "Everything has been backuped in $HOME/.config/HyprBackup-${USER}..."
sleep 1
#_____ if OpenBangla Keyboard is installed
keyboard_path="/usr/share/openbangla-keyboard"
if [[ -d "$keyboard_path" ]]; then
msg act "Setting up OpenBangla-Keyboard..."
# Add fcitx5 environment variables to /etc/environment if not already present
if ! grep -q "GTK_IM_MODULE=fcitx" /etc/environment; then
printf "\nGTK_IM_MODULE=fcitx\n" | sudo tee -a /etc/environment 2>&1 | tee -a >(sed 's/\x1B\[[0-9;]*[JKmsu]//g' >> "$log") &> /dev/null
fi
if ! grep -q "QT_IM_MODULE=fcitx" /etc/environment; then
printf "QT_IM_MODULE=fcitx\n" | sudo tee -a /etc/environment 2>&1 | tee -a >(sed 's/\x1B\[[0-9;]*[JKmsu]//g' >> "$log") &> /dev/null
fi
if ! grep -q "XMODIFIERS=@im=fcitx" /etc/environment; then
printf "XMODIFIERS=@im=fcitx\n" | sudo tee -a /etc/environment 2>&1 | tee -a >(sed 's/\x1B\[[0-9;]*[JKmsu]//g' >> "$log") &> /dev/null
fi
fi
#_____ for virtual machine
# Check if the configuration is in a virtual box
if hostnamectl | grep -q 'Chassis: vm'; then
msg att "You are using this script in a Virtual Machine..."
msg act "Setting up things for you..."
sed -i '/env = WLR_NO_HARDWARE_CURSORS,1/s/^#//' "$dir/config/hypr/configs/environment.conf"
sed -i '/env = WLR_RENDERER_ALLOW_SOFTWARE,1/s/^#//' "$dir/config/hypr/configs/environment.conf"
echo -e '#Monitor\nmonitor=Virtual-1, 1920x1080@60,auto,1' > "$dir/config/hypr/configs/monitor.conf"
else
#_____ setting up the monitor
msg act "Setting the high resolution and maximum refresh rate for your monitor..."
echo -e "#Monitor\nmonitor=,highres,auto,1\nmonitor=,highrr,auto,1" > "$dir/config/hypr/configs/monitor.conf"
fi
#_____ for nvidia gpu. I don't know if it's gonna work or not. Because I don't have any gpu.
# uncommenting WLR_NO_HARDWARE_CURSORS if nvidia is detected
if lspci -k | grep -A 2 -E "(VGA|3D)" | grep -iq nvidia; then
msg act "Nvidia GPU detected. Setting up proper env's" 2>&1 | tee -a >(sed 's/\x1B\[[0-9;]*[JKmsu]//g' >> "$log") || true
sed -i '/env = WLR_NO_HARDWARE_CURSORS,1/s/^#//' config/hypr/configs/environment.conf
sed -i '/env = LIBVA_DRIVER_NAME,nvidia/s/^#//' config/hypr/configs/environment.conf
sed -i '/env = __GLX_VENDOR_LIBRARY_NAME,nvidia/s/^# //' config/hypr/configs/environment.conf
fi
sleep 1
# cloning the dotfiles repository into ~/.config/hypr
cp -r "$dir/config"/* "$HOME/.config/"
sleep 1
if [[ -d "$scripts_dir" ]]; then
# make all the scripts executable...
chmod +x "$scripts_dir"/* 2>&1 | tee -a "$log"
chmod +x "$HOME/.config/fish/change_style.sh" 2>&1 | tee -a "$log"
msg dn "All the necessary scripts have been executable..."
sleep 1
else
msg err "Could not find necessary scripts.."
fi
# Install Fonts
msg act "Installing some fonts..."
if [[ ! -d "$fonts_dir" ]]; then
mkdir -p "$fonts_dir"
fi
cp -r "$dir/extras/fonts" "$fonts_dir"
msg act "Updating font cache..."
sudo fc-cache -fv 2>&1 | tee -a "$log" &> /dev/null
wayland_session_dir=/usr/share/wayland-sessions
if [ -d "$wayland_session_dir" ]; then
msg att "$wayland_session_dir found..."
else
msg att "$wayland_session_dir NOT found, creating..."
sudo mkdir $wayland_session_dir 2>&1 | tee -a "$log"
fi
sudo cp "$dir/extras/hyprland.desktop" /usr/share/wayland-sessions/ 2>&1 | tee -a "$log"
# restore the backuped items into the original location
restore_backup() {
local backup_path="$1" # Path to the backup file/directory
local original_path="$2" # Original file/directory path
local file_type="$3" # Description of the file/directory
if [[ -e "$backup_path" ]]; then
# Create a backup of the current file/directory if it exists
if [[ -e "$original_path" ]]; then
mv "$original_path" "${original_path}.backup"
fi
# Restore the file/directory from the backup
if cp -r "$backup_path" "$original_path"; then
msg dn "$file_type restored to its original location: $original_path."
else
msg err "Could not restore defaults."
fi
fi
}
# Restore files
restore_backup "$keybinds_backup" "$keybinds" "keybinds config file"
restore_backup "$wrules_backup" "$wrules" "window rules config file"
restore_backup "$wallpapers_backup" "$wallpapers" "wallpaper directory"
# restoring hyprland cache
[[ -e "$HOME/.config/hypr/.cache" ]] && rm -rf "$HOME/.config/hypr/.cache"
[[ -e "$hypr_cache_backup" ]] && cp -r "$hypr_cache_backup" "$hypr_cache"
rm -rf "$backup_dir"
clear && sleep 1
# Asking if the user wants to download more wallpapers
msg ask "Would you like to add more ${green}Wallpapers${end}? ${blue}[ y/n ]${end}..."
read -r -p "$(echo -e '\e[1;32mSelect: \e[0m')" wallpaper
printf " \n"
# ========= wallpaper section ========= #
if [[ "$wallpaper" =~ ^[Y|y]$ ]]; then
msg act "Downloading some wallpapers..."
# cloning the wallpapers in a temporary directory
git clone --depth=1 https://github.com/shell-ninja/Wallpapers.git ~/.cache/wallpaper-cache 2>&1 | tee -a "$log" &> /dev/null
# copying the wallpaper to the main directory
if [[ -d "$HOME/.cache/wallpaper-cache" ]]; then
cp -r "$HOME/.cache/wallpaper-cache"/* ~/.config/hypr/Wallpaper/ &> /dev/null
rm -rf "$HOME/.cache/wallpaper-cache" &> /dev/null
msg dn "Wallpapers were downloaded successfully..." 2>&1 | tee -a >(sed 's/\x1B\[[0-9;]*[JKmsu]//g' >> "$log") & sleep 0.5
else
msg err "Sorry, could not download more wallpapers. Going forward with the limited wallpapers..." 2>&1 | tee -a >(sed 's/\x1B\[[0-9;]*[JKmsu]//g' >> "$log") && sleep 0.5
fi
fi
# ========= wallpaper section ========= #
check_distro &> /dev/null
if [[ -d "$HOME/.config/hypr/Wallpaper" ]]; then
mkdir -p "$HOME/.config/hypr/.cache"
engine="$HOME/.config/hypr/.cache/.engine"
wallCache="$HOME/.config/hypr/.cache/.wallpaper"
touch "$engine"
touch "$wallCache"
echo "hyprpaper" > "$engine"
if [ -f "$HOME/.config/hypr/Wallpaper/${distro}.png" ]; then
echo "$distro" > "$wallCache"
wallpaper="$HOME/.config/hypr/Wallpaper/${distro}.png"
fi
# setting the default wallpaper
ln -sf "$wallpaper" "$HOME/.config/hypr/.cache/current_wallpaper.png"
echo "wallpaper = ,~/.config/hypr/.cache/current_wallpaper.png" > "$HOME/.config/hypr/hyprpaper.conf"
fi
# setting up the waybar
ln -sf "$HOME/.config/waybar/configs/catppuccin-top" "$HOME/.config/waybar/config"
ln -sf "$HOME/.config/waybar/style/catppuccin-top.css" "$HOME/.config/waybar/style.css"
msg act "Generating colors and other necessary things..."
"$HOME/.config/hypr/scripts/wallcache.sh" &> /dev/null
"$HOME/.config/hypr/scripts/pywal.sh" &> /dev/null
# setting default themes, icon and cursor
gsettings set org.gnome.desktop.interface gtk-theme "Dracula"
gsettings set org.gnome.desktop.interface icon-theme "TokyoNight-SE"
gsettings set org.gnome.desktop.interface cursor-theme "Bibata-Modern-Ice"
msg dn "Script execution was successful! Now logout and log back in and enjoy your customization..." && sleep 1
# === ___ Script Ends Here ___ === #