mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-19 17:53:00 +01:00
Add prompts when particular options are not given in config files
This commit is contained in:
parent
7ea6f75b53
commit
306dac7ba6
6 changed files with 134 additions and 19 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -7,4 +7,4 @@ tmp/
|
||||||
kernel
|
kernel
|
||||||
sources/
|
sources/
|
||||||
__pycache__
|
__pycache__
|
||||||
sysglobal/bootstrap.cfg
|
sysa/bootstrap.cfg
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ class SysGeneral:
|
||||||
|
|
||||||
def deploy_sysglobal_files(self):
|
def deploy_sysglobal_files(self):
|
||||||
"""Deploy files common to all Sys*"""
|
"""Deploy files common to all Sys*"""
|
||||||
sysglobal_files = ['bootstrap.cfg', 'helpers.sh']
|
sysglobal_files = ['helpers.sh']
|
||||||
for file in sysglobal_files:
|
for file in sysglobal_files:
|
||||||
shutil.copy2(os.path.join(self.git_dir, 'sysglobal', file),
|
shutil.copy2(os.path.join(self.git_dir, 'sysglobal', file),
|
||||||
self.base_dir)
|
self.base_dir)
|
||||||
|
|
|
||||||
52
rootfs.py
52
rootfs.py
|
|
@ -26,7 +26,7 @@ def create_configuration_file(args):
|
||||||
Creates bootstrap.cfg file which would contain options used to
|
Creates bootstrap.cfg file which would contain options used to
|
||||||
customize bootstrap.
|
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:
|
with open(config_path, "w", encoding="utf_8") as config:
|
||||||
config.write("FORCE_TIMESTAMPS=" + str(args.force_timestamps) + "\n")
|
config.write("FORCE_TIMESTAMPS=" + str(args.force_timestamps) + "\n")
|
||||||
config.write("CHROOT=" + str(args.chroot) + "\n")
|
config.write("CHROOT=" + str(args.chroot) + "\n")
|
||||||
|
|
@ -49,26 +49,59 @@ def main():
|
||||||
parser.add_argument("--force_timestamps",
|
parser.add_argument("--force_timestamps",
|
||||||
help="Force all files timestamps to be 0 unix time",
|
help="Force all files timestamps to be 0 unix time",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
parser.add_argument("--no-create-config",
|
||||||
|
help="Do not automatically create config file",
|
||||||
|
action="store_true")
|
||||||
|
|
||||||
# QEMU arguments
|
# 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")
|
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)
|
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")
|
default="kernel")
|
||||||
|
|
||||||
parser.add_argument("-m", "--minikernel", help="Use minikernel",
|
parser.add_argument("-m", "--minikernel", help="Use minikernel",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
parser.add_argument("-b", "--bare-metal", help="Build images for bare metal",
|
||||||
|
action="store_true")
|
||||||
|
|
||||||
args = parser.parse_args()
|
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":
|
if args.arch != "x86":
|
||||||
raise ValueError("Only x86 is supported at the moment.")
|
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,
|
system_c = SysC(arch=args.arch, preserve_tmp=args.preserve,
|
||||||
tmpdir=args.tmpdir, chroot=args.chroot)
|
tmpdir=args.tmpdir, chroot=args.chroot)
|
||||||
|
|
@ -114,6 +147,11 @@ print(shutil.which('chroot'))
|
||||||
'--initrd', system_a.initramfs_path,
|
'--initrd', system_a.initramfs_path,
|
||||||
'--log', '/tmp/bootstrap.log')
|
'--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:
|
else:
|
||||||
run(args.qemu_cmd,
|
run(args.qemu_cmd,
|
||||||
'-enable-kvm',
|
'-enable-kvm',
|
||||||
|
|
|
||||||
2
sysa.py
2
sysa.py
|
|
@ -93,7 +93,7 @@ class SysA(SysGeneral):
|
||||||
|
|
||||||
def deploy_extra_files(self):
|
def deploy_extra_files(self):
|
||||||
"""Deploy misc files"""
|
"""Deploy misc files"""
|
||||||
extra_files = ['run.sh']
|
extra_files = ['run.sh', 'bootstrap.cfg']
|
||||||
for extra_file in extra_files:
|
for extra_file in extra_files:
|
||||||
shutil.copy2(os.path.join(self.sys_dir, extra_file), self.after_dir)
|
shutil.copy2(os.path.join(self.sys_dir, extra_file), self.after_dir)
|
||||||
|
|
||||||
|
|
|
||||||
54
sysa/run.sh
54
sysa/run.sh
|
|
@ -24,6 +24,7 @@ create_sysb() {
|
||||||
for d in bin include lib libexec sbin share; do
|
for d in bin include lib libexec sbin share; do
|
||||||
cp -r "${PREFIX}/${d}" "/sysb/usr/${d}"
|
cp -r "${PREFIX}/${d}" "/sysb/usr/${d}"
|
||||||
done
|
done
|
||||||
|
cp "${SOURCES}/bootstrap.cfg" /sysb/usr/src/bootstrap.cfg
|
||||||
populate_device_nodes /sysb
|
populate_device_nodes /sysb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,6 +41,59 @@ go_sysb() {
|
||||||
kexec -e
|
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
|
build flex-2.5.11
|
||||||
|
|
||||||
# Patch meslibc to support > 255 command line arguments
|
# Patch meslibc to support > 255 command line arguments
|
||||||
|
|
|
||||||
41
sysb/run.sh
41
sysb/run.sh
|
|
@ -30,19 +30,40 @@ create_hdx() {
|
||||||
done
|
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
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Otherwise, add stuff from sysa to sysb
|
|
||||||
echo "Mounting sysc"
|
|
||||||
mkdir /sysc
|
|
||||||
# All the various structures that don't exist but needed to mount
|
# All the various structures that don't exist but needed to mount
|
||||||
mkdir -p /etc /dev
|
mkdir -p /etc /dev
|
||||||
populate_device_nodes ""
|
populate_device_nodes ""
|
||||||
create_hdx
|
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
|
||||||
mount -t ext4 "/dev/${DISK}" /sysc
|
mount -t ext4 "/dev/${DISK}" /sysc
|
||||||
|
|
||||||
# Copy over appropriate data
|
# Copy over appropriate data
|
||||||
|
|
@ -50,6 +71,8 @@ echo "Copying data into sysc"
|
||||||
cp -r /dev /sysc/
|
cp -r /dev /sysc/
|
||||||
# Don't include /usr/src
|
# Don't include /usr/src
|
||||||
find /usr -mindepth 1 -maxdepth 1 -type d -not -name src -exec cp -r {} /sysc/{} \;
|
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
|
sync
|
||||||
|
|
||||||
# switch_root into sysc 1. for simplicity 2. to avoid kexecing again
|
# switch_root into sysc 1. for simplicity 2. to avoid kexecing again
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue