diff --git a/aif.xml b/aif.xml index c2eb3c4..b42b1c9 100644 --- a/aif.xml +++ b/aif.xml @@ -8,14 +8,14 @@ - + - + = 129 or partnums[-1:] >= 129: + if len(partnums) >= 129 or partnums[-1] >= 129: exit('GPT only supports 128 partitions (and partition allocations).') cmds.append(['sgdisk', '-og', d]) elif self.disk[d]['fmt'] == 'bios': @@ -745,34 +743,33 @@ class archInstall(object): f.write(('# Generated by AIF-NG.\ntitle\t\tArch Linux\nlinux /vmlinuz-linux\n') + ('initrd /initramfs-linux.img\noptions root=PARTUUID={0} rw\n').format(partuuid)) bootcmds.append(['bootctl', '--path={0}', 'install']) + # TODO: Add a bit here to alter EFI boot order so we boot right to the newly-installed env. + # should probably be optional. return(bootcmds) - def scriptcmds(self): - if xmlobj.find('scripts') is not None: - self.scripts['pre'] = [] - self.scripts['post'] = [] - tempscriptdict = {'pre': {}, 'post': {}} - for x in xmlobj.find('scripts'): - if all(keyname in list(x.attrib.keys()) for keyname in ('user', 'password')): - auth = {} - auth['user'] = x.attrib['user'] - auth['password'] = x.attrib['password'] - if 'realm' in x.attrib.keys(): - auth['realm'] = x.attrib['realm'] - if 'authtype' in x.attrib.keys(): - auth['type'] = x.attrib['authtype'] - scriptcontents = self.webFetch(x.attrib['uri'], auth).decode('utf-8') + def scriptcmds(self, scripttype): + # Pre-run/"booststrap" scripts + t = scripttype + if t in self.scripts.keys(): + for i, s in enumerate(self.scripts[t]): + if t == 'post': + dirpath = '{0}/scripts/{1}'.format(self.system['chrootpath'], t) else: - scriptcontents = self.webFetch(x.attrib['uri']).decode('utf-8') - if x.attrib['bootstrap'].lower() in ('true', '1'): - tempscriptdict['pre'][x.attrib['order']] = scriptcontents - else: - tempscriptdict['post'][x.attrib['order']] = scriptcontents - for d in ('pre', 'post'): - keylst = list(tempscriptdict[d].keys()) - keylst.sort() - for s in keylst: - self.scripts[d].append(tempscriptdict[d][s]) + dirpath = '/root/scripts/{0}'.format(t) + os.makedirs(dirpath, exist_ok = True) + filepath = '{0}/{1}'.format(dirpath, i) + with open(filepath, 'w') as f: + f.write(s) + os.chmod(filepath, 0o700) + os.chown(filepath, 0, 0) # shouldn't be necessary, but just in case the umask's messed up or something. + if t == 'pre': + # We want to run these right away. + with open(os.devnull, 'w') as DEVNULL: + for i, s in enumerate(self.scripts['pre']): + subprocess.call('/root/scripts/post/{0}'.format(i), + stdout = DEVNULL, + stderr = subproces.STDOUT) + return() def packagecmds(self): pass @@ -789,34 +786,19 @@ class archInstall(object): #with open('{0}/root/aif.sh'.format(self.system['chrootpath']), 'w') as f: # f.write(chrootscript) #os.chmod('{0}/root/aif.sh'.format(self.system['chrootpath']), 0o700) - for t in self.scripts.keys(): - os.makedirs('{0}/root/scripts/{1}'.format(self.system['chrootpath'], t), exist_ok = True) - cnt = 0 - for s in self.scripts[t]: - with open('{0}/root/scripts/{1}/{2}'.format(self.system['chrootpath'], - t, - cnt), 'w') as f: - f.write(self.scripts[t][cnt]) - os.chmod('{0}/root/scripts/{1}/{2}'.format(self.system['chrootpath'], - t, - cnt), 0o700) - cnt += 1 real_root = os.open("/", os.O_RDONLY) os.chroot(self.system['chrootpath']) # Does this even work with an os.chroot()? Let's hope so! with open(os.devnull, 'w') as DEVNULL: - if scriptcmds['pre']: - for s in len(scriptcmds['pre']): - script = '/root/scripts/pre/{0}'.format(s - 1) - subprocess.call(script, stdout = DEVNULL, stderr = subprocess.STDOUT) for c in chrootcmds: subprocess.call(c, stdout = DEVNULL, stderr = subprocess.STDOUT) for b in bootcmds: subprocess.call(b, stdout = DEVNULL, stderr = subprocess.STDOUT) if scriptcmds['post']: - for s in len(scriptcmds['post']): - script = '/root/scripts/post/{0}'.format(s - 1) - subprocess.call(script, stdout = DEVNULL, stderr = subprocess.STDOUT) + for i, s in enumerate(scriptcmds['post']): + subprocess.call('/root/scripts/post/{0}'.format(i), + stdout = DEVNULL, + stderr = subproces.STDOUT) #os.system('{0}/root/aif-pre.sh'.format(self.system['chrootpath'])) #os.system('{0}/root/aif-post.sh'.format(self.system['chrootpath'])) os.fchdir(real_root) @@ -831,9 +813,10 @@ class archInstall(object): def runInstall(confdict): install = archInstall(confdict) - #install.format() - #install.mounts() - #install.bootloader() + install.scriptcmds('pre') + install.format() + install.mounts() + install.bootloader() #install.chroot() #install.unmount() @@ -841,9 +824,10 @@ def main(): if os.getuid() != 0: exit('This must be run as root.') conf = aif() - import pprint instconf = conf.buildDict() - pprint.pprint(instconf) + if 'DEBUG' in os.environ.keys(): + import pprint + pprint.pprint(instconf) runInstall(instconf) if __name__ == "__main__":