@@ -43,7 +43,19 @@ load_install_state() {
4343 local key=" $1 "
4444
4545 if [[ -f " $INSTALL_CONFIG_FILE " ]]; then
46- grep " ^${key} =" " $INSTALL_CONFIG_FILE " | cut -d' =' -f2-
46+ local value
47+ value=$( grep " ^${key} =" " $INSTALL_CONFIG_FILE " | cut -d' =' -f2-)
48+
49+ if [[ -z " $value " ]]; then
50+ log_error " Configuration key '$key ' not found or empty"
51+ return 1
52+ fi
53+
54+ echo " $value "
55+ return 0
56+ else
57+ log_error " Configuration file not found: $INSTALL_CONFIG_FILE "
58+ return 1
4759 fi
4860}
4961
@@ -128,12 +140,38 @@ check_prerequisites() {
128140
129141 if gum confirm " Install missing tools now? (Requires internet connection)" ; then
130142 log_info " Installing missing tools..."
131- if ! pacman -Sy --noconfirm " ${missing_tools[@]} " ; then
132- log_error " Failed to install required tools"
133- log_info " Please install manually: pacman -S ${missing_tools[*]} "
134- exit 1
135- fi
136- log_success " Tools installed successfully"
143+
144+ # Add retry logic for pacman installation
145+ local install_attempts=0
146+ local max_install_attempts=3
147+ local install_success=false
148+
149+ while [[ $install_attempts -lt $max_install_attempts ]] && [[ " $install_success " != " true" ]]; do
150+ install_attempts=$(( install_attempts + 1 ))
151+ log_info " Installation attempt $install_attempts of $max_install_attempts ..."
152+
153+ if pacman -Sy --noconfirm " ${missing_tools[@]} " ; then
154+ install_success=true
155+ log_success " Tools installed successfully"
156+ break
157+ else
158+ if [[ $install_attempts -lt $max_install_attempts ]]; then
159+ log_warning " Installation attempt $install_attempts failed, retrying in 3 seconds..."
160+ sleep 3
161+ else
162+ log_error " Failed to install required tools after $max_install_attempts attempts"
163+ log_info " Possible issues: network connectivity, package mirrors, or disk space"
164+ log_info " Please try manually: pacman -Sy && pacman -S ${missing_tools[*]} "
165+
166+ if gum confirm " Continue without installing tools? (Installation may fail)" ; then
167+ log_warning " Continuing without required tools - installation may fail"
168+ break
169+ else
170+ exit 1
171+ fi
172+ fi
173+ fi
174+ done
137175 else
138176 log_error " Cannot proceed without required tools"
139177 log_info " Please install manually: pacman -S ${missing_tools[*]} "
@@ -382,15 +420,79 @@ manual_partition() {
382420 exit 1
383421 fi
384422
385- # Let user select partitions
423+ # Let user select partitions with validation
386424 local boot_part root_part
387- boot_part=$( printf ' %s\n' " ${partitions[@]} " | gum choose --header=" Select EFI/Boot partition:" )
388- root_part=$( printf ' %s\n' " ${partitions[@]} " | gum choose --header=" Select Root partition:" )
389425
390- if [[ " $boot_part " == " $root_part " ]]; then
391- log_error " Boot and root partitions cannot be the same"
392- exit 1
393- fi
426+ # Select boot partition with validation
427+ local boot_selection_attempts=0
428+ local max_selection_attempts=3
429+
430+ while [[ $boot_selection_attempts -lt $max_selection_attempts ]]; do
431+ boot_selection_attempts=$(( boot_selection_attempts + 1 ))
432+ log_info " Select EFI/Boot partition (attempt $boot_selection_attempts of $max_selection_attempts ):"
433+
434+ boot_part=$( printf ' %s\n' " ${partitions[@]} " | gum choose --header=" Select EFI/Boot partition:" )
435+
436+ if [[ -z " $boot_part " ]]; then
437+ log_error " No boot partition selected"
438+ if [[ $boot_selection_attempts -lt $max_selection_attempts ]]; then
439+ log_warning " Please select a valid partition. Retrying..."
440+ continue
441+ else
442+ log_error " Failed to select boot partition after $max_selection_attempts attempts"
443+ exit 1
444+ fi
445+ elif [[ ! -b " $boot_part " ]]; then
446+ log_error " Selected boot partition '$boot_part ' is not a valid block device"
447+ if [[ $boot_selection_attempts -lt $max_selection_attempts ]]; then
448+ continue
449+ else
450+ exit 1
451+ fi
452+ else
453+ log_success " Boot partition selected: $boot_part "
454+ break
455+ fi
456+ done
457+
458+ # Select root partition with validation
459+ local root_selection_attempts=0
460+
461+ while [[ $root_selection_attempts -lt $max_selection_attempts ]]; do
462+ root_selection_attempts=$(( root_selection_attempts + 1 ))
463+ log_info " Select root partition (attempt $root_selection_attempts of $max_selection_attempts ):"
464+
465+ root_part=$( printf ' %s\n' " ${partitions[@]} " | gum choose --header=" Select Root partition:" )
466+
467+ if [[ -z " $root_part " ]]; then
468+ log_error " No root partition selected"
469+ if [[ $root_selection_attempts -lt $max_selection_attempts ]]; then
470+ log_warning " Please select a valid partition. Retrying..."
471+ continue
472+ else
473+ log_error " Failed to select root partition after $max_selection_attempts attempts"
474+ exit 1
475+ fi
476+ elif [[ ! -b " $root_part " ]]; then
477+ log_error " Selected root partition '$root_part ' is not a valid block device"
478+ if [[ $root_selection_attempts -lt $max_selection_attempts ]]; then
479+ continue
480+ else
481+ exit 1
482+ fi
483+ elif [[ " $boot_part " == " $root_part " ]]; then
484+ log_error " Boot and root partitions cannot be the same"
485+ if [[ $root_selection_attempts -lt $max_selection_attempts ]]; then
486+ log_warning " Please select a different partition for root. Retrying..."
487+ continue
488+ else
489+ exit 1
490+ fi
491+ else
492+ log_success " Root partition selected: $root_part "
493+ break
494+ fi
495+ done
394496
395497 # Validate EFI System Partition
396498 log_info " Validating EFI System Partition..."
@@ -433,8 +535,28 @@ manual_partition() {
433535
434536 if [[ " $root_fstype " == " unknown" || " $root_fstype " == " " ]]; then
435537 log_warning " Root partition ($root_part ) appears unformatted"
538+
436539 local fs_choice
437- fs_choice=$( echo -e " ext4\nbtrfs" | gum choose --header=" Choose filesystem for root partition:" )
540+ local fs_attempts=0
541+ local max_fs_attempts=3
542+
543+ while [[ $fs_attempts -lt $max_fs_attempts ]]; do
544+ fs_attempts=$(( fs_attempts + 1 ))
545+ fs_choice=$( echo -e " ext4\nbtrfs" | gum choose --header=" Choose filesystem for root partition:" )
546+
547+ if [[ -z " $fs_choice " ]]; then
548+ log_error " No filesystem selected"
549+ if [[ $fs_attempts -lt $max_fs_attempts ]]; then
550+ log_warning " Please select a filesystem type. Retrying..."
551+ continue
552+ else
553+ log_error " Failed to select filesystem after $max_fs_attempts attempts"
554+ exit 1
555+ fi
556+ else
557+ break
558+ fi
559+ done
438560
439561 case " $fs_choice " in
440562 " ext4" )
@@ -467,12 +589,14 @@ install_base_system() {
467589 local root_part
468590 local boot_part
469591
470- # Load partition information from config
471- root_part=$( load_install_state " OSVMARCHI_ROOT_PART" )
472- boot_part=$( load_install_state " OSVMARCHI_BOOT_PART" )
592+ # Load partition information from config with error handling
593+ if ! root_part=$( load_install_state " OSVMARCHI_ROOT_PART" ) ; then
594+ log_error " Failed to load root partition information from configuration"
595+ exit 1
596+ fi
473597
474- if [[ -z " $root_part " || -z " $boot_part " ]] ; then
475- log_error " Partition information not found in configuration"
598+ if ! boot_part= $( load_install_state " OSVMARCHI_BOOT_PART " ) ; then
599+ log_error " Failed to load boot partition information from configuration"
476600 exit 1
477601 fi
478602
@@ -514,10 +638,8 @@ configure_base_system() {
514638
515639 # Get partition information
516640 local root_part
517- root_part=$( load_install_state " OSVMARCHI_ROOT_PART" )
518-
519- if [[ -z " $root_part " ]]; then
520- log_error " Root partition information not found"
641+ if ! root_part=$( load_install_state " OSVMARCHI_ROOT_PART" ) ; then
642+ log_error " Failed to load root partition information"
521643 exit 1
522644 fi
523645
@@ -603,6 +725,10 @@ echo "user:\$TEMP_PASSWORD" | chpasswd
603725echo "TEMP_USER_PASSWORD=\$ TEMP_PASSWORD" > /etc/osvmarchi-first-login.info
604726chmod 600 /etc/osvmarchi-first-login.info
605727
728+ # Also save to host system for immediate display
729+ echo "TEMP_USER_PASSWORD=\$ TEMP_PASSWORD" > /tmp/osvmarchi-temp-password.info
730+ chmod 600 /tmp/osvmarchi-temp-password.info
731+
606732echo "Base system configuration complete"
607733echo "SECURITY: User password is randomly generated and must be changed on first login"
608734echo "SECURITY: Root account is locked for security"
613739 arch-chroot /mnt /configure_system.sh
614740 rm /mnt/configure_system.sh
615741
742+ # Display temporary password immediately after generation
743+ local temp_password_now
744+ if [[ -f /tmp/osvmarchi-temp-password.info ]]; then
745+ temp_password_now=$( grep " TEMP_USER_PASSWORD=" /tmp/osvmarchi-temp-password.info | cut -d' =' -f2)
746+ if [[ -n " $temp_password_now " ]]; then
747+ echo
748+ log_warning " IMPORTANT: Temporary user password generated: $temp_password_now "
749+ log_warning " WRITE THIS DOWN - This password must be changed on first login!"
750+ log_info " This password will also be shown again after installation completes"
751+ echo
752+
753+ # Give user time to write it down
754+ if gum confirm " Have you written down the temporary password?" ; then
755+ log_info " Great! Continuing with installation..."
756+ else
757+ log_warning " Please write down the password: $temp_password_now "
758+ read -p " Press Enter when you have written down the password..." -r
759+ fi
760+ fi
761+ rm -f /tmp/osvmarchi-temp-password.info
762+ fi
763+
616764 log_success " Base system configuration complete"
617765}
618766
@@ -640,11 +788,31 @@ log_error() {
640788
641789log_info "Downloading OSVMarchi installer..."
642790
643- # Download the installer script
644- if ! curl -fsSL -o osvmarchi-boot.sh https://raw.githubusercontent.com/openSVM/osvmarchi/master/boot.sh; then
645- log_error "Failed to download OSVMarchi installer"
646- exit 1
647- fi
791+ # Download the installer script with retry logic
792+ local download_attempts=0
793+ local max_download_attempts=3
794+ local download_success=false
795+
796+ while [[ $download_attempts -lt $max_download_attempts ]] && [[ "$download_success" != "true" ]]; do
797+ download_attempts=$((download_attempts + 1))
798+ log_info "Download attempt $download_attempts of $max_download_attempts..."
799+
800+ if curl -fsSL -o osvmarchi-boot.sh https://raw.githubusercontent.com/openSVM/osvmarchi/master/boot.sh; then
801+ download_success=true
802+ log_success "OSVMarchi installer downloaded successfully"
803+ break
804+ else
805+ if [[ $download_attempts -lt $max_download_attempts ]]; then
806+ log_warning "Download attempt $download_attempts failed, retrying in 5 seconds..."
807+ rm -f osvmarchi-boot.sh 2>/dev/null || true
808+ sleep 5
809+ else
810+ log_error "Failed to download OSVMarchi installer after $max_download_attempts attempts"
811+ log_info "Possible issues: network connectivity, GitHub availability, or DNS resolution"
812+ exit 1
813+ fi
814+ fi
815+ done
648816
649817# Verify the downloaded script is not empty and contains expected content
650818if [[ ! -s osvmarchi-boot.sh ]]; then
0 commit comments