Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archinstall.py57
-rw-r--r--archinstall/__init__.py5
-rw-r--r--archinstall/lib/__init__.py (renamed from helpers/__init__.py)0
-rw-r--r--archinstall/lib/disk.py (renamed from helpers/disk.py)19
-rw-r--r--archinstall/lib/exceptions.py (renamed from exceptions.py)0
-rw-r--r--archinstall/lib/general.py (renamed from helpers/general.py)0
-rw-r--r--archinstall/lib/installer.py104
-rw-r--r--archinstall/lib/user_interaction.py (renamed from helpers/user_interaction.py)2
-rw-r--r--docs/description.jpg (renamed from description.jpg)bin96324 -> 96324 bytes
-rw-r--r--docs/logo.png (renamed from logo.png)bin44691 -> 44691 bytes
-rw-r--r--docs/logo.psd (renamed from logo.psd)bin603666 -> 603666 bytes
-rw-r--r--installer.py5
-rw-r--r--setup.py22
-rw-r--r--test_archinstall.py14
14 files changed, 147 insertions, 81 deletions
diff --git a/archinstall.py b/archinstall.py
deleted file mode 100644
index 1175b406..00000000
--- a/archinstall.py
+++ /dev/null
@@ -1,57 +0,0 @@
-import os, stat
-
-from exceptions import *
-from helpers.disk import *
-from helpers.general import *
-from helpers.user_interaction import *
-
-class Installer():
- def __init__(self, partition, *, profile=None, mountpoint='/mnt', hostname='ArchInstalled'):
- self.profile = profile
- self.hostname = hostname
- self.mountpoint = mountpoint
-
- self.partition = partition
-
- def __enter__(self, *args, **kwargs):
- self.partition.mount(self.mountpoint)
- return self
-
- def __exit__(self, *args, **kwargs):
- # b''.join(sys_command(f'sync')) # No need to, since the underlaying fs() object will call sync.
- # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
- if len(args) >= 2 and args[1]:
- raise args[1]
- return True
-
- def minimal_installation(self):
- if (sync_mirrors := sys_command('/usr/bin/pacman -Syy')).exit_code == 0:
- if (pacstrap := sys_command(f'/usr/bin/pacstrap {self.mountpoint} base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog')).exit_code == 0:
- return True
- else:
- log(f'Could not strap in base: {pacstrap.exit_code}')
- else:
- log(f'Could not sync mirrors: {sync_mirrors.exit_code}')
-
- def add_bootloader(self, partition):
- os.makedirs(f'{self.mountpoint}/boot', exist_ok=True)
- partition.mount(f'{self.mountpoint}/boot')
- o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} bootctl --no-variables --path=/boot install'))
-
- with open('/mnt/boot/loader/loader.conf', 'w') as loader:
- loader.write('default arch\n')
- loader.write('timeout 5\n')
-
- ## For some reason, blkid and /dev/disk/by-uuid are not getting along well.
- ## And blkid is wrong in terms of LUKS.
- #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip()
- with open('/mnt/boot/loader/entries/arch.conf', 'w') as entry:
- entry.write('title Arch Linux\n')
- entry.write('linux /vmlinuz-linux\n')
- entry.write('initrd /initramfs-linux.img\n')
- ## blkid doesn't trigger on loopback devices really well,
- ## so we'll use the old manual method until we get that sorted out.
- # UUID = simple_command(f"blkid -s PARTUUID -o value /dev/{os.path.basename(args['drive'])}{args['partitions']['2']}").decode('UTF-8').strip()
- # entry.write('options root=PARTUUID={UUID} rw intel_pstate=no_hwp\n'.format(UUID=UUID))
- UUID = b''.join(sys_command(f"ls -l /dev/disk/by-uuid/ | grep {os.path.basename(partition.path)} | awk '{{print $9}}'")).decode('UTF-8').strip()
- entry.write(f'options cryptdevice=UUID={UUID}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') \ No newline at end of file
diff --git a/archinstall/__init__.py b/archinstall/__init__.py
new file mode 100644
index 00000000..83ba26af
--- /dev/null
+++ b/archinstall/__init__.py
@@ -0,0 +1,5 @@
+from .lib.general import *
+from .lib.disk import *
+from .lib.user_interaction import *
+from .lib.exceptions import *
+from .lib.installer import *
diff --git a/helpers/__init__.py b/archinstall/lib/__init__.py
index e69de29b..e69de29b 100644
--- a/helpers/__init__.py
+++ b/archinstall/lib/__init__.py
diff --git a/helpers/disk.py b/archinstall/lib/disk.py
index 84a6c2e5..a56b4f63 100644
--- a/helpers/disk.py
+++ b/archinstall/lib/disk.py
@@ -1,12 +1,13 @@
import glob, re, os, json
from collections import OrderedDict
-#import ctypes
-#import ctypes.util
-from exceptions import *
-from helpers.general import sys_command
+from .exceptions import *
+from .general import sys_command
ROOT_DIR_PATTERN = re.compile('^.*?/devices')
GPT = 0b00000001
+
+#import ctypes
+#import ctypes.util
#libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
#libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p)
@@ -89,6 +90,7 @@ class Partition():
return f'Partition({self.path}, fs={self.filesystem}, mounted={self.mountpoint})'
def format(self, filesystem):
+ print(f'Formatting {self} -> {filesystem}')
if filesystem == 'btrfs':
o = b''.join(sys_command(f'/usr/bin/mkfs.btrfs -f {self.path}'))
if not b'UUID' in o:
@@ -104,6 +106,7 @@ class Partition():
return True
def mount(self, target, fs=None, options=''):
+ print(f'Mounting {self} to {target}')
if not fs:
if not self.filesystem: raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.')
fs = self.filesystem
@@ -127,9 +130,11 @@ class luks2():
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
if len(args) >= 2 and args[1]:
raise args[1]
+ print(args)
return True
def encrypt(self, partition, password, key_size=512, hash_type='sha512', iter_time=10000, key_file=None):
+ print(f'Encrypting {partition}')
if not key_file: key_file = f'/tmp/{os.path.basename(self.filesystem.blockdevice.device)}.disk_pw' #TODO: Make disk-pw-file randomly unique?
if type(password) != bytes: password = bytes(password, 'UTF-8')
@@ -177,7 +182,12 @@ class Filesystem():
raise DiskError(f'Unknown mode selected to format in: {self.mode}')
def __exit__(self, *args, **kwargs):
+ # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
+ if len(args) >= 2 and args[1]:
+ raise args[1]
+ print(args)
b''.join(sys_command(f'sync'))
+ return True
def raw_parted(self, string:str):
x = sys_command(f'/usr/bin/parted -s {string}')
@@ -204,6 +214,7 @@ class Filesystem():
self.add_partition('primary', start='1MiB', end='513MiB', format='ext4')
def add_partition(self, type, start, end, format=None):
+ print(f'Adding partition to {self.blockdevice}')
if format:
return self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0
else:
diff --git a/exceptions.py b/archinstall/lib/exceptions.py
index 24f3f273..24f3f273 100644
--- a/exceptions.py
+++ b/archinstall/lib/exceptions.py
diff --git a/helpers/general.py b/archinstall/lib/general.py
index 32814ddc..32814ddc 100644
--- a/helpers/general.py
+++ b/archinstall/lib/general.py
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
new file mode 100644
index 00000000..c83d9d3c
--- /dev/null
+++ b/archinstall/lib/installer.py
@@ -0,0 +1,104 @@
+import os, stat
+
+from .exceptions import *
+from .disk import *
+from .general import *
+from .user_interaction import *
+
+class Installer():
+ def __init__(self, partition, *, profile=None, mountpoint='/mnt', hostname='ArchInstalled'):
+ self.profile = profile
+ self.hostname = hostname
+ self.mountpoint = mountpoint
+
+ self.partition = partition
+
+ def __enter__(self, *args, **kwargs):
+ self.partition.mount(self.mountpoint)
+ return self
+
+ def __exit__(self, *args, **kwargs):
+ # b''.join(sys_command(f'sync')) # No need to, since the underlaying fs() object will call sync.
+ # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
+ if len(args) >= 2 and args[1]:
+ raise args[1]
+ print(args)
+ return True
+
+ def pacstrap(self, *packages):
+ if type(packages[0]) in (list, tuple): packages = packages[0]
+ print(f'Installing packages: {packages}')
+
+ if (sync_mirrors := sys_command('/usr/bin/pacman -Syy')).exit_code == 0:
+ if (pacstrap := sys_command(f'/usr/bin/pacstrap {self.mountpoint} {" ".join(packages)}')).exit_code == 0:
+ return True
+ else:
+ print(f'Could not strap in packages: {pacstrap.exit_code}')
+ else:
+ print(f'Could not sync mirrors: {sync_mirrors.exit_code}')
+
+ def minimal_installation(self):
+ return self.pacstrap('base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog'.split(' '))
+
+ def add_bootloader(self, partition):
+ print(f'Adding bootloader to {partition}')
+ os.makedirs(f'{self.mountpoint}/boot', exist_ok=True)
+ partition.mount(f'{self.mountpoint}/boot')
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} bootctl --no-variables --path=/boot install'))
+
+ with open(f'{self.mountpoint}/boot/loader/loader.conf', 'w') as loader:
+ loader.write('default arch\n')
+ loader.write('timeout 5\n')
+
+ ## For some reason, blkid and /dev/disk/by-uuid are not getting along well.
+ ## And blkid is wrong in terms of LUKS.
+ #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip()
+ with open(f'{self.mountpoint}/boot/loader/entries/arch.conf', 'w') as entry:
+ entry.write('title Arch Linux\n')
+ entry.write('linux /vmlinuz-linux\n')
+ entry.write('initrd /initramfs-linux.img\n')
+ ## blkid doesn't trigger on loopback devices really well,
+ ## so we'll use the old manual method until we get that sorted out.
+ # UUID = simple_command(f"blkid -s PARTUUID -o value /dev/{os.path.basename(args['drive'])}{args['partitions']['2']}").decode('UTF-8').strip()
+ # entry.write('options root=PARTUUID={UUID} rw intel_pstate=no_hwp\n'.format(UUID=UUID))
+ for root, folders, uids in os.walk('/dev/disk/by-uuid'):
+ for uid in uids:
+ real_path = os.path.realpath(os.path.join(root, uid))
+ if not os.path.basename(real_path) == os.path.basename(partition.path): continue
+
+ entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n')
+ return True
+ break
+ raise RequirementError(f'Could not identify the UUID of {partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.')
+
+ def add_additional_packages(self, *packages):
+ self.pacstrap(*packages)
+
+ def install_profile(self, profile):
+ print(f'[STUB] Installing network profile {profile}')
+ pass
+
+ def user_create(self, user :str, password=None, groups=[]):
+ print(f'Creating user {user}')
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} useradd -m -G wheel {user}'))
+ if password:
+ self.user_set_pw(user, password)
+ if groups:
+ for group in groups:
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} gpasswd -a {user} {group}'))
+
+ def user_set_pw(self, user, password):
+ print(f'Setting password for {user}')
+ o = b''.join(sys_command(f"/usr/bin/arch-chroot {self.mountpoint} sh -c \"echo '{user}:{password}' | chpasswd\""))
+ pass
+
+ def add_AUR_support(self):
+ print(f'Building and installing yay support into {self.mountpoint}')
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} sh -c "useradd -m -G wheel aibuilder"'))
+ o = b''.join(sys_command(f"/usr/bin/sed -i 's/# %wheel ALL=(ALL) NO/%wheel ALL=(ALL) NO/' {self.mountpoint}/etc/sudoers"))
+
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} sh -c "su - aibuilder -c \\"(cd /home/aibuilder; git clone https://aur.archlinux.org/yay.git)\\""'))
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} sh -c "chown -R aibuilder.aibuilder /home/aibuilder/yay"'))
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} sh -c "su - aibuilder -c \\"(cd /home/aibuilder/yay; makepkg -si --noconfirm)\\" >/dev/null"'))
+
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} sh -c "userdel aibuilder; rm -rf /hoem/aibuilder"')) \ No newline at end of file
diff --git a/helpers/user_interaction.py b/archinstall/lib/user_interaction.py
index c19919c6..bd6d117c 100644
--- a/helpers/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -1,4 +1,4 @@
-from exceptions import *
+from .exceptions import *
def select_disk(dict_o_disks):
drives = sorted(list(dict_o_disks.keys()))
diff --git a/description.jpg b/docs/description.jpg
index b05daf2b..b05daf2b 100644
--- a/description.jpg
+++ b/docs/description.jpg
Binary files differ
diff --git a/logo.png b/docs/logo.png
index ac3ed4e8..ac3ed4e8 100644
--- a/logo.png
+++ b/docs/logo.png
Binary files differ
diff --git a/logo.psd b/docs/logo.psd
index d23965b9..d23965b9 100644
--- a/logo.psd
+++ b/docs/logo.psd
Binary files differ
diff --git a/installer.py b/installer.py
index faeb7edc..1204ecd2 100644
--- a/installer.py
+++ b/installer.py
@@ -10,25 +10,20 @@ harddrive = archinstall.all_disks()['/dev/loop0']
disk_password = '1234' # getpass.getpass(prompt='Disk password (won\'t echo): ')
with archinstall.Filesystem(harddrive, archinstall.GPT) as fs:
- print(f'Formatting {harddrive}')
fs.use_entire_disk('luks2')
with archinstall.luks2(fs) as crypt:
if harddrive.partition[1].size == '512M':
raise OSError('Trying to encrypt the boot partition for petes sake..')
- print(f'Encrypting {harddrive.partition[1]}')
key_file = crypt.encrypt(harddrive.partition[1], password=disk_password, key_size=512, hash_type='sha512', iter_time=10000, key_file='./pwfile')
unlocked_device = crypt.unlock(harddrive.partition[1], 'luksloop', key_file)
- print('Formatting partitions.')
harddrive.partition[0].format('fat32')
unlocked_device.format('btrfs')
with archinstall.Installer(unlocked_device, hostname='testmachine') as installation:
- print('Installing minimal installation to disk.')
if installation.minimal_installation():
- print('Adding bootloader.')
installation.add_bootloader(harddrive.partition[0])
installation.add_additional_packages(['nano', 'wget', 'git'])
diff --git a/setup.py b/setup.py
new file mode 100644
index 00000000..9571d41d
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,22 @@
+import setuptools
+
+with open("README.md", "r") as fh:
+ long_description = fh.read()
+
+setuptools.setup(
+ name="archinstall-Torxed", # Replace with your own username
+ version="2.0.0",
+ author="Anton Hvornum",
+ author_email="anton@hvornum.se",
+ description="Arch Linux installer - guided, templates etc.",
+ long_description=long_description,
+ long_description_content_type="text/markdown",
+ url="https://github.com/Torxed/archinstall",
+ packages=setuptools.find_packages(),
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ "License :: OSI Approved :: GPL 3.0 License",
+ "Operating System :: Arch Linux",
+ ],
+ python_requires='>=3.8',
+) \ No newline at end of file
diff --git a/test_archinstall.py b/test_archinstall.py
deleted file mode 100644
index 30bc76e7..00000000
--- a/test_archinstall.py
+++ /dev/null
@@ -1,14 +0,0 @@
-import json
-import archinstall
-
-archinstall.update_drive_list(emulate=False)
-archinstall.setup_args_defaults(archinstall.args, interactive=False)
-#for drive in archinstall.harddrives:
-# print(drive, archinstall.human_disk_info(drive))
-
-instructions = archinstall.load_automatic_instructions(emulate=False)
-profile_instructions = archinstall.get_instructions('workstation', emulate=False)
-profile_instructions = archinstall.merge_in_includes(profile_instructions, emulate=False)
-archinstall.args['password'] = 'test'
-
-print(json.dumps(archinstall.args, indent=4)) \ No newline at end of file