From: Plom Heller Date: Thu, 10 Sep 2026 21:05:50 +0000 (+0200) Subject: Split most of _lib.sh into individual per-declaration modules. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/edit?a=commitdiff_plain;h=f4cdb3b3e0dca033e6dbb6824ffe48acdb985797;p=confplom Split most of _lib.sh into individual per-declaration modules. --- diff --git a/setup_scripts/_lib.sh b/setup_scripts/_lib.sh index 3f3172c..832abe0 100644 --- a/setup_scripts/_lib.sh +++ b/setup_scripts/_lib.sh @@ -1,269 +1,3 @@ set -Ceu SCRIPT_NAME=$0 cd "$(dirname "${SCRIPT_NAME}")" - -# constants unlikely to change -DIRNAME_DEV=dev -DIRNAME_SSH=.ssh -FNAME_FIRST_BOOT_PENDING=.first-boot-pending -FNAME_INITRD=initrd.img -FNAME_PROFILE=.profile -FNAME_VMLINUZ=vmlinuz -PATH_DEV="/${DIRNAME_DEV}" -PATH_EFI=/boot/efi -PATH_MNT=/mnt -TO_RBIND="${DIRNAME_DEV} proc sys" - -# constants we might want to change at some point -IDX_PARTITION_EFI=1 -IDX_PARTITION_LUKSVG=3 -IDX_PARTITION_RESCUE=2 -NAME_BOOT_DEVICE=nvme0n1 -NAME_DATA=data -NAME_LUKSVG=cryptolvm -NAME_SWAP=swap -PATH_APT_NORECOMMENDS=/etc/apt/apt.conf.d/90-no-recommends -PATH_MNT_ROOT="${PATH_MNT}/root" -TIMEZONE=Europe/Berlin -USERNAME=plom - -# constants derived from changeables -PATH_BOOT_DEVICE="${PATH_DEV}/${NAME_BOOT_DEVICE}" -PATH_FIRST_BOOT_PENDING="/root/${FNAME_FIRST_BOOT_PENDING}" -PATH_MY_SSH="${HOME}/${DIRNAME_SSH}" -PATH_PARTITION_EFI="${PATH_BOOT_DEVICE}p${IDX_PARTITION_EFI}" -PATH_PARTITION_LUKSVG="${PATH_BOOT_DEVICE}p${IDX_PARTITION_LUKSVG}" -PATH_PARTITION_RESCUE="${PATH_BOOT_DEVICE}p${IDX_PARTITION_RESCUE}" -PATH_PROFILE="${HOME}/${FNAME_PROFILE}" -PATH_REPO=$(cd .. && pwd) -PATH_SCRIPTS="${PATH_REPO}/setup_scripts" -DIRNAME_REPO=$(basename "${PATH_REPO}") -PATH_TEMPLATES="${PATH_REPO}/templates" - -# path constructors -path_luks_mapper() { - printf '%s/mapper/%s' "${PATH_DEV}" "$1" -} -path_vg() { - printf '%s/%s' "${PATH_DEV}" "$1" -} - -# helpers: logging, testing, failing basics -msg_nonl() { - printf '[## %s ##] ' "${SCRIPT_NAME}" - # shellcheck disable=SC2059 - # (assume we'll always pass a literal format string) - printf -- "$@" -} -msg() { - msg_nonl "$@" - printf '\n' -} -die() { - msg '%s' "$*" >&2 - exit 1 -} -error() { - die "error: $*" -} -try_quiet() { - "$@" >/dev/null 2>&1 -} - -# helpers: more involved testing -check_tools() { - for CMD in "$@"; do - try_quiet command -v "${CMD}"\ - || error "required tool not found: ${CMD}" - done -} -check_partition_mountable() { - local PARTITION=$1 - [ -b "${PARTITION}" ]\ - || error "${PARTITION} is not a block device" - try_quiet findmnt --source "${PARTITION}"\ - && error "${PARTITION} is already mounted" - true -} -check_boot_device_layout() { - local COUNT_NVME - COUNT_NVME=$(find "${PATH_DEV}" -maxdepth 1 -name 'nvme*n[0-9]' | wc -l) - [ "${COUNT_NVME}" -eq 1 ]\ - || error "expected 1 NVMe device in ${PATH_DEV}, found ${COUNT_NVME}" - [ -b "${PATH_BOOT_DEVICE}" ]\ - || error "NVMe device in ${PATH_DEV} not expected ${PATH_BOOT_DEVICE}" - - local COUNT_PARTITIONS - COUNT_PARTITIONS=$(find "${PATH_DEV}" -maxdepth 1 \ - -name "$(basename "${PATH_BOOT_DEVICE}")p[0-9]*" | wc -l) - [ "${COUNT_PARTITIONS}" -eq 3 ]\ - || error "expected 3 partitions on ${PATH_BOOT_DEVICE}, found ${COUNT_PARTITIONS}" - local IDX - for IDX in 1 2 3; do - [ -b "${PATH_BOOT_DEVICE}p${IDX}" ]\ - || error "missing expected partition ${PATH_BOOT_DEVICE}p${IDX}" - done - - try_quiet findmnt --source "${PATH_PARTITION_RESCUE}" --target /\ - || error "not running from expected rescue partition \ -${PATH_PARTITION_RESCUE} (mounted as /)" - try_quiet findmnt --source "${PATH_PARTITION_EFI}" --target "${PATH_EFI}"\ - || error "expected ${PATH_PARTITION_EFI} mounted at ${PATH_EFI}" -} -check_new_luksvg() { - local PATH_LUKS_MAPPER - PATH_LUKS_MAPPER=$(path_luks_mapper "${NAME_LUKSVG}") - try_quiet vgs "${NAME_LUKSVG}"\ - && error "volume group '${NAME_LUKSVG}' already exists" - [ -e "${PATH_LUKS_MAPPER}" ]\ - && error "${PATH_LUKS_MAPPER} already exists" - true -} -check_openable_luksvg() { - check_new_luksvg - try_quiet cryptsetup isLuks "${PATH_PARTITION_LUKSVG}"\ - || error "${PATH_PARTITION_LUKSVG} not a LUKS container" -} - -# helpers: luks open/close -open_luksvg() { - msg 'Opening LUKS container as "%s" …' "${NAME_LUKSVG}" - cryptsetup luksOpen "${PATH_PARTITION_LUKSVG}" "${NAME_LUKSVG}" -} -close_luksvg() { - msg 'Deactivating volume group and closing LUKS container …' - vgchange -an "${NAME_LUKSVG}" - cryptsetup luksClose "${NAME_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 - # to reach for closing their references e.g. into what we'll want to - # 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}" "${DEST}" - mkdir -p "${DEST}" - mount "${TO_MOUNT}" "${DEST}" -} -await_path() { - local TO_AWAIT=$1 - msg_nonl 'Waiting for %s to appear …' "${TO_AWAIT}" - while [ ! -e "${TO_AWAIT}" ]; do - printf " …" - sleep 0.5 - done - printf ' there it is!\n' -} -rbind_mnt() { - for NAME in ${TO_RBIND}; do - local PATH_NAME="/${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}" - done -} -unmount_unrbind() { - msg 'Unmounting chroot environment …' - for NAME in ${TO_RBIND}; do - umount -R "${PATH_MNT_ROOT}/${NAME}" - done - umount "${PATH_MNT_ROOT}" -} - -# helpers: miscellaneous -chroot_sh() { - LANG=C.UTF-8 chroot "${PATH_MNT_ROOT}" /bin/sh -c "$@" -} -retry_until_success() { - until "$@"; do - msg 'Command failed, retrying: %s …' "$*" - done -} -create_lv() { - local VG=$1 - local LV=$2 - local SIZE=$3 - msg 'Creating logical volume "%s" inside volume group …' "${LV}" - lvcreate -L "${SIZE}" -n "${LV}" "${VG}" -} -usage() { - local COUNT_INPUTS=$1 - shift - local MSG="usage: ${SCRIPT_NAME}" - for PARAMETER in "$@"; do - MSG="${MSG} <${PARAMETER}>" - done - [ "${COUNT_INPUTS}" -eq $# ]\ - || die "${MSG}" -} -augment_profile() { - local ALIAS_LS='alias ls="ls --color=auto"' - msg 'Augmenting user %s …' "${FNAME_PROFILE}" - # test ensures idempotency - grep -qxF "${ALIAS_LS}" "${PATH_PROFILE}" 2>/dev/null\ - || echo "${ALIAS_LS}" >> "${PATH_PROFILE}" -} -start_root() { - local TARGET=$1 - - # Assuming read file ends with a newline, has no blank lines, and its - # package-name lines contain no whitespace besides that newline. - local TO_INSTALL= - while read -r LINE; do - case "${LINE}" in - '#'*) continue ;; - esac - TO_INSTALL="${TO_INSTALL} ${LINE}" - done < "${PATH_REPO}/to_install/${TARGET}" - apt-get -y update - msg 'Ensuring packages: %s' "${TO_INSTALL}" - apt-get -y install ${TO_INSTALL} - - if try_quiet id -u "${USERNAME}"; then - msg 'User %s already exists, skipping creation …' "${USERNAME}" - else - msg 'Setting up user: %s' "${USERNAME}" - adduser --disabled-password --comment "" "${USERNAME}" - retry_until_success passwd "${USERNAME}" - msg 'Running start_user.sh as %s …' "${USERNAME}" - su - "${USERNAME}" -c "sh ${PATH_SCRIPTS}/start_user.sh" - fi - usermod -a -G sudo "${USERNAME}" - - msg 'Setting system timezone to %s …' "${TIMEZONE}" - timedatectl set-timezone "${TIMEZONE}" - - augment_profile -} -disable_apt_recommends() { - local PREFIX=${1:-} - local TARGET="${PREFIX}${PATH_APT_NORECOMMENDS}" - msg 'Disabling automatic installation of APT recommends …' - printf 'APT::Install-Recommends "false";\n' >| "${TARGET}" -} -efi_copy_kernel_vmlinuz() { - local PATH_EFI_NAME_BOOT=$1 - local PREFIX=${2:-} - msg 'EFI setup: copying kernel and initrd into %s …' "${PATH_EFI_NAME_BOOT}" - for FILENAME in "${FNAME_INITRD}" "${FNAME_VMLINUZ}"; do - cp "${PREFIX}/${FILENAME}" "${PATH_EFI_NAME_BOOT}/" - done -} -render_template() { - local PATH_TEMPLATE=$1 - # eval'd instead of just `cat`, so ${...}/$(...) inside the template - # get expanded against the calling script's own variables, exactly as - # if its content were still an inline heredoc in that script. - eval "cat <| "${PATH_MNT_FSTAB}" +render_template "${FNAME_FSTAB}" >| "${PATH_MNT_FSTAB}" msg 'Setting up crypttab …' printf '%s %s none luks\n' "${NAME_LUKSVG}" "${PATH_PARTITION_LUKSVG}" \ @@ -92,7 +130,7 @@ printf '[ -e "%s" ] && sh "%s"\n' \ msg 'For firmware-iwlwifi, enabling non-free-firmware in target sources.list …' sed -i 's/ main$/ main non-free-firmware/' "${PATH_MNT_APT_SOURCES}" -disable_apt_recommends "${PATH_MNT_ROOT}" +disable_apt_recommends "${PATH_MNT_CHROOT}" msg 'Into chroot environment installing LVM tools, kernel, initrd etc. …' chroot_sh "apt-get -qq update" @@ -115,11 +153,11 @@ msg 'Writing NetworkManager connection profile for "%s" …' \ "${NAME_WIFI_SSID}" mkdir -p "${PATH_MNT_NM_CONNECTIONS}" chmod 700 "${PATH_MNT_NM_CONNECTIONS}" -render_template "${PATH_TEMPLATES}/wifi.nmconnection" >| "${PATH_MNT_NM_CONN}" +render_template "${FNAME_NM_CONN}" >| "${PATH_MNT_NM_CONN}" chmod 600 "${PATH_MNT_NM_CONN}" mkdir "${PATH_EFI_NAME_BOOT}" -efi_copy_kernel_vmlinuz "${PATH_EFI_NAME_BOOT}" "${PATH_MNT_ROOT}" +efi_copy_kernel_vmlinuz "${PATH_EFI_NAME_BOOT}" "${PATH_MNT_CHROOT}" msg 'EFI setup: adding boot entry %s …' "${NAME_BOOT}" efibootmgr \ --create \ diff --git a/setup_scripts/install_server.sh b/setup_scripts/install_server.sh index 387744f..b5b50a9 100755 --- a/setup_scripts/install_server.sh +++ b/setup_scripts/install_server.sh @@ -1,5 +1,12 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" +. lib/DIRNAME_REPO.sh +. lib/DIRNAME_SCRIPTS.sh +. lib/PATH_MY_SSH.sh +. lib/PATH_REPO.sh +. lib/check_tools.sh +. lib/msg.sh +. lib/usage.sh # constants we might want to change at some point FNAME_REPO_TAR=repo.tar @@ -7,12 +14,12 @@ OPTS_SSH_NEW_HOST="-o StrictHostKeyChecking=accept-new" # constants derived from changeables PATH_REPO_PARENT=$(dirname "${PATH_REPO}") -PATH_SETUP_SCRIPT="./${PATH_SCRIPTS}/start_root_server.sh" +RELPATH_SETUP_SCRIPT="${DIRNAME_REPO}/${DIRNAME_SCRIPTS}/start_root_server.sh" # inputs to confirm usage $# "server" SERVER=$1 -TARGET="root@${SERVER}" +LOGIN="root@${SERVER}" PATH_MY_KNOWN_HOSTS="${PATH_MY_SSH}/known_hosts" # sanity checks @@ -24,14 +31,13 @@ msg 'Creating tar of repo in temporary directory %s …' "${PATH_TEMP}" tar cf "${PATH_REPO_TAR}" -C "${PATH_REPO_PARENT}" "${DIRNAME_REPO}" msg 'Uploading repo tar to server …' -if [ -e "${PATH_MY_KNOWN_HOSTS}" ]; then - ssh-keygen -f "${PATH_MY_KNOWN_HOSTS}" -R "${SERVER}" -fi -scp ${OPTS_SSH_NEW_HOST} "${PATH_REPO_TAR}" "${TARGET}:~" +[ -e "${PATH_MY_KNOWN_HOSTS}" ]\ + && ssh-keygen -f "${PATH_MY_KNOWN_HOSTS}" -R "${SERVER}" +scp ${OPTS_SSH_NEW_HOST} "${PATH_REPO_TAR}" "${LOGIN}:~" rm -rf "${PATH_TEMP}" msg 'Unpacking repo and running setup script …' # --no-same-owner owns the files to root, prevening "dubious ownership" when # running setup_git_mirror.sh on it later! -ssh ${OPTS_SSH_NEW_HOST} "${TARGET}" tar xf "${FNAME_REPO_TAR}" --no-same-owner -ssh -t ${OPTS_SSH_NEW_HOST} "${TARGET}" "${PATH_SETUP_SCRIPT}" +ssh ${OPTS_SSH_NEW_HOST} "${LOGIN}" tar xf "${FNAME_REPO_TAR}" --no-same-owner +ssh -t ${OPTS_SSH_NEW_HOST} "${LOGIN}" "./${RELPATH_SETUP_SCRIPT}" diff --git a/setup_scripts/lib/DIRNAME_CHROOT.sh b/setup_scripts/lib/DIRNAME_CHROOT.sh new file mode 100644 index 0000000..a04cb92 --- /dev/null +++ b/setup_scripts/lib/DIRNAME_CHROOT.sh @@ -0,0 +1 @@ +DIRNAME_CHROOT=chroot diff --git a/setup_scripts/lib/DIRNAME_DEV.sh b/setup_scripts/lib/DIRNAME_DEV.sh new file mode 100644 index 0000000..79d6491 --- /dev/null +++ b/setup_scripts/lib/DIRNAME_DEV.sh @@ -0,0 +1 @@ +DIRNAME_DEV=dev diff --git a/setup_scripts/lib/DIRNAME_REPO.sh b/setup_scripts/lib/DIRNAME_REPO.sh new file mode 100644 index 0000000..5da52f7 --- /dev/null +++ b/setup_scripts/lib/DIRNAME_REPO.sh @@ -0,0 +1,4 @@ +. lib/PATH_REPO.sh + +DIRNAME_REPO=$(basename "${PATH_REPO}") + diff --git a/setup_scripts/lib/DIRNAME_SCRIPTS.sh b/setup_scripts/lib/DIRNAME_SCRIPTS.sh new file mode 100644 index 0000000..756c657 --- /dev/null +++ b/setup_scripts/lib/DIRNAME_SCRIPTS.sh @@ -0,0 +1,2 @@ +DIRNAME_SCRIPTS=$(basename "$(dirname "${SCRIPT_NAME}")") + diff --git a/setup_scripts/lib/DIRNAME_SSH.sh b/setup_scripts/lib/DIRNAME_SSH.sh new file mode 100644 index 0000000..5cf194b --- /dev/null +++ b/setup_scripts/lib/DIRNAME_SSH.sh @@ -0,0 +1,2 @@ +DIRNAME_SSH=.ssh + diff --git a/setup_scripts/lib/FNAME_FIRST_BOOT_PENDING.sh b/setup_scripts/lib/FNAME_FIRST_BOOT_PENDING.sh new file mode 100644 index 0000000..ea8a3c6 --- /dev/null +++ b/setup_scripts/lib/FNAME_FIRST_BOOT_PENDING.sh @@ -0,0 +1,2 @@ +FNAME_FIRST_BOOT_PENDING=.first-boot-pending + diff --git a/setup_scripts/lib/FNAME_INITRD.sh b/setup_scripts/lib/FNAME_INITRD.sh new file mode 100644 index 0000000..b93d691 --- /dev/null +++ b/setup_scripts/lib/FNAME_INITRD.sh @@ -0,0 +1 @@ +FNAME_INITRD=initrd.img diff --git a/setup_scripts/lib/FNAME_PROFILE.sh b/setup_scripts/lib/FNAME_PROFILE.sh new file mode 100644 index 0000000..e46ab87 --- /dev/null +++ b/setup_scripts/lib/FNAME_PROFILE.sh @@ -0,0 +1 @@ +FNAME_PROFILE=.profile diff --git a/setup_scripts/lib/FNAME_VMLINUZ.sh b/setup_scripts/lib/FNAME_VMLINUZ.sh new file mode 100644 index 0000000..e3bf565 --- /dev/null +++ b/setup_scripts/lib/FNAME_VMLINUZ.sh @@ -0,0 +1 @@ +FNAME_VMLINUZ=vmlinuz diff --git a/setup_scripts/lib/IDX_PARTITION_EFI.sh b/setup_scripts/lib/IDX_PARTITION_EFI.sh new file mode 100644 index 0000000..cd3c6cd --- /dev/null +++ b/setup_scripts/lib/IDX_PARTITION_EFI.sh @@ -0,0 +1 @@ +IDX_PARTITION_EFI=1 diff --git a/setup_scripts/lib/IDX_PARTITION_LUKSVG.sh b/setup_scripts/lib/IDX_PARTITION_LUKSVG.sh new file mode 100644 index 0000000..eabae5c --- /dev/null +++ b/setup_scripts/lib/IDX_PARTITION_LUKSVG.sh @@ -0,0 +1 @@ +IDX_PARTITION_LUKSVG=3 diff --git a/setup_scripts/lib/IDX_PARTITION_RESCUE.sh b/setup_scripts/lib/IDX_PARTITION_RESCUE.sh new file mode 100644 index 0000000..68368c9 --- /dev/null +++ b/setup_scripts/lib/IDX_PARTITION_RESCUE.sh @@ -0,0 +1,2 @@ +IDX_PARTITION_RESCUE=2 + diff --git a/setup_scripts/lib/NAME_BOOT_DEVICE.sh b/setup_scripts/lib/NAME_BOOT_DEVICE.sh new file mode 100644 index 0000000..366a8ce --- /dev/null +++ b/setup_scripts/lib/NAME_BOOT_DEVICE.sh @@ -0,0 +1,2 @@ +NAME_BOOT_DEVICE=nvme0n1 + diff --git a/setup_scripts/lib/NAME_DATA.sh b/setup_scripts/lib/NAME_DATA.sh new file mode 100644 index 0000000..74bee5e --- /dev/null +++ b/setup_scripts/lib/NAME_DATA.sh @@ -0,0 +1,2 @@ +NAME_DATA=data + diff --git a/setup_scripts/lib/NAME_LUKSVG.sh b/setup_scripts/lib/NAME_LUKSVG.sh new file mode 100644 index 0000000..c4456ac --- /dev/null +++ b/setup_scripts/lib/NAME_LUKSVG.sh @@ -0,0 +1,2 @@ +NAME_LUKSVG=cryptolvm + diff --git a/setup_scripts/lib/NAME_SWAP.sh b/setup_scripts/lib/NAME_SWAP.sh new file mode 100644 index 0000000..91adfc4 --- /dev/null +++ b/setup_scripts/lib/NAME_SWAP.sh @@ -0,0 +1,2 @@ +NAME_SWAP=swap + diff --git a/setup_scripts/lib/PATH_BOOT_DEVICE.sh b/setup_scripts/lib/PATH_BOOT_DEVICE.sh new file mode 100644 index 0000000..34b8ede --- /dev/null +++ b/setup_scripts/lib/PATH_BOOT_DEVICE.sh @@ -0,0 +1,4 @@ +. lib/NAME_BOOT_DEVICE.sh +. lib/PATH_DEV.sh + +PATH_BOOT_DEVICE="${PATH_DEV}/${NAME_BOOT_DEVICE}" diff --git a/setup_scripts/lib/PATH_DATA.sh b/setup_scripts/lib/PATH_DATA.sh new file mode 100644 index 0000000..7c10386 --- /dev/null +++ b/setup_scripts/lib/PATH_DATA.sh @@ -0,0 +1,4 @@ +. lib/NAME_DATA.sh + +PATH_DATA="/${NAME_DATA}" + diff --git a/setup_scripts/lib/PATH_DEV.sh b/setup_scripts/lib/PATH_DEV.sh new file mode 100644 index 0000000..d27ecf1 --- /dev/null +++ b/setup_scripts/lib/PATH_DEV.sh @@ -0,0 +1,4 @@ +. lib/DIRNAME_DEV.sh + +PATH_DEV="/${DIRNAME_DEV}" + diff --git a/setup_scripts/lib/PATH_EFI.sh b/setup_scripts/lib/PATH_EFI.sh new file mode 100644 index 0000000..47a8961 --- /dev/null +++ b/setup_scripts/lib/PATH_EFI.sh @@ -0,0 +1 @@ +PATH_EFI=/boot/efi diff --git a/setup_scripts/lib/PATH_FIRST_BOOT_PENDING.sh b/setup_scripts/lib/PATH_FIRST_BOOT_PENDING.sh new file mode 100644 index 0000000..05e0c83 --- /dev/null +++ b/setup_scripts/lib/PATH_FIRST_BOOT_PENDING.sh @@ -0,0 +1,5 @@ +. lib/FNAME_FIRST_BOOT_PENDING.sh +. lib/PATH_HOME_ROOT.sh + +PATH_FIRST_BOOT_PENDING="${PATH_HOME_ROOT}/${FNAME_FIRST_BOOT_PENDING}" + diff --git a/setup_scripts/lib/PATH_HOME_ROOT.sh b/setup_scripts/lib/PATH_HOME_ROOT.sh new file mode 100644 index 0000000..7e2672a --- /dev/null +++ b/setup_scripts/lib/PATH_HOME_ROOT.sh @@ -0,0 +1,2 @@ +PATH_HOME_ROOT=/root + diff --git a/setup_scripts/lib/PATH_MNT.sh b/setup_scripts/lib/PATH_MNT.sh new file mode 100644 index 0000000..145f6ed --- /dev/null +++ b/setup_scripts/lib/PATH_MNT.sh @@ -0,0 +1,2 @@ +PATH_MNT=/mnt + diff --git a/setup_scripts/lib/PATH_MNT_CHROOT.sh b/setup_scripts/lib/PATH_MNT_CHROOT.sh new file mode 100644 index 0000000..31aaab5 --- /dev/null +++ b/setup_scripts/lib/PATH_MNT_CHROOT.sh @@ -0,0 +1,4 @@ +. lib/DIRNAME_CHROOT.sh +. lib/PATH_MNT.sh + +PATH_MNT_CHROOT="${PATH_MNT}/${DIRNAME_CHROOT}" diff --git a/setup_scripts/lib/PATH_MY_SSH.sh b/setup_scripts/lib/PATH_MY_SSH.sh new file mode 100644 index 0000000..cab8fdc --- /dev/null +++ b/setup_scripts/lib/PATH_MY_SSH.sh @@ -0,0 +1,4 @@ +. lib/DIRNAME_SSH.sh + +PATH_MY_SSH="${HOME}/${DIRNAME_SSH}" + diff --git a/setup_scripts/lib/PATH_PARTITION_EFI.sh b/setup_scripts/lib/PATH_PARTITION_EFI.sh new file mode 100644 index 0000000..17f2184 --- /dev/null +++ b/setup_scripts/lib/PATH_PARTITION_EFI.sh @@ -0,0 +1,4 @@ +. lib/IDX_PARTITION_EFI.sh +. lib/PATH_BOOT_DEVICE.sh + +PATH_PARTITION_EFI="${PATH_BOOT_DEVICE}p${IDX_PARTITION_EFI}" diff --git a/setup_scripts/lib/PATH_PARTITION_LUKSVG.sh b/setup_scripts/lib/PATH_PARTITION_LUKSVG.sh new file mode 100644 index 0000000..b45b688 --- /dev/null +++ b/setup_scripts/lib/PATH_PARTITION_LUKSVG.sh @@ -0,0 +1,5 @@ +. lib/IDX_PARTITION_LUKSVG.sh +. lib/PATH_BOOT_DEVICE.sh + +PATH_PARTITION_LUKSVG="${PATH_BOOT_DEVICE}p${IDX_PARTITION_LUKSVG}" + diff --git a/setup_scripts/lib/PATH_PARTITION_RESCUE.sh b/setup_scripts/lib/PATH_PARTITION_RESCUE.sh new file mode 100644 index 0000000..cb88090 --- /dev/null +++ b/setup_scripts/lib/PATH_PARTITION_RESCUE.sh @@ -0,0 +1,5 @@ +. lib/IDX_PARTITION_RESCUE.sh +. lib/PATH_BOOT_DEVICE.sh + +PATH_PARTITION_RESCUE="${PATH_BOOT_DEVICE}p${IDX_PARTITION_RESCUE}" + diff --git a/setup_scripts/lib/PATH_PROFILE.sh b/setup_scripts/lib/PATH_PROFILE.sh new file mode 100644 index 0000000..857673e --- /dev/null +++ b/setup_scripts/lib/PATH_PROFILE.sh @@ -0,0 +1,4 @@ +. lib/FNAME_PROFILE.sh + +PATH_PROFILE="${HOME}/${FNAME_PROFILE}" + diff --git a/setup_scripts/lib/PATH_REPO.sh b/setup_scripts/lib/PATH_REPO.sh new file mode 100644 index 0000000..a2b457e --- /dev/null +++ b/setup_scripts/lib/PATH_REPO.sh @@ -0,0 +1,2 @@ +PATH_REPO=$(cd .. && pwd) + diff --git a/setup_scripts/lib/TIMEZONE.sh b/setup_scripts/lib/TIMEZONE.sh new file mode 100644 index 0000000..0aaf39b --- /dev/null +++ b/setup_scripts/lib/TIMEZONE.sh @@ -0,0 +1 @@ +TIMEZONE=Europe/Berlin diff --git a/setup_scripts/lib/TO_RBIND.sh b/setup_scripts/lib/TO_RBIND.sh new file mode 100644 index 0000000..345845b --- /dev/null +++ b/setup_scripts/lib/TO_RBIND.sh @@ -0,0 +1,4 @@ +. lib/DIRNAME_DEV.sh + +TO_RBIND="${DIRNAME_DEV} proc sys" + diff --git a/setup_scripts/lib/USERNAME.sh b/setup_scripts/lib/USERNAME.sh new file mode 100644 index 0000000..f18a72a --- /dev/null +++ b/setup_scripts/lib/USERNAME.sh @@ -0,0 +1,2 @@ +USERNAME=plom + diff --git a/setup_scripts/lib/augment_profile.sh b/setup_scripts/lib/augment_profile.sh new file mode 100644 index 0000000..75411f5 --- /dev/null +++ b/setup_scripts/lib/augment_profile.sh @@ -0,0 +1,12 @@ +. lib/FNAME_PROFILE.sh +. lib/PATH_PROFILE.sh +. lib/msg.sh + +augment_profile() { + local ALIAS_LS='alias ls="ls --color=auto"' + msg 'Augmenting user %s …' "${FNAME_PROFILE}" + # test ensures idempotency + grep -qxF "${ALIAS_LS}" "${PATH_PROFILE}" 2>/dev/null\ + || echo "${ALIAS_LS}" >> "${PATH_PROFILE}" +} + diff --git a/setup_scripts/lib/await_path.sh b/setup_scripts/lib/await_path.sh new file mode 100644 index 0000000..fb594fd --- /dev/null +++ b/setup_scripts/lib/await_path.sh @@ -0,0 +1,12 @@ +. lib/msg.sh + +await_path() { + local TO_AWAIT=$1 + msg_nonl 'Waiting for %s to appear …' "${TO_AWAIT}" + while [ ! -e "${TO_AWAIT}" ]; do + printf " …" + sleep 0.5 + done + printf ' there it is!\n' +} + diff --git a/setup_scripts/lib/check_boot_device_layout.sh b/setup_scripts/lib/check_boot_device_layout.sh new file mode 100644 index 0000000..60f1cad --- /dev/null +++ b/setup_scripts/lib/check_boot_device_layout.sh @@ -0,0 +1,34 @@ +. lib/PATH_BOOT_DEVICE.sh +. lib/PATH_DEV.sh +. lib/PATH_EFI.sh +. lib/PATH_PARTITION_EFI.sh +. lib/PATH_PARTITION_RESCUE.sh +. lib/error.sh +. lib/try_quiet.sh + +check_boot_device_layout() { + local COUNT_NVME + COUNT_NVME=$(find "${PATH_DEV}" -maxdepth 1 -name 'nvme*n[0-9]' | wc -l) + [ "${COUNT_NVME}" -eq 1 ]\ + || error "expected 1 NVMe device in ${PATH_DEV}, found ${COUNT_NVME}" + [ -b "${PATH_BOOT_DEVICE}" ]\ + || error "NVMe device in ${PATH_DEV} not expected ${PATH_BOOT_DEVICE}" + + local COUNT_PARTITIONS + COUNT_PARTITIONS=$(find "${PATH_DEV}" -maxdepth 1 \ + -name "$(basename "${PATH_BOOT_DEVICE}")p[0-9]*" | wc -l) + [ "${COUNT_PARTITIONS}" -eq 3 ]\ + || error "expected 3 partitions on ${PATH_BOOT_DEVICE}, found ${COUNT_PARTITIONS}" + local IDX + for IDX in 1 2 3; do + [ -b "${PATH_BOOT_DEVICE}p${IDX}" ]\ + || error "missing expected partition ${PATH_BOOT_DEVICE}p${IDX}" + done + + try_quiet findmnt --source "${PATH_PARTITION_RESCUE}" --target /\ + || error "not running from expected rescue partition \ +${PATH_PARTITION_RESCUE} (mounted as /)" + try_quiet findmnt --source "${PATH_PARTITION_EFI}" --target "${PATH_EFI}"\ + || error "expected ${PATH_PARTITION_EFI} mounted at ${PATH_EFI}" +} + diff --git a/setup_scripts/lib/check_new_luksvg.sh b/setup_scripts/lib/check_new_luksvg.sh new file mode 100644 index 0000000..499ea73 --- /dev/null +++ b/setup_scripts/lib/check_new_luksvg.sh @@ -0,0 +1,15 @@ +. lib/NAME_LUKSVG.sh +. lib/error.sh +. lib/path_luks_mapper.sh +. lib/try_quiet.sh + +check_new_luksvg() { + local PATH_LUKS_MAPPER + PATH_LUKS_MAPPER=$(path_luks_mapper "${NAME_LUKSVG}") + try_quiet vgs "${NAME_LUKSVG}"\ + && error "volume group '${NAME_LUKSVG}' already exists" + [ -e "${PATH_LUKS_MAPPER}" ]\ + && error "${PATH_LUKS_MAPPER} already exists" + true +} + diff --git a/setup_scripts/lib/check_openable_luksvg.sh b/setup_scripts/lib/check_openable_luksvg.sh new file mode 100644 index 0000000..42383a1 --- /dev/null +++ b/setup_scripts/lib/check_openable_luksvg.sh @@ -0,0 +1,11 @@ +. lib/PATH_PARTITION_LUKSVG.sh +. lib/check_new_luksvg.sh +. lib/error.sh +. lib/try_quiet.sh + +check_openable_luksvg() { + check_new_luksvg + try_quiet cryptsetup isLuks "${PATH_PARTITION_LUKSVG}"\ + || error "${PATH_PARTITION_LUKSVG} not a LUKS container" +} + diff --git a/setup_scripts/lib/check_partition_mountable.sh b/setup_scripts/lib/check_partition_mountable.sh new file mode 100644 index 0000000..e0a71fa --- /dev/null +++ b/setup_scripts/lib/check_partition_mountable.sh @@ -0,0 +1,12 @@ +. lib/error.sh +. lib/try_quiet.sh + +check_partition_mountable() { + local PARTITION=$1 + [ -b "${PARTITION}" ]\ + || error "${PARTITION} is not a block device" + try_quiet findmnt --source "${PARTITION}"\ + && error "${PARTITION} is already mounted" + true +} + diff --git a/setup_scripts/lib/check_tools.sh b/setup_scripts/lib/check_tools.sh new file mode 100644 index 0000000..66c453c --- /dev/null +++ b/setup_scripts/lib/check_tools.sh @@ -0,0 +1,9 @@ +. lib/error.sh +. lib/try_quiet.sh + +check_tools() { + for CMD in "$@"; do + try_quiet command -v "${CMD}"\ + || error "required tool not found: ${CMD}" + done +} diff --git a/setup_scripts/lib/chroot_sh.sh b/setup_scripts/lib/chroot_sh.sh new file mode 100644 index 0000000..c9063ac --- /dev/null +++ b/setup_scripts/lib/chroot_sh.sh @@ -0,0 +1,6 @@ +. lib/PATH_MNT_CHROOT.sh + +chroot_sh() { + LANG=C.UTF-8 chroot "${PATH_MNT_CHROOT}" /bin/sh -c "$@" +} + diff --git a/setup_scripts/lib/close_luksvg.sh b/setup_scripts/lib/close_luksvg.sh new file mode 100644 index 0000000..d6deae1 --- /dev/null +++ b/setup_scripts/lib/close_luksvg.sh @@ -0,0 +1,8 @@ +. lib/NAME_LUKSVG.sh +. lib/msg.sh + +close_luksvg() { + msg 'Deactivating volume group and closing LUKS container …' + vgchange -an "${NAME_LUKSVG}" + cryptsetup luksClose "${NAME_LUKSVG}" +} diff --git a/setup_scripts/lib/create_lv.sh b/setup_scripts/lib/create_lv.sh new file mode 100644 index 0000000..5e8aef5 --- /dev/null +++ b/setup_scripts/lib/create_lv.sh @@ -0,0 +1,10 @@ +. lib/msg.sh + +create_lv() { + local VG=$1 + local LV=$2 + local SIZE=$3 + msg 'Creating logical volume "%s" inside volume group …' "${LV}" + lvcreate -L "${SIZE}" -n "${LV}" "${VG}" +} + diff --git a/setup_scripts/lib/die.sh b/setup_scripts/lib/die.sh new file mode 100644 index 0000000..e27bc0f --- /dev/null +++ b/setup_scripts/lib/die.sh @@ -0,0 +1,6 @@ +. lib/msg.sh + +die() { + msg '%s' "$*" >&2 + exit 1 +} diff --git a/setup_scripts/lib/disable_apt_recommends.sh b/setup_scripts/lib/disable_apt_recommends.sh new file mode 100644 index 0000000..658768a --- /dev/null +++ b/setup_scripts/lib/disable_apt_recommends.sh @@ -0,0 +1,9 @@ +. lib/msg.sh + +disable_apt_recommends() { + local PREFIX=${1:-} + local TARGET="${PREFIX}/etc/apt/apt.conf.d/90-no-recommends" + msg 'Disabling automatic installation of APT recommends …' + printf 'APT::Install-Recommends "false";\n' >| "${TARGET}" +} + diff --git a/setup_scripts/lib/efi_copy_kernel_vmlinuz.sh b/setup_scripts/lib/efi_copy_kernel_vmlinuz.sh new file mode 100644 index 0000000..7e8d5ef --- /dev/null +++ b/setup_scripts/lib/efi_copy_kernel_vmlinuz.sh @@ -0,0 +1,13 @@ +. lib/FNAME_INITRD.sh +. lib/FNAME_VMLINUZ.sh +. lib/msg.sh + +efi_copy_kernel_vmlinuz() { + local PATH_EFI_NAME_BOOT=$1 + local PREFIX=${2:-} + msg 'EFI setup: copying kernel and initrd into %s …' "${PATH_EFI_NAME_BOOT}" + for FILENAME in "${FNAME_INITRD}" "${FNAME_VMLINUZ}"; do + cp "${PREFIX}/${FILENAME}" "${PATH_EFI_NAME_BOOT}/" + done +} + diff --git a/setup_scripts/lib/error.sh b/setup_scripts/lib/error.sh new file mode 100644 index 0000000..05726b4 --- /dev/null +++ b/setup_scripts/lib/error.sh @@ -0,0 +1,5 @@ +. lib/die.sh + +error() { + die "error: $*" +} diff --git a/setup_scripts/lib/mount_privately.sh b/setup_scripts/lib/mount_privately.sh new file mode 100644 index 0000000..fd37cc8 --- /dev/null +++ b/setup_scripts/lib/mount_privately.sh @@ -0,0 +1,18 @@ +. lib/msg.sh + +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 + # to reach for closing their references e.g. into what we'll want to + # 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}" "${DEST}" + mkdir -p "${DEST}" + mount "${TO_MOUNT}" "${DEST}" +} diff --git a/setup_scripts/lib/msg.sh b/setup_scripts/lib/msg.sh new file mode 100644 index 0000000..a89952d --- /dev/null +++ b/setup_scripts/lib/msg.sh @@ -0,0 +1,6 @@ +. lib/msg_nonl.sh + +msg() { + msg_nonl "$@" + printf '\n' +} diff --git a/setup_scripts/lib/msg_nonl.sh b/setup_scripts/lib/msg_nonl.sh new file mode 100644 index 0000000..0ab0c11 --- /dev/null +++ b/setup_scripts/lib/msg_nonl.sh @@ -0,0 +1,7 @@ +msg_nonl() { + printf '[## %s ##] ' "${SCRIPT_NAME}" + # shellcheck disable=SC2059 + # (assume we'll always pass a literal format string) + printf -- "$@" +} + diff --git a/setup_scripts/lib/open_luksvg.sh b/setup_scripts/lib/open_luksvg.sh new file mode 100644 index 0000000..9335810 --- /dev/null +++ b/setup_scripts/lib/open_luksvg.sh @@ -0,0 +1,9 @@ +. lib/NAME_LUKSVG.sh +. lib/PATH_PARTITION_LUKSVG.sh +. lib/msg.sh + +open_luksvg() { + msg 'Opening LUKS container as "%s" …' "${NAME_LUKSVG}" + cryptsetup luksOpen "${PATH_PARTITION_LUKSVG}" "${NAME_LUKSVG}" +} + diff --git a/setup_scripts/lib/path_luks_mapper.sh b/setup_scripts/lib/path_luks_mapper.sh new file mode 100644 index 0000000..f4c456d --- /dev/null +++ b/setup_scripts/lib/path_luks_mapper.sh @@ -0,0 +1,5 @@ +. lib/PATH_DEV.sh + +path_luks_mapper() { + printf '%s/mapper/%s' "${PATH_DEV}" "$1" +} diff --git a/setup_scripts/lib/path_vg.sh b/setup_scripts/lib/path_vg.sh new file mode 100644 index 0000000..6b62b48 --- /dev/null +++ b/setup_scripts/lib/path_vg.sh @@ -0,0 +1,6 @@ +. lib/PATH_DEV.sh + +path_vg() { + printf '%s/%s' "${PATH_DEV}" "$1" +} + diff --git a/setup_scripts/lib/rbind_mnt.sh b/setup_scripts/lib/rbind_mnt.sh new file mode 100644 index 0000000..5018b62 --- /dev/null +++ b/setup_scripts/lib/rbind_mnt.sh @@ -0,0 +1,14 @@ +. lib/PATH_MNT_CHROOT.sh +. lib/TO_RBIND.sh +. lib/msg.sh + +rbind_mnt() { + for NAME in ${TO_RBIND}; do + local PATH_NAME="/${NAME}" + local SLAVE="${PATH_MNT_CHROOT}${PATH_NAME}" + msg 'For working chroot also mounting %s into there …' "${PATH_NAME}" + mount --rbind "${PATH_NAME}" "${SLAVE}" + mount --make-rslave "${SLAVE}" + done +} + diff --git a/setup_scripts/lib/render_template.sh b/setup_scripts/lib/render_template.sh new file mode 100644 index 0000000..8b6d452 --- /dev/null +++ b/setup_scripts/lib/render_template.sh @@ -0,0 +1,11 @@ +. lib/PATH_REPO.sh + +render_template() { + local PATH_TEMPLATE="${PATH_REPO}/templates/$1" + # eval'd instead of just `cat`, so ${...}/$(...) inside the template + # get expanded against the calling script's own variables, exactly as + # if its content were still an inline heredoc in that script. + eval "cat </dev/null 2>&1 +} diff --git a/setup_scripts/lib/unmount_unrbind.sh b/setup_scripts/lib/unmount_unrbind.sh new file mode 100644 index 0000000..a410614 --- /dev/null +++ b/setup_scripts/lib/unmount_unrbind.sh @@ -0,0 +1,12 @@ +. lib/PATH_MNT_CHROOT.sh +. lib/TO_RBIND.sh +. lib/msg.sh + +unmount_unrbind() { + msg 'Unmounting chroot environment …' + for NAME in ${TO_RBIND}; do + umount -R "${PATH_MNT_CHROOT}/${NAME}" + done + umount "${PATH_MNT_CHROOT}" +} + diff --git a/setup_scripts/lib/usage.sh b/setup_scripts/lib/usage.sh new file mode 100644 index 0000000..4e8f5b6 --- /dev/null +++ b/setup_scripts/lib/usage.sh @@ -0,0 +1,12 @@ +. lib/die.sh + +usage() { + local COUNT_INPUTS=$1 + shift + local MSG="usage: ${SCRIPT_NAME}" + for PARAMETER in "$@"; do + MSG="${MSG} <${PARAMETER}>" + done + [ "${COUNT_INPUTS}" -eq $# ]\ + || die "${MSG}" +} diff --git a/setup_scripts/setup_git_mirror.sh b/setup_scripts/setup_git_mirror.sh index e531f1a..8f7b10d 100755 --- a/setup_scripts/setup_git_mirror.sh +++ b/setup_scripts/setup_git_mirror.sh @@ -1,13 +1,20 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" +. lib/DIRNAME_REPO.sh +. lib/PATH_REPO.sh +. lib/USERNAME.sh +. lib/error.sh +. lib/msg.sh +. lib/render_template.sh # constants we might want to change at some point PATH_GIT_BASE=/srv/git # constants derived from changeables -PATH_GIT_DAEMON_UNIT=/etc/systemd/system/git-daemon.service +FNAME_GIT_DAEMON_UNIT=git-daemon.service +PATH_GIT_DAEMON_UNIT="/etc/systemd/system/${FNAME_GIT_DAEMON_UNIT}" PATH_GIT_MIRROR="${PATH_GIT_BASE}/${DIRNAME_REPO}.git" -PATH_TEMPLATE_GIT_DAEMON="${PATH_TEMPLATES}/git-daemon.service" +PATH_GIT_MIRROR_EXPORT_OK="${PATH_GIT_MIRROR}/git-daemon-export-ok" [ -e "${PATH_GIT_MIRROR}" ]\ && error "${PATH_GIT_MIRROR} already exists" @@ -19,13 +26,13 @@ apt-get -y install git msg 'Bare-cloning repo to %s for anonymous serving …' "${PATH_GIT_MIRROR}" mkdir -p "${PATH_GIT_BASE}" git clone --quiet --bare "${PATH_REPO}" "${PATH_GIT_MIRROR}" -touch "${PATH_GIT_MIRROR}/git-daemon-export-ok" +touch "${PATH_GIT_MIRROR_EXPORT_OK}" msg 'Own repo to %s so they can update it via ssh …' "${USERNAME}" chown -R "${USERNAME}:${USERNAME}" "${PATH_GIT_MIRROR}" msg 'Writing and enabling git-daemon systemd unit …' -render_template "${PATH_TEMPLATE_GIT_DAEMON}" >| "${PATH_GIT_DAEMON_UNIT}" +render_template "${FNAME_GIT_DAEMON_UNIT}" >| "${PATH_GIT_DAEMON_UNIT}" systemctl daemon-reload systemctl enable --now git-daemon diff --git a/setup_scripts/setup_luksvg.sh b/setup_scripts/setup_luksvg.sh index 76377d7..f71d8d7 100755 --- a/setup_scripts/setup_luksvg.sh +++ b/setup_scripts/setup_luksvg.sh @@ -1,12 +1,32 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" +. lib/NAME_DATA.sh +. lib/NAME_LUKSVG.sh +. lib/NAME_SWAP.sh +. lib/PATH_MNT.sh +. lib/PATH_DATA.sh +. lib/PATH_PARTITION_LUKSVG.sh +. lib/check_boot_device_layout.sh +. lib/check_partition_mountable.sh +. lib/check_new_luksvg.sh +. lib/check_tools.sh +. lib/close_luksvg.sh +. lib/create_lv.sh +. lib/die.sh +. lib/error.sh +. lib/msg.sh +. lib/msg_nonl.sh +. lib/open_luksvg.sh +. lib/mount_privately.sh +. lib/path_vg.sh +. lib/try_quiet.sh # inputs to confirm usage $# # constants derived from changeables PATH_LUKS_MAPPER=$(path_luks_mapper "${NAME_LUKSVG}") -PATH_MNT_DATA="${PATH_MNT}/${NAME_DATA}" +PATH_MNT_DATA="${PATH_MNT}${PATH_DATA}" PATH_VG=$(path_vg "${NAME_LUKSVG}") PATH_VG_DATA=${PATH_VG}/${NAME_DATA} PATH_VG_SWAP=${PATH_VG}/${NAME_SWAP} diff --git a/setup_scripts/start_root_server.sh b/setup_scripts/start_root_server.sh index 21bbc5b..da5effe 100755 --- a/setup_scripts/start_root_server.sh +++ b/setup_scripts/start_root_server.sh @@ -1,5 +1,12 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" +. lib/DIRNAME_SSH.sh +. lib/PATH_MY_SSH.sh +. lib/USERNAME.sh +. lib/disable_apt_recommends.sh +. lib/msg.sh +. lib/retry_until_success.sh +. lib/start_root.sh # constants unlikely to change PATH_SSHD_DROPIN=/etc/ssh/sshd_config.d/60-ssh-hardening.conf diff --git a/setup_scripts/start_root_t490s.sh b/setup_scripts/start_root_t490s.sh index 8a93697..dea9f15 100755 --- a/setup_scripts/start_root_t490s.sh +++ b/setup_scripts/start_root_t490s.sh @@ -1,14 +1,22 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" +. lib/DIRNAME_SCRIPTS.sh +. lib/PATH_FIRST_BOOT_PENDING.sh +. lib/PATH_REPO.sh +. lib/msg.sh +. lib/start_root.sh +. lib/render_template.sh # constants unlikely to change PATH_DEFAULT_LOCALE=/etc/default/locale -PATH_HOOK_UPDATE_EFI=/etc/initramfs/post-update.d/update-efi +PATH_HOOK_EFI=/etc/initramfs/post-update.d/update-efi PATH_SYSCTL_PRINTK=/etc/sysctl.d/60-printk-console.conf PATH_TLP_THRESH_CONF=/etc/tlp.conf.d/60-thresholds.conf PATH_UDEV_RULES=/etc/udev/rules.d # constants we might want to change at some point +DIRNAME_TO_COPY=to_copy +FNAME_SCRIPT_EFI=update_efi.sh FNAME_UDEV_RULES_BACKLIGHT=90-backlight.rules LOCALE=C.UTF-8 PRINTK_LEVELS="4 4 1 7" @@ -16,16 +24,16 @@ TLP_THRESH_START=40 TLP_THRESH_STOP=80 # constants derived from changeables -PATH_TO_COPY="${PATH_REPO}/to_copy" +PATH_TO_COPY="${PATH_REPO}/${DIRNAME_TO_COPY}" # shellcheck disable=SC2034 # (used only inside templates/update-efi-hook, rendered via render_template) -PATH_UPDATE_EFI_SCRIPT="${PATH_SCRIPTS}/update_efi.sh" +PATH_SCRIPT_EFI="${PATH_REPO}/${DIRNAME_SCRIPTS}/${FNAME_SCRIPT_EFI}" # before any apt-get call gets a chance to pull in a kernel update of its own … msg 'Installing initramfs hook to refresh EFI boot files on kernel updates …' -mkdir -p "$(dirname "${PATH_HOOK_UPDATE_EFI}")" -render_template "${PATH_TEMPLATES}/update-efi-hook" >| "${PATH_HOOK_UPDATE_EFI}" -chmod +x "${PATH_HOOK_UPDATE_EFI}" +mkdir -p "$(dirname "${PATH_HOOK_EFI}")" +render_template "update-efi-hook" >| "${PATH_HOOK_EFI}" +chmod +x "${PATH_HOOK_EFI}" start_root t490s diff --git a/setup_scripts/start_user.sh b/setup_scripts/start_user.sh index 778d1d4..fdb3f58 100755 --- a/setup_scripts/start_user.sh +++ b/setup_scripts/start_user.sh @@ -1,8 +1,14 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" +. lib/PATH_REPO.sh +. lib/augment_profile.sh +. lib/msg.sh # constants we might want to change at some point -PATH_SKEL_USER="${PATH_REPO}/home_user" +DIRNAME_HOME_USER=home_user + +# constants derived from changeables +PATH_SKEL_USER="${PATH_REPO}/${DIRNAME_HOME_USER}" augment_profile msg 'Linking %s files into home directory …' "${PATH_SKEL_USER}" diff --git a/setup_scripts/update_efi.sh b/setup_scripts/update_efi.sh index cb345c1..8ca452b 100755 --- a/setup_scripts/update_efi.sh +++ b/setup_scripts/update_efi.sh @@ -1,5 +1,10 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" +. lib/PATH_PARTITION_EFI.sh +. lib/check_partition_mountable.sh +. lib/efi_copy_kernel_vmlinuz.sh +. lib/msg.sh +. lib/usage.sh usage $# diff --git a/templates/fstab b/templates/fstab index 44d6fb4..302225a 100644 --- a/templates/fstab +++ b/templates/fstab @@ -1,3 +1,3 @@ ${PATH_VG_ROOT} / ext4 errors=remount-ro 0 1 -${PATH_VG_DATA} /${NAME_DATA} ext4 errors=remount-ro 0 2 +${PATH_VG_DATA} ${PATH_DATA} ext4 errors=remount-ro 0 2 ${PATH_VG_SWAP} none swap sw 0 0 diff --git a/templates/update-efi-hook b/templates/update-efi-hook index ce241f3..6af5308 100644 --- a/templates/update-efi-hook +++ b/templates/update-efi-hook @@ -1,2 +1,2 @@ #!/bin/sh -exec "${PATH_UPDATE_EFI_SCRIPT}" +exec "${PATH_SCRIPT_EFI}"