Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archinstall/__init__.py1
-rw-r--r--archinstall/lib/networking.py20
-rw-r--r--archinstall/lib/profiles.py16
-rw-r--r--examples/unattended.py6
-rw-r--r--profiles/52-54-00-12-34-56.py32
5 files changed, 72 insertions, 3 deletions
diff --git a/archinstall/__init__.py b/archinstall/__init__.py
index 7042322c..69e98ec7 100644
--- a/archinstall/__init__.py
+++ b/archinstall/__init__.py
@@ -6,3 +6,4 @@ from .lib.installer import *
from .lib.profiles import *
from .lib.luks import *
from .lib.mirrors import *
+from .lib.networking import * \ No newline at end of file
diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py
new file mode 100644
index 00000000..ae4126a9
--- /dev/null
+++ b/archinstall/lib/networking.py
@@ -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
diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py
index 47d6eaf8..b63a26c4 100644
--- a/archinstall/lib/profiles.py
+++ b/archinstall/lib/profiles.py
@@ -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
diff --git a/examples/unattended.py b/examples/unattended.py
new file mode 100644
index 00000000..7dfa58c1
--- /dev/null
+++ b/examples/unattended.py
@@ -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) \ No newline at end of file
diff --git a/profiles/52-54-00-12-34-56.py b/profiles/52-54-00-12-34-56.py
new file mode 100644
index 00000000..4c487938
--- /dev/null
+++ b/profiles/52-54-00-12-34-56.py
@@ -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() \ No newline at end of file