@@ -28,12 +28,65 @@ execute_command() {
2828 fi
2929}
3030
31- # New function to check and prompt user input for required variables
31+ check_dependencies () {
32+ local deps=(" git" " sudo" )
33+ local missing_deps=()
34+
35+ for dep in " ${deps[@]} " ; do
36+ if ! command -v " $dep " > /dev/null 2>&1 ; then
37+ missing_deps+=(" $dep " )
38+ fi
39+ done
40+
41+ # Check for yay
42+ if ! command -v yay > /dev/null 2>&1 ; then
43+ print_warning " YAY is not installed. Installing YAY..."
44+ (
45+ cd /tmp || exit 1
46+ git clone https://aur.archlinux.org/yay.git
47+ cd yay || exit 1
48+ makepkg -si --noconfirm
49+ ) || {
50+ print_error " Failed to install YAY"
51+ exit 1
52+ }
53+ fi
54+
55+ if [ ${# missing_deps[@]} -ne 0 ]; then
56+ print_error " Missing dependencies: ${missing_deps[*]} "
57+ exit 1
58+ fi
59+ }
60+
61+ validate_wallpaper_dir () {
62+ if [ ! -d " $WALLPAPER_DIR " ]; then
63+ print_error " Wallpaper directory does not exist: $WALLPAPER_DIR "
64+ return 1
65+ fi
66+
67+ # Check for at least one image file
68+ if ! find " $WALLPAPER_DIR " -maxdepth 1 -type f -exec file {} \; | grep -q " image" ; then
69+ print_error " No image files found in wallpaper directory"
70+ return 1
71+ fi
72+ return 0
73+ }
74+
75+ create_backup () {
76+ local file=" $1 "
77+ if [ -f " $file " ]; then
78+ local backup
79+ backup=" ${file} .bak.$( date +%Y%m%d_%H%M%S) "
80+ cp " $file " " $backup " && print_message " Created backup: $backup "
81+ fi
82+ }
83+
84+ # Function to check and prompt user input for required variables
3285check_user_input () {
3386 # Check if WALLPAPER_DIR is set, prompt if not
3487 if [ -z " $WALLPAPER_DIR " ]; then
3588 echo " WARNING: WALLPAPER_DIR is not set."
36- read -p " Please enter the path to your wallpaper directory: " input_wallpaper_dir
89+ read -rp " Please enter the path to your wallpaper directory: " input_wallpaper_dir
3790 export WALLPAPER_DIR=" $input_wallpaper_dir "
3891 fi
3992
@@ -42,12 +95,13 @@ check_user_input() {
4295 echo " WARNING: MONITORS variable is not set."
4396 echo " Please enter your monitor names separated by spaces, check with 'hyprctl monitors' (eg: \" DP-1 HDMI-A-1\" ): "
4497 read -r input_monitors
45- # Convert input into an array and export it
46- export MONITORS=($input_monitors )
98+ # Convert input into an array properly using read -a
99+ IFS=' ' read -ra MONITORS <<< " $input_monitors"
100+ export MONITORS
47101 fi
48102}
49103
50- # New function to update configuration files with user input
104+ # Function to update configuration files with user input
51105update_configs () {
52106 # Update the wallpaper configuration file
53107 local wallpaper_conf=" $HOME /dotfiles/.config/hypr/sources/change_wallpaper.conf"
@@ -64,9 +118,9 @@ update_configs() {
64118 echo " # Display Configuration"
65119 for monitor in " ${MONITORS[@]} " ; do
66120 # Prompt for resolution and refresh rate for each monitor
67- read -p " Enter resolution for monitor ${monitor} [2560x1440]: " res
121+ read -rp " Enter resolution for monitor ${monitor} [2560x1440]: " res
68122 res=${res:- 2560x1440}
69- read -p " Enter refresh rate for monitor ${monitor} [144]: " refresh
123+ read -rp " Enter refresh rate for monitor ${monitor} [144]: " refresh
70124 refresh=${refresh:- 144}
71125 # Here, position is fixed; adjust as necessary
72126 echo " monitor=${monitor} ,${res} @${refresh} ,0x0,1"
@@ -76,43 +130,54 @@ update_configs() {
76130 print_message " Configuration files updated with user input."
77131}
78132
79- # New function to update fish language config in fish config file
133+ # Function to update fish language config in fish config file
80134set_fish_language_config () {
81135 local fish_conf=" $HOME /dotfiles/.config/fish/config.fish"
82136 echo " Select your preferred language setting for Fish Shell:"
83137 echo " 1) de_CH (Default: LC_ALL=de_CH.UTF-8, LANG=de_CH.UTF-8, LANGUAGE=de_CH:en_US)"
84138 echo " 2) de (German: LC_ALL=de_DE.UTF-8, LANG=de_DE.UTF-8, LANGUAGE=de_DE:en_US)"
85139 echo " 3) us (US English: LC_ALL=en_US.UTF-8, LANG=en_US.UTF-8, LANGUAGE=en_US:de_CH)"
86- read -p " Enter selection number (1-3): " fish_sel
140+ read -rp " Enter selection number (1-3): " fish_sel
87141 local lc_all lang language
88- switch " $fish_sel "
89- case 1
142+ case " $fish_sel " in
143+ 1)
90144 lc_all=" de_CH.UTF-8"
91145 lang=" de_CH.UTF-8"
92146 language=" de_CH:de_DE"
93- case 2
147+ ;;
148+ 2)
94149 lc_all=" de_DE.UTF-8"
95150 lang=" de_DE.UTF-8"
96151 language=" de_DE:en_US"
97- case 3
152+ ;;
153+ 3)
98154 lc_all=" en_US.UTF-8"
99155 lang=" en_US.UTF-8"
100156 language=" en_US:de_DE"
101- case ' *'
157+ ;;
158+ * )
102159 echo " Invalid selection, using default (de_CH)."
103- lc_all=" en_US.UTF-8"
104- lang=" en_US.UTF-8"
105- language=" en_US:de_DE"
106- end
107- # Remove existing language settings block if present, then append new settings
160+ lc_all=" de_CH.UTF-8"
161+ lang=" de_CH.UTF-8"
162+ language=" de_CH:de_DE"
163+ ;;
164+ esac
165+
166+ mkdir -p " $( dirname " $fish_conf " ) "
167+ touch " $fish_conf "
168+
169+ # Remove existing language settings block if present
108170 sed -i ' /^## LANGUAGE SETTINGS START/,/^## LANGUAGE SETTINGS END/d' " $fish_conf "
171+
172+ # Append new language settings
109173 {
110174 echo " ## LANGUAGE SETTINGS START"
111- echo " set -gx LC_ALL $lc_all "
112- echo " set -gx LANG $lang "
113- echo " set -gx LANGUAGE $language "
175+ echo " set -gx LC_ALL \" $lc_all \" "
176+ echo " set -gx LANG \" $lang \" "
177+ echo " set -gx LANGUAGE \" $language \" "
114178 echo " ## LANGUAGE SETTINGS END"
115179 } >> " $fish_conf "
180+
116181 print_message " Fish language settings updated in $fish_conf "
117182}
118183
@@ -149,7 +214,6 @@ hyprland_packages=(
149214 # System Integration
150215 " xdg-desktop-portal-hyprland"
151216 " xdg-desktop-portal-gtk"
152- " polkit-kde-agent"
153217 " gnome-keyring"
154218 " network-manager-applet"
155219 " networkmanager"
@@ -219,18 +283,41 @@ check_hyprland() {
219283# #############################################################
220284main () {
221285 print_message " Starting Hyprland Setup..."
286+
287+ check_dependencies
222288 check_user_input
289+
290+ if ! validate_wallpaper_dir; then
291+ read -rp " Continue anyway? (y/N): " choice
292+ if [[ ! $choice =~ ^[Yy]$ ]]; then
293+ print_error " Setup aborted by user"
294+ exit 1
295+ fi
296+ fi
297+
298+ # Create backups before updating configs
299+ local config_files=(
300+ " $HOME /dotfiles/.config/hypr/sources/change_wallpaper.conf"
301+ " $HOME /dotfiles/.config/hypr/sources/displays.conf"
302+ " $HOME /dotfiles/.config/fish/config.fish"
303+ )
304+
305+ for file in " ${config_files[@]} " ; do
306+ create_backup " $file "
307+ done
308+
223309 update_configs
224310 set_fish_language_config
225311 install_pacman_packages
226312 install_aur_extras
227313
228314 # Setup dotfiles via stow
229315 if [ -f " $HOME /dotfiles/.local/scripts/Start_stow_solve.sh" ]; then
230- echo " Setting up dotfiles with Start_stow_solve.sh..."
316+ print_message " Setting up dotfiles with Start_stow_solve.sh..."
231317 bash " $HOME /dotfiles/.local/scripts/Start_stow_solve.sh"
232318 else
233- echo " Warning: Start_stow_solve.sh not found at $HOME /dotfiles/.local/scripts. Skipping dotfiles setup."
319+ print_warning " Start_stow_solve.sh not found at $HOME /dotfiles/.local/scripts"
320+ print_warning " Skipping dotfiles setup"
234321 fi
235322
236323 print_message " Hyprland setup completed successfully!"
0 commit comments