Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
svartkanin committed Feb 9, 2025
1 parent 2bd5129 commit cc18876
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 44 deletions.
9 changes: 5 additions & 4 deletions archinstall/scripts/unattended.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import time

import archinstall
from archinstall import info, profile
from archinstall.lib.output import info
from archinstall.lib.profile.profiles_handler import profile_handler
from archinstall.lib.storage import storage
from archinstall.tui import Tui

for p in profile.profile_handler.get_mac_addr_profiles():
for p in profile_handler.get_mac_addr_profiles():
# Tailored means it's a match for this machine
# based on it's MAC address (or some other criteria
# that fits the requirements for this machine specifically).
Expand All @@ -15,5 +16,5 @@
Tui.print(f'{i}...')
time.sleep(1)

install_session = archinstall.storage['installation_session']
install_session = storage['installation_session']
p.install(install_session)
9 changes: 5 additions & 4 deletions examples/auto_discovery_mounted.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pathlib import Path

from archinstall import disk
from archinstall.lib.disk.device_handler import device_handler
from archinstall.lib.models.device_model import DiskLayoutConfiguration, DiskLayoutType

root_mount_dir = Path('/mnt/archinstall')

mods = disk.device_handler.detect_pre_mounted_mods(root_mount_dir)
mods = device_handler.detect_pre_mounted_mods(root_mount_dir)

disk_config = disk.DiskLayoutConfiguration(
disk.DiskLayoutType.Pre_mount,
disk_config = DiskLayoutConfiguration(
DiskLayoutType.Pre_mount,
device_modifications=mods,
)
73 changes: 46 additions & 27 deletions examples/full_automated_installation.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
from pathlib import Path

from archinstall import Installer, disk, models, profile
from archinstall.default_profiles.minimal import MinimalProfile
from archinstall.lib.disk.device_handler import device_handler
from archinstall.lib.disk.filesystem import FilesystemHandler
from archinstall.lib.installer import Installer
from archinstall.lib.models.device_model import (
DeviceModification,
DiskEncryption,
DiskLayoutConfiguration,
DiskLayoutType,
EncryptionType,
FilesystemType,
ModificationStatus,
PartitionFlag,
PartitionModification,
PartitionType,
Size,
Unit,
)
from archinstall.lib.models.profile_model import ProfileConfiguration
from archinstall.lib.models.users import User
from archinstall.lib.profile import profile_handler

# we're creating a new ext4 filesystem installation
fs_type = disk.FilesystemType('ext4')
fs_type = FilesystemType('ext4')
device_path = Path('/dev/sda')

# get the physical disk device
device = disk.device_handler.get_device(device_path)
device = device_handler.get_device(device_path)

if not device:
raise ValueError('No device found for given path')

# create a new modification for the specific device
device_modification = disk.DeviceModification(device, wipe=True)
device_modification = DeviceModification(device, wipe=True)

# create a new boot partition
boot_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create,
type=disk.PartitionType.Primary,
start=disk.Size(1, disk.Unit.MiB, device.device_info.sector_size),
length=disk.Size(512, disk.Unit.MiB, device.device_info.sector_size),
boot_partition = PartitionModification(
status=ModificationStatus.Create,
type=PartitionType.Primary,
start=Size(1, Unit.MiB, device.device_info.sector_size),
length=Size(512, Unit.MiB, device.device_info.sector_size),
mountpoint=Path('/boot'),
fs_type=disk.FilesystemType.Fat32,
flags=[disk.PartitionFlag.BOOT]
fs_type=FilesystemType.Fat32,
flags=[PartitionFlag.BOOT]
)
device_modification.add_partition(boot_partition)

# create a root partition
root_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create,
type=disk.PartitionType.Primary,
start=disk.Size(513, disk.Unit.MiB, device.device_info.sector_size),
length=disk.Size(20, disk.Unit.GiB, device.device_info.sector_size),
root_partition = PartitionModification(
status=ModificationStatus.Create,
type=PartitionType.Primary,
start=Size(513, Unit.MiB, device.device_info.sector_size),
length=Size(20, Unit.GiB, device.device_info.sector_size),
mountpoint=None,
fs_type=fs_type,
mount_options=[],
Expand All @@ -44,9 +63,9 @@
length_home = device.device_info.total_size - start_home

# create a new home partition
home_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create,
type=disk.PartitionType.Primary,
home_partition = PartitionModification(
status=ModificationStatus.Create,
type=PartitionType.Primary,
start=start_home,
length=length_home,
mountpoint=Path('/home'),
Expand All @@ -55,21 +74,21 @@
)
device_modification.add_partition(home_partition)

disk_config = disk.DiskLayoutConfiguration(
config_type=disk.DiskLayoutType.Default,
disk_config = DiskLayoutConfiguration(
config_type=DiskLayoutType.Default,
device_modifications=[device_modification]
)

# disk encryption configuration (Optional)
disk_encryption = disk.DiskEncryption(
disk_encryption = DiskEncryption(
encryption_password="enc_password",
encryption_type=disk.EncryptionType.Luks,
encryption_type=EncryptionType.Luks,
partitions=[home_partition],
hsm_device=None
)

# initiate file handler with the disk config and the optional disk encryption config
fs_handler = disk.FilesystemHandler(disk_config, disk_encryption)
fs_handler = FilesystemHandler(disk_config, disk_encryption)

# perform all file operations
# WARNING: this will potentially format the filesystem and delete all data
Expand All @@ -89,8 +108,8 @@

# Optionally, install a profile of choice.
# In this case, we install a minimal profile that is empty
profile_config = profile.ProfileConfiguration(MinimalProfile())
profile.profile_handler.install_profile_config(installation, profile_config)
profile_config = ProfileConfiguration(MinimalProfile())
profile_handler.install_profile_config(installation, profile_config)

user = models.User('archinstall', 'password', True)
user = User('archinstall', 'password', True)
installation.create_users(user)
9 changes: 5 additions & 4 deletions examples/mac_address_installation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import time

import archinstall
from archinstall import info, profile
from archinstall.lib.output import info
from archinstall.lib.profile import profile_handler
from archinstall.lib.storage import storage
from archinstall.tui import Tui

for _profile in profile.profile_handler.get_mac_addr_profiles():
for _profile in profile_handler.get_mac_addr_profiles():
# Tailored means it's a match for this machine
# based on it's MAC address (or some other criteria
# that fits the requirements for this machine specifically).
Expand All @@ -15,5 +16,5 @@
Tui.print(f'{i}...')
time.sleep(1)

install_session = archinstall.storage['installation_session']
install_session = storage['installation_session']
_profile.install(install_session)
9 changes: 4 additions & 5 deletions tests/test_configuration_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from archinstall.lib.args import ArchConfigHandler
from archinstall.lib.configuration import ConfigurationOutput
from archinstall.lib.models.device_model import DiskLayoutType


def test_user_config_roundtrip(
Expand All @@ -29,10 +28,10 @@ def test_user_config_roundtrip(

# the parsed config will check if the given device exists otherwise
# it will ignore the modification; as this test will run on various local systems
# and the CI pipeline there's no good way specify a real device so we'll ivnore
# that entry in the comparison for now
expected['disk_config']['config_type'] = DiskLayoutType.Default.value
expected['disk_config']['device_modifications'] = []
# and the CI pipeline there's no good way specify a real device so we'll simply
# copy the expected result to the actual result
result['disk_config']['config_type'] = expected['disk_config']['config_type']
result['disk_config']['device_modifications'] = expected['disk_config']['device_modifications']

assert sorted(result.items()) == sorted(expected.items())

Expand Down

0 comments on commit cc18876

Please sign in to comment.