From e194886ae8946392eb0524143532565ba1428362 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 25 Feb 2025 03:18:40 +0100 Subject: [PATCH] Improve testing setup. --- constants.sh | 16 ++++----- many_releases/scripts/_misc.sh | 10 +++--- testing/scripts/misc.sh | 29 +++++++++++++++ testing/scripts/setup_desktop.sh | 60 ++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 testing/scripts/misc.sh create mode 100644 testing/scripts/setup_desktop.sh diff --git a/constants.sh b/constants.sh index 2cf8718..3c52e61 100755 --- a/constants.sh +++ b/constants.sh @@ -2,11 +2,11 @@ set -e set -x -PATH_REL_ETC="/etc" -PATH_REL_APTMARK="/aptmark" -PATH_REL_REPO="/config" -PATH_REL_HOME="/home" -PATH_REPO="${HOME}${PATH_REL_REPO}" +PATH_REL_ETC="etc" +PATH_REL_APTMARK="aptmark" +PATH_REL_REPO="config" +PATH_REL_HOME="home" +PATH_REPO="${HOME}/${PATH_REL_REPO}" PATH_MANY="${PATH_REPO}/many_releases" PATH_MANY_MISC="${PATH_MANY}/scripts/_misc.sh" @@ -15,8 +15,8 @@ PATH_USER_HOME="/home/${USERNAME}" FILENAME_PUBLIC_KEY='id_rsa.pub' URL_PUBLIC_KEY="https://dump.plomlompom.com/dump/${FILENAME_PUBLIC_KEY}" -PATH_REL_LOCAL_SSH="/.ssh" +PATH_REL_LOCAL_SSH=".ssh" PATH_REL_AUTHORIZED_KEYS="${PATH_REL_LOCAL_SSH}/authorized_keys" -PATH_AUTHORIZED_KEYS="${HOME}${PATH_REL_AUTHORIZED_KEYS}" -PATH_USER_SSH="${PATH_USER_HOME}${PATH_REL_LOCAL_SSH}" +PATH_AUTHORIZED_KEYS="${HOME}/${PATH_REL_AUTHORIZED_KEYS}" +PATH_USER_SSH="${PATH_USER_HOME}/${PATH_REL_LOCAL_SSH}" diff --git a/many_releases/scripts/_misc.sh b/many_releases/scripts/_misc.sh index aed1526..8cf0ca7 100755 --- a/many_releases/scripts/_misc.sh +++ b/many_releases/scripts/_misc.sh @@ -125,16 +125,16 @@ setup_for_raspi() { # properly configure apt and reduce system to minimum that satisfies our own # aptmark/ package lists for root in "${PATH_MANY}" '..'; do - copy_dirtree "${root}${PATH_REL_ETC}/all" '/etc/apt' apt + copy_dirtree "${root}/${PATH_REL_ETC}/all" '/etc/apt' apt done apt update mark_nonrequireds_auto for root in "${PATH_MANY}" '..'; do - install_for_modules "${root}${PATH_REL_APTMARK}" all raspi + install_for_modules "${root}/${PATH_REL_APTMARK}" all raspi done apt -y --purge autoremove for root in "${PATH_MANY}" '..'; do - copy_dirtree "${root}${PATH_REL_ETC}" '/etc' all raspi + copy_dirtree "${root}/${PATH_REL_ETC}" '/etc' all raspi done # Ensure our desired locale is available. @@ -149,14 +149,14 @@ setup_for_raspi() { # Set up root environment. for root in "${PATH_MANY}" '..'; do - copy_dirtree "${root}${PATH_REL_HOME}" '/root' all root raspi_root + copy_dirtree "${root}/${PATH_REL_HOME}" '/root' all root raspi_root done # Set up user and their environment. adduser --disabled-password --gecos "" "${USERNAME}" usermod -a -G sudo "${USERNAME}" for root in "${PATH_MANY}" '..'; do - copy_dirtree "${root}${PATH_REL_HOME}" "${PATH_USER_HOME}" all desktop raspi + copy_dirtree "${root}/${PATH_REL_HOME}" "${PATH_USER_HOME}" all desktop raspi done mkdir "${PATH_USER_SSH}" cp "${PATH_AUTHORIZED_KEYS}" "${PATH_USER_SSH}" diff --git a/testing/scripts/misc.sh b/testing/scripts/misc.sh new file mode 100644 index 0000000..ad1d4d6 --- /dev/null +++ b/testing/scripts/misc.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e +set -x + +. ../../constants.sh +. "${PATH_MANY_MISC}" + +repo_path="${HOME}/public_repos/${PATH_REL_REPO}" +if [ ! -d "${repo_path}" ]; then + repo_path="${HOME}/${PATH_REL_REPO}" +fi +config_tree_prefix="${repo_path}/testing" +setup_scripts_dir="${config_tree_prefix}/scripts" + +get_system_name_arg() { + legal_system_names="t490s" + found=0 + for system_name_i in $legal_system_names; do + if [ "$1" = "$system_name_i" ]; then + found=1 + system_name="${system_name_i}" + continue + fi + done + if [ "$found" = 0 ]; then + echo "Need legal system name." + false + fi +} diff --git a/testing/scripts/setup_desktop.sh b/testing/scripts/setup_desktop.sh new file mode 100644 index 0000000..b3e5e11 --- /dev/null +++ b/testing/scripts/setup_desktop.sh @@ -0,0 +1,60 @@ +#!/bin/sh +set -e +. ./misc.sh + +expect_n_args 1 "(system name)" "$@" +get_system_name_arg "$1" + +# Adapt /etc/ to our needs by copying from ./etc_files. This will set +# basic configurations affecting following steps, such as setup of APT +# and the locale selection, so needs to be right at the beginning. +copy_dirtree.sh "${config_tree_prefix}/${PATH_REL_ETC}" "" all + +# Migrate to testing. +upgrade_from_older_release + +# Set hostname and FQDN. +echo "${system_name}" > /etc/hostname +hostname "${system_name}" +final_ip="127.0.1.1" +for ip in $(hostname -I); do + if [ $(echo "${ip}" | grep ':' | wc -l) -eq 1 ]; then + continue + fi + range_1=$(echo "${ip}" | cut -d "." -f 1) + range_2=$(echo "${ip}" | cut -d "." -f 2) + if [ "${range_1}" -eq 127 ]; then + continue + elif [ "${range_1}" -eq 10 ]; then + continue + elif [ "${range_1}" -eq 172 ]; then + if [ "${range_2}" -ge 16 ] && [ "${range_2}" -le 31 ]; then + continue + fi + elif [ "${range_1}" -eq 192 ]; then + if [ "${range_2}" -eq 168 ]; then + continue + fi + fi + final_ip="${ip}" +done +echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts +echo "${final_ip} ${system_name}" >> /etc/hosts + +# Ensure package installation state as defined by what packages are +# defined as required by Debian policy and by settings in ./apt-mark/. +mark_nonrequireds_auto +for root in "${PATH_MANY}" '..'; do + install_for_modules "${root}/${PATH_REL_APTMARK}" all +done +apt -y --purge autoremove +for root in "${PATH_MANY}" '..'; do + copy_dirtree "${root}/${PATH_REL_ETC}" '/etc' all +done + +# Ensure our desired locale is available. +locale-gen + +# Set Berlin localtime. +ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime +ntpdate-debian -- 2.30.2