From e8cc8a3109c114f4d86cce1560502fc9fc7eedf3 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 26 Mar 2025 03:38:59 +0100 Subject: [PATCH] Some linking reoragnization. --- bookworm/preseed.cfg | 27 +++++++ bookworm/scripts/lib/abort | 4 + bookworm/scripts/lib/abort_if_not_user | 7 ++ bookworm/scripts/lib/abort_if_offline | 7 ++ bookworm/scripts/lib/constants_installer | 3 + .../scripts/lib/expect_min_n_args | 0 .../scripts/lib/get_mountable_device_path | 11 +++ bookworm/scripts/make_writable_installer.sh | 79 +++++++++++++++++++ bookworm/scripts/update_preseed.sh | 16 ++++ .../home/desktop/.plomlib.sh/get_passphrase | 7 +- .../desktop/.plomlib.sh/path_tmp_timestamped | 4 +- testing/scripts/lib/abort | 5 +- testing/scripts/lib/abort_if_not_user | 8 +- testing/scripts/lib/abort_if_offline | 8 +- testing/scripts/lib/get_passphrase | 6 ++ testing/scripts/lib/path_tmp_timestamped | 3 + testing/scripts/setup_desktop.sh | 1 - testing/scripts/setup_secrets.sh | 10 +-- 18 files changed, 172 insertions(+), 34 deletions(-) create mode 100644 bookworm/preseed.cfg create mode 100644 bookworm/scripts/lib/abort create mode 100644 bookworm/scripts/lib/abort_if_not_user create mode 100644 bookworm/scripts/lib/abort_if_offline create mode 100644 bookworm/scripts/lib/constants_installer rename {testing => bookworm}/scripts/lib/expect_min_n_args (100%) create mode 100644 bookworm/scripts/lib/get_mountable_device_path create mode 100755 bookworm/scripts/make_writable_installer.sh create mode 100755 bookworm/scripts/update_preseed.sh mode change 100644 => 120000 testing/home/desktop/.plomlib.sh/get_passphrase mode change 100644 => 120000 testing/home/desktop/.plomlib.sh/path_tmp_timestamped mode change 100644 => 120000 testing/scripts/lib/abort mode change 100644 => 120000 testing/scripts/lib/abort_if_not_user mode change 100644 => 120000 testing/scripts/lib/abort_if_offline create mode 100644 testing/scripts/lib/get_passphrase create mode 100644 testing/scripts/lib/path_tmp_timestamped diff --git a/bookworm/preseed.cfg b/bookworm/preseed.cfg new file mode 100644 index 0000000..67ed33b --- /dev/null +++ b/bookworm/preseed.cfg @@ -0,0 +1,27 @@ +#_preseed_V1 + +d-i passwd/root-login boolean true +user-setup-udeb passwd/make-user boolean false + +d-i netcfg/choose_interface select auto +d-i netcfg/link_wait_timeout string 3 +d-i netcfg/wireless_wep string +d-i netcfg/disable_autoconfig boolean false +d-i netcfg/get_hostname string unassigned-hostname +d-i netcfg/get_domain string unassigned-domain + +# d-i partman-auto/method string crypto +d-i partman-auto-lvm/guided_size string max +# d-i partman-auto/choose_recipe select atomic +d-i partman-auto-crypto/erase_disks boolean false +# d-i partman-lvm/confirm boolean true + +d-i base-installer/kernel/image string linux-image-amd64 + +d-i mirror/protocol string http +d-i apt-setup/non-free-firmware boolean true +d-i apt-setup/non-free boolean true +d-i apt-setup/contrib boolean true + +clock-setup clock-setup/utc boolean true +d-i finish-install/reboot_in_progress note diff --git a/bookworm/scripts/lib/abort b/bookworm/scripts/lib/abort new file mode 100644 index 0000000..b0a1704 --- /dev/null +++ b/bookworm/scripts/lib/abort @@ -0,0 +1,4 @@ +abort() { + echo "$1" + exit 1 +} diff --git a/bookworm/scripts/lib/abort_if_not_user b/bookworm/scripts/lib/abort_if_not_user new file mode 100644 index 0000000..a7b3da3 --- /dev/null +++ b/bookworm/scripts/lib/abort_if_not_user @@ -0,0 +1,7 @@ +. lib/abort + +abort_if_not_user() { + if [ "$(whoami)" != "$1" ]; then + abort "Must be run as ${1}." + fi +} diff --git a/bookworm/scripts/lib/abort_if_offline b/bookworm/scripts/lib/abort_if_offline new file mode 100644 index 0000000..b81c784 --- /dev/null +++ b/bookworm/scripts/lib/abort_if_offline @@ -0,0 +1,7 @@ +. lib/abort + +abort_if_offline() { + if ! ping -c1 -W2 1.1.1.1 > /dev/null 2>&1; then + abort 'Must be run online.' + fi +} diff --git a/bookworm/scripts/lib/constants_installer b/bookworm/scripts/lib/constants_installer new file mode 100644 index 0000000..b710116 --- /dev/null +++ b/bookworm/scripts/lib/constants_installer @@ -0,0 +1,3 @@ +FILENAME_PRESEED_CFG=preseed.cfg +PATH_PRESEED_CFG="../${FILENAME_PRESEED_CFG}" +PATH_MNT_STICK=/mnt/stick diff --git a/testing/scripts/lib/expect_min_n_args b/bookworm/scripts/lib/expect_min_n_args similarity index 100% rename from testing/scripts/lib/expect_min_n_args rename to bookworm/scripts/lib/expect_min_n_args diff --git a/bookworm/scripts/lib/get_mountable_device_path b/bookworm/scripts/lib/get_mountable_device_path new file mode 100644 index 0000000..7090a46 --- /dev/null +++ b/bookworm/scripts/lib/get_mountable_device_path @@ -0,0 +1,11 @@ +. lib/abort + +get_mountable_device_path() { + PATH_DEV="/dev/$1" + if [ ! -b "${PATH_DEV}" ]; then + abort "No block device at ${PATH_DEV}." + elif [ $(mount | grep -E "^${PATH_DEV}" | wc -l) -gt 0 ]; then + abort "${PATH_DEV} already mounted." + fi + printf "${PATH_DEV}" +} diff --git a/bookworm/scripts/make_writable_installer.sh b/bookworm/scripts/make_writable_installer.sh new file mode 100755 index 0000000..d828344 --- /dev/null +++ b/bookworm/scripts/make_writable_installer.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# based on +set -e +cd $(dirname "$0") +. lib/abort +. lib/abort_if_not_user +. lib/abort_if_offline +. lib/constants_installer +. lib/expect_min_n_args +. lib/get_mountable_device_path + +INSTALLER_VERSION=12.10.0 +PATH_MNT_ISO=/mnt/iso + +abort_if_not_user root +abort_if_offline root +abort_if_command_unknown() { + if ! which "$1" > /dev/null; then + abort "expected command unavailable: ${1}." + fi +} +abort_if_command_unknown wget +abort_if_command_unknown rsync +abort_if_command_unknown parted +abort_if_command_unknown mkfs.vfat + +expect_min_n_args 1 '(device name, e.g. "sdb")' $@ +PATH_STICK="$(get_mountable_device_path $1)" + +FILENAME_ISO="debian-${INSTALLER_VERSION}-amd64-netinst.iso" +echo "Retrieving ${FILENAME_ISO}." +URL_ISO="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/${FILENAME_ISO}" +PATH_ISO="/tmp/${FILENAME_ISO}" +wget --output-document "${PATH_ISO}" "${URL_ISO}" + +echo "Preparing partition/filesystem on ${PATH_STICK}." +parted --script "${PATH_STICK}" mklabel msdos +parted --script "${PATH_STICK}" mkpart primary fat32 0% 100% +PATH_PARTITION="${PATH_STICK}1" +mkfs.vfat "${PATH_PARTITION}" + +echo "Mounting ${PATH_MNT_ISO} and ${PATH_MNT_STICK}." +mkdir -p "${PATH_MNT_ISO}" "${PATH_MNT_STICK}" +mount "${PATH_PARTITION}" "${PATH_MNT_STICK}" +mount -o loop "${PATH_ISO}" "${PATH_MNT_ISO}" +do_umounts() { + set +e + echo "Unmounting ${PATH_MNT_ISO}" + umount "${PATH_MNT_ISO}" + echo "Unmounting ${PATH_MNT_STICK}" + umount "${PATH_MNT_STICK}" + set -e +} +trap do_umounts EXIT INT TERM + +echo "Copying contents of ${PATH_MNT_ISO} to ${PATH_MNT_STICK}/." +PATH_RSYNC_ERRORS=/tmp/rsync_errors +set +e +rsync -a "${PATH_MNT_ISO}/" "${PATH_MNT_STICK}/" 2> "${PATH_RSYNC_ERRORS}" +RESULT=$? +set -e +if [ "${RESULT}" != "0" ]; then + echo 'rsync errors:' + cat "${PATH_RSYNC_ERRORS}" + echo 'rsync encountered errors, see above – continue? (Y/N)' + rm "${PATH_RSYNC_ERRORS}" + read ANSWER + FIRST_CHAR=$(echo "${ANSWER}" | cut -c1) + if ! [ "${FIRST_CHAR}" = 'y' -o "${FIRST_CHAR}" = 'Y' ]; then + abort 'as requested' + fi +fi + +echo "Installing preseed file." +cp "${PATH_PRESEED_CFG}" "${PATH_MNT_STICK}/" +sed --in-place 's/ --- / --- preseed\/file=\/cdrom\/'"${FILENAME_PRESEED_CFG}"' /g' "${PATH_MNT_STICK}/boot/grub/grub.cfg" + +rm "${PATH_ISO}" +echo "Done!" diff --git a/bookworm/scripts/update_preseed.sh b/bookworm/scripts/update_preseed.sh new file mode 100755 index 0000000..17f5098 --- /dev/null +++ b/bookworm/scripts/update_preseed.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e +set -x +cd $(dirname "$0") +. lib/abort_if_not_user +. lib/constants_installer +. lib/expect_min_n_args +. lib/get_mountable_device_path + +abort_if_not_user root +expect_min_n_args 1 '(e.g. "sdb1")' $@ +PATH_STICK="$(get_mountable_device_path $1)" + +mount "${PATH_STICK}" "${PATH_MNT_STICK}" +trap "umount ${PATH_MNT_STICK}" EXIT INT TERM +cp "${PATH_PRESEED_CFG}" "${PATH_MNT_STICK}/" diff --git a/testing/home/desktop/.plomlib.sh/get_passphrase b/testing/home/desktop/.plomlib.sh/get_passphrase deleted file mode 100644 index 6e3f0ff..0000000 --- a/testing/home/desktop/.plomlib.sh/get_passphrase +++ /dev/null @@ -1,6 +0,0 @@ -get_passphrase() { - stty -echo - read PASSPHRASE - stty echo - printf "${PASSPHRASE}" -} diff --git a/testing/home/desktop/.plomlib.sh/get_passphrase b/testing/home/desktop/.plomlib.sh/get_passphrase new file mode 120000 index 0000000..3d542b5 --- /dev/null +++ b/testing/home/desktop/.plomlib.sh/get_passphrase @@ -0,0 +1 @@ +../../../scripts/lib/get_passphrase \ No newline at end of file diff --git a/testing/home/desktop/.plomlib.sh/path_tmp_timestamped b/testing/home/desktop/.plomlib.sh/path_tmp_timestamped deleted file mode 100644 index 7ae63cd..0000000 --- a/testing/home/desktop/.plomlib.sh/path_tmp_timestamped +++ /dev/null @@ -1,3 +0,0 @@ -path_tmp_timestamped () { - printf "/tmp/${1}_$(date +'%s')" -} diff --git a/testing/home/desktop/.plomlib.sh/path_tmp_timestamped b/testing/home/desktop/.plomlib.sh/path_tmp_timestamped new file mode 120000 index 0000000..0752df5 --- /dev/null +++ b/testing/home/desktop/.plomlib.sh/path_tmp_timestamped @@ -0,0 +1 @@ +../../../scripts/lib/path_tmp_timestamped \ No newline at end of file diff --git a/testing/scripts/lib/abort b/testing/scripts/lib/abort deleted file mode 100644 index b0a1704..0000000 --- a/testing/scripts/lib/abort +++ /dev/null @@ -1,4 +0,0 @@ -abort() { - echo "$1" - exit 1 -} diff --git a/testing/scripts/lib/abort b/testing/scripts/lib/abort new file mode 120000 index 0000000..5574233 --- /dev/null +++ b/testing/scripts/lib/abort @@ -0,0 +1 @@ +../../../bookworm/scripts/lib/abort \ No newline at end of file diff --git a/testing/scripts/lib/abort_if_not_user b/testing/scripts/lib/abort_if_not_user deleted file mode 100644 index a7b3da3..0000000 --- a/testing/scripts/lib/abort_if_not_user +++ /dev/null @@ -1,7 +0,0 @@ -. lib/abort - -abort_if_not_user() { - if [ "$(whoami)" != "$1" ]; then - abort "Must be run as ${1}." - fi -} diff --git a/testing/scripts/lib/abort_if_not_user b/testing/scripts/lib/abort_if_not_user new file mode 120000 index 0000000..b152dca --- /dev/null +++ b/testing/scripts/lib/abort_if_not_user @@ -0,0 +1 @@ +../../../bookworm/scripts/lib/abort_if_not_user \ No newline at end of file diff --git a/testing/scripts/lib/abort_if_offline b/testing/scripts/lib/abort_if_offline deleted file mode 100644 index b81c784..0000000 --- a/testing/scripts/lib/abort_if_offline +++ /dev/null @@ -1,7 +0,0 @@ -. lib/abort - -abort_if_offline() { - if ! ping -c1 -W2 1.1.1.1 > /dev/null 2>&1; then - abort 'Must be run online.' - fi -} diff --git a/testing/scripts/lib/abort_if_offline b/testing/scripts/lib/abort_if_offline new file mode 120000 index 0000000..c2f519f --- /dev/null +++ b/testing/scripts/lib/abort_if_offline @@ -0,0 +1 @@ +../../../bookworm/scripts/lib/abort_if_offline \ No newline at end of file diff --git a/testing/scripts/lib/get_passphrase b/testing/scripts/lib/get_passphrase new file mode 100644 index 0000000..6e3f0ff --- /dev/null +++ b/testing/scripts/lib/get_passphrase @@ -0,0 +1,6 @@ +get_passphrase() { + stty -echo + read PASSPHRASE + stty echo + printf "${PASSPHRASE}" +} diff --git a/testing/scripts/lib/path_tmp_timestamped b/testing/scripts/lib/path_tmp_timestamped new file mode 100644 index 0000000..7ae63cd --- /dev/null +++ b/testing/scripts/lib/path_tmp_timestamped @@ -0,0 +1,3 @@ +path_tmp_timestamped () { + printf "/tmp/${1}_$(date +'%s')" +} diff --git a/testing/scripts/setup_desktop.sh b/testing/scripts/setup_desktop.sh index 53327ef..9834ceb 100755 --- a/testing/scripts/setup_desktop.sh +++ b/testing/scripts/setup_desktop.sh @@ -1,7 +1,6 @@ #!/bin/sh set -e cd $(dirname "$0") - . lib/constants # PATH_USER_HOME, USERNAME . lib/expect_min_n_args . lib/abort diff --git a/testing/scripts/setup_secrets.sh b/testing/scripts/setup_secrets.sh index 4eb2645..f417788 100755 --- a/testing/scripts/setup_secrets.sh +++ b/testing/scripts/setup_secrets.sh @@ -1,16 +1,14 @@ #!/bin/sh set -e cd $(dirname "$0") - -. lib/constants # PATH_USER_HOME, USERNAME -. lib/expect_min_n_args . lib/abort . lib/abort_if_exists . lib/abort_if_not_user . lib/abort_if_offline - -. "${PATH_USER_HOME}/.plomlib.sh/get_passphrase" -. "${PATH_USER_HOME}/.plomlib.sh/path_tmp_timestamped" +. lib/constants # PATH_USER_HOME, USERNAME +. lib/expect_min_n_args +. lib/get_passphrase +. lib/path_tmp_timestamped PATH_REL_SECRETS=to_usb export PATH_SECRETS="${PATH_USER_HOME}/${PATH_REL_SECRETS}" -- 2.30.2