55
66set -euo pipefail
77
8+ # Cleanup function for signals and errors
9+ cleanup () {
10+ local exit_code=$?
11+
12+ # Unmount partitions if they exist
13+ if [[ -d " /mnt" ]]; then
14+ if mountpoint -q " /mnt/boot" 2> /dev/null; then
15+ log_warning " Unmounting /mnt/boot..."
16+ umount " /mnt/boot" 2> /dev/null || true
17+ fi
18+ if mountpoint -q " /mnt" 2> /dev/null; then
19+ log_warning " Unmounting /mnt..."
20+ umount " /mnt" 2> /dev/null || true
21+ fi
22+ fi
23+
24+ # Clean up temporary files
25+ if [[ -f " oswmarchi-boot.sh" ]]; then
26+ rm -f " oswmarchi-boot.sh"
27+ fi
28+
29+ # Clean up secure config directory if empty
30+ if [[ -d " $INSTALL_CONFIG_DIR " ]]; then
31+ rmdir " $INSTALL_CONFIG_DIR " 2> /dev/null || true
32+ fi
33+
34+ # Sync filesystem changes
35+ sync
36+
37+ exit $exit_code
38+ }
39+
40+ # Set up signal traps
41+ trap cleanup EXIT ERR SIGINT SIGTERM
42+
43+ # Source shared utilities first (logging functions)
44+ if [[ -f /home/runner/work/osvmarchi/osvmarchi/bin/osvmarchi-utils ]]; then
45+ source /home/runner/work/osvmarchi/osvmarchi/bin/osvmarchi-utils
46+ elif [[ -f ~ /.local/share/osvmarchi/bin/osvmarchi-utils ]]; then
47+ source ~ /.local/share/osvmarchi/bin/osvmarchi-utils
48+ fi
49+
850# Configuration file for installation state - secure location
951INSTALL_CONFIG_DIR=" /run/user/$( id -u) /osvmarchi"
1052INSTALL_CONFIG_FILE=" ${INSTALL_CONFIG_DIR} /install.conf"
@@ -65,28 +107,68 @@ cleanup_install_state() {
65107 [[ -d " $INSTALL_CONFIG_DIR " ]] && rmdir " $INSTALL_CONFIG_DIR " 2> /dev/null || true
66108}
67109
68- # Colors for output
110+ # Colors for output (fallback if utils not loaded)
69111RED=' \033[0;31m'
70- GREEN=' \033[0;32m'
112+ GREEN=' \033[0;32m'
71113BLUE=' \033[0;34m'
72114YELLOW=' \033[1;33m'
73115NC=' \033[0m' # No Color
74116
75- # Logging functions
76- log_info () {
77- echo -e " ${BLUE} [INFO]${NC} $1 "
78- }
79-
80- log_success () {
81- echo -e " ${GREEN} [SUCCESS]${NC} $1 "
82- }
117+ # Fallback logging functions if utils not loaded
118+ if ! declare -f log_info > /dev/null 2>&1 ; then
119+ log_info () {
120+ echo -e " ${BLUE} [INFO]${NC} $1 "
121+ }
122+
123+ log_success () {
124+ echo -e " ${GREEN} [SUCCESS]${NC} $1 "
125+ }
126+
127+ log_warning () {
128+ echo -e " ${YELLOW} [WARNING]${NC} $1 "
129+ }
130+
131+ log_error () {
132+ echo -e " ${RED} [ERROR]${NC} $1 "
133+ }
134+ fi
83135
84- log_warning () {
85- echo -e " ${YELLOW} [WARNING]${NC} $1 "
136+ # Install packages with failure tracking
137+ install_packages_with_tracking () {
138+ local package_script=" $1 "
139+ local failed_packages=()
140+
141+ log_info " Installing packages from $package_script ..."
142+
143+ # Source the package script but capture failures
144+ if source " $package_script " ; then
145+ log_success " Package installation completed successfully"
146+ return 0
147+ else
148+ # Installation had some failures, but continue
149+ log_warning " Some package installations may have failed"
150+ failed_packages+=(" $package_script " )
151+ return 1
152+ fi
86153}
87154
88- log_error () {
89- echo -e " ${RED} [ERROR]${NC} $1 "
155+ # Report installation summary
156+ report_installation_summary () {
157+ local failed_installers=(" $@ " )
158+
159+ if [[ ${# failed_installers[@]} -eq 0 ]]; then
160+ log_success " All package installations completed successfully"
161+ else
162+ echo
163+ log_warning " Installation Summary:"
164+ log_warning " The following package installers had some failures:"
165+ for installer in " ${failed_installers[@]} " ; do
166+ log_warning " - $installer "
167+ done
168+ log_info " The system should still be functional, but some packages may be missing"
169+ log_info " You can manually install missing packages later using 'pacman -S <package>'"
170+ echo
171+ fi
90172}
91173
92174# Check if running on Arch Linux live environment
@@ -359,6 +441,9 @@ automatic_partition() {
359441 wipefs -a " $disk "
360442 sgdisk --zap-all " $disk "
361443
444+ # Sync to ensure disk changes are written
445+ sync
446+
362447 # Create GPT partition table and partitions
363448 log_info " Creating partition table..."
364449 sgdisk --clear \
@@ -370,6 +455,9 @@ automatic_partition() {
370455 partprobe " $disk "
371456 sleep 2
372457
458+ # Sync partition table changes
459+ sync
460+
373461 # Determine partition names (handle nvme vs sda naming)
374462 local boot_part root_part
375463 if [[ $disk =~ nvme ]]; then
@@ -387,6 +475,9 @@ automatic_partition() {
387475 log_info " Formatting root partition..."
388476 mkfs.ext4 -L " OSVMarchi" " $root_part "
389477
478+ # Sync filesystem changes
479+ sync
480+
390481 # Save partition information to config file
391482 save_install_state " OSVMARCHI_BOOT_PART" " $boot_part "
392483 save_install_state " OSVMARCHI_ROOT_PART" " $root_part "
@@ -504,6 +595,7 @@ manual_partition() {
504595 if gum confirm " Format $boot_part as FAT32?" ; then
505596 log_info " Formatting EFI partition as FAT32..."
506597 mkfs.fat -F 32 -n " EFI" " $boot_part "
598+ sync # Ensure filesystem changes are written
507599 else
508600 log_error " EFI partition must be FAT32 for UEFI boot"
509601 exit 1
@@ -521,6 +613,7 @@ manual_partition() {
521613 log_warning " EFI partition does not have ESP (EF00) type code"
522614 if gum confirm " Set ESP type code on $boot_part ?" ; then
523615 sgdisk -t " ${part_num} :EF00" " $disk_path "
616+ sync # Ensure partition table changes are written
524617 log_success " ESP type code set"
525618 else
526619 log_warning " Continuing without ESP type code (may cause boot issues)"
@@ -562,10 +655,12 @@ manual_partition() {
562655 " ext4" )
563656 log_info " Formatting root partition as ext4..."
564657 mkfs.ext4 -L " OSVMarchi" " $root_part "
658+ sync # Ensure filesystem changes are written
565659 ;;
566660 " btrfs" )
567661 log_info " Formatting root partition as btrfs..."
568662 mkfs.btrfs -L " OSVMarchi" " $root_part "
663+ sync # Ensure filesystem changes are written
569664 ;;
570665 esac
571666 elif [[ " $root_fstype " != " ext4" && " $root_fstype " != " btrfs" && " $root_fstype " != " xfs" ]]; then
@@ -692,9 +787,9 @@ console-mode max
692787editor no
693788EOL
694789
695- # Generate a secure random password
790+ # Generate a secure random password (hex-based for maximum entropy)
696791generate_secure_password() {
697- openssl rand -base64 12 | tr -d "=+/" | cut -c1-16
792+ openssl rand -hex 12 # 24-character hex password
698793}
699794
700795# Create user
@@ -715,8 +810,8 @@ chmod 0440 /etc/sudoers.d/wheel
715810# Force password change on first login for user
716811chage -d 0 user
717812
718- # Generate secure random password
719- TEMP_PASSWORD=\$ (openssl rand -base64 12 | tr -d "=+/" | cut -c1-16)
813+ # Generate secure random password (hex-based for maximum entropy)
814+ TEMP_PASSWORD=\$ (openssl rand -hex 12) # 24-character hex password
720815
721816# Set the random password
722817echo "user:\$ TEMP_PASSWORD" | chpasswd
@@ -788,7 +883,7 @@ log_error() {
788883
789884log_info "Downloading OSVMarchi installer..."
790885
791- # Download the installer script with retry logic
886+ # Download the installer script with retry logic and enhanced verification
792887local download_attempts=0
793888local max_download_attempts=3
794889local download_success=false
@@ -797,14 +892,38 @@ while [[ $download_attempts -lt $max_download_attempts ]] && [[ "$download_succe
797892 download_attempts=$((download_attempts + 1))
798893 log_info "Download attempt $download_attempts of $max_download_attempts..."
799894
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
895+ # Download both script and SHA256 hash if available
896+ if curl -fsSL -o osvmarchi-boot.sh https://raw.githubusercontent.com/openSVM/osvmarchi/master/boot.sh && \
897+ curl -fsSL -o boot.sh.sha256 https://raw.githubusercontent.com/openSVM/osvmarchi/master/boot.sh.sha256 2>/dev/null; then
898+
899+ # Verify SHA256 if available
900+ if [[ -f boot.sh.sha256 ]]; then
901+ log_info "Verifying script integrity with SHA256..."
902+ if sha256sum -c boot.sh.sha256 &>/dev/null; then
903+ log_success "Script integrity verified with SHA256"
904+ download_success=true
905+ break
906+ else
907+ log_warning "SHA256 verification failed, falling back to basic verification"
908+ rm -f boot.sh.sha256
909+ fi
910+ fi
911+
912+ # Fall back to basic verification if SHA256 not available or failed
913+ if [[ -s osvmarchi-boot.sh ]] && \
914+ head -1 osvmarchi-boot.sh | grep -q "^#!/bin/bash" && \
915+ grep -q "OSVMarchi" osvmarchi-boot.sh; then
916+ log_success "OSVMarchi installer downloaded and verified"
917+ download_success=true
918+ break
919+ else
920+ log_error "Downloaded script failed basic verification"
921+ rm -f osvmarchi-boot.sh boot.sh.sha256
922+ fi
804923 else
805924 if [[ $download_attempts -lt $max_download_attempts ]]; then
806925 log_warning "Download attempt $download_attempts failed, retrying in 5 seconds..."
807- rm -f osvmarchi-boot.sh 2>/dev/null || true
926+ rm -f osvmarchi-boot.sh boot.sh.sha256 2>/dev/null || true
808927 sleep 5
809928 else
810929 log_error "Failed to download OSVMarchi installer after $max_download_attempts attempts"
@@ -814,15 +933,9 @@ while [[ $download_attempts -lt $max_download_attempts ]] && [[ "$download_succe
814933 fi
815934done
816935
817- # Verify the downloaded script is not empty and contains expected content
936+ # Verify the downloaded script is ready for execution
818937if [[ ! -s osvmarchi-boot.sh ]]; then
819- log_error "Downloaded installer is empty"
820- exit 1
821- fi
822-
823- # Basic verification - check for expected OSVMarchi signatures
824- if ! grep -q "OSVMarchi" osvmarchi-boot.sh || ! grep -q "#!/bin/bash" osvmarchi-boot.sh; then
825- log_error "Downloaded installer does not appear to be a valid OSVMarchi script"
938+ log_error "Downloaded installer is empty or missing"
826939 exit 1
827940fi
828941
@@ -832,8 +945,8 @@ log_info "Downloaded installer verified, executing..."
832945chmod +x osvmarchi-boot.sh
833946./osvmarchi-boot.sh
834947
835- # Clean up downloaded script
836- rm -f osvmarchi-boot.sh
948+ # Clean up downloaded script and hash
949+ rm -f osvmarchi-boot.sh boot.sh.sha256
837950
838951USEREOF
839952
0 commit comments