update the mnt path so we don't conflict with existing mounts
This commit is contained in:
parent
83fd8546ca
commit
c2685b6073
4
aif.xml
4
aif.xml
@ -8,14 +8,14 @@
|
||||
<part num="2" start="10%" size="80%" fstype="8300" />
|
||||
<part num="3" start="80%" size="10%" fstype="8200" />
|
||||
</disk>
|
||||
<mount source="/dev/sda2" target="/mnt" order="1" />
|
||||
<mount source="/dev/sda2" target="/mnt/aif" order="1" />
|
||||
<mount source="/dev/sda1" target="/mnt/boot" order="2" />
|
||||
<mount source="/dev/sda3" target="swap" order="3" />
|
||||
</storage>
|
||||
<network hostname="aiftest.square-r00t.net">
|
||||
<iface device="auto" address="auto" netproto="ipv4" />
|
||||
</network>
|
||||
<system timezone="EST5EDT" locale="en_US.UTF-8" chrootpath="/mnt">
|
||||
<system timezone="EST5EDT" locale="en_US.UTF-8" chrootpath="/mnt/aif">
|
||||
<!-- note: all password hashes below are "test"; don't waste your time trying to crack. :) -->
|
||||
<users rootpass="$6$3YPpiS.l3SQC6ELe$NQ4qMvcDpv5j1cCM6AGNc5Hyg.rsvtzCt2VWlSbuZXCGg2GB21CMUN8TMGS35tdUezZ/n9y3UFGlmLRVWXvZR.">
|
||||
<user name="aifusr"
|
||||
|
86
aifclient.py
86
aifclient.py
@ -339,7 +339,6 @@ class aif(object):
|
||||
aifdict['scripts']['post'] = []
|
||||
tempscriptdict = {'pre': {}, 'post': {}}
|
||||
for x in xmlobj.find('scripts'):
|
||||
print(x.attrib['uri'])
|
||||
if all(keyname in list(x.attrib.keys()) for keyname in ('user', 'password')):
|
||||
auth = {}
|
||||
auth['user'] = x.attrib['user']
|
||||
@ -351,7 +350,6 @@ class aif(object):
|
||||
scriptcontents = self.webFetch(x.attrib['uri'], auth).decode('utf-8')
|
||||
else:
|
||||
scriptcontents = self.webFetch(x.attrib['uri']).decode('utf-8')
|
||||
print(scriptcontents)
|
||||
if x.attrib['bootstrap'].lower() in ('true', '1'):
|
||||
tempscriptdict['pre'][x.attrib['order']] = scriptcontents
|
||||
else:
|
||||
@ -391,7 +389,7 @@ class archInstall(object):
|
||||
cmds.append(['sgdisk', '-Z', d])
|
||||
if self.disk[d]['fmt'] == 'gpt':
|
||||
diskfmt = 'gpt'
|
||||
if len(partnums) >= 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,8 +824,9 @@ def main():
|
||||
if os.getuid() != 0:
|
||||
exit('This must be run as root.')
|
||||
conf = aif()
|
||||
import pprint
|
||||
instconf = conf.buildDict()
|
||||
if 'DEBUG' in os.environ.keys():
|
||||
import pprint
|
||||
pprint.pprint(instconf)
|
||||
runInstall(instconf)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user