Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/installer.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/installer.py')
-rw-r--r--archinstall/lib/installer.py51
1 files changed, 35 insertions, 16 deletions
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index 0e5f5ca7..553fad80 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -1,4 +1,4 @@
-import os, stat
+import os, stat, time
from .exceptions import *
from .disk import *
@@ -6,6 +6,8 @@ from .general import *
from .user_interaction import *
from .profiles import Profile
from .mirrors import *
+from .output import log, LOG_LEVELS
+from .storage import storage
class Installer():
"""
@@ -35,6 +37,8 @@ class Installer():
self.profile = profile
self.hostname = hostname
self.mountpoint = mountpoint
+ self.init_time = time.strftime('%Y-%m-%d %H:%M:%S')
+ self.milliseconds = int(str(time.time()).split('.')[1])
self.helper_flags = {
'bootloader' : False,
@@ -43,10 +47,25 @@ class Installer():
}
self.base_packages = base_packages.split(' ')
+ storage['session'] = self
self.partition = partition
self.boot_partition = boot_partition
+ @property
+ def log(self, message, *args, level=LOG_LEVELS.Debug, file=None, **kwargs):
+ if not file:
+ if 'logfile' not in storage:
+ log_root = os.path.join(os.path.expanduser('~/'), '.cache/archinstall')
+ if not os.path.isdir(log_root):
+ os.makedirs(log_root)
+
+ storage['logfile'] = f"{log_root}/install-session_{self.init_time}.{self.milliseconds}.log"
+
+ file = storage['logfile']
+
+ log(message, *args, level=level, file=file, **kwargs)
+
def __enter__(self, *args, **kwargs):
self.partition.mount(self.mountpoint)
os.makedirs(f'{self.mountpoint}/boot', exist_ok=True)
@@ -60,14 +79,14 @@ class Installer():
raise args[1]
if not (missing_steps := self.post_install_check()):
- log('Installation completed without any errors. You may now reboot.', bg='black', fg='green')
+ self.log('Installation completed without any errors. You may now reboot.', bg='black', fg='green')
return True
else:
- log('Some required steps were not successfully installed/configured before leaving the installer:', bg='black', fg='red')
+ self.log('Some required steps were not successfully installed/configured before leaving the installer:', bg='black', fg='red')
for step in missing_steps:
- log(f' - {step}', bg='black', fg='red')
- log(f"Detailed error logs can be found at: {log_path}")
- log(f"Submit this zip file as an issue to https://github.com/Torxed/archinstall/issues")
+ self.log(f' - {step}', bg='black', fg='red')
+ self.log(f"Detailed error logs can be found at: {log_path}")
+ self.log(f"Submit this zip file as an issue to https://github.com/Torxed/archinstall/issues")
return False
def post_install_check(self, *args, **kwargs):
@@ -75,15 +94,15 @@ class Installer():
def pacstrap(self, *packages, **kwargs):
if type(packages[0]) in (list, tuple): packages = packages[0]
- log(f'Installing packages: {packages}')
+ self.log(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)}', **kwargs)).exit_code == 0:
return True
else:
- log(f'Could not strap in packages: {pacstrap.exit_code}')
+ self.log(f'Could not strap in packages: {pacstrap.exit_code}')
else:
- log(f'Could not sync mirrors: {sync_mirrors.exit_code}')
+ self.log(f'Could not sync mirrors: {sync_mirrors.exit_code}')
def set_mirrors(self, mirrors):
return use_mirrors(mirrors, destination=f'{self.mountpoint}/etc/pacman.d/mirrorlist')
@@ -116,13 +135,13 @@ class Installer():
return True
def activate_ntp(self):
- log(f'Installing and activating NTP.')
+ self.log(f'Installing and activating NTP.')
if self.pacstrap('ntp'):
if self.enable_service('ntpd'):
return True
def enable_service(self, service):
- log(f'Enabling service {service}')
+ self.log(f'Enabling service {service}')
return self.arch_chroot(f'systemctl enable {service}').exit_code == 0
def run_command(self, cmd, *args, **kwargs):
@@ -171,7 +190,7 @@ class Installer():
return True
def add_bootloader(self, bootloader='systemd-bootctl'):
- log(f'Adding bootloader {bootloader} to {self.boot_partition}')
+ self.log(f'Adding bootloader {bootloader} to {self.boot_partition}')
if bootloader == 'systemd-bootctle':
o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} bootctl --no-variables --path=/boot install'))
@@ -222,17 +241,17 @@ class Installer():
def install_profile(self, profile):
profile = Profile(self, profile)
- log(f'Installing network profile {profile}')
+ self.log(f'Installing network profile {profile}')
return profile.install()
def enable_sudo(self, entity :str, group=False):
- log(f'Enabling sudo permissions for {entity}.')
+ self.log(f'Enabling sudo permissions for {entity}.')
with open(f'{self.mountpoint}/etc/sudoers', 'a') as sudoers:
sudoers.write(f'{"%" if group else ""}{entity} ALL=(ALL) ALL\n')
return True
def user_create(self, user :str, password=None, groups=[], sudo=False):
- log(f'Creating user {user}')
+ self.log(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)
@@ -245,7 +264,7 @@ class Installer():
self.helper_flags['user'] = True
def user_set_pw(self, user, password):
- log(f'Setting password for {user}')
+ self.log(f'Setting password for {user}')
if user == 'root':
# This means the root account isn't locked/disabled with * in /etc/passwd