Compare commits

..

15 Commits

Author SHA1 Message Date
maride
858ca5d3ab Add return codes everywhere 2018-03-05 14:22:08 +01:00
maride
d40c5deb44 Add separators 2018-03-05 14:21:06 +01:00
maride
3c8664b1f5 Move from integer to string check 2018-03-04 15:18:32 +01:00
maride
54530ac202 Actually allow to skip flavours 2018-03-04 15:03:03 +01:00
maride
d872a99180 Move crypt question to main script 2018-03-04 14:00:22 +01:00
maride
408f2aa873 Fix: variable name change 2018-03-03 20:08:49 +01:00
maride
28dab7b58b Add 'settings' to 'motd()' function signature 2018-02-02 23:40:32 +01:00
maride
226ad45325 Compress three near-to equal functions into one 2018-02-02 23:39:37 +01:00
maride
5a3b4914a0 Fix listdir sorting 2018-02-02 17:44:32 +01:00
maride
8d27e18464 Sort listdir output which is arbitrary (un)sorted before 2018-02-02 17:02:40 +01:00
maride
9cd968b4bd Don't enforce choices for blockdevice question 2018-02-02 16:40:22 +01:00
maride
6f3bdc8008 Also execute steps and not only checks and flavours 2018-02-02 16:30:09 +01:00
maride
b0f3d0de65 Rename 'targetdevice' to 'blockdevice' to be compliant with steps 2018-02-02 16:29:48 +01:00
maride
b0c9ab111c Add settings as environment variables 2018-02-02 16:28:24 +01:00
maride
b72d05f329 Replace bash install script with python install script 2018-02-02 14:42:39 +01:00
7 changed files with 143 additions and 98 deletions

View File

@ -1,90 +0,0 @@
#!/bin/sh
echo "HOI, this is the 'Arch w/ maride flavour' install script (chainloader)"
echo "Hope you used TLS..."
echo -e "=-=-=-=-=-=-=-=-=-=-=\n"
echo "=> Things you should've set up already:"
echo " * Your keyboard layout (consider passwords!)"
echo " * Any RAID setup that you are planning to set up"
echo " * An internet connection (DHCP or static, idc...)"
echo -n "=> Did you set that up? (y/N) "
read answer
if [ "$answer" != "y" ] && [ "$answer" != "Y" ]; then
echo "OK, then do necessary steps and see you soon."
exit 1
fi
echo -n "=> Do you want to install on EFI or BIOS? BIOS is required for VirtalBox hosts (E/b) "
read answer
if [ "$answer" != "e" ] && [ "$answer" != "E" ]; then
export bootloader="BIOS";
else
export bootloader="EFI";
fi
echo "=> Please enter the full path to the block device the installation should take place on: (e.g. /dev/sda)"
echo " Make sure to choose a drive, not a partition."
echo " Hint: here's a list of devices that may be the right:"
ls /dev/sd* /dev/mmc* 2>/dev/null
echo -n "Install to: "
read blockdevice
export blockdevice
for check in checks/*.check
do
echo "=> Running check '$check'..."
source $check
if [ "$amf_return" -ne 0 ]; then
echo "=> Check failed. Fix it, maybe."
exit
fi
done
for step in steps/*.step
do
echo "=> Running step '$step'..."
source $step
if [ "$amf_return" -ne 0 ]; then
echo "=> Step failed. That is weird. Sorry. Check logs maybe."
exit
fi
done
for flavour in flavours/*.flavour
do
# in any case, run it once
rerun=1
while [ $rerun -eq 1 ]; do
echo -n "=> Do you want to run flavour '$flavour'? (y/N) "
read answer
rerun=0;
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
echo "=> Running flavour '$flavour'..."
pushd $flavour
source ./install.sh
if [ "$amf_return" -ne 0 ]; then
echo "=> Flavour failed. :( Rerun? (Y/n) "
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
rerun=1;
fi
fi
popd
fi
done
done
echo -n "=> Finished \o/ reboot now? (Y/n) "
read answer
if [ "$answer" == "n" ] || [ "$answer" == "N" ]; then
exit
fi
reboot

132
run.py Executable file
View File

@ -0,0 +1,132 @@
#!/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()

View File

@ -18,3 +18,4 @@ else
amf_return=1
fi
fi
return $amf_return

View File

@ -13,3 +13,4 @@ else
echo "~> Failed. :("
amf_return=1
fi
return $amf_return

View File

@ -6,11 +6,7 @@ mkfs.fat -F32 ${blockdevice}1
echo -n "~> Do you want to encrypt root? (Y/n) "
read answer
if [ "$answer" == "n" ] || [ "$answer" == "N" ]; then
echo "~> There are close to no reasons to not do this, but hey, you're an adult."
rootformat=${blockdevice}2
didCrypt=0
else
if [ "$cryptroot" == "yes" ]; then
echo "~> Formatting root (/) for crypto"
cryptsetup -v luksFormat ${blockdevice}2
echo "~> Here's the header crypto:"
@ -18,7 +14,9 @@ else
echo "~> Open the crypt container"
cryptsetup luksOpen ${blockdevice}2 cryptroot
rootformat=/dev/mapper/cryptroot
didCrypt=1
else
echo "~> There are close to no reasons to not do this, but hey, you're an adult."
rootformat=${blockdevice}2
fi
echo "~> Formatting $rootformat EXT4"
@ -30,3 +28,4 @@ mkdir -p /mnt/boot
mount ${blockdevice}1 /mnt/boot
amf_return=0
return $amf_return

View File

@ -4,3 +4,4 @@ echo "~> Installing 'base' group and 'grub', 'efibootmgr'"
pacstrap /mnt base grub efibootmgr
amf_return=0
return $amf_return

View File

@ -18,7 +18,7 @@ read hostname
echo $hostname > /mnt/etc/hostname
echo "~> Configuring 'grub' for $bootloader"
if [ "$bootloader" == "EFI" ]; then
if [ "$bootmethod" == "EFI" ]; then
arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=BOOT
# thanks to Virtualbox, this step is necessary
cp /mnt/boot/EFI/BOOT/{grubx64.efi,BOOTX64.EFI}
@ -26,7 +26,7 @@ else
arch-chroot /mnt grub-install --target=i386-pc /dev/*da
fi
if [ "$didCrypt" -eq 1 ]; then
if [ "$cryptroot" == "yes" ]; then
echo "GRUB_CMDLINE_LINUX='cryptdevice=UUID=`blkid -o value ${blockdevice}2 | head -n 1`:cryptroot'" > /mnt/etc/default/grub
fi
@ -43,3 +43,4 @@ echo "~> Patching pacman.conf for some pacman magic."
arch-chroot /mnt sed -i "s/\[options\]/\[options\]\nILoveCandy/g" /etc/pacman.conf
amf_return=0
return $amf_return