From 968fad8f948a9f644098f51e8a04fb5ad985c9ec Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Apr 2019 16:06:35 +0200 Subject: Testing application specific configratuin (might auto-trigger in the future --- archinstall.py | 21 +++++++++++++++++++++ deployments/applications/postgresql.json | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 deployments/applications/postgresql.json diff --git a/archinstall.py b/archinstall.py index 0d909d0f..6b4a5ce5 100644 --- a/archinstall.py +++ b/archinstall.py @@ -312,6 +312,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: @@ -602,6 +620,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 {} 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 -- cgit v1.2.3-70-g09d2 From 33610debefe9cc8382c3053ab57a2ed2101796d6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Apr 2019 17:27:19 +0200 Subject: Fixing login scenario --- archinstall.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 6b4a5ce5..74f4e223 100644 --- a/archinstall.py +++ b/archinstall.py @@ -683,8 +683,8 @@ if __name__ == '__main__': ## since we set the password as the last step. And then the command itself which will be executed by looking for: ## [root@ ~]# o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', opts={'triggers' : { - bytes(f'{args["hostname"]} login', 'UTF-8') : b'root\n', - b'Password' : bytes(args['password']+'\n', 'UTF-8'), + bytes(f'login:', 'UTF-8') : b'root\n', # {args["hostname"]} login: + #b'Password' : bytes(args['password']+'\n', 'UTF-8'), bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), }, **opts}).exec()) -- cgit v1.2.3-70-g09d2 From e3b60326e03a642de27a79b86a8aecf454c393de Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Apr 2019 17:37:00 +0200 Subject: Debugging --- archinstall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall.py b/archinstall.py index 74f4e223..4e19c8ce 100644 --- a/archinstall.py +++ b/archinstall.py @@ -186,6 +186,7 @@ class sys_command(): yield output + print('Debug...') # Since we're in a subsystem, we gotta bail out! # Bail bail bail! os.write(child_fd, b'shutdown now\n') -- cgit v1.2.3-70-g09d2 From 35cfef9857ba198b3efd829f532b816cee886975 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Apr 2019 18:55:35 +0200 Subject: Something --- archinstall.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/archinstall.py b/archinstall.py index 4e19c8ce..eaff3409 100644 --- a/archinstall.py +++ b/archinstall.py @@ -191,7 +191,11 @@ class sys_command(): # Bail bail bail! os.write(child_fd, b'shutdown now\n') + print('Shutdown initatied') + exit_code = os.waitpid(self.pid, 0)[1] + + print('Exit code:', exit_code) if exit_code != 0: print('[E] Command "{}" exited with status code:'.format(self.cmd[0]), exit_code) print(trace_log) -- cgit v1.2.3-70-g09d2 From 65aed10fa2c56dcce38bfbd6059e64a67f7118e6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Apr 2019 21:30:35 +0200 Subject: Added more templates and removed debugging --- archinstall.py | 6 +----- deployments/applications/awesome.json | 14 ++++++++++++++ deployments/workstation.json | 19 ++++--------------- 3 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 deployments/applications/awesome.json diff --git a/archinstall.py b/archinstall.py index eaff3409..afb22d65 100644 --- a/archinstall.py +++ b/archinstall.py @@ -186,16 +186,12 @@ class sys_command(): yield output - print('Debug...') # Since we're in a subsystem, we gotta bail out! # Bail bail bail! os.write(child_fd, b'shutdown now\n') - print('Shutdown initatied') - exit_code = os.waitpid(self.pid, 0)[1] - print('Exit code:', exit_code) if exit_code != 0: print('[E] Command "{}" exited with status code:'.format(self.cmd[0]), exit_code) print(trace_log) @@ -641,7 +637,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/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" } } -- cgit v1.2.3-70-g09d2 From 620db3623ccf5328766656c89d023d89c4c056f6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Apr 2019 23:13:19 +0200 Subject: Added support to select --drive= and it now maps to a drive. To ensure /dev/sda haven't changed location and the wrong drive gets wiped --- archinstall.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/archinstall.py b/archinstall.py index afb22d65..734bb6d0 100644 --- a/archinstall.py +++ b/archinstall.py @@ -218,6 +218,18 @@ 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('blkid -s PTUUID -o value /dev/sda') + if len(o): + return drive + + return None + def update_git(): default_gw = get_default_gateway_linux() if(default_gw): @@ -387,6 +399,10 @@ 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. + args['drive'] = get_drive_from_uuid(args['drive']) + ## == If we got networking, # Try fetching instructions for this box and execute them. instructions = {} -- cgit v1.2.3-70-g09d2 From d0de593976a913c9b6f1742f5f960c65ca740d7c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Apr 2019 23:20:39 +0200 Subject: Added support to select --drive= and it now maps to a drive. To ensure /dev/sda haven't changed location and the wrong drive gets wiped --- archinstall.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index 734bb6d0..9fb0f22c 100644 --- a/archinstall.py +++ b/archinstall.py @@ -224,12 +224,23 @@ def get_drive_from_uuid(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('blkid -s PTUUID -o value /dev/sda') - if len(o): + 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): @@ -401,7 +412,16 @@ if __name__ == '__main__': if args['drive'][0] != '/': ## Remap the selected UUID to the device to be formatted. - args['drive'] = get_drive_from_uuid(args['drive']) + 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. -- cgit v1.2.3-70-g09d2 From 9b1310ead83bcbcc9327436c62b0edc5e5d91b67 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 9 Jun 2019 20:25:20 +0200 Subject: Added sorted drives and partition debug information --- archinstall.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index 9fb0f22c..72ba3dc4 100644 --- a/archinstall.py +++ b/archinstall.py @@ -397,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' @@ -526,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) @@ -720,8 +723,8 @@ if __name__ == '__main__': ## since we set the password as the last step. And then the command itself which will be executed by looking for: ## [root@ ~]# o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', opts={'triggers' : { - bytes(f'login:', 'UTF-8') : b'root\n', # {args["hostname"]} login: - #b'Password' : bytes(args['password']+'\n', 'UTF-8'), + bytes(f'{args["hostname"]} login', 'UTF-8') : b'root\n', + b'Password' : bytes(args['password']+'\n', 'UTF-8'), bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), }, **opts}).exec()) -- cgit v1.2.3-70-g09d2