From 6dff42c21ea203248a3fb97d735f3828eb57e082 Mon Sep 17 00:00:00 2001 From: Plom Heller Date: Wed, 2 Sep 2026 16:20:55 +0200 Subject: [PATCH] Add rump system-setup scripts. --- _lib.sh | 20 +++++++++++--------- chrooted_command.sh | 2 +- install_debian.sh | 17 +++++++++-------- make_luksvg.sh => setup_luksvg.sh | 15 +++++++++++++++ start_home.sh | 12 ++++++++++++ start_root.sh | 24 ++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 18 deletions(-) rename make_luksvg.sh => setup_luksvg.sh (76%) create mode 100755 start_home.sh create mode 100755 start_root.sh diff --git a/_lib.sh b/_lib.sh index 2e24cc7..0e8c1ca 100644 --- a/_lib.sh +++ b/_lib.sh @@ -4,12 +4,13 @@ SCRIPT_NAME=$0 # constants unlikely to change NAME_DEV=dev PATH_DEV="/${NAME_DEV}" +PATH_MNT=/mnt TO_RBIND="${NAME_DEV} proc sys" # constants we might want to change at some point NAME_DATA=data NAME_SWAP=swap -PATH_MNT=/mnt/debinst +PATH_MNT_ROOT="${PATH_MNT}/root" # path constructors path_luks_mapper() { @@ -97,6 +98,7 @@ close_luksvg () { # helpers: mount/unmount root mount_privately() { local TO_MOUNT=$1 + local DEST=$2 # to facilitate later unmounting of the chrooted system: isolate our mounts # against propagation to services sandboxed with PrivateMounts=yes (e.g. # systemd-udevd), into whose private namespaces our later umount might fail @@ -104,11 +106,11 @@ mount_privately() { # vgchange -an, only to be blocked by referenced devices claimed as "busy" msg "Privatize script's process' mount namespace …" mount --make-rprivate / - + # mount and install base - msg 'Mounting %s at %s …' "${TO_MOUNT}" "${PATH_MNT}" - mkdir -p "${PATH_MNT}" - mount "${TO_MOUNT}" "${PATH_MNT}" + msg 'Mounting %s at %s …' "${TO_MOUNT}" "${DEST}" + mkdir -p "${DEST}" + mount "${TO_MOUNT}" "${DEST}" } await_path() { local TO_AWAIT=$1 @@ -122,7 +124,7 @@ await_path() { rbind_mnt() { for NAME in ${TO_RBIND}; do local PATH_NAME="/${NAME}" - local SLAVE="${PATH_MNT}${PATH_NAME}" + local SLAVE="${PATH_MNT_ROOT}${PATH_NAME}" msg 'For working chroot also mounting %s into there …' "${PATH_NAME}" mount --rbind "${PATH_NAME}" "${SLAVE}" mount --make-rslave "${SLAVE}" @@ -131,14 +133,14 @@ rbind_mnt() { unmount_unrbind() { msg 'Unmounting chroot environment …' for NAME in ${TO_RBIND}; do - umount -R "${PATH_MNT}/${NAME}" + umount -R "${PATH_MNT_ROOT}/${NAME}" done - umount "${PATH_MNT}" + umount "${PATH_MNT_ROOT}" } # helpers: miscellaneous chroot_sh() { - LANG=C.UTF-8 chroot "${PATH_MNT}" /bin/sh -c "$@" + LANG=C.UTF-8 chroot "${PATH_MNT_ROOT}" /bin/sh -c "$@" } create_lv() { local VG=$1 diff --git a/chrooted_command.sh b/chrooted_command.sh index e90665c..bcee658 100755 --- a/chrooted_command.sh +++ b/chrooted_command.sh @@ -19,7 +19,7 @@ check_input_openable_luksvg "${PARTITION}" "${NAME_LUKSVG}" # mount open_luksvg "${PARTITION}" "${NAME_LUKSVG}" await_path "${PATH_VG_ROOT}" -mount_privately "${PATH_VG_ROOT}" +mount_privately "${PATH_VG_ROOT}" "${PATH_MNT_ROOT}" rbind_mnt # enact command diff --git a/install_debian.sh b/install_debian.sh index c212aef..e723d3a 100755 --- a/install_debian.sh +++ b/install_debian.sh @@ -25,10 +25,11 @@ NAME_ROOT="${NAME_BOOT}" # constants derived from changeables PATH_EFI_NAME_BOOT="${PATH_EFI}/${NAME_BOOT}" -PATH_MNT_CRYPTTAB="${PATH_MNT}${PATH_CRYPTTAB}" -PATH_MNT_FSTAB="${PATH_MNT}${PATH_FSTAB}" -PATH_MNT_NM_CONN="${PATH_MNT}${PATH_NM_CONNECTIONS}/${FNAME_NM_CONN}" -PATH_MNT_NM_CONNECTIONS="${PATH_MNT}${PATH_NM_CONNECTIONS}" +PATH_MNT_APT_SOURCES="${PATH_MNT_ROOT}/etc/apt/sources.list" +PATH_MNT_CRYPTTAB="${PATH_MNT_ROOT}${PATH_CRYPTTAB}" +PATH_MNT_FSTAB="${PATH_MNT_ROOT}${PATH_FSTAB}" +PATH_MNT_NM_CONN="${PATH_MNT_ROOT}${PATH_NM_CONNECTIONS}/${FNAME_NM_CONN}" +PATH_MNT_NM_CONNECTIONS="${PATH_MNT_ROOT}${PATH_NM_CONNECTIONS}" PATH_VG=$(path_vg "${NAME_LUKSVG}") PATH_VG_DATA=${PATH_VG}/${NAME_DATA} PATH_VG_ROOT=${PATH_VG}/${NAME_ROOT} @@ -61,9 +62,9 @@ msg 'Creating EXT4 filesystem …' mkfs.ext4 -q "${PATH_VG_ROOT}" # mount and install base -mount_privately "${PATH_VG_ROOT}" +mount_privately "${PATH_VG_ROOT}" "${PATH_MNT_ROOT}" msg 'Installing Debian Suite "%s" there via debootstrap …' "${DEB_SUITE}" -debootstrap "${DEB_SUITE}" "${PATH_MNT}" +debootstrap "${DEB_SUITE}" "${PATH_MNT_ROOT}" rbind_mnt # set up minimal fstab @@ -83,7 +84,7 @@ printf '%s UUID=%s none luks\n' \ # enable non-free-firmware component for firmware-iwlwifi below (as debootstrap # only enables "main" by default) msg 'Enabling non-free-firmware component in target sources.list …' -sed -i 's/ main$/ main non-free-firmware/' "${PATH_MNT}/etc/apt/sources.list" +sed -i 's/ main$/ main non-free-firmware/' "${PATH_MNT_APT_SOURCES}" # set up kernel, initrd etc. msg 'Into chroot environment installing LVM tools, kernel, initrd etc. …' @@ -133,7 +134,7 @@ chmod 600 "${PATH_MNT_NM_CONN}" msg 'EFI setup: copying kernel and initrd into %s …' "${PATH_EFI_NAME_BOOT}" mkdir "${PATH_EFI_NAME_BOOT}" for FILENAME in "${FNAME_INITRD}" "${FNAME_VMLINUZ}"; do - cp "${PATH_MNT}/${FILENAME}" "${PATH_EFI_NAME_BOOT}/" + cp "${PATH_MNT_ROOT}/${FILENAME}" "${PATH_EFI_NAME_BOOT}/" done msg 'EFI setup: adding boot entry %s …' "${NAME_BOOT}" efibootmgr \ diff --git a/make_luksvg.sh b/setup_luksvg.sh similarity index 76% rename from make_luksvg.sh rename to setup_luksvg.sh index 8db13dc..432c87e 100755 --- a/make_luksvg.sh +++ b/setup_luksvg.sh @@ -6,8 +6,13 @@ usage $# "partition" "volume-group-name" PARTITION=$1 NAME_LUKSVG=$2 +# constants we might want to change at some point +CONFIG_FILES_TO_COPY="start_root.sh start_home.sh _lib.sh" + # constants derived from changeables PATH_LUKS_MAPPER=$(path_luks_mapper "${NAME_LUKSVG}") +PATH_MNT_DATA="${PATH_MNT}/${NAME_DATA}" +PATH_MNT_DATA_CONFIG="${PATH_MNT_DATA}/config" PATH_VG=$(path_vg "${NAME_LUKSVG}") PATH_VG_DATA=${PATH_VG}/${NAME_DATA} PATH_VG_SWAP=${PATH_VG}/${NAME_SWAP} @@ -42,6 +47,16 @@ create_lv "${NAME_LUKSVG}" "${NAME_DATA}" 256G msg 'Creating EXT4 filesystem …' mkfs.ext4 -q "${PATH_VG_DATA}" +# place config setup scripts +mount_privately "${PATH_VG_DATA}" "${PATH_MNT_DATA}" +mkdir "${PATH_MNT_DATA_CONFIG}" +msg 'Copying config setup scripts …' +for FNAME in ${CONFIG_FILES_TO_COPY}; do + cp "${FNAME}" "${PATH_MNT_DATA_CONFIG}/" +done +msg 'Unmounting …' +umount "${PATH_MNT_DATA}" + # clean-up close_luksvg "${NAME_LUKSVG}" msg 'Finished!' diff --git a/start_home.sh b/start_home.sh new file mode 100755 index 0000000..c4c838f --- /dev/null +++ b/start_home.sh @@ -0,0 +1,12 @@ +#!/bin/sh +cd "$(dirname "$0")" || exit +. ./_lib.sh + +# constants unlikely to change +FNAME_PROFILE=.profile + +# constants derived from changeables +PATH_PROFILE="${HOME}/${FNAME_PROFILE}" + +msg 'Augmenting user %s …' "${FNAME_PROFILE}" +echo 'alias ls="ls --color=auto"' >> "${PATH_PROFILE}" diff --git a/start_root.sh b/start_root.sh new file mode 100755 index 0000000..eb57d1c --- /dev/null +++ b/start_root.sh @@ -0,0 +1,24 @@ +#!/bin/sh +cd "$(dirname "$0")" || exit +. ./_lib.sh + +# constants unlikely to change +FNAME_START_HOME=start_home.sh + +# constants we might want to change at some point +TO_INSTALL="man-db ntpsec-ntpdate sudo vim" +USERNAME=plom + +msg 'Calling %s …' "${FNAME_START_HOME}" +"./${FNAME_START_HOME}" + +msg 'Ensuring packages: %s' "${TO_INSTALL}" +apt-get -y update +apt-get -y install ${TO_INSTALL} + +msg 'Setting up user: %s' "${USERNAME}" +adduser --comment "" "${USERNAME}" +usermod -a -G sudo "${USERNAME}" + +msg 'Synchronizing clock …' +ntpsec-ntpdate -- 2.30.2