Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds@gmail.com>2019-06-09 20:28:16 +0200
committerGitHub <noreply@github.com>2019-06-09 20:28:16 +0200
commit6df29346606e744cffc6378bcde9c4bb1b1df172 (patch)
treeb3eb722c50bd1823dd8ffdb12d5a9b5411ef04b0
parent221640b83dd18a8885f274bde43e28d57e1d6e1f (diff)
parent730452f7e3aa580ce1cd9700b306ec2f68242112 (diff)
Merge pull request #13 from Torxed/experimental
Adding experimental features
-rw-r--r--archinstall.py65
-rw-r--r--deployments/applications/awesome.json14
-rw-r--r--deployments/applications/postgresql.json5
-rw-r--r--deployments/workstation.json19
4 files changed, 86 insertions, 17 deletions
diff --git a/archinstall.py b/archinstall.py
index 0d909d0f..72ba3dc4 100644
--- a/archinstall.py
+++ b/archinstall.py
@@ -191,6 +191,7 @@ class sys_command():
os.write(child_fd, b'shutdown now\n')
exit_code = os.waitpid(self.pid, 0)[1]
+
if exit_code != 0:
print('[E] Command "{}" exited with status code:'.format(self.cmd[0]), exit_code)
print(trace_log)
@@ -217,6 +218,29 @@ def simple_command(cmd, opts=None, *args, **kwargs):
handle.stdout.close()
return output
+def get_drive_from_uuid(uuid):
+ if len(harddrives) <= 0: raise ValueError("No hard drives to iterate in order to find: {}".format(uuid))
+
+ for drive in harddrives:
+ #for partition in psutil.disk_partitions('/dev/{}'.format(name)):
+ # pass #blkid -s PARTUUID -o value /dev/sda2
+ o = simple_command(f'blkid -s PTUUID -o value /dev/{drive}')
+ if len(o) and o == uuid:
+ return drive
+
+ return None
+
+def get_drive_from_part_uuid(partuuid):
+ if len(harddrives) <= 0: raise ValueError("No hard drives to iterate in order to find: {}".format(uuid))
+
+ for drive in harddrives:
+ for partition in grab_partitions(f'/dev/{drive}'):
+ o = simple_command(f'blkid -s PARTUUID -o value /dev/{drive}')
+ if len(o) and o == partuuid:
+ return drive
+
+ return None
+
def update_git():
default_gw = get_default_gateway_linux()
if(default_gw):
@@ -312,6 +336,24 @@ def grab_url_data(path):
response = urllib.request.urlopen(safe_path, context=ssl_context)
return response.read()
+def get_application_instructions(target):
+ instructions = {}
+ try:
+ instructions = grab_url_data('{}/applications/{}.json'.format(args['profiles-path'], target))
+ except urllib.error.HTTPError:
+ print('[N] No instructions found for: {}'.format(target))
+ return instructions
+
+ print('[N] Found application instructions for: {}'.format(target))
+ try:
+ instructions = json.loads(instructions.decode('UTF-8'), object_pairs_hook=oDict)
+ except:
+ print('[E] JSON syntax error in {}'.format('{}/applications/{}.json'.format(args['profiles-path'], target)))
+ traceback.print_exc()
+ exit(1)
+
+ return instructions
+
def get_instructions(target):
instructions = {}
try:
@@ -355,7 +397,7 @@ if __name__ == '__main__':
exit(1)
## Setup some defaults (in case no command-line parameters or netdeploy-params were given)
- if not 'drive' in args: args['drive'] = list(harddrives.keys())[0] # First drive found
+ if not 'drive' in args: args['drive'] = sorted(list(harddrives.keys()))[0] # First drive found
if not 'size' in args: args['size'] = '100%'
if not 'start' in args: args['start'] = '513MiB'
if not 'pwfile' in args: args['pwfile'] = '/tmp/diskpw'
@@ -368,6 +410,19 @@ if __name__ == '__main__':
if not 'profile' in args: args['profile'] = None
if not 'profiles-path' in args: args['profiles-path'] = profiles_path
+ if args['drive'][0] != '/':
+ ## Remap the selected UUID to the device to be formatted.
+ drive = get_drive_from_uuid(args['drive'])
+ if not drive:
+ print(f'[N] Could not map UUID "{args["drive"]}" to a device. Trying to match via PARTUUID instead!')
+
+ drive = get_drive_from_part_uuid(args['drive'])
+ if not drive:
+ print(f'[E] Could not map UUID "{args["drive"]}" to a device. Aborting!')
+ exit(1)
+
+ args['drive'] = drive
+
## == If we got networking,
# Try fetching instructions for this box and execute them.
instructions = {}
@@ -471,6 +526,9 @@ if __name__ == '__main__':
o = b''.join(sys_command('/usr/bin/parted -s {drive} mkpart primary {start} {size}'.format(**args)).exec())
args['paritions'] = grab_partitions(args['drive'])
+ print(f'Partitions: (Boot: {list(args['paritions'].keys())[0]})')
+ print(json.dumps(args['paritions'], indent=4))
+
if len(args['paritions']) <= 0:
print('[E] No paritions were created on {drive}'.format(**args), o)
exit(1)
@@ -602,6 +660,9 @@ if __name__ == '__main__':
for title in conf:
print('[N] Network Deploy: {}'.format(title))
+ if type(conf[title]) == str:
+ print('[N] Loading {} configuration'.format(conf[title]))
+ conf[title] = get_application_instructions(conf[title])
for command in conf[title]:
raw_command = command
opts = conf[title][command] if type(conf[title][command]) in (dict, oDict) else {}
@@ -615,7 +676,7 @@ if __name__ == '__main__':
del(opts['pass-args'])
elif 'format' in opts:
del(opts['format'])
- else:
+ elif ('debug' in opts and opts['debug']) or ('debug' in conf and conf['debug']):
print('[-] Options: {}'.format(opts))
if 'pass-args' in opts and opts['pass-args']:
command = command.format(**args)
diff --git a/deployments/applications/awesome.json b/deployments/applications/awesome.json
new file mode 100644
index 00000000..32b05beb
--- /dev/null
+++ b/deployments/applications/awesome.json
@@ -0,0 +1,14 @@
+{
+ "sed -i 's/^twm &/#&/' /etc/X11/xinit/xinitrc" : null,
+ "sed -i 's/^xclock/#&/' /etc/X11/xinit/xinitrc" : null,
+ "sed -i 's/^xterm/#&/' /etc/X11/xinit/xinitrc" : null,
+ "sed -i 's/^exec xterm/#&/' /etc/X11/xinit/xinitrc" : null,
+ "sh -c \"echo 'xscreensaver -no-splash &' >> /etc/X11/xinit/xinitrc\"" : null,
+ "sh -c \"echo 'exec {_window_manager}' >> /etc/X11/xinit/xinitrc\"" : {"pass-args" : true},
+ "sh -c \"sed -i 's/{ \\\"open terminal\\\", terminal/{ \\\"Chromium\\\", \\\"chromium\\\" },\n &1/' /etc/xdg/awesome/rc.lua\"" : null,
+ "sh -c \"sed -i 's/{ \\\"open terminal\\\", terminal/{ \\\"File handler\\\", \\\"nemo\\\" },\n &1/' /etc/xdg/awesome/rc.lua\"" : null,
+ "sh -c \"sed -i 's/^globalkeys = gears.table.join(/&\n awful.key({ modkey, }, \\\"l\\\", function() awful.spawn(\\\"xscreensaver-command -lock &\\\") end),\n/' /etc/xdg/awesome/rc.lua\"" : null,
+ "sh -c \"awk -i inplace -v RS='' '{gsub(/awful.key\\({ modkey,.*?}, \\\"Tab\\\",.*?\\\"client\\\"}\\),/, \\\"awful.key({ modkey, }, \\\"Tab\\\",\n function ()\n awful.client.focus.byidx(-1)\n if client.focus then\n client.focus:raise()\n end\n end),\n awful.key({ modkey, \\\"Shift\\\" }, \\\"Tab\\\",\n function ()\n awful.client.focus.byidx(1)\n if client.focus then\n client.focus.raise()\n end\n end),\\\"); print}' /etc/xdg/awesome/rc.lua\"" : null,
+ "gsettings set org.nemo.desktop show-desktop-icons false" : null,
+ "xdg-mime default nemo.desktop inode/directory application/x-gnome-saved-search" : null
+} \ No newline at end of file
diff --git a/deployments/applications/postgresql.json b/deployments/applications/postgresql.json
new file mode 100644
index 00000000..c420551b
--- /dev/null
+++ b/deployments/applications/postgresql.json
@@ -0,0 +1,5 @@
+{
+ "pacman -Syy --noconfirm postgresql" : null,
+ "systemctl enable postgresql" : null,
+ "su - postgres -c \"initdb -D /var/lib/postgres/data\"" : null
+} \ No newline at end of file
diff --git a/deployments/workstation.json b/deployments/workstation.json
index 07f8f112..23c725b3 100644
--- a/deployments/workstation.json
+++ b/deployments/workstation.json
@@ -16,21 +16,10 @@
"Setup virtulization" : {
"sh -c \"Description=\\\"Bridge for virtual machines\\\"\nInterface=br0\nConnection=bridge\nBindsToInterfaces=(eno1)\nIP=no\nExecUpPost=\\\"ip link set dev br0 address $(cat /sys/class/net/eno1/address); IP=dhcp; ip_set\\\"\nExecDownPre=\\\"IP=dhcp\\\"\n\n## Ignore (R)STP and immediately activate the bridge\nSkipForwardingDelay=yes\"" : null
},
- "Setup desktop environment" : {
- "sed -i 's/^twm &/#&/' /etc/X11/xinit/xinitrc" : null,
- "sed -i 's/^xclock/#&/' /etc/X11/xinit/xinitrc" : null,
- "sed -i 's/^xterm/#&/' /etc/X11/xinit/xinitrc" : null,
- "sed -i 's/^exec xterm/#&/' /etc/X11/xinit/xinitrc" : null,
+ "Setup loclization" : {
"sh -c \"echo 'setxkbmap se' >> /etc/X11/xinit/xinitrc\"" : null,
- "sh -c \"echo 'xscreensaver -no-splash &' >> /etc/X11/xinit/xinitrc\"" : null,
- "sh -c \"echo 'exec {_window_manager}' >> /etc/X11/xinit/xinitrc\"" : {"pass-args" : true},
- "sh -c \"echo 'KEYMAP={_keyboard_layout}\nFONT=lat9w-16' >> /etc/vconsole.conf\"" : {"pass-args" : true},
- "sh -c \"sed -i 's/{ \\\"open terminal\\\", terminal/{ \\\"Chromium\\\", \\\"chromium\\\" },\n &1/' /etc/xdg/awesome/rc.lua\"" : null,
- "sh -c \"sed -i 's/{ \\\"open terminal\\\", terminal/{ \\\"File handler\\\", \\\"nemo\\\" },\n &1/' /etc/xdg/awesome/rc.lua\"" : null,
- "sh -c \"sed -i 's/^globalkeys = gears.table.join(/&\n awful.key({ modkey, }, \\\"l\\\", function() awful.spawn(\\\"xscreensaver-command -lock &\\\") end),\n/' /etc/xdg/awesome/rc.lua\"" : null,
- "sh -c \"awk -i inplace -v RS='' '{gsub(/awful.key\\({ modkey,.*?}, \\\"Tab\\\",.*?\\\"client\\\"}\\),/, \\\"awful.key({ modkey, }, \\\"Tab\\\",\n function ()\n awful.client.focus.byidx(-1)\n if client.focus then\n client.focus:raise()\n end\n end),\n awful.key({ modkey, \\\"Shift\\\" }, \\\"Tab\\\",\n function ()\n awful.client.focus.byidx(1)\n if client.focus then\n client.focus.raise()\n end\n end),\\\"); print}' /etc/xdg/awesome/rc.lua\"" : null,
- "gsettings set org.nemo.desktop show-desktop-icons false" : null,
- "xdg-mime default nemo.desktop inode/directory application/x-gnome-saved-search" : null
- }
+ "sh -c \"echo 'KEYMAP={_keyboard_layout}\nFONT=lat9w-16' >> /etc/vconsole.conf\"" : {"pass-args" : true}
+ },
+ "Configure desktop environment" : "awesome"
}
}