Skip to content

Commit

Permalink
Update function to get bootmnt device and mount
Browse files Browse the repository at this point in the history
  • Loading branch information
pkgdemon committed Jan 14, 2024
1 parent fb0496a commit 0efcb7c
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions installer/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,60 @@
with open("/tmp/password", encoding="utf-8") as password_file:
PASSWORD = password_file.read().strip()

def get_iso_device():
'''
This function only runs if it needs to when bootmnt is not mounted.
'''
try:
# Run the shell command
command = "lsblk -f | awk '/ARCH/ && /iso/ && NF {getline; print $1}' | sed 's/[^a-zA-Z0-9]//g'"
result = subprocess.run(command, shell=True, capture_output=True, text=True, check=True)

# Return the cleaned device name with /dev/ prefix
iso_device = result.stdout.strip()
return f"/dev/{iso_device}"

except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return None

def detect_media():
'''
This function will be to workaround differences in the Arch Linux installation media.
This function will get iso device if bootmnt is not mounted.
'''
# 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}")
try:
# Check if /run/archiso/bootmnt exists
bootmnt_path = '/run/archiso/bootmnt'

if os.path.exists(bootmnt_path):
print(f"{bootmnt_path} already exists. Skipping operation.")
return

# Get the ISO device
iso_device = get_iso_device()

if iso_device:
print(f"The ISO device is: {iso_device}")

# Create /run/archiso/bootmnt directory
os.makedirs(bootmnt_path, exist_ok=True)
print(f"Created directory: {bootmnt_path}")

# Mount the ISO device to /run/archiso/bootmnt
subprocess.run(['mount', iso_device, bootmnt_path], check=True)
print(f"Mounted {iso_device} to {bootmnt_path}")

# Continue with the rest of your logic here

else:
print("Failed to retrieve ISO device.")
return

except FileNotFoundError as e:
print(f"File not found error: {e}")
except PermissionError as e:
print(f"Permission error: {e}")

def cleanup():
"""
Cleans up the system by removing existing boot entries, unmounting file systems,
Expand Down

0 comments on commit 0efcb7c

Please sign in to comment.