55
66set -euo pipefail
77
8- # Configuration file for installation state
9- INSTALL_CONFIG_FILE=" /tmp/osvmarchi-install.conf"
8+ # Configuration file for installation state - secure location
9+ INSTALL_CONFIG_DIR=" /run/user/$( id -u) /osvmarchi"
10+ INSTALL_CONFIG_FILE=" ${INSTALL_CONFIG_DIR} /install.conf"
11+
12+ # Ensure secure config directory
13+ ensure_secure_config () {
14+ if [[ ! -d " $INSTALL_CONFIG_DIR " ]]; then
15+ mkdir -p " $INSTALL_CONFIG_DIR "
16+ chmod 700 " $INSTALL_CONFIG_DIR "
17+ fi
18+ }
1019
1120# Save installation state
1221save_install_state () {
1322 local key=" $1 "
1423 local value=" $2 "
1524
16- # Create config file if it doesn't exist
17- [[ ! -f " $INSTALL_CONFIG_FILE " ]] && touch " $INSTALL_CONFIG_FILE "
25+ # Ensure secure config directory exists
26+ ensure_secure_config
27+
28+ # Create config file if it doesn't exist with secure permissions
29+ if [[ ! -f " $INSTALL_CONFIG_FILE " ]]; then
30+ touch " $INSTALL_CONFIG_FILE "
31+ chmod 600 " $INSTALL_CONFIG_FILE "
32+ fi
1833
1934 # Remove existing key if present
2035 sed -i " /^${key} =/d" " $INSTALL_CONFIG_FILE "
@@ -35,6 +50,7 @@ load_install_state() {
3550# Clean up configuration
3651cleanup_install_state () {
3752 [[ -f " $INSTALL_CONFIG_FILE " ]] && rm -f " $INSTALL_CONFIG_FILE "
53+ [[ -d " $INSTALL_CONFIG_DIR " ]] && rmdir " $INSTALL_CONFIG_DIR " 2> /dev/null || true
3854}
3955
4056# Colors for output
@@ -132,7 +148,7 @@ detect_disks() {
132148
133149 # Get list of block devices that are disks (not partitions)
134150 local disks
135- if ! mapfile -t disks < <( lsblk -dpno NAME,SIZE,MODEL | grep -E ' ^/dev/(sd|nvme|vd|hd) [a-z]' | head -10) ; then
151+ if ! mapfile -t disks < <( lsblk -dpno NAME,SIZE,MODEL | grep -E ' ^/dev/(sd[a-z]+ |nvme[0-9]+n[0-9]+ |vd[a-z]+ |hd[a-z]+)$ ' | head -10) ; then
136152 log_error " Failed to detect disks using lsblk"
137153 exit 1
138154 fi
@@ -188,7 +204,7 @@ partition_disk() {
188204 if [[ $line =~ ^(/dev/[^[:space:]]+) ]]; then
189205 disk_choices+=(" ${BASH_REMATCH[1]} " )
190206 fi
191- done < <( lsblk -dpno NAME,SIZE,MODEL | grep -E ' ^/dev/(sd|nvme|vd) [a-z]' )
207+ done < <( lsblk -dpno NAME,SIZE,MODEL | grep -E ' ^/dev/(sd[a-z]+ |nvme[0-9]+n[0-9]+ |vd[a-z]+)$ ' )
192208
193209 if [[ ${# disk_choices[@]} -eq 0 ]]; then
194210 log_error " No disks available for selection"
@@ -239,13 +255,22 @@ partition_disk() {
239255# Automatic partitioning for UEFI systems
240256automatic_partition () {
241257 local disk=" $1 "
242- log_info " Creating automatic UEFI partition layout on $disk ..."
258+ log_info " Creating automatic partition layout on $disk ..."
243259
244260 # Check if system is UEFI
245261 if [[ ! -d /sys/firmware/efi ]]; then
246262 log_error " Automatic partitioning currently only supports UEFI systems"
247- log_info " Please use manual partitioning for BIOS systems"
248- exit 1
263+ log_warning " Your system appears to be using BIOS/Legacy boot mode"
264+ log_info " BIOS systems require manual partitioning with the following layout:"
265+ log_info " 1. Create a small boot partition (512MB, ext4, bootable flag)"
266+ log_info " 2. Create root partition (remaining space, ext4 or btrfs)"
267+ log_info " "
268+ if gum confirm " Switch to manual partitioning mode for BIOS setup?" ; then
269+ manual_partition " $disk "
270+ return
271+ else
272+ exit 1
273+ fi
249274 fi
250275
251276 # Safely unmount any existing partitions
@@ -257,14 +282,37 @@ automatic_partition() {
257282 log_warning " Found mounted partitions, unmounting safely..."
258283 for mount_point in " ${mounted_parts[@]} " ; do
259284 log_info " Unmounting $mount_point "
260- if ! umount " $mount_point " 2> /dev/null; then
261- log_warning " Normal unmount failed, forcing unmount of $mount_point "
262- if ! umount -f " $mount_point " 2> /dev/null; then
263- log_error " Failed to unmount $mount_point , disk may be busy"
264- log_info " Please manually unmount all partitions on $disk before continuing"
265- exit 1
285+
286+ # Try normal unmount with retries
287+ local attempts=0
288+ local max_attempts=3
289+ while [[ $attempts -lt $max_attempts ]]; do
290+ if umount " $mount_point " 2> /dev/null; then
291+ log_success " Successfully unmounted $mount_point "
292+ break
266293 fi
267- fi
294+
295+ attempts=$(( attempts + 1 ))
296+ if [[ $attempts -lt $max_attempts ]]; then
297+ log_warning " Unmount attempt $attempts failed, waiting 2 seconds before retry..."
298+ sleep 2
299+ else
300+ log_warning " Normal unmount failed after $max_attempts attempts"
301+ if gum confirm " Force unmount $mount_point ? (This may cause data loss)" ; then
302+ if umount -f " $mount_point " 2> /dev/null; then
303+ log_warning " Force unmount successful for $mount_point "
304+ break
305+ else
306+ log_error " Failed to force unmount $mount_point , disk may be busy"
307+ log_info " Please manually unmount all partitions on $disk before continuing"
308+ exit 1
309+ fi
310+ else
311+ log_error " Cannot proceed with mounted partitions"
312+ exit 1
313+ fi
314+ fi
315+ done
268316 done
269317 fi
270318
@@ -522,6 +570,11 @@ console-mode max
522570editor no
523571EOL
524572
573+ # Generate a secure random password
574+ generate_secure_password() {
575+ openssl rand -base64 12 | tr -d "=+/" | cut -c1-16
576+ }
577+
525578# Create user
526579useradd -m -G wheel -s /bin/bash user
527580
@@ -540,11 +593,18 @@ chmod 0440 /etc/sudoers.d/wheel
540593# Force password change on first login for user
541594chage -d 0 user
542595
543- # Set a temporary password that must be changed
544- echo "user:changeme" | chpasswd
596+ # Generate secure random password
597+ TEMP_PASSWORD=\$ (openssl rand -base64 12 | tr -d "=+/" | cut -c1-16)
598+
599+ # Set the random password
600+ echo "user:\$ TEMP_PASSWORD" | chpasswd
601+
602+ # Save the password to a secure location for the installer to display
603+ echo "TEMP_USER_PASSWORD=\$ TEMP_PASSWORD" > /etc/osvmarchi-first-login.info
604+ chmod 600 /etc/osvmarchi-first-login.info
545605
546606echo "Base system configuration complete"
547- echo "SECURITY: User password must be changed on first login"
607+ echo "SECURITY: User password is randomly generated and must be changed on first login"
548608echo "SECURITY: Root account is locked for security"
549609EOF
550610
@@ -569,8 +629,43 @@ set -e
569629sudo -u user bash << 'USEREOF'
570630cd /home/user
571631
572- # Download and install OSVMarchi
573- curl -fsSL https://raw.githubusercontent.com/openSVM/osvmarchi/master/boot.sh | bash
632+ # SECURITY: Download and verify OSVMarchi installer instead of direct execution
633+ log_info() {
634+ echo -e "\033[0;34m[INFO]\033[0m $1"
635+ }
636+
637+ log_error() {
638+ echo -e "\033[0;31m[ERROR]\033[0m $1"
639+ }
640+
641+ log_info "Downloading OSVMarchi installer..."
642+
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
648+
649+ # Verify the downloaded script is not empty and contains expected content
650+ if [[ ! -s osvmarchi-boot.sh ]]; then
651+ log_error "Downloaded installer is empty"
652+ exit 1
653+ fi
654+
655+ # Basic verification - check for expected OSVMarchi signatures
656+ if ! grep -q "OSVMarchi" osvmarchi-boot.sh || ! grep -q "#!/bin/bash" osvmarchi-boot.sh; then
657+ log_error "Downloaded installer does not appear to be a valid OSVMarchi script"
658+ exit 1
659+ fi
660+
661+ log_info "Downloaded installer verified, executing..."
662+
663+ # Make executable and run
664+ chmod +x osvmarchi-boot.sh
665+ ./osvmarchi-boot.sh
666+
667+ # Clean up downloaded script
668+ rm -f osvmarchi-boot.sh
574669
575670USEREOF
576671
@@ -620,9 +715,22 @@ main() {
620715 # Clean up temporary configuration
621716 cleanup_install_state
622717
718+ # Get the temporary password that was generated
719+ local temp_password
720+ if [[ -f /mnt/etc/osvmarchi-first-login.info ]]; then
721+ temp_password=$( grep " TEMP_USER_PASSWORD=" /mnt/etc/osvmarchi-first-login.info | cut -d' =' -f2)
722+ fi
723+
623724 log_success " OSVMarchi installation completed successfully!"
624725 log_info " You can now reboot into your new OSVMarchi system"
625- log_warning " IMPORTANT: User password is 'changeme' and MUST be changed on first login"
726+
727+ if [[ -n " $temp_password " ]]; then
728+ log_warning " IMPORTANT: Temporary user password is: $temp_password "
729+ log_warning " This password MUST be changed on first login!"
730+ else
731+ log_warning " IMPORTANT: Check /etc/osvmarchi-first-login.info for temporary password"
732+ fi
733+
626734 log_info " Root account is locked for security - use sudo for administrative tasks"
627735
628736 if gum confirm " Reboot now?" ; then
@@ -704,7 +812,7 @@ test_mode() {
704812 if [[ $line =~ ^(/dev/[^[:space:]]+) ]]; then
705813 disk_choices+=(" ${BASH_REMATCH[1]} " )
706814 fi
707- done < <( lsblk -dpno NAME,SIZE,MODEL | grep -E ' ^/dev/(sd|nvme|vd|hd) [a-z]' )
815+ done < <( lsblk -dpno NAME,SIZE,MODEL | grep -E ' ^/dev/(sd[a-z]+ |nvme[0-9]+n[0-9]+ |vd[a-z]+ |hd[a-z]+)$ ' )
708816
709817 log_info " Available disks for installation:"
710818 printf ' %s\n' " ${disk_choices[@]} "
0 commit comments