-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·412 lines (342 loc) · 12.6 KB
/
install.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/bin/bash
YELLOW="\e[93m"
GREEN="\e[32m"
RED="\e[91m"
RESET="\e[0m"
HOME_DIR="$HOME"
DOTFILES_DIR="$HOME/.dotfiles"
BACKUP_DIR="./backup"
LOG_FILE="function_log.txt"
backup_file() {
local source_file="$1"
local destination_dir="$2"
mkdir -p "$destination_dir"
cp "$source_file" "$destination_dir/$(basename "$source_file")_$(date +'%Y%m%d%H%M%S').bak"
echo -e "${YELLOW}Backup Created:${RESET} $(basename "$source_file") to $destination_dir."
}
remove_file() {
local file="$1"
rm "$file"
echo -e "${RED}Removed file:${RESET} $(basename "$file")"
}
create_symlink() {
local source_file="$1"
local destination_file="$2"
ln -s "$source_file" "$destination_file"
echo -e "${GREEN}Symlink Created:${RESET} For $(basename "$source_file") in $(dirname "$destination_file")."
}
check_executed() {
local function_name="$1"
if [ -f "$LOG_FILE" ] && grep -q "$function_name" "$LOG_FILE"; then
return 0
fi
return 1
}
set_dotProfile() {
if check_executed "set_dotProfile"; then
echo -e "${RED}set_dotProfile has already been executed.${RESET}"
return
fi
local PROFILE_FILE="$HOME/.profile"
local DOTPROFILE_FILE="$DOTFILES_DIR/src/.profile"
mkdir -p "$BACKUP_DIR"
if [ -f "$PROFILE_FILE" ]; then
backup_file "$PROFILE_FILE" "$BACKUP_DIR"
remove_file "$PROFILE_FILE"
fi
create_symlink "$DOTPROFILE_FILE" "$PROFILE_FILE"
echo "set_dotProfile $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}DotProfile setup complete.${RESET}"
}
apply_nix_configuration() {
if check_executed "apply_nix_configuration"; then
echo -e "${RED}apply_nix_configuration has already been executed.${RESET}"
return
fi
local NIXOS_DIR="/etc/nixos"
local DOTFILES_NIXOS_DIR="$DOTFILES_DIR/src/nixos"
if [ -d "$NIXOS_DIR" ]; then
mkdir -p "$BACKUP_DIR/nixos"
for file in "$NIXOS_DIR"/*; do
if [ -f "$file" ]; then
if [ "$(basename "$file")" = "hardware-configuration.nix" ]; then
echo "Skipping file: $(basename "$file")"
continue
fi
echo -e "Backing up $(basename "$file") in $NIXOS_DIR..."
backup_file "$file" "$BACKUP_DIR/nixos"
remove_file "$file"
fi
done
for file in "$DOTFILES_NIXOS_DIR"/*; do
if [ -f "$file" ]; then
create_symlink "$file" "$NIXOS_DIR/$(basename "$file")"
fi
done
echo "apply_nix_configuration $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}Nix configuration applied successfully.${RESET}"
else
echo -e "${RED}${NIXOS_DIR} does not exist.${RESET} Skipping the backup and symlink creation."
fi
}
apply_qtile_configuration() {
if check_executed "apply_qtile_configuration"; then
echo -e "${RED}apply_qtile_configuration has already been executed.${RESET}"
return
fi
local QTILE_CONFIG_DIR="$HOME/.config/qtile"
local DOTFILES_QTILE_DIR="$DOTFILES_DIR/src/qtile"
if [ -d "$QTILE_CONFIG_DIR" ]; then
mkdir -p "$BACKUP_DIR/qtile"
for file in "$QTILE_CONFIG_DIR"/*; do
if [ -f "$file" ]; then
echo -e "Backing up $(basename "$file") in $QTILE_CONFIG_DIR..."
backup_file "$file" "$BACKUP_DIR/qtile"
rm "$file"
fi
done
for file in "$DOTFILES_QTILE_DIR"/*; do
if [ -f "$file" ]; then
create_symlink "$file" "$QTILE_CONFIG_DIR/$(basename "$file")"
fi
done
echo "apply_qtile_configuration $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}Qtile configuration applied successfully.${RESET}"
else
echo -e "${RED}${QTILE_CONFIG_DIR} does not exist.${RESET} Skipping the backup and symlink creation."
fi
}
apply_picom_configuration() {
local CONFIG_DIR="$HOME/.config/picom"
local DOTFILES_PICOM_DIR="$DOTFILES_DIR/src/picom"
if check_executed "apply_picom_configuration"; then
echo -e "${RED}apply_picom_configuration has already been executed.${RESET}"
return
fi
if [ -d "$CONFIG_DIR" ]; then
mkdir -p "$BACKUP_DIR/picom"
for file in "$CONFIG_DIR"/*; do
if [ -f "$file" ]; then
backup_file "$file" "$BACKUP_DIR/picom"
rm "$file"
fi
done
for file in "$DOTFILES_PICOM_DIR"/*; do
if [ -f "$file" ]; then
create_symlink "$file" "$CONFIG_DIR/$(basename "$file")"
fi
done
echo "apply_picom_configuration $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}Picom configuration applied successfully.${RESET}"
else
echo -e "${RED}${CONFIG_DIR} does not exist.${RESET} Skipping the backup and symlink creation."
fi
}
apply_i3_configuration() {
local CONFIG_DIR="$HOME/.config/i3"
local DOTFILES_I3_DIR="$DOTFILES_DIR/src/i3"
if check_executed "apply_i3_configuration"; then
echo -e "${RED}apply_i3_configuration has already been executed.${RESET}"
return
fi
if [ -d "$CONFIG_DIR" ]; then
mkdir -p "$BACKUP_DIR/i3"
for file in "$CONFIG_DIR"/*; do
if [ -f "$file" ]; then
backup_file "$file" "$BACKUP_DIR/i3"
rm "$file"
fi
done
for file in "$DOTFILES_I3_DIR"/*; do
if [ -f "$file" ]; then
create_symlink "$file" "$CONFIG_DIR/$(basename "$file")"
fi
done
echo "apply_i3_configuration $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}i3 configuration applied successfully.${RESET}"
else
echo -e "${RED}${CONFIG_DIR} does not exist.${RESET} Skipping the backup and symlink creation."
fi
}
apply_polybar_configuration() {
local CONFIG_DIR="$HOME/.config/polybar"
local DOTFILES_POLYBAR_DIR="$DOTFILES_DIR/src/polybar"
if check_executed "apply_polybar_configuration"; then
echo -e "${RED}apply_polybar_configuration has already been executed.${RESET}"
return
fi
if [ -d "$CONFIG_DIR" ]; then
mkdir -p "$BACKUP_DIR/polybar"
for file in "$CONFIG_DIR"/*; do
if [ -f "$file" ]; then
backup_file "$file" "$BACKUP_DIR/polybar"
rm "$file"
fi
done
for file in "$DOTFILES_POLYBAR_DIR"/*; do
if [ -f "$file" ]; then
create_symlink "$file" "$CONFIG_DIR/$(basename "$file")"
fi
done
echo "apply_polybar_configuration $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}Polybar configuration applied successfully.${RESET}"
else
echo -e "${RED}${CONFIG_DIR} does not exist.${RESET} Skipping the backup and symlink creation."
fi
}
apply_rofi_configuration() {
echo -e "${YELLOW}For rofi ricing visit: https://github.com/newmanls/rofi-themes-collection${RESET}"
}
apply_alacritty_configuration() {
local CONFIG_DIR="$HOME/.config/alacritty"
local DOTFILES_ALACRITTY_DIR="$DOTFILES_DIR/src/alacritty"
if check_executed "apply_alacritty_configuration"; then
echo -e "${RED}apply_alacritty_configuration has already been executed.${RESET}"
return
fi
if [ -d "$CONFIG_DIR" ]; then
mkdir -p "$BACKUP_DIR/alacritty"
for file in "$CONFIG_DIR"/*; do
if [ -f "$file" ]; then
backup_file "$file" "$BACKUP_DIR/alacritty"
rm "$file"
fi
done
for file in "$DOTFILES_ALACRITTY_DIR"/*; do
if [ -f "$file" ]; then
create_symlink "$file" "$CONFIG_DIR/$(basename "$file")"
fi
done
echo "apply_alacritty_configuration $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}Alacritty configuration applied successfully.${RESET}"
else
echo -e "${RED}${CONFIG_DIR} does not exist.${RESET} Skipping the backup and symlink creation."
fi
}
apply_i3status_configuration() {
local CONFIG_DIR="$HOME/.config/i3status"
local DOTFILES_I3STATUS_DIR="$DOTFILES_DIR/src/i3status"
if check_executed "apply_i3status_configuration"; then
echo -e "${RED}apply_i3status_configuration has already been executed.${RESET}"
return
fi
if [ -d "$CONFIG_DIR" ]; then
mkdir -p "$BACKUP_DIR/i3status"
for file in "$CONFIG_DIR"/*; do
if [ -f "$file" ]; then
backup_file "$file" "$BACKUP_DIR/i3status"
rm "$file"
fi
done
for file in "$DOTFILES_I3STATUS_DIR"/*; do
if [ -f "$file" ]; then
create_symlink "$file" "$CONFIG_DIR/$(basename "$file")"
fi
done
echo "apply_i3status_configuration $(date +'%Y%m%d%H%M%S')" >> "$LOG_FILE"
echo -e "${GREEN}i3status configuration applied successfully.${RESET}"
else
echo -e "${RED}${CONFIG_DIR} does not exist.${RESET} Skipping the backup and symlink creation."
fi
}
show_menu() {
clear
echo -e "======================\n"
echo -e "DotFiles Menu\n"
local dotProfile_status="[${RED}✗${RESET}]"
local nix_configuration_status="[${RED}✗${RESET}]"
local qtile_configuration_status="[${RED}✗${RESET}]"
local picom_configuration_status="[${RED}✗${RESET}]"
local i3_configuration_status="[${RED}✗${RESET}]"
local polybar_configuration_status="[${RED}✗${RESET}]"
local rofi_configuration_status="[${RED}✗${RESET}]"
local alacritty_configuration_status="[${RED}✗${RESET}]"
local i3status_configuration_status="[${RED}✗${RESET}]"
if check_executed "set_dotProfile"; then
dotProfile_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_nix_configuration"; then
nix_configuration_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_qtile_configuration"; then
qtile_configuration_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_picom_configuration"; then
picom_configuration_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_i3_configuration"; then
i3_configuration_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_polybar_configuration"; then
polybar_configuration_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_rofi_configuration"; then
rofi_configuration_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_alacritty_configuration"; then
alacritty_configuration_status="[${GREEN}✓${RESET}]"
fi
if check_executed "apply_i3status_configuration"; then
i3status_configuration_status="[${GREEN}✓${RESET}]"
fi
echo -e "1. $dotProfile_status Set dotProfile"
echo -e "2. $nix_configuration_status Apply Nix configuration"
echo -e "3. $qtile_configuration_status Apply Qtile configuration"
echo -e "4. $picom_configuration_status Apply Picom configuration"
echo -e "5. $i3_configuration_status Apply i3 configuration"
echo -e "6. $polybar_configuration_status Apply Polybar configuration"
echo -e "7. $rofi_configuration_status Apply Rofi configuration"
echo -e "8. $alacritty_configuration_status Apply Alacritty configuration"
echo -e "9. $i3status_configuration_status Apply i3status configuration"
echo "0. Exit"
echo -e "\n======================\n"
}
execute_selected_functions() {
local selected_functions="$1"
local IFS=" "
local function_numbers=($selected_functions)
for number in "${function_numbers[@]}"; do
case $number in
1)
set_dotProfile
;;
2)
apply_nix_configuration
;;
3)
apply_qtile_configuration
;;
4)
apply_picom_configuration
;;
5)
apply_i3_configuration
;;
6)
apply_polybar_configuration
;;
7)
apply_rofi_configuration
;;
8)
apply_alacritty_configuration
;;
9)
apply_i3status_configuration
;;
0)
echo "Exiting the script."
exit 0
;;
*)
echo -e "${RED}Invalid function number: $number. Skipping.${RESET}"
;;
esac
done
}
while true; do
show_menu
read -p "Enter the function numbers to execute (space-separated): " selected_functions
execute_selected_functions "$selected_functions"
read -n 1 -s -r -p "Press any key to continue..."
done