From 1466fdcb012194317c7dcb46dd045cc6b1029c71 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 31 Mar 2025 10:01:29 +0200 Subject: [PATCH] Fixes. --- bookworm/scripts/lib/init_packages | 38 ++++++++++++++++++++++++++++++ bookworm/scripts/lib/setup_users | 17 +++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 bookworm/scripts/lib/init_packages create mode 100644 bookworm/scripts/lib/setup_users diff --git a/bookworm/scripts/lib/init_packages b/bookworm/scripts/lib/init_packages new file mode 100644 index 0000000..0264f74 --- /dev/null +++ b/bookworm/scripts/lib/init_packages @@ -0,0 +1,38 @@ +init_packages() { + echo "\nInstalling and/or keeping only what's required by us or Debian." + MIN_TAGS="$1" + export DEBIAN_FRONTEND=noninteractive + + # mark non-requireds auto + PATH_LIST_PREFIX=/tmp/list_ + PATH_LIST_UNSORTED="${PATH_LIST_PREFIX}unsorted" + PATH_LIST_ALL_PACKAGES="${PATH_LIST_PREFIX}all_packages" + PATH_LIST_WHITE="${PATH_LIST_PREFIX}white" + PATH_LIST_BLACK="${PATH_LIST_PREFIX}black" + TOK_REQ=' required' + dpkg-query -Wf '${Package} ${Priority}\n' | grep "${TOK_REQ}" | sed "s/${TOK_REQ}//" > "${PATH_LIST_UNSORTED}" + sort "${PATH_LIST_UNSORTED}" | uniq > "${PATH_LIST_WHITE}" + dpkg-query -Wf '${Package}\n' > "${PATH_LIST_UNSORTED}" + sort "${PATH_LIST_UNSORTED}" | uniq > "${PATH_LIST_ALL_PACKAGES}" + comm -3 "${PATH_LIST_ALL_PACKAGES}" "${PATH_LIST_WHITE}" > "${PATH_LIST_BLACK}" + apt-mark auto `cat "${PATH_LIST_BLACK}"` + rm "${PATH_LIST_UNSORTED}" "${PATH_LIST_ALL_PACKAGES}" "${PATH_LIST_WHITE}" "${PATH_LIST_BLACK}" + + # Walk through the package names in ../aptmark/ files to ensure the respective + # packages are installed. + for TAG in $@; do + PATH_APTMARK_TAG="../aptmark/${TAG}" + if [ ! -f "${PATH_APTMARK_TAG}" ]; then + continue + fi + cat "${PATH_APTMARK_TAG}" | while read LINE; do + if [ ! $(echo "${LINE}" | cut -c1) = "#" ]; then + apt-get -y -o Dpkg::Options::="--force-confnew" install "${LINE}" + fi + done + done + + apt -y --purge autoremove + echo read "DEBUG: Check if this makes a difference …" + apt -y dist-upgrade +} diff --git a/bookworm/scripts/lib/setup_users b/bookworm/scripts/lib/setup_users new file mode 100644 index 0000000..8604a3a --- /dev/null +++ b/bookworm/scripts/lib/setup_users @@ -0,0 +1,17 @@ +. lib/copy_dirtree + +setup_users() { + USERNAME="$1" + MIN_TAGS="$2" + PATH_CONF_HOME=../home + PATH_USER_HOME=/home/"${USERNAME}" + + echo "\nSetting up root user's home directory." + copy_dirtree "${PATH_CONF_HOME}" '/root' ${MIN_TAGS} root + + echo "\nSetting up user ${USERNAME}." + adduser --disabled-password --gecos "" "${USERNAME}" + usermod -a -G sudo "${USERNAME}" + copy_dirtree "${PATH_CONF_HOME}" "${PATH_USER_HOME}" ${MIN_TAGS} user + chown -R "${USERNAME}:${USERNAME}" "${PATH_USER_HOME}" +} -- 2.30.2