logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>
commit: 306dac7ba6c20cf91fa0e497306a9d138e6860d5
parent 7ea6f75b539f52cf2416ab92a31a685d20b50f76
Author: fosslinux <fosslinux@aussies.space>
Date:   Sun,  3 Oct 2021 12:28:08 +1100

Add prompts when particular options are not given in config files

Diffstat:

M.gitignore2+-
Mlib/sysgeneral.py2+-
Mrootfs.py52+++++++++++++++++++++++++++++++++++++++++++++-------
Msysa.py2+-
Msysa/run.sh54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msysb/run.sh39+++++++++++++++++++++++++++++++--------
6 files changed, 133 insertions(+), 18 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -7,4 +7,4 @@ tmp/ kernel sources/ __pycache__ -sysglobal/bootstrap.cfg +sysa/bootstrap.cfg diff --git a/lib/sysgeneral.py b/lib/sysgeneral.py @@ -137,7 +137,7 @@ class SysGeneral: def deploy_sysglobal_files(self): """Deploy files common to all Sys*""" - sysglobal_files = ['bootstrap.cfg', 'helpers.sh'] + sysglobal_files = ['helpers.sh'] for file in sysglobal_files: shutil.copy2(os.path.join(self.git_dir, 'sysglobal', file), self.base_dir) diff --git a/rootfs.py b/rootfs.py @@ -26,7 +26,7 @@ def create_configuration_file(args): Creates bootstrap.cfg file which would contain options used to customize bootstrap. """ - config_path = os.path.join('sysglobal', 'bootstrap.cfg') + config_path = os.path.join('sysa', 'bootstrap.cfg') with open(config_path, "w", encoding="utf_8") as config: config.write("FORCE_TIMESTAMPS=" + str(args.force_timestamps) + "\n") config.write("CHROOT=" + str(args.chroot) + "\n") @@ -49,26 +49,59 @@ def main(): parser.add_argument("--force_timestamps", help="Force all files timestamps to be 0 unix time", action="store_true") + parser.add_argument("--no-create-config", + help="Do not automatically create config file", + action="store_true") # QEMU arguments - parser.add_argument("-q", "--qemu-cmd", help="QEMU command", + parser.add_argument("-q", "--qemu", help="Use QEMU", + action="store_true") + parser.add_argument("-qc", "--qemu-cmd", help="QEMU command to run", default="qemu-system-x86_64") - parser.add_argument("-r", "--qemu-ram", help="Memory (in megabytes) allocated to QEMU VM", + parser.add_argument("-qr", "--qemu-ram", help="Memory (in megabytes) allocated to QEMU VM", default=8000) - parser.add_argument("-k", "--kernel", help="Kernel to use (default is ./kernel)", + parser.add_argument("-qk", "--kernel", help="Kernel to use (default is ./kernel)", default="kernel") parser.add_argument("-m", "--minikernel", help="Use minikernel", action="store_true") + parser.add_argument("-b", "--bare-metal", help="Build images for bare metal", + action="store_true") args = parser.parse_args() - if args.chroot and args.minikernel: - raise ValueError("chroot and minikernel options cannot be used simultaneously.") + + def check_types(): + count = 0 + if args.qemu: + count += 1 + if args.chroot: + count += 1 + if args.minikernel: + count += 1 + if args.bare_metal: + count += 1 + return count + + if check_types() > 1: + raise ValueError("No more than one of qemu, chroot, minikernel, bare metal may be used.") + if check_types() == 0: + raise ValueError("One of qemu, chroot, minikernel or bare metal must be selected.") + + if args.bare_metal: + args.no_create_config = True if args.arch != "x86": raise ValueError("Only x86 is supported at the moment.") - create_configuration_file(args) + try: + os.remove(os.path.join('sysa', 'bootstrap.cfg')) + except FileNotFoundError: + pass + if not args.no_create_config: + create_configuration_file(args) + else: + with open(os.path.join('sysa', 'bootstrap.cfg'), 'a', encoding='UTF-8'): + pass system_c = SysC(arch=args.arch, preserve_tmp=args.preserve, tmpdir=args.tmpdir, chroot=args.chroot) @@ -114,6 +147,11 @@ print(shutil.which('chroot')) '--initrd', system_a.initramfs_path, '--log', '/tmp/bootstrap.log') + elif args.bare_metal: + print("Please:") + print(" 1. Take sysa/tmp/initramfs and your kernel, boot using this.") + print(" 2. Take sysc/tmp/disk.img and put this on a writable storage medium.") + else: run(args.qemu_cmd, '-enable-kvm', diff --git a/sysa.py b/sysa.py @@ -93,7 +93,7 @@ class SysA(SysGeneral): def deploy_extra_files(self): """Deploy misc files""" - extra_files = ['run.sh'] + extra_files = ['run.sh', 'bootstrap.cfg'] for extra_file in extra_files: shutil.copy2(os.path.join(self.sys_dir, extra_file), self.after_dir) diff --git a/sysa/run.sh b/sysa/run.sh @@ -24,6 +24,7 @@ create_sysb() { for d in bin include lib libexec sbin share; do cp -r "${PREFIX}/${d}" "/sysb/usr/${d}" done + cp "${SOURCES}/bootstrap.cfg" /sysb/usr/src/bootstrap.cfg populate_device_nodes /sysb } @@ -40,6 +41,59 @@ go_sysb() { kexec -e } +# Ask some questions +echo +echo "Now that bash has been built, there are potentially some questions for you!" +echo "To give your answer, type your answer, press Enter, and then Control-D." +echo + +ask_chroot() { + read -r CHROOT_STRING + if [ "${CHROOT_STRING}" = "yes" ] || [ "${CHROOT_STRING}" = "y" ]; then + CHROOT=True + elif [ "${CHROOT_STRING}" = "no" ] || [ "${CHROOT_STRING}" = "n" ]; then + CHROOT=False + else + echo "Invalid response. Please give a yes/no answer." + ask_chroot + fi +} + +if [ -z "${CHROOT}" ]; then + echo "Currently, it is unknown if live-bootstrap is running in a chroot" + echo "or not. Is it? (yes/no answer)" + ask_chroot + echo +fi + +ask_timestamps() { + read -r TIMESTAMPS_STRING + if [ "${TIMESTAMPS_STRING}" = "yes" ] || [ "${TIMESTAMPS_STRING}" = "y" ]; then + FORCE_TIMESTAMPS=True + elif [ "${TIMESTAMPS_STRING}" = "no" ] || [ "${TIMESTAMPS_STRING}" = "n" ]; then + FORCE_TIMESTAMPS=False + else + echo "Invalid response. Please give a yes/no answer." + ask_timestamps + fi +} + +if [ -z "${FORCE_TIMESTAMPS}" ]; then + echo "Would you like all timestamps to be set to unix time 0" + echo "(Jan 1 1970 00:00) at the end of the bootstrap? This makes a" + echo "fully reproducible disk image. (yes/no answer)" + ask_timestamps + echo +fi + +echo "Thank you! All done." + +# Write to bootstrap.cfg +rm "${SOURCES}/bootstrap.cfg" +for var in CHROOT FORCE_TIMESTAMPS DISK; do + echo "${var}=${!var}" >> "${SOURCES}/bootstrap.cfg" +done + build flex-2.5.11 # Patch meslibc to support > 255 command line arguments diff --git a/sysb/run.sh b/sysb/run.sh @@ -30,19 +30,40 @@ create_hdx() { done } -# If there is no disk specified error out -if [ -z "${DISK}" ]; then - echo "You must specify a disk where sysb will be located!" - exit 1 +# All the various structures that don't exist but needed to mount +mkdir -p /etc /dev +populate_device_nodes "" +create_hdx + +ask_disk() { + echo + echo "What disk would you like to use for live-bootstrap?" + echo "(live-bootstrap assumes you have pre-prepared the disk)." + echo "Please provide in format sdxx (as you would find under /dev)." + echo "You can type 'list' to get a list of disks to help you figure" + echo "out which is the right disk." + echo + read -r DISK + + if [ "${DISK}" = "list" ]; then + fdisk -l + ask_disk + elif [ -z "${DISK}" ] || ! [ -e "/dev/${DISK}" ]; then + echo "Invalid." + ask_disk + fi +} + +if [ -z "${DISK}" ] || ! [ -e "/dev/${DISK}" ]; then + echo "You did not provide a valid disk in the configuration file." + ask_disk fi +echo "DISK=${DISK}" >> /usr/src/bootstrap.cfg + # Otherwise, add stuff from sysa to sysb echo "Mounting sysc" mkdir /sysc -# All the various structures that don't exist but needed to mount -mkdir -p /etc /dev -populate_device_nodes "" -create_hdx mount -t ext4 "/dev/${DISK}" /sysc # Copy over appropriate data @@ -50,6 +71,8 @@ echo "Copying data into sysc" cp -r /dev /sysc/ # Don't include /usr/src find /usr -mindepth 1 -maxdepth 1 -type d -not -name src -exec cp -r {} /sysc/{} \; +# Except for bootstrap.cfg +cp /usr/src/bootstrap.cfg /sysc/usr/src/bootstrap.cfg sync # switch_root into sysc 1. for simplicity 2. to avoid kexecing again