Skip to content

Commit

Permalink
Move function up and detect media
Browse files Browse the repository at this point in the history
  • Loading branch information
pkgdemon committed Jan 14, 2024
1 parent 8547456 commit c2a9c95
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions installer/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@
with open("/tmp/password", encoding="utf-8") as password_file:
PASSWORD = password_file.read().strip()

def detect_media():
'''
This function will be to workaround differences in the Arch Linux installation media.
'''
# Check if /run/archiso/bootmnt exists
if os.path.exists('/run/archiso/bootmnt'):
print("/run/archiso/bootmnt already exists. Skipping operation.")
return

# Get the device from which the script is running
script_device = os.path.realpath("/")

# Get all removable devices
removable_devices = [dev.device for dev in psutil.disk_partitions() if dev.opts == 'rm']

# Find the device that contains the script
for device in removable_devices:
if script_device.startswith(device):
arch_usb = device
print(f"Install from USB device detected: {arch_usb}")
return

print("Install from optical media detected")

def cleanup():
"""
Cleans up the system by removing existing boot entries, unmounting file systems,
Expand Down Expand Up @@ -81,36 +105,6 @@ def cleanup():
# Ensure disk has been erased properly with wipefs
subprocess.run(["wipefs", "-aq", DISK], check=True)


def detect_usb_media(file_path='/tmp/arch-usb-stick'):
'''
This function will be to workaround differences in the Arch Linux installation media.
'''
# Check if /run/archiso/bootmnt exists
if os.path.exists('/run/archiso/bootmnt'):
print("/run/archiso/bootmnt already exists. Skipping operation.")
return

# Get the device from which the script is running
script_device = os.path.realpath("/")

# Get all removable devices
removable_devices = [dev.device for dev in psutil.disk_partitions() if dev.opts == 'rm']

# Find the device that contains the script
for device in removable_devices:
if script_device.startswith(device):
arch_usb = device
print(f"Arch Linux USB device found: {arch_usb}")

# Write USB variable to /tmp/arch-usb-stick
with open(file_path, 'w', encoding='utf-8') as file:
file.write(arch_usb)
print(f"USB device written to {file_path}")
return

print("Arch Linux USB device not found.")

def filesystem():
"""
Creates and mounts filesystems.
Expand Down Expand Up @@ -292,6 +286,7 @@ def export_pools():
"""
subprocess.run(["zpool", "export", "-a"], check=True)

detect_media()
cleanup()
filesystem()
install()
Expand Down

0 comments on commit c2a9c95

Please sign in to comment.