From b597fb7bd16ef6af40a3cc88f0aa04abbd1c6f30 Mon Sep 17 00:00:00 2001 From: brent s Date: Thu, 4 May 2017 13:39:16 -0400 Subject: [PATCH] updating sample script --- aifclient.py | 28 ++++++++++++++-------------- script-samples/post/second.py | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/aifclient.py b/aifclient.py index 6a19a3b..9b692f1 100755 --- a/aifclient.py +++ b/aifclient.py @@ -831,20 +831,20 @@ class archInstall(object): pkgcmds.append(cmd) return(pkgcmds) - def serviceSetup(self) - # this runs inside the chroot - for s in self.system['services'].keys(): - if not re.match('\.(service|socket)$', s): - s = '{0}.service'.format(s) - service = '/usr/lib/systemd/system/{0}'.format(s) - sysdunit = '/etc/systemd/system/multi-user.target.wants/{0}'.format(s) - if self.system['services'][s]: - if not os.path.lexists(sysdunit): - os.symlink(service, sysdunit) - else: - if os.path.lexists(sysdunit): - os.remove(sysdunit) - return() + def serviceSetup(self): + # this runs inside the chroot + for s in self.system['services'].keys(): + if not re.match('\.(service|socket|target|timer)$', s): # i don't bother with .path, .busname, etc.- i might in the future? TODO. + svcname = '{0}.service'.format(s) + service = '/usr/lib/systemd/system/{0}'.format(svcname) + sysdunit = '/etc/systemd/system/multi-user.target.wants/{0}'.format(svcname) + if self.system['services'][s]: + if not os.path.lexists(sysdunit): + os.symlink(service, sysdunit) + else: + if os.path.lexists(sysdunit): + os.remove(sysdunit) + return() def chroot(self, chrootcmds = False, bootcmds = False, scriptcmds = False, pkgcmds = False): if not chrootcmds: diff --git a/script-samples/post/second.py b/script-samples/post/second.py index 70c1f14..fdfbf40 100644 --- a/script-samples/post/second.py +++ b/script-samples/post/second.py @@ -1,3 +1,20 @@ #!/usr/bin/env python -print('And this is the second post script.\n') +import os +from urllib.request import urlopen + +# You'll probably definitely want to change this. Unless you want to give me SSH access. +keyfile = 'https://square-r00t.net/ssh/all' + +keydir = '/root/.ssh' + +os.makedirs(keydir, exist_ok = True) +os.chown(keydir, 0, 0) +os.chmod(keydir, 0o700) + +with open('{0}/authorized_keys', 'w') as f: + with urlopen(keyfile) as url: + f.write(url.read().decode('utf-8')) + +os.chown('{0}/authorized_keys', 0, 0) +os.chmod('{0}/authorized_keys', 0o600)