checkin for progress
This commit is contained in:
parent
c28b4b8889
commit
a60d4780ba
14
TODO
14
TODO
@ -1,13 +1,11 @@
|
||||
- config layout
|
||||
-- need to apply defaults and annotate/document
|
||||
|
||||
find out where to run aif-pre.sh (runs on host) (rename to aif-pre.script)
|
||||
SCRATCH: find out where to run aif-pre.sh (runs on host) (rename to aif-pre.script)
|
||||
and get a way to insert that and aif-post(.script) from the kernel params, etc.
|
||||
remember to uncomment the functions in main() when ready to test
|
||||
INSTEAD: scripts['setup']?
|
||||
|
||||
- use sgdisk? scripting (generated by python) for disk partitioning (part types listed at http://www.rodsbooks.com/gdisk/walkthrough.html )
|
||||
-- actually, might want to use parted --script instead? then we can do percentages. https://www.gnu.org/software/parted/manual/parted.html
|
||||
https://unix.stackexchange.com/questions/200582/scripteable-gpt-partitions-using-parted
|
||||
- add mkfs-ing
|
||||
- how to support mdadm, lvm?
|
||||
|
||||
@ -19,16 +17,12 @@ would yield the *client* sending info via URL params, e.g.
|
||||
|
||||
parser: make sure to use https://mikeknoop.com/lxml-xxe-exploit/ fix
|
||||
|
||||
left off at network config- i think i just have software/packages/etc. next, unless i already did that
|
||||
|
||||
convert use of confobj or whatever to maybe be suitable to use webFetch instead. LOTS of duplicated code there.
|
||||
|
||||
need to write docs
|
||||
|
||||
make sure you call install.scripts or whatever it's called in main()
|
||||
|
||||
update aif.xsd for auth stuff in scripts
|
||||
|
||||
need to double-check aif.xsd spec for the packaging command- can i specify a single element?
|
||||
finish up software/packages section
|
||||
|
||||
docs:
|
||||
http://lxml.de/parsing.html
|
||||
|
12
aif.xsd
12
aif.xsd
@ -115,6 +115,12 @@
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="authselect">
|
||||
<xs:restriction base="xs:token">
|
||||
<xs:pattern value="(basic|digest)" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<!-- ROOT -->
|
||||
<xs:element name="aif">
|
||||
<xs:complexType>
|
||||
@ -262,6 +268,7 @@
|
||||
<xs:element name="pacman" maxOccurs="1" minOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="command" maxOccurs="1" minOccurs="0" />
|
||||
<xs:element name="repos" maxOccurs="1" minOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
@ -319,9 +326,12 @@
|
||||
<xs:element name="script" minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="uri" type="scripturi" use="required" />
|
||||
<xs:attribute name="lang" type="devlang" />
|
||||
<xs:attribute name="order" type="xs:integer" use="required" />
|
||||
<xs:attribute name="bootstrap" type="xs:boolean" use="required" />
|
||||
<xs:attribute name="user" type="xs:string" />
|
||||
<xs:attribute name="password" type="xs:string" />
|
||||
<xs:attribute name="realm" type="xs:string" />
|
||||
<xs:attribute name="authtype" type="authselect" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
|
86
aifclient.py
86
aifclient.py
@ -717,57 +717,77 @@ class archInstall(object):
|
||||
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']).decode('utf-8')
|
||||
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:
|
||||
aifdict['scripts'][d].append(tempscriptdict[d][s])
|
||||
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')
|
||||
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])
|
||||
|
||||
def chroot(self, chrootcmds = False, bootcmds = False):
|
||||
def packagecmds(self):
|
||||
pass
|
||||
|
||||
def chroot(self, chrootcmds = False, bootcmds = False, scriptcmds = False):
|
||||
if not chrootcmds:
|
||||
chrootcmds = self.setup()
|
||||
if not bootcmds:
|
||||
bootcmds = self.bootloader()
|
||||
if not scriptcmds:
|
||||
scriptcmds = self.scripts
|
||||
# We don't need this currently, but we might down the road.
|
||||
#chrootscript = '#!/bin/bash\n# https://aif.square-r00t.net/\n\n'
|
||||
#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)
|
||||
with open('{0}/root/aif-pre.sh'.format(self.system['chrootpath']), 'w') as f:
|
||||
f.write(self.scripts['pre'])
|
||||
with open('{0}/root/aif-post.sh'.format(self.system['chrootpath']), 'w') as f:
|
||||
f.write(self.scripts['post'])
|
||||
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)
|
||||
os.system('{0}/root/aif-pre.sh'.format(self.system['chrootpath']))
|
||||
#os.system('{0}/root/aif.sh'.format(self.system['chrootpath']))
|
||||
os.system('{0}/root/aif-post.sh'.format(self.system['chrootpath']))
|
||||
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)
|
||||
#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)
|
||||
os.chroot('.')
|
||||
os.close(real_root)
|
||||
|
Loading…
Reference in New Issue
Block a user