Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds+github@gmail.com>2020-11-11 21:37:40 +0000
committerGitHub <noreply@github.com>2020-11-11 21:37:40 +0000
commitbe8ac2558ef31bbd135ad5cea6c7f4c562061d7a (patch)
tree3ca98a8fc779aea829568b5d9b30b04532e1da1e
parent9a1199333a0a00b74f884dfee1b324500d4b8060 (diff)
parent4dd20ae4d4abeed916c0d1271a637dcb3c80b9a6 (diff)
Implemented systemd-networkd for installed mediums
Some bug fixes, but mostly added the option to configure **one** network interface.
-rw-r--r--.gitignore2
-rw-r--r--archinstall/lib/installer.py26
-rw-r--r--archinstall/lib/systemd.py40
-rw-r--r--archinstall/lib/user_interaction.py4
-rw-r--r--examples/guided.py59
5 files changed, 117 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index 5c83c4aa..955e7784 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,5 @@ SAFETY_LOCK
**/**.pkg.*.xz
**/**archinstall-*.tar.gz
**/**.zst
+**/**.network
+**/**.target
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index 775de50a..543f2ca3 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -6,6 +6,7 @@ from .general import *
from .user_interaction import *
from .profiles import Profile
from .mirrors import *
+from .systemd import Networkd
from .output import log, LOG_LEVELS
from .storage import storage
@@ -149,6 +150,24 @@ class Installer():
def arch_chroot(self, cmd, *args, **kwargs):
return self.run_command(cmd)
+ def configure_nic(self, nic, dhcp=True, ip=None, gateway=None, dns=None, *args, **kwargs):
+ if dhcp:
+ conf = Networkd(Match={"Name": nic}, Network={"DHCP": "yes"})
+ else:
+ assert ip
+
+ network = {"Address": ip}
+ if gateway:
+ network["Gateway"] = gateway
+ if dns:
+ assert type(dns) == list
+ network["DNS"] = dns
+
+ conf = Networkd(Match={"Name": nic}, Network=network)
+
+ with open(f"{self.mountpoint}/etc/systemd/network/10-{nic}.network", "a") as netconf:
+ netconf.write(str(conf))
+
def minimal_installation(self):
## Add nessecary packages if encrypting the drive
## (encrypted partitions default to btrfs for now, so we need btrfs-progs)
@@ -273,7 +292,8 @@ class Installer():
pass
def set_keyboard_language(self, language):
- with open(f'{self.mountpoint}/etc/vconsole.conf', 'w') as vconsole:
- vconsole.write(f'KEYMAP={language}\n')
- vconsole.write(f'FONT=lat9w-16\n')
+ if len(language.strip()):
+ with open(f'{self.mountpoint}/etc/vconsole.conf', 'w') as vconsole:
+ vconsole.write(f'KEYMAP={language}\n')
+ vconsole.write(f'FONT=lat9w-16\n')
return True \ No newline at end of file
diff --git a/archinstall/lib/systemd.py b/archinstall/lib/systemd.py
new file mode 100644
index 00000000..edd75098
--- /dev/null
+++ b/archinstall/lib/systemd.py
@@ -0,0 +1,40 @@
+class Ini():
+ def __init__(self, *args, **kwargs):
+ """
+ Limited INI handler for now.
+ Supports multiple keywords through dictionary list items.
+ """
+ self.kwargs = kwargs
+
+ def __str__(self):
+ result = ''
+ first_row_done = False
+ for top_level in self.kwargs:
+ if first_row_done:
+ result += f"\n[{top_level}]\n"
+ else:
+ result += f"[{top_level}]\n"
+ first_row_done = True
+
+ for key, val in self.kwargs[top_level].items():
+ if type(val) == list:
+ for item in val:
+ result += f"{key}={item}\n"
+ else:
+ result += f"{key}={val}\n"
+
+ return result
+
+class Systemd(Ini):
+ def __init__(self, *args, **kwargs):
+ """
+ Placeholder class to do systemd specific setups.
+ """
+ super(Systemd, self).__init__(*args, **kwargs)
+
+class Networkd(Systemd):
+ def __init__(self, *args, **kwargs):
+ """
+ Placeholder class to do systemd-network specific setups.
+ """
+ super(Networkd, self).__init__(*args, **kwargs) \ No newline at end of file
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py
index 29dfaed2..fdbabe96 100644
--- a/archinstall/lib/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -24,7 +24,9 @@ def generic_select(options, input_text="Select one of the above by index or abso
print(f"{index}: {option}")
selected_option = input(input_text)
- if selected_option.isdigit():
+ if len(selected_option.strip()) <= 0:
+ return None
+ elif selected_option.isdigit():
selected_option = options[int(selected_option)]
elif selected_option in options:
pass # We gave a correct absolute value
diff --git a/examples/guided.py b/examples/guided.py
index c0fcd97b..69162244 100644
--- a/examples/guided.py
+++ b/examples/guided.py
@@ -49,20 +49,25 @@ def perform_installation(device, boot_partition, language, mirrors):
installation.set_keyboard_language(language)
installation.add_bootloader()
- if len(archinstall.storage['_guided']['packages']) and archinstall.storage['_guided']['packages'][0] != '':
+ if archinstall.storage['_guided']['network']:
+ installation.configure_nic(**archinstall.storage['_guided']['network'])
+ installation.enable_service('systemd-networkd')
+
+ if archinstall.storage['_guided']['packages'] and archinstall.storage['_guided']['packages'][0] != '':
installation.add_additional_packages(archinstall.storage['_guided']['packages'])
if 'profile' in archinstall.storage['_guided'] and len(profile := archinstall.storage['_guided']['profile']['path'].strip()):
installation.install_profile(profile)
- for user in archinstall.storage['_guided']['users']:
- password = users[user]
+ if archinstall.storage['_guided']['users']:
+ for user in archinstall.storage['_guided']['users']:
+ password = users[user]
- sudo = False
- if 'root_pw' not in archinstall.storage['_guided_hidden'] or len(archinstall.storage['_guided_hidden']['root_pw'].strip()) == 0:
- sudo = True
+ sudo = False
+ if 'root_pw' not in archinstall.storage['_guided_hidden'] or len(archinstall.storage['_guided_hidden']['root_pw'].strip()) == 0:
+ sudo = True
- installation.user_create(user, password, sudo=sudo)
+ installation.user_create(user, password, sudo=sudo)
if 'root_pw' in archinstall.storage['_guided_hidden'] and archinstall.storage['_guided_hidden']['root_pw']:
installation.user_set_pw('root', archinstall.storage['_guided_hidden']['root_pw'])
@@ -77,8 +82,8 @@ archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', suppress_error
will we continue with the actual installation steps.
"""
-keyboard_language = archinstall.select_language(archinstall.list_keyboard_languages())
-archinstall.set_keyboard_language(keyboard_language)
+if len(keyboard_language := archinstall.select_language(archinstall.list_keyboard_languages()).strip()):
+ archinstall.set_keyboard_language(keyboard_language)
# Create a storage structure for all our information.
# We'll print this right before the user gets informed about the formatting timer.
@@ -121,6 +126,7 @@ new_user_text = 'Any additional users to install (leave blank for no users): '
if len(root_pw.strip()) == 0:
new_user_text = 'Create a super-user with sudo privileges: '
+archinstall.storage['_guided']['users'] = None
while 1:
new_user = input(new_user_text)
if len(new_user.strip()) == 0:
@@ -129,7 +135,7 @@ while 1:
continue
break
- if 'users' not in archinstall.storage['_guided']:
+ if not archinstall.storage['_guided']['users']:
archinstall.storage['_guided']['users'] = []
archinstall.storage['_guided']['users'].append(new_user)
@@ -167,6 +173,7 @@ while 1:
break
# Additional packages (with some light weight error handling for invalid package names)
+archinstall.storage['_guided']['packages'] = None
while 1:
packages = [package for package in input('Additional packages aside from base (space separated): ').split(' ') if len(package)]
@@ -180,6 +187,38 @@ while 1:
except archinstall.RequirementError as e:
print(e)
+# Optionally configure one network interface.
+#while 1:
+interfaces = archinstall.list_interfaces() # {MAC: Ifname}
+archinstall.storage['_guided']['network'] = None
+
+nic = archinstall.generic_select(interfaces.values(), "Select one network interface to configure (leave blank to skip): ")
+if nic:
+ mode = archinstall.generic_select(['DHCP (auto detect)', 'IP (static)'], f"Select which mode to configure for {nic}: ")
+ if mode == 'IP (static)':
+ while 1:
+ ip = input(f"Enter the IP and subnet for {nic} (example: 192.168.0.5/24): ").strip()
+ if ip:
+ break
+ else:
+ ArchInstall.log(
+ "You need to enter a valid IP in IP-config mode.",
+ level=archinstall.LOG_LEVELS.Warning,
+ bg='black',
+ fg='red'
+ )
+
+ if not len(gateway := input('Enter your gateway (router) IP address or leave blank for none: ').strip()):
+ gateway = None
+
+ dns = None
+ if len(dns_input := input('Enter your DNS servers (space separated, blank for none): ').strip()):
+ dns = dns_input.split(' ')
+
+ archinstall.storage['_guided']['network'] = {'nic': nic, 'dhcp': False, 'ip': ip, 'gateway' : gateway, 'dns' : dns}
+ else:
+ archinstall.storage['_guided']['network'] = {'nic': nic}
+
print()
print('This is your chosen configuration:')