Starting to add networking helpers in archinstall. First up is archinstall.getHwAddr(ifname) which returns the mac of a interface name. second is archinstall.list_interfaces() which lists all the local MAC addresses and which interface it is bound to. Also starting to add the unattended installer back step by step. Currently with one MAC profile. The MAC profile filtering/detection has also been added in archinstall.list_profiles() - it will filter out all MAC address-specific profiles when called, unless a MAC matches a profile or filter_irrelevant_macs=False is given.

This commit is contained in:
Anton Hvornum 2020-08-20 17:08:13 +00:00
parent aaad480ab8
commit 056b800c8e
5 changed files with 72 additions and 3 deletions

View File

@ -6,3 +6,4 @@ from .lib.installer import *
from .lib.profiles import *
from .lib.luks import *
from .lib.mirrors import *
from .lib.networking import *

View File

@ -0,0 +1,20 @@
import fcntl
import socket
import struct
from collections import OrderedDict
from .exceptions import *
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(ifname, 'utf-8')[:15]))
return ':'.join('%02x' % b for b in info[18:24])
def list_interfaces(skip_loopback=True):
interfaces = OrderedDict()
for index, iface in socket.if_nameindex():
if skip_loopback and iface == 'lo': continue
mac = getHwAddr(iface).replace(':', '-')
interfaces[mac] = iface
return interfaces

View File

@ -1,8 +1,9 @@
import os, urllib.request, urllib.parse, ssl, json
import os, urllib.request, urllib.parse, ssl, json, re
import importlib.util, sys
from collections import OrderedDict
from .general import multisplit, sys_command, log
from .exceptions import *
from .networking import *
UPSTREAM_URL = 'https://raw.githubusercontent.com/Torxed/archinstall/master/profiles'
@ -14,19 +15,28 @@ def grab_url_data(path):
response = urllib.request.urlopen(safe_path, context=ssl_context)
return response.read()
def list_profiles(base='./profiles/'):
def list_profiles(base='./profiles/', filter_irrelevant_macs=True):
# TODO: Grab from github page as well, not just local static files
if filter_irrelevant_macs:
local_macs = list_interfaces()
cache = {}
for root, folders, files in os.walk(base):
for file in files:
tailored = False
if os.path.splitext(file)[1] == '.py':
if len(mac := re.findall('(([a-zA-z0-9]{2}[-:]){5}([a-zA-z0-9]{2}))', file)):
if filter_irrelevant_macs and mac[0][0] not in local_macs::
continue
tailored = True
description = ''
with open(os.path.join(root, file), 'r') as fh:
first_line = fh.readline()
if first_line[0] == '#':
description = first_line[1:].strip()
cache[file] = {'path' : os.path.join(root, file), 'description' : description}
cache[file] = {'path' : os.path.join(root, file), 'description' : description, 'tailored' : tailored}
break
return cache

6
examples/unattended.py Normal file
View File

@ -0,0 +1,6 @@
import archinstall
for profile in archinstall.list_profiles():
# Tailored means it's a match for this machine.
if profile['tailored']:
print('Selecting profile to be installed:', profile)

View File

@ -0,0 +1,32 @@
import archinstall, getpass
# Unmount and close previous runs
archinstall.sys_command(f'umount -R /mnt', surpress_errors=True)
archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', surpress_errors=True)
# Select a harddrive and a disk password
harddrive = archinstall.all_disks()['/dev/sda']
disk_password = '1234'
with archinstall.Filesystem(harddrive, archinstall.GPT) as fs:
# Use the entire disk instead of setting up partitions on your own
fs.use_entire_disk('luks2')
if harddrive.partition[1].size == '512M':
raise OSError('Trying to encrypt the boot partition for petes sake..')
harddrive.partition[0].format('fat32')
with archinstall.luks2(harddrive.partition[1], 'luksloop', disk_password) as unlocked_device:
unlocked_device.format('btrfs')
with archinstall.Installer(unlocked_device, boot_partition=harddrive.partition[0], hostname='testmachine') as installation:
if installation.minimal_installation():
installation.add_bootloader()
installation.add_additional_packages(['nano', 'wget', 'git'])
installation.install_profile('workstation')
installation.user_create('anton', 'test')
installation.user_set_pw('root', 'toor')
installation.add_AUR_support()