arch-maride-flavour/run.py
2018-03-05 14:21:06 +01:00

133 lines
3.8 KiB
Python
Executable File

#!/usr/bin/env python
import os
import subprocess
import sys
def quit():
print("OK, then do necessary steps and see you soon.")
sys.exit(1)
def motd(termsize, settings):
print("HOI, this is the 'Arch w/ maride flavour' install script (chainloader)")
print("Hope you used TLS...")
_separator(termsize)
print("Things you should've set up already:")
print(" * Your keyboard layout (consider passwords!)")
print(" * Any RAID setup that you are planning to set up")
print(" * An internet connection (DHCP or static, idc...)")
answer = _ask("Did you set that up?", [ "yes", "no" ])
if answer == "no":
quit()
_separator(termsize)
def efibios(termsize, settings):
print("Please choose the installation/startup method.")
print("Note that BIOS is required for VirtalBox hosts due a long-time unfixed bug.")
print("It's possible that you need to change Mainboard settings for EFI. (But it's recommended!)")
settings["bootmethod"] = _ask("Do you want to install on EFI or BIOS?", [ "EFI", "BIOS" ])
_separator(termsize)
def blockdevice(termsize, settings):
print("Please enter the full path to the block device the installation should take place on: (e.g. /dev/sda)")
print("Make sure to choose a drive, not a partition.")
print("Here's a list of devices that may be the right:")
settings["blockdevice"] = _ask("Install where?", os.listdir("/sys/block/"), enforce=False)
_separator(termsize)
def cryptroot(termsize, settings):
print("Do you want to encrypt your root partition?")
print("Please note that there is no way to recover your data if you forget your password.")
settings["cryptroot"] = _ask("Encrypt root?", [ "yes", "no" ])
_separator(termsize)
def rundir(termsize, settings, directory, validation_suffix, subfile="", ask=False):
for filename in sorted(os.listdir(directory)):
if filename[-len(validation_suffix):] == validation_suffix:
# Run loop
run = True
while run:
if ask and _ask("Do you want to run %s?" % (filename), [ "yes", "no" ]) == "no":
run = False
continue
_separator(termsize)
print("Running '%s'" % (filename))
if subfile:
executable = os.path.join(directory, filename, subfile)
else:
executable = os.path.join(directory, filename)
with subprocess.Popen([executable], env=settings) as process:
# Wait for process termination
process.wait()
if process.returncode > 0:
# Woops, check failed somehow
print("Executable %s returned non-null error code %i." % (executable, process.returncode))
answer = _ask("Do you want to re-run the executable, skip the check or abort the installation?", [ "run", "skip", "abort"])
if answer == "run":
# doesn't matter, run is already 'True'
continue
elif answer == "skip":
run = False
elif answer == "abort":
quit()
else:
run = False
else:
print("Uh. Found this executable: '%s' (Not executing)" % (filename))
_separator(termsize)
def finish(termsize, settings):
_separator(termsize)
if _ask("Finished! \\o/ reboot now?", [ "yes", "no" ]) == "yes":
os.system("reboot")
def _separator(termsize):
print("~" * termsize["cols"])
def _ask(question, choices, enforce=True):
while True:
print("=> %s (%s) " % (question, ", ".join(choices)))
answer = sys.stdin.readline()[:-1]
if answer in choices or not enforce:
return answer
def main():
rows, columns = os.popen('stty size', 'r').read().split()
termsize = {
"rows": int(rows),
"cols": int(columns)
}
settings = {}
motd(termsize, settings)
efibios(termsize, settings)
blockdevice(termsize, settings)
cryptroot(termsize, settings)
rundir(termsize, settings, "checks", ".check")
rundir(termsize, settings, "steps", ".step")
rundir(termsize, settings, "flavours", ".flavour", "install.sh", ask=True)
finish(termsize, settings)
if __name__ == '__main__':
main()