#!/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): 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" ]) 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["targetdevice"] = _ask("Install where?", os.listdir("/sys/block/")) def checks(termsize, settings): for check in os.listdir("checks/"): if check[-6:] == ".check": # Run loop run = True while run: _separator(termsize) print("Running '%s'" % (check)) with subprocess.Popen(["checks/%s" % check]) as process: # Wait for process termination process.wait() if process.returncode > 0: # Woops, check failed somehow print("Check %s returned non-null error code %i." % (check, process.returncode)) answer = _ask("Do you want to re-run the check, 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 non-check script in the 'checks' folder: '%s' (Not executing)" % (check)) def flavours(termsize, settings): for flavour in os.listdir("flavours/"): if flavour[-8:] == ".flavour": # Run loop if _ask("Do you want to run flavour %s?" % (flavour), [ "yes", "no" ]) == "no": continue run = True while run: _separator(termsize) with subprocess.Popen(["flavours/%s/install.sh" % flavour]) as process: # Wait for process termination process.wait() if process.returncode > 0: # Woops, flavour failed somehow print("Flavour %s returned non-null error code %i." % (flavour, process.returncode)) answer = _ask("Do you want to re-run the flavour, skip the flavour 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 non-flavour script in the 'flavours' folder: '%s' (Not executing)" % (flavour)) 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): while True: print("=> %s (%s) " % (question, ", ".join(choices))) answer = sys.stdin.readline()[:-1] if answer in choices: return answer def main(): rows, columns = os.popen('stty size', 'r').read().split() termsize = { "rows": int(rows), "cols": int(columns) } settings = {} motd(termsize) efibios(termsize, settings) blockdevice(termsize, settings) checks(termsize, settings) flavours(termsize, settings) finish(termsize, settings) if __name__ == '__main__': main()