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="2" start="10%" size="80%" fstype="8300" />
|
||||||
<part num="3" start="80%" size="10%" fstype="8200" />
|
<part num="3" start="80%" size="10%" fstype="8200" />
|
||||||
</disk>
|
</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/sda1" target="/mnt/boot" order="2" />
|
||||||
<mount source="/dev/sda3" target="swap" order="3" />
|
<mount source="/dev/sda3" target="swap" order="3" />
|
||||||
</storage>
|
</storage>
|
||||||
<network hostname="aiftest.square-r00t.net">
|
<network hostname="aiftest.square-r00t.net">
|
||||||
<iface device="auto" address="auto" netproto="ipv4" />
|
<iface device="auto" address="auto" netproto="ipv4" />
|
||||||
</network>
|
</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. :) -->
|
<!-- note: all password hashes below are "test"; don't waste your time trying to crack. :) -->
|
||||||
<users rootpass="$6$3YPpiS.l3SQC6ELe$NQ4qMvcDpv5j1cCM6AGNc5Hyg.rsvtzCt2VWlSbuZXCGg2GB21CMUN8TMGS35tdUezZ/n9y3UFGlmLRVWXvZR.">
|
<users rootpass="$6$3YPpiS.l3SQC6ELe$NQ4qMvcDpv5j1cCM6AGNc5Hyg.rsvtzCt2VWlSbuZXCGg2GB21CMUN8TMGS35tdUezZ/n9y3UFGlmLRVWXvZR.">
|
||||||
<user name="aifusr"
|
<user name="aifusr"
|
||||||
|
86
aifclient.py
86
aifclient.py
@ -339,7 +339,6 @@ class aif(object):
|
|||||||
aifdict['scripts']['post'] = []
|
aifdict['scripts']['post'] = []
|
||||||
tempscriptdict = {'pre': {}, 'post': {}}
|
tempscriptdict = {'pre': {}, 'post': {}}
|
||||||
for x in xmlobj.find('scripts'):
|
for x in xmlobj.find('scripts'):
|
||||||
print(x.attrib['uri'])
|
|
||||||
if all(keyname in list(x.attrib.keys()) for keyname in ('user', 'password')):
|
if all(keyname in list(x.attrib.keys()) for keyname in ('user', 'password')):
|
||||||
auth = {}
|
auth = {}
|
||||||
auth['user'] = x.attrib['user']
|
auth['user'] = x.attrib['user']
|
||||||
@ -351,7 +350,6 @@ class aif(object):
|
|||||||
scriptcontents = self.webFetch(x.attrib['uri'], auth).decode('utf-8')
|
scriptcontents = self.webFetch(x.attrib['uri'], auth).decode('utf-8')
|
||||||
else:
|
else:
|
||||||
scriptcontents = self.webFetch(x.attrib['uri']).decode('utf-8')
|
scriptcontents = self.webFetch(x.attrib['uri']).decode('utf-8')
|
||||||
print(scriptcontents)
|
|
||||||
if x.attrib['bootstrap'].lower() in ('true', '1'):
|
if x.attrib['bootstrap'].lower() in ('true', '1'):
|
||||||
tempscriptdict['pre'][x.attrib['order']] = scriptcontents
|
tempscriptdict['pre'][x.attrib['order']] = scriptcontents
|
||||||
else:
|
else:
|
||||||
@ -391,7 +389,7 @@ class archInstall(object):
|
|||||||
cmds.append(['sgdisk', '-Z', d])
|
cmds.append(['sgdisk', '-Z', d])
|
||||||
if self.disk[d]['fmt'] == 'gpt':
|
if self.disk[d]['fmt'] == 'gpt':
|
||||||
diskfmt = '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).')
|
exit('GPT only supports 128 partitions (and partition allocations).')
|
||||||
cmds.append(['sgdisk', '-og', d])
|
cmds.append(['sgdisk', '-og', d])
|
||||||
elif self.disk[d]['fmt'] == 'bios':
|
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') +
|
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))
|
('initrd /initramfs-linux.img\noptions root=PARTUUID={0} rw\n').format(partuuid))
|
||||||
bootcmds.append(['bootctl', '--path={0}', 'install'])
|
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)
|
return(bootcmds)
|
||||||
|
|
||||||
def scriptcmds(self):
|
def scriptcmds(self, scripttype):
|
||||||
if xmlobj.find('scripts') is not None:
|
# Pre-run/"booststrap" scripts
|
||||||
self.scripts['pre'] = []
|
t = scripttype
|
||||||
self.scripts['post'] = []
|
if t in self.scripts.keys():
|
||||||
tempscriptdict = {'pre': {}, 'post': {}}
|
for i, s in enumerate(self.scripts[t]):
|
||||||
for x in xmlobj.find('scripts'):
|
if t == 'post':
|
||||||
if all(keyname in list(x.attrib.keys()) for keyname in ('user', 'password')):
|
dirpath = '{0}/scripts/{1}'.format(self.system['chrootpath'], t)
|
||||||
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')
|
|
||||||
else:
|
else:
|
||||||
scriptcontents = self.webFetch(x.attrib['uri']).decode('utf-8')
|
dirpath = '/root/scripts/{0}'.format(t)
|
||||||
if x.attrib['bootstrap'].lower() in ('true', '1'):
|
os.makedirs(dirpath, exist_ok = True)
|
||||||
tempscriptdict['pre'][x.attrib['order']] = scriptcontents
|
filepath = '{0}/{1}'.format(dirpath, i)
|
||||||
else:
|
with open(filepath, 'w') as f:
|
||||||
tempscriptdict['post'][x.attrib['order']] = scriptcontents
|
f.write(s)
|
||||||
for d in ('pre', 'post'):
|
os.chmod(filepath, 0o700)
|
||||||
keylst = list(tempscriptdict[d].keys())
|
os.chown(filepath, 0, 0) # shouldn't be necessary, but just in case the umask's messed up or something.
|
||||||
keylst.sort()
|
if t == 'pre':
|
||||||
for s in keylst:
|
# We want to run these right away.
|
||||||
self.scripts[d].append(tempscriptdict[d][s])
|
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):
|
def packagecmds(self):
|
||||||
pass
|
pass
|
||||||
@ -789,34 +786,19 @@ class archInstall(object):
|
|||||||
#with open('{0}/root/aif.sh'.format(self.system['chrootpath']), 'w') as f:
|
#with open('{0}/root/aif.sh'.format(self.system['chrootpath']), 'w') as f:
|
||||||
# f.write(chrootscript)
|
# f.write(chrootscript)
|
||||||
#os.chmod('{0}/root/aif.sh'.format(self.system['chrootpath']), 0o700)
|
#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)
|
real_root = os.open("/", os.O_RDONLY)
|
||||||
os.chroot(self.system['chrootpath'])
|
os.chroot(self.system['chrootpath'])
|
||||||
# Does this even work with an os.chroot()? Let's hope so!
|
# Does this even work with an os.chroot()? Let's hope so!
|
||||||
with open(os.devnull, 'w') as DEVNULL:
|
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:
|
for c in chrootcmds:
|
||||||
subprocess.call(c, stdout = DEVNULL, stderr = subprocess.STDOUT)
|
subprocess.call(c, stdout = DEVNULL, stderr = subprocess.STDOUT)
|
||||||
for b in bootcmds:
|
for b in bootcmds:
|
||||||
subprocess.call(b, stdout = DEVNULL, stderr = subprocess.STDOUT)
|
subprocess.call(b, stdout = DEVNULL, stderr = subprocess.STDOUT)
|
||||||
if scriptcmds['post']:
|
if scriptcmds['post']:
|
||||||
for s in len(scriptcmds['post']):
|
for i, s in enumerate(scriptcmds['post']):
|
||||||
script = '/root/scripts/post/{0}'.format(s - 1)
|
subprocess.call('/root/scripts/post/{0}'.format(i),
|
||||||
subprocess.call(script, stdout = DEVNULL, stderr = subprocess.STDOUT)
|
stdout = DEVNULL,
|
||||||
|
stderr = subproces.STDOUT)
|
||||||
#os.system('{0}/root/aif-pre.sh'.format(self.system['chrootpath']))
|
#os.system('{0}/root/aif-pre.sh'.format(self.system['chrootpath']))
|
||||||
#os.system('{0}/root/aif-post.sh'.format(self.system['chrootpath']))
|
#os.system('{0}/root/aif-post.sh'.format(self.system['chrootpath']))
|
||||||
os.fchdir(real_root)
|
os.fchdir(real_root)
|
||||||
@ -831,9 +813,10 @@ class archInstall(object):
|
|||||||
|
|
||||||
def runInstall(confdict):
|
def runInstall(confdict):
|
||||||
install = archInstall(confdict)
|
install = archInstall(confdict)
|
||||||
#install.format()
|
install.scriptcmds('pre')
|
||||||
#install.mounts()
|
install.format()
|
||||||
#install.bootloader()
|
install.mounts()
|
||||||
|
install.bootloader()
|
||||||
#install.chroot()
|
#install.chroot()
|
||||||
#install.unmount()
|
#install.unmount()
|
||||||
|
|
||||||
@ -841,8 +824,9 @@ def main():
|
|||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
exit('This must be run as root.')
|
exit('This must be run as root.')
|
||||||
conf = aif()
|
conf = aif()
|
||||||
import pprint
|
|
||||||
instconf = conf.buildDict()
|
instconf = conf.buildDict()
|
||||||
|
if 'DEBUG' in os.environ.keys():
|
||||||
|
import pprint
|
||||||
pprint.pprint(instconf)
|
pprint.pprint(instconf)
|
||||||
runInstall(instconf)
|
runInstall(instconf)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user