2021-07-06 01:52:10 +01:00
|
|
|
#!/usr/bin/bash
|
|
|
|
|
2022-03-07 07:58:20 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
|
2021-07-06 01:52:10 +01:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-04-13 00:08:29 +01:00
|
|
|
# shellcheck source=sysa/helpers.sh
|
2021-08-05 13:16:19 +01:00
|
|
|
. helpers.sh
|
2021-07-06 01:52:10 +01:00
|
|
|
|
|
|
|
# Unload the current kernel before things go weird
|
|
|
|
kexec -u
|
|
|
|
|
|
|
|
create_hdx() {
|
2021-08-04 03:56:07 +01:00
|
|
|
# Create all of the sd{a,b,c..}
|
2021-07-06 01:52:10 +01:00
|
|
|
minor=0
|
|
|
|
alpha="a b c d e f g h i j k l m n o p" # 16 disks -- more than enough
|
|
|
|
# For each disk...
|
|
|
|
for a in ${alpha}; do
|
2021-08-04 03:56:07 +01:00
|
|
|
mknod -m 600 "/dev/sd${a}" b 8 "$((minor++))"
|
2021-07-06 01:52:10 +01:00
|
|
|
# For each partition...
|
|
|
|
for p in $(seq 15); do
|
2021-08-04 03:56:07 +01:00
|
|
|
mknod -m 600 "/dev/sd${a}${p}" b 8 "$((minor++))"
|
2021-07-06 01:52:10 +01:00
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-10-03 02:28:08 +01:00
|
|
|
# All the various structures that don't exist but needed to mount
|
|
|
|
mkdir -p /etc /dev
|
2022-05-23 06:56:18 +01:00
|
|
|
populate_device_nodes
|
2021-10-03 02:28:08 +01:00
|
|
|
create_hdx
|
|
|
|
|
|
|
|
ask_disk() {
|
|
|
|
echo
|
|
|
|
echo "What disk would you like to use for live-bootstrap?"
|
2022-05-22 01:03:21 +01:00
|
|
|
echo "This disk may have pre-prepared sources on it."
|
|
|
|
echo "If there is no partition we will make one".
|
|
|
|
echo "Please provide in format sdxx (as you would find under /dev),"
|
|
|
|
echo "or sdx if it is a blank disk. An ext4 partition is expected on"
|
|
|
|
echo "existing disks."
|
2021-10-03 02:28:08 +01:00
|
|
|
echo "You can type 'list' to get a list of disks to help you figure"
|
|
|
|
echo "out which is the right disk."
|
2022-05-22 01:03:21 +01:00
|
|
|
echo "NO WARRANTY IS PROVIDED FOR BUGGY BEHAVIOUR, INCLUDING THAT"
|
|
|
|
echo "REGARDING DISKS & DATA."
|
2021-10-03 02:28:08 +01:00
|
|
|
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
|
2022-03-06 12:07:03 +00:00
|
|
|
|
2022-05-15 09:49:50 +01:00
|
|
|
echo "DISK=${DISK}" >> /usr/src/bootstrap.cfg
|
2021-07-06 01:52:10 +01:00
|
|
|
fi
|
|
|
|
|
2022-05-23 06:56:18 +01:00
|
|
|
# Is it a full disk, and not a partition
|
|
|
|
# shellcheck disable=SC2012
|
|
|
|
if [ $(($(ls -l "/dev/${DISK}" | sed "s/.*, *//" | sed "s/ .*//") % 8)) -eq 0 ]; then
|
|
|
|
if ! fdisk -l "/dev/${DISK}" | grep -qE "${DISK}p?[0-9]" ; then
|
|
|
|
echo "Creating partition table and partition"
|
|
|
|
echo ";" | sfdisk "/dev/${DISK}"
|
|
|
|
mkfs.ext4 "/dev/${DISK}1"
|
|
|
|
DISK="${DISK}1"
|
|
|
|
fi
|
2022-05-22 01:03:21 +01:00
|
|
|
fi
|
|
|
|
echo "export DISK=${DISK}" >> /usr/src/bootstrap.cfg
|
|
|
|
|
2022-05-08 20:04:29 +01:00
|
|
|
PREFIX=/usr
|
|
|
|
SOURCES="${PREFIX}/src"
|
|
|
|
SYSC=/sysc
|
|
|
|
|
2021-07-06 01:52:10 +01:00
|
|
|
# Otherwise, add stuff from sysa to sysb
|
|
|
|
echo "Mounting sysc"
|
|
|
|
mkdir /sysc
|
2021-08-04 03:56:07 +01:00
|
|
|
mount -t ext4 "/dev/${DISK}" /sysc
|
2021-07-06 01:52:10 +01:00
|
|
|
|
|
|
|
# Copy over appropriate data
|
|
|
|
echo "Copying data into sysc"
|
2022-05-22 01:03:21 +01:00
|
|
|
sys_transfer "${SYSC}" /sysc_src gzip patch
|
2021-07-06 01:52:10 +01:00
|
|
|
sync
|
|
|
|
|
|
|
|
# switch_root into sysc 1. for simplicity 2. to avoid kexecing again
|
|
|
|
# spouts a few errors because we don't have /proc /sys or /dev mounted
|
|
|
|
echo "Switching into sysc"
|
|
|
|
exec switch_root /sysc /init
|