From b4a6f03b962d9309a1a18bd6de6a50a0146252a1 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 6 Jul 2020 18:44:42 +0200 Subject: Converted the lib to a pip supported structure to make packaging easier. Also tweaked some minor issues and added the AUR function --- archinstall.py | 57 -------- archinstall/__init__.py | 5 + archinstall/lib/__init__.py | 0 archinstall/lib/disk.py | 255 ++++++++++++++++++++++++++++++++++++ archinstall/lib/exceptions.py | 4 + archinstall/lib/general.py | 187 ++++++++++++++++++++++++++ archinstall/lib/installer.py | 104 +++++++++++++++ archinstall/lib/user_interaction.py | 17 +++ description.jpg | Bin 96324 -> 0 bytes docs/description.jpg | Bin 0 -> 96324 bytes docs/logo.png | Bin 0 -> 44691 bytes docs/logo.psd | Bin 0 -> 603666 bytes exceptions.py | 4 - helpers/__init__.py | 0 helpers/disk.py | 244 ---------------------------------- helpers/general.py | 187 -------------------------- helpers/user_interaction.py | 17 --- installer.py | 5 - logo.png | Bin 44691 -> 0 bytes logo.psd | Bin 603666 -> 0 bytes setup.py | 22 ++++ test_archinstall.py | 14 -- 22 files changed, 594 insertions(+), 528 deletions(-) delete mode 100644 archinstall.py create mode 100644 archinstall/__init__.py create mode 100644 archinstall/lib/__init__.py create mode 100644 archinstall/lib/disk.py create mode 100644 archinstall/lib/exceptions.py create mode 100644 archinstall/lib/general.py create mode 100644 archinstall/lib/installer.py create mode 100644 archinstall/lib/user_interaction.py delete mode 100644 description.jpg create mode 100644 docs/description.jpg create mode 100644 docs/logo.png create mode 100644 docs/logo.psd delete mode 100644 exceptions.py delete mode 100644 helpers/__init__.py delete mode 100644 helpers/disk.py delete mode 100644 helpers/general.py delete mode 100644 helpers/user_interaction.py delete mode 100644 logo.png delete mode 100644 logo.psd create mode 100644 setup.py delete mode 100644 test_archinstall.py 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/archinstall/lib/__init__.py b/archinstall/lib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py new file mode 100644 index 00000000..a56b4f63 --- /dev/null +++ b/archinstall/lib/disk.py @@ -0,0 +1,255 @@ +import glob, re, os, json +from collections import OrderedDict +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) + +class BlockDevice(): + def __init__(self, path, info): + self.path = path + self.info = info + self.part_cache = OrderedDict() + + @property + def device(self): + """ + Returns the actual device-endpoint of the BlockDevice. + If it's a loop-back-device it returns the back-file, + If it's a ATA-drive it returns the /dev/X device + And if it's a crypto-device it returns the parent device + """ + if not 'type' in self.info: raise DiskError(f'Could not locate backplane info for "{self.path}"') + + if self.info['type'] == 'loop': + for drive in json.loads(b''.join(sys_command(f'losetup --json', hide_from_log=True)).decode('UTF_8'))['loopdevices']: + if not drive['name'] == self.path: continue + + return drive['back-file'] + elif self.info['type'] == 'disk': + return self.path + elif self.info['type'] == 'crypt': + if not 'pkname' in self.info: raise DiskError(f'A crypt device ({self.path}) without a parent kernel device name.') + return f"/dev/{self.info['pkname']}" + + # if not stat.S_ISBLK(os.stat(full_path).st_mode): + # raise DiskError(f'Selected disk "{full_path}" is not a block device.') + + @property + def partitions(self): + o = b''.join(sys_command(f'partprobe {self.path}')) + + #o = b''.join(sys_command('/usr/bin/lsblk -o name -J -b {dev}'.format(dev=dev))) + o = b''.join(sys_command(f'/usr/bin/lsblk -J {self.path}')) + if b'not a block device' in o: + raise DiskError(f'Can not read partitions off something that isn\'t a block device: {self.path}') + + if not o[:1] == b'{': + raise DiskError(f'Error getting JSON output from:', f'/usr/bin/lsblk -J {self.path}') + + r = json.loads(o.decode('UTF-8')) + if len(r['blockdevices']) and 'children' in r['blockdevices'][0]: + root_path = f"/dev/{r['blockdevices'][0]['name']}" + for part in r['blockdevices'][0]['children']: + part_id = part['name'][len(os.path.basename(self.path)):] + if part_id not in self.part_cache: + ## TODO: Force over-write even if in cache? + self.part_cache[part_id] = Partition(root_path + part_id, part_id=part_id, size=part['size']) + + return {k: self.part_cache[k] for k in sorted(self.part_cache)} + + @property + def partition(self): + all_partitions = self.partitions + return [all_partitions[k] for k in all_partitions] + + def __repr__(self, *args, **kwargs): + return f"BlockDevice({self.device})" + + def __getitem__(self, key, *args, **kwargs): + if not key in self.info: + raise KeyError(f'{self} does not contain information: "{key}"') + return self.info[key] + +class Partition(): + def __init__(self, path, part_id=None, size=-1): + if not part_id: part_id = os.path.basename(path) + self.path = path + self.part_id = part_id + self.mountpoint = None + self.filesystem = None # TODO: Autodetect if we're reusing a partition + self.size = size # TODO: Refresh? + + def __repr__(self, *args, **kwargs): + 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: + raise DiskError(f'Could not format {self.path} with {filesystem} because: {o}') + self.filesystem = 'btrfs' + elif filesystem == 'fat32': + o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {self.path}')) + if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: + raise DiskError(f'Could not format {self.path} with {filesystem} because: {o}') + self.filesystem = 'fat32' + else: + raise DiskError(f'Fileformat {filesystem} is not yet implemented.') + 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 + ## libc has some issues with loop devices, defaulting back to sys calls + # ret = libc.mount(self.path.encode(), target.encode(), fs.encode(), 0, options.encode()) + # if ret < 0: + # errno = ctypes.get_errno() + # raise OSError(errno, f"Error mounting {self.path} ({fs}) on {target} with options '{options}': {os.strerror(errno)}") + if sys_command(f'/usr/bin/mount {self.path} {target}').exit_code == 0: + self.mountpoint = target + return True + +class luks2(): + def __init__(self, filesystem): + self.filesystem = filesystem + + def __enter__(self): + return self + + 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) + 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') + + with open(key_file, 'wb') as fh: + fh.write(password) + + o = b''.join(sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}')) + if not b'Command successful.' in o: + raise DiskError(f'Could not encrypt volume "{partition.path}": {o}') + + return key_file + + def unlock(self, partition, mountpoint, key_file): + """ + Mounts a lukts2 compatible partition to a certain mountpoint. + Keyfile must be specified as there's no way to interact with the pw-prompt atm. + + :param mountpoint: The name without absolute path, for instance "luksdev" will point to /dev/mapper/luksdev + :type mountpoint: str + """ + if '/' in mountpoint: os.path.basename(mountpoint) # TODO: Raise exception instead? + sys_command(f'/usr/bin/cryptsetup open {partition.path} {mountpoint} --key-file {os.path.abspath(key_file)} --type luks2') + if os.path.islink(f'/dev/mapper/{mountpoint}'): + return Partition(f'/dev/mapper/{mountpoint}') + + def close(self, mountpoint): + sys_command(f'cryptsetup close /dev/mapper/{mountpoint}') + return os.path.islink(f'/dev/mapper/{mountpoint}') is False + +class Filesystem(): + # TODO: + # When instance of a HDD is selected, check all usages and gracefully unmount them + # as well as close any crypto handles. + def __init__(self, blockdevice, mode=GPT): + self.blockdevice = blockdevice + self.mode = mode + + def __enter__(self, *args, **kwargs): + if self.mode == GPT: + if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt',).exit_code == 0: + return self + else: + raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') + else: + 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}') + o = b''.join(x) + return x + + def parted(self, string:str): + """ + Performs a parted execution of the given string + + :param string: A raw string passed to /usr/bin/parted -s + :type string: str + """ + return self.raw_parted(string).exit_code + + def use_entire_disk(self, prep_mode=None): + self.add_partition('primary', start='1MiB', end='513MiB', format='fat32') + self.set_name(0, 'EFI') + self.set(0, 'boot on') + self.set(0, 'esp on') # TODO: Redundant, as in GPT mode it's an alias for "boot on"? https://www.gnu.org/software/parted/manual/html_node/set.html + if prep_mode == 'luks2': + self.add_partition('primary', start='513MiB', end='100%') + else: + 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: + return self.parted(f'{self.blockdevice.device} mkpart {type} {start} {end}') == 0 + + def set_name(self, partition:int, name:str): + return self.parted(f'{self.blockdevice.device} name {partition+1} "{name}"') == 0 + + def set(self, partition:int, string:str): + return self.parted(f'{self.blockdevice.device} set {partition+1} {string}') == 0 + +def device_state(name, *args, **kwargs): + # Based out of: https://askubuntu.com/questions/528690/how-to-get-list-of-all-non-removable-disk-device-names-ssd-hdd-and-sata-ide-onl/528709#528709 + if os.path.isfile('/sys/block/{}/device/block/{}/removable'.format(name, name)): + with open('/sys/block/{}/device/block/{}/removable'.format(name, name)) as f: + if f.read(1) == '1': + return + + path = ROOT_DIR_PATTERN.sub('', os.readlink('/sys/block/{}'.format(name))) + hotplug_buses = ("usb", "ieee1394", "mmc", "pcmcia", "firewire") + for bus in hotplug_buses: + if os.path.exists('/sys/bus/{}'.format(bus)): + for device_bus in os.listdir('/sys/bus/{}/devices'.format(bus)): + device_link = ROOT_DIR_PATTERN.sub('', os.readlink('/sys/bus/{}/devices/{}'.format(bus, device_bus))) + if re.search(device_link, path): + return + return True + +# lsblk --json -l -n -o path +def all_disks(*args, **kwargs): + if not 'partitions' in kwargs: kwargs['partitions'] = False + drives = OrderedDict() + #for drive in json.loads(sys_command(f'losetup --json', *args, **lkwargs, hide_from_log=True)).decode('UTF_8')['loopdevices']: + for drive in json.loads(b''.join(sys_command(f'lsblk --json -l -n -o path,size,type,mountpoint,label,pkname', *args, **kwargs, hide_from_log=True)).decode('UTF_8'))['blockdevices']: + if not kwargs['partitions'] and drive['type'] == 'part': continue + + drives[drive['path']] = BlockDevice(drive['path'], drive) + return drives \ No newline at end of file diff --git a/archinstall/lib/exceptions.py b/archinstall/lib/exceptions.py new file mode 100644 index 00000000..24f3f273 --- /dev/null +++ b/archinstall/lib/exceptions.py @@ -0,0 +1,4 @@ +class RequirementError(BaseException): + pass +class DiskError(BaseException): + pass \ No newline at end of file diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py new file mode 100644 index 00000000..32814ddc --- /dev/null +++ b/archinstall/lib/general.py @@ -0,0 +1,187 @@ +import os, json, hashlib, shlex +import time, pty +from subprocess import Popen, STDOUT, PIPE, check_output +from select import epoll, EPOLLIN, EPOLLHUP + +def log(*args, **kwargs): + print(' '.join([str(x) for x in args])) + +def gen_uid(entropy_length=256): + return hashlib.sha512(os.urandom(entropy_length)).hexdigest() + +class sys_command():#Thread): + """ + Stolen from archinstall_gui + """ + def __init__(self, cmd, callback=None, start_callback=None, *args, **kwargs): + if not 'worker_id' in kwargs: kwargs['worker_id'] = gen_uid() + if not 'emulate' in kwargs: kwargs['emulate'] = False + if not 'surpress_errors' in kwargs: kwargs['surpress_errors'] = False + if kwargs['emulate']: + log(f"Starting command '{cmd}' in emulation mode.") + self.raw_cmd = cmd + self.cmd = shlex.split(cmd) + self.args = args + self.kwargs = kwargs + if not 'worker' in self.kwargs: self.kwargs['worker'] = None + self.callback = callback + self.pid = None + self.exit_code = None + self.started = time.time() + self.ended = None + self.worker_id = kwargs['worker_id'] + self.trace_log = b'' + self.status = 'starting' + + user_catalogue = os.path.expanduser('~') + self.cwd = f"{user_catalogue}/archinstall/cache/workers/{kwargs['worker_id']}/" + self.exec_dir = f'{self.cwd}/{os.path.basename(self.cmd[0])}_workingdir' + + if not self.cmd[0][0] == '/': + #log('Worker command is not executed with absolute path, trying to find: {}'.format(self.cmd[0]), origin='spawn', level=5) + o = check_output(['/usr/bin/which', self.cmd[0]]) + #log('This is the binary {} for {}'.format(o.decode('UTF-8'), self.cmd[0]), origin='spawn', level=5) + self.cmd[0] = o.decode('UTF-8').strip() + + if not os.path.isdir(self.exec_dir): + os.makedirs(self.exec_dir) + + if start_callback: start_callback(self, *args, **kwargs) + self.run() + + def __iter__(self, *args, **kwargs): + for line in self.trace_log.split(b'\n'): + yield line + + def __repr__(self, *args, **kwargs): + return f"{self.cmd, self.trace_log}" + + def decode(self, fmt='UTF-8'): + return self.trace_log.decode(fmt) + + def dump(self): + return { + 'status' : self.status, + 'worker_id' : self.worker_id, + 'worker_result' : self.trace_log.decode('UTF-8'), + 'started' : self.started, + 'ended' : self.ended, + 'started_pprint' : '{}-{}-{} {}:{}:{}'.format(*time.localtime(self.started)), + 'ended_pprint' : '{}-{}-{} {}:{}:{}'.format(*time.localtime(self.ended)) if self.ended else None, + 'exit_code' : self.exit_code + } + + def run(self): + self.status = 'running' + old_dir = os.getcwd() + os.chdir(self.exec_dir) + self.pid, child_fd = pty.fork() + if not self.pid: # Child process + # Replace child process with our main process + if not self.kwargs['emulate']: + try: + os.execv(self.cmd[0], self.cmd) + except FileNotFoundError: + self.status = 'done' + log(f"{self.cmd[0]} does not exist.", origin='spawn', level=2) + self.exit_code = 1 + return False + + os.chdir(old_dir) + + poller = epoll() + poller.register(child_fd, EPOLLIN | EPOLLHUP) + + if 'events' in self.kwargs and 'debug' in self.kwargs: + log(f'[D] Using triggers for command: {self.cmd}') + log(json.dumps(self.kwargs['events'])) + + alive = True + last_trigger_pos = 0 + while alive and not self.kwargs['emulate']: + for fileno, event in poller.poll(0.1): + try: + output = os.read(child_fd, 8192).strip() + self.trace_log += output + except OSError: + alive = False + break + + if 'debug' in self.kwargs and self.kwargs['debug'] and len(output): + log(self.cmd, 'gave:', output.decode('UTF-8')) + + if 'on_output' in self.kwargs: + self.kwargs['on_output'](self.kwargs['worker'], output) + + lower = output.lower() + broke = False + if 'events' in self.kwargs: + for trigger in list(self.kwargs['events']): + if type(trigger) != bytes: + original = trigger + trigger = bytes(original, 'UTF-8') + self.kwargs['events'][trigger] = self.kwargs['events'][original] + del(self.kwargs['events'][original]) + if type(self.kwargs['events'][trigger]) != bytes: + self.kwargs['events'][trigger] = bytes(self.kwargs['events'][trigger], 'UTF-8') + + if trigger.lower() in self.trace_log[last_trigger_pos:].lower(): + trigger_pos = self.trace_log[last_trigger_pos:].lower().find(trigger.lower()) + + if 'debug' in self.kwargs and self.kwargs['debug']: + log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}") + log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}", origin='spawn', level=5) + + last_trigger_pos = trigger_pos + os.write(child_fd, self.kwargs['events'][trigger]) + del(self.kwargs['events'][trigger]) + broke = True + break + + if broke: + continue + + ## Adding a exit trigger: + if len(self.kwargs['events']) == 0: + if 'debug' in self.kwargs and self.kwargs['debug']: + log(f"Waiting for last command {self.cmd[0]} to finish.", origin='spawn', level=4) + + if bytes(f']$'.lower(), 'UTF-8') in self.trace_log[0-len(f']$')-5:].lower(): + if 'debug' in self.kwargs and self.kwargs['debug']: + log(f"{self.cmd[0]} has finished.", origin='spawn', level=4) + alive = False + break + + self.status = 'done' + + if 'debug' in self.kwargs and self.kwargs['debug']: + log(f"{self.cmd[0]} waiting for exit code.", origin='spawn', level=5) + + if not self.kwargs['emulate']: + try: + self.exit_code = os.waitpid(self.pid, 0)[1] + except ChildProcessError: + try: + self.exit_code = os.waitpid(child_fd, 0)[1] + except ChildProcessError: + self.exit_code = 1 + else: + self.exit_code = 0 + + if 'ignore_errors' in self.kwargs: + self.exit_code = 0 + + if self.exit_code != 0 and not self.kwargs['surpress_errors']: + log(f"'{self.raw_cmd}' did not exit gracefully, exit code {self.exit_code}.", origin='spawn', level=3) + log(self.trace_log.decode('UTF-8'), origin='spawn', level=3) + + self.ended = time.time() + with open(f'{self.cwd}/trace.log', 'wb') as fh: + fh.write(self.trace_log) + +def prerequisit_check(): + if not os.path.isdir('/sys/firmware/efi'): + raise RequirementError('Archinstall only supports machines in UEFI mode.') + + return True + 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/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py new file mode 100644 index 00000000..bd6d117c --- /dev/null +++ b/archinstall/lib/user_interaction.py @@ -0,0 +1,17 @@ +from .exceptions import * + +def select_disk(dict_o_disks): + drives = sorted(list(dict_o_disks.keys())) + if len(drives) > 1: + for index, drive in enumerate(drives): + print(f"{index}: {drive} ({dict_o_disks[drive]['size'], dict_o_disks[drive].device, dict_o_disks[drive]['label']})") + drive = input('Select one of the above disks (by number or full path): ') + if drive.isdigit(): + drive = dict_o_disks[drives[int(drive)]] + elif drive in dict_o_disks: + drive = dict_o_disks[drive] + else: + raise DiskError(f'Selected drive does not exist: "{drive}"') + return drive + + raise DiskError('select_disk() requires a non-empty dictionary of disks to select from.') \ No newline at end of file diff --git a/description.jpg b/description.jpg deleted file mode 100644 index b05daf2b..00000000 Binary files a/description.jpg and /dev/null differ diff --git a/docs/description.jpg b/docs/description.jpg new file mode 100644 index 00000000..b05daf2b Binary files /dev/null and b/docs/description.jpg differ diff --git a/docs/logo.png b/docs/logo.png new file mode 100644 index 00000000..ac3ed4e8 Binary files /dev/null and b/docs/logo.png differ diff --git a/docs/logo.psd b/docs/logo.psd new file mode 100644 index 00000000..d23965b9 Binary files /dev/null and b/docs/logo.psd differ diff --git a/exceptions.py b/exceptions.py deleted file mode 100644 index 24f3f273..00000000 --- a/exceptions.py +++ /dev/null @@ -1,4 +0,0 @@ -class RequirementError(BaseException): - pass -class DiskError(BaseException): - pass \ No newline at end of file diff --git a/helpers/__init__.py b/helpers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/helpers/disk.py b/helpers/disk.py deleted file mode 100644 index 84a6c2e5..00000000 --- a/helpers/disk.py +++ /dev/null @@ -1,244 +0,0 @@ -import glob, re, os, json -from collections import OrderedDict -#import ctypes -#import ctypes.util -from exceptions import * -from helpers.general import sys_command - -ROOT_DIR_PATTERN = re.compile('^.*?/devices') -GPT = 0b00000001 -#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) - -class BlockDevice(): - def __init__(self, path, info): - self.path = path - self.info = info - self.part_cache = OrderedDict() - - @property - def device(self): - """ - Returns the actual device-endpoint of the BlockDevice. - If it's a loop-back-device it returns the back-file, - If it's a ATA-drive it returns the /dev/X device - And if it's a crypto-device it returns the parent device - """ - if not 'type' in self.info: raise DiskError(f'Could not locate backplane info for "{self.path}"') - - if self.info['type'] == 'loop': - for drive in json.loads(b''.join(sys_command(f'losetup --json', hide_from_log=True)).decode('UTF_8'))['loopdevices']: - if not drive['name'] == self.path: continue - - return drive['back-file'] - elif self.info['type'] == 'disk': - return self.path - elif self.info['type'] == 'crypt': - if not 'pkname' in self.info: raise DiskError(f'A crypt device ({self.path}) without a parent kernel device name.') - return f"/dev/{self.info['pkname']}" - - # if not stat.S_ISBLK(os.stat(full_path).st_mode): - # raise DiskError(f'Selected disk "{full_path}" is not a block device.') - - @property - def partitions(self): - o = b''.join(sys_command(f'partprobe {self.path}')) - - #o = b''.join(sys_command('/usr/bin/lsblk -o name -J -b {dev}'.format(dev=dev))) - o = b''.join(sys_command(f'/usr/bin/lsblk -J {self.path}')) - if b'not a block device' in o: - raise DiskError(f'Can not read partitions off something that isn\'t a block device: {self.path}') - - if not o[:1] == b'{': - raise DiskError(f'Error getting JSON output from:', f'/usr/bin/lsblk -J {self.path}') - - r = json.loads(o.decode('UTF-8')) - if len(r['blockdevices']) and 'children' in r['blockdevices'][0]: - root_path = f"/dev/{r['blockdevices'][0]['name']}" - for part in r['blockdevices'][0]['children']: - part_id = part['name'][len(os.path.basename(self.path)):] - if part_id not in self.part_cache: - ## TODO: Force over-write even if in cache? - self.part_cache[part_id] = Partition(root_path + part_id, part_id=part_id, size=part['size']) - - return {k: self.part_cache[k] for k in sorted(self.part_cache)} - - @property - def partition(self): - all_partitions = self.partitions - return [all_partitions[k] for k in all_partitions] - - def __repr__(self, *args, **kwargs): - return f"BlockDevice({self.device})" - - def __getitem__(self, key, *args, **kwargs): - if not key in self.info: - raise KeyError(f'{self} does not contain information: "{key}"') - return self.info[key] - -class Partition(): - def __init__(self, path, part_id=None, size=-1): - if not part_id: part_id = os.path.basename(path) - self.path = path - self.part_id = part_id - self.mountpoint = None - self.filesystem = None # TODO: Autodetect if we're reusing a partition - self.size = size # TODO: Refresh? - - def __repr__(self, *args, **kwargs): - return f'Partition({self.path}, fs={self.filesystem}, mounted={self.mountpoint})' - - def format(self, filesystem): - if filesystem == 'btrfs': - o = b''.join(sys_command(f'/usr/bin/mkfs.btrfs -f {self.path}')) - if not b'UUID' in o: - raise DiskError(f'Could not format {self.path} with {filesystem} because: {o}') - self.filesystem = 'btrfs' - elif filesystem == 'fat32': - o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {self.path}')) - if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: - raise DiskError(f'Could not format {self.path} with {filesystem} because: {o}') - self.filesystem = 'fat32' - else: - raise DiskError(f'Fileformat {filesystem} is not yet implemented.') - return True - - def mount(self, target, fs=None, options=''): - if not fs: - if not self.filesystem: raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.') - fs = self.filesystem - ## libc has some issues with loop devices, defaulting back to sys calls - # ret = libc.mount(self.path.encode(), target.encode(), fs.encode(), 0, options.encode()) - # if ret < 0: - # errno = ctypes.get_errno() - # raise OSError(errno, f"Error mounting {self.path} ({fs}) on {target} with options '{options}': {os.strerror(errno)}") - if sys_command(f'/usr/bin/mount {self.path} {target}').exit_code == 0: - self.mountpoint = target - return True - -class luks2(): - def __init__(self, filesystem): - self.filesystem = filesystem - - def __enter__(self): - return self - - 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] - return True - - def encrypt(self, partition, password, key_size=512, hash_type='sha512', iter_time=10000, key_file=None): - 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') - - with open(key_file, 'wb') as fh: - fh.write(password) - - o = b''.join(sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}')) - if not b'Command successful.' in o: - raise DiskError(f'Could not encrypt volume "{partition.path}": {o}') - - return key_file - - def unlock(self, partition, mountpoint, key_file): - """ - Mounts a lukts2 compatible partition to a certain mountpoint. - Keyfile must be specified as there's no way to interact with the pw-prompt atm. - - :param mountpoint: The name without absolute path, for instance "luksdev" will point to /dev/mapper/luksdev - :type mountpoint: str - """ - if '/' in mountpoint: os.path.basename(mountpoint) # TODO: Raise exception instead? - sys_command(f'/usr/bin/cryptsetup open {partition.path} {mountpoint} --key-file {os.path.abspath(key_file)} --type luks2') - if os.path.islink(f'/dev/mapper/{mountpoint}'): - return Partition(f'/dev/mapper/{mountpoint}') - - def close(self, mountpoint): - sys_command(f'cryptsetup close /dev/mapper/{mountpoint}') - return os.path.islink(f'/dev/mapper/{mountpoint}') is False - -class Filesystem(): - # TODO: - # When instance of a HDD is selected, check all usages and gracefully unmount them - # as well as close any crypto handles. - def __init__(self, blockdevice, mode=GPT): - self.blockdevice = blockdevice - self.mode = mode - - def __enter__(self, *args, **kwargs): - if self.mode == GPT: - if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt',).exit_code == 0: - return self - else: - raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') - else: - raise DiskError(f'Unknown mode selected to format in: {self.mode}') - - def __exit__(self, *args, **kwargs): - b''.join(sys_command(f'sync')) - - def raw_parted(self, string:str): - x = sys_command(f'/usr/bin/parted -s {string}') - o = b''.join(x) - return x - - def parted(self, string:str): - """ - Performs a parted execution of the given string - - :param string: A raw string passed to /usr/bin/parted -s - :type string: str - """ - return self.raw_parted(string).exit_code - - def use_entire_disk(self, prep_mode=None): - self.add_partition('primary', start='1MiB', end='513MiB', format='fat32') - self.set_name(0, 'EFI') - self.set(0, 'boot on') - self.set(0, 'esp on') # TODO: Redundant, as in GPT mode it's an alias for "boot on"? https://www.gnu.org/software/parted/manual/html_node/set.html - if prep_mode == 'luks2': - self.add_partition('primary', start='513MiB', end='100%') - else: - self.add_partition('primary', start='1MiB', end='513MiB', format='ext4') - - def add_partition(self, type, start, end, format=None): - if format: - return self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 - else: - return self.parted(f'{self.blockdevice.device} mkpart {type} {start} {end}') == 0 - - def set_name(self, partition:int, name:str): - return self.parted(f'{self.blockdevice.device} name {partition+1} "{name}"') == 0 - - def set(self, partition:int, string:str): - return self.parted(f'{self.blockdevice.device} set {partition+1} {string}') == 0 - -def device_state(name, *args, **kwargs): - # Based out of: https://askubuntu.com/questions/528690/how-to-get-list-of-all-non-removable-disk-device-names-ssd-hdd-and-sata-ide-onl/528709#528709 - if os.path.isfile('/sys/block/{}/device/block/{}/removable'.format(name, name)): - with open('/sys/block/{}/device/block/{}/removable'.format(name, name)) as f: - if f.read(1) == '1': - return - - path = ROOT_DIR_PATTERN.sub('', os.readlink('/sys/block/{}'.format(name))) - hotplug_buses = ("usb", "ieee1394", "mmc", "pcmcia", "firewire") - for bus in hotplug_buses: - if os.path.exists('/sys/bus/{}'.format(bus)): - for device_bus in os.listdir('/sys/bus/{}/devices'.format(bus)): - device_link = ROOT_DIR_PATTERN.sub('', os.readlink('/sys/bus/{}/devices/{}'.format(bus, device_bus))) - if re.search(device_link, path): - return - return True - -# lsblk --json -l -n -o path -def all_disks(*args, **kwargs): - if not 'partitions' in kwargs: kwargs['partitions'] = False - drives = OrderedDict() - #for drive in json.loads(sys_command(f'losetup --json', *args, **lkwargs, hide_from_log=True)).decode('UTF_8')['loopdevices']: - for drive in json.loads(b''.join(sys_command(f'lsblk --json -l -n -o path,size,type,mountpoint,label,pkname', *args, **kwargs, hide_from_log=True)).decode('UTF_8'))['blockdevices']: - if not kwargs['partitions'] and drive['type'] == 'part': continue - - drives[drive['path']] = BlockDevice(drive['path'], drive) - return drives \ No newline at end of file diff --git a/helpers/general.py b/helpers/general.py deleted file mode 100644 index 32814ddc..00000000 --- a/helpers/general.py +++ /dev/null @@ -1,187 +0,0 @@ -import os, json, hashlib, shlex -import time, pty -from subprocess import Popen, STDOUT, PIPE, check_output -from select import epoll, EPOLLIN, EPOLLHUP - -def log(*args, **kwargs): - print(' '.join([str(x) for x in args])) - -def gen_uid(entropy_length=256): - return hashlib.sha512(os.urandom(entropy_length)).hexdigest() - -class sys_command():#Thread): - """ - Stolen from archinstall_gui - """ - def __init__(self, cmd, callback=None, start_callback=None, *args, **kwargs): - if not 'worker_id' in kwargs: kwargs['worker_id'] = gen_uid() - if not 'emulate' in kwargs: kwargs['emulate'] = False - if not 'surpress_errors' in kwargs: kwargs['surpress_errors'] = False - if kwargs['emulate']: - log(f"Starting command '{cmd}' in emulation mode.") - self.raw_cmd = cmd - self.cmd = shlex.split(cmd) - self.args = args - self.kwargs = kwargs - if not 'worker' in self.kwargs: self.kwargs['worker'] = None - self.callback = callback - self.pid = None - self.exit_code = None - self.started = time.time() - self.ended = None - self.worker_id = kwargs['worker_id'] - self.trace_log = b'' - self.status = 'starting' - - user_catalogue = os.path.expanduser('~') - self.cwd = f"{user_catalogue}/archinstall/cache/workers/{kwargs['worker_id']}/" - self.exec_dir = f'{self.cwd}/{os.path.basename(self.cmd[0])}_workingdir' - - if not self.cmd[0][0] == '/': - #log('Worker command is not executed with absolute path, trying to find: {}'.format(self.cmd[0]), origin='spawn', level=5) - o = check_output(['/usr/bin/which', self.cmd[0]]) - #log('This is the binary {} for {}'.format(o.decode('UTF-8'), self.cmd[0]), origin='spawn', level=5) - self.cmd[0] = o.decode('UTF-8').strip() - - if not os.path.isdir(self.exec_dir): - os.makedirs(self.exec_dir) - - if start_callback: start_callback(self, *args, **kwargs) - self.run() - - def __iter__(self, *args, **kwargs): - for line in self.trace_log.split(b'\n'): - yield line - - def __repr__(self, *args, **kwargs): - return f"{self.cmd, self.trace_log}" - - def decode(self, fmt='UTF-8'): - return self.trace_log.decode(fmt) - - def dump(self): - return { - 'status' : self.status, - 'worker_id' : self.worker_id, - 'worker_result' : self.trace_log.decode('UTF-8'), - 'started' : self.started, - 'ended' : self.ended, - 'started_pprint' : '{}-{}-{} {}:{}:{}'.format(*time.localtime(self.started)), - 'ended_pprint' : '{}-{}-{} {}:{}:{}'.format(*time.localtime(self.ended)) if self.ended else None, - 'exit_code' : self.exit_code - } - - def run(self): - self.status = 'running' - old_dir = os.getcwd() - os.chdir(self.exec_dir) - self.pid, child_fd = pty.fork() - if not self.pid: # Child process - # Replace child process with our main process - if not self.kwargs['emulate']: - try: - os.execv(self.cmd[0], self.cmd) - except FileNotFoundError: - self.status = 'done' - log(f"{self.cmd[0]} does not exist.", origin='spawn', level=2) - self.exit_code = 1 - return False - - os.chdir(old_dir) - - poller = epoll() - poller.register(child_fd, EPOLLIN | EPOLLHUP) - - if 'events' in self.kwargs and 'debug' in self.kwargs: - log(f'[D] Using triggers for command: {self.cmd}') - log(json.dumps(self.kwargs['events'])) - - alive = True - last_trigger_pos = 0 - while alive and not self.kwargs['emulate']: - for fileno, event in poller.poll(0.1): - try: - output = os.read(child_fd, 8192).strip() - self.trace_log += output - except OSError: - alive = False - break - - if 'debug' in self.kwargs and self.kwargs['debug'] and len(output): - log(self.cmd, 'gave:', output.decode('UTF-8')) - - if 'on_output' in self.kwargs: - self.kwargs['on_output'](self.kwargs['worker'], output) - - lower = output.lower() - broke = False - if 'events' in self.kwargs: - for trigger in list(self.kwargs['events']): - if type(trigger) != bytes: - original = trigger - trigger = bytes(original, 'UTF-8') - self.kwargs['events'][trigger] = self.kwargs['events'][original] - del(self.kwargs['events'][original]) - if type(self.kwargs['events'][trigger]) != bytes: - self.kwargs['events'][trigger] = bytes(self.kwargs['events'][trigger], 'UTF-8') - - if trigger.lower() in self.trace_log[last_trigger_pos:].lower(): - trigger_pos = self.trace_log[last_trigger_pos:].lower().find(trigger.lower()) - - if 'debug' in self.kwargs and self.kwargs['debug']: - log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}") - log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}", origin='spawn', level=5) - - last_trigger_pos = trigger_pos - os.write(child_fd, self.kwargs['events'][trigger]) - del(self.kwargs['events'][trigger]) - broke = True - break - - if broke: - continue - - ## Adding a exit trigger: - if len(self.kwargs['events']) == 0: - if 'debug' in self.kwargs and self.kwargs['debug']: - log(f"Waiting for last command {self.cmd[0]} to finish.", origin='spawn', level=4) - - if bytes(f']$'.lower(), 'UTF-8') in self.trace_log[0-len(f']$')-5:].lower(): - if 'debug' in self.kwargs and self.kwargs['debug']: - log(f"{self.cmd[0]} has finished.", origin='spawn', level=4) - alive = False - break - - self.status = 'done' - - if 'debug' in self.kwargs and self.kwargs['debug']: - log(f"{self.cmd[0]} waiting for exit code.", origin='spawn', level=5) - - if not self.kwargs['emulate']: - try: - self.exit_code = os.waitpid(self.pid, 0)[1] - except ChildProcessError: - try: - self.exit_code = os.waitpid(child_fd, 0)[1] - except ChildProcessError: - self.exit_code = 1 - else: - self.exit_code = 0 - - if 'ignore_errors' in self.kwargs: - self.exit_code = 0 - - if self.exit_code != 0 and not self.kwargs['surpress_errors']: - log(f"'{self.raw_cmd}' did not exit gracefully, exit code {self.exit_code}.", origin='spawn', level=3) - log(self.trace_log.decode('UTF-8'), origin='spawn', level=3) - - self.ended = time.time() - with open(f'{self.cwd}/trace.log', 'wb') as fh: - fh.write(self.trace_log) - -def prerequisit_check(): - if not os.path.isdir('/sys/firmware/efi'): - raise RequirementError('Archinstall only supports machines in UEFI mode.') - - return True - diff --git a/helpers/user_interaction.py b/helpers/user_interaction.py deleted file mode 100644 index c19919c6..00000000 --- a/helpers/user_interaction.py +++ /dev/null @@ -1,17 +0,0 @@ -from exceptions import * - -def select_disk(dict_o_disks): - drives = sorted(list(dict_o_disks.keys())) - if len(drives) > 1: - for index, drive in enumerate(drives): - print(f"{index}: {drive} ({dict_o_disks[drive]['size'], dict_o_disks[drive].device, dict_o_disks[drive]['label']})") - drive = input('Select one of the above disks (by number or full path): ') - if drive.isdigit(): - drive = dict_o_disks[drives[int(drive)]] - elif drive in dict_o_disks: - drive = dict_o_disks[drive] - else: - raise DiskError(f'Selected drive does not exist: "{drive}"') - return drive - - raise DiskError('select_disk() requires a non-empty dictionary of disks to select from.') \ No newline at end of file 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/logo.png b/logo.png deleted file mode 100644 index ac3ed4e8..00000000 Binary files a/logo.png and /dev/null differ diff --git a/logo.psd b/logo.psd deleted file mode 100644 index d23965b9..00000000 Binary files a/logo.psd and /dev/null differ 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 -- cgit v1.2.3-54-g00ecf