From: Christian Heller Date: Wed, 16 Apr 2025 05:02:31 +0000 (+0200) Subject: Fix. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/conditions?a=commitdiff_plain;h=e241cf8a240d541e55cd5aef28b9d0d5b1789a1a;p=config Fix. --- diff --git a/bookworm/aptmark/all b/bookworm/aptmark/all index 68791c8..e56c358 100644 --- a/bookworm/aptmark/all +++ b/bookworm/aptmark/all @@ -13,4 +13,7 @@ iputils-ping ntpsec-ntpdate # generally used in my scripts, so necessary calc +# generally useful for debugging, so necessary +vim +ack # diff --git a/bookworm/scripts/lib/chown_to_user b/bookworm/scripts/lib/chown_to_user deleted file mode 100644 index 2463d76..0000000 --- a/bookworm/scripts/lib/chown_to_user +++ /dev/null @@ -1,9 +0,0 @@ -. lib/constants_user # USERNAME - -chown_to_user() { - if [ ! -z "$@" ]; then - for _PATH in $@; do - chown -R "${USERNAME}:${USERNAME}" "${_PATH}" - done - fi -} diff --git a/bookworm/scripts/lib/copy_dirtree b/bookworm/scripts/lib/copy_dirtree index 44b9f2b..5c7a227 100644 --- a/bookworm/scripts/lib/copy_dirtree +++ b/bookworm/scripts/lib/copy_dirtree @@ -1,10 +1,12 @@ . lib/expect_n_args +. lib/mkdir_p_for_user copy_dirtree() { - expect_n_args 3 99 'SOURCE_ROOT TARGET_ROOT TAG...' $@ - _SOURCE_ROOT="$1" - _TARGET_ROOT="$2" - shift 2 + expect_n_args 4 99 'OWNER_TO_ENFORCE (to ignore, pass empty string) SOURCE_ROOT TARGET_ROOT TAG...' $@ + _OWNER="$1" + _SOURCE_ROOT="$2" + _TARGET_ROOT="$3" + shift 3 _TAGS="$@" for _TAG in ${_TAGS}; do _PATH_TAG="${_SOURCE_ROOT}/${_TAG}" @@ -16,8 +18,13 @@ copy_dirtree() { _PATH_TARGET="${_TARGET_ROOT}"$(echo "${_PATH_REL}" | cut -c2-) _PATH_SOURCE=$(realpath "${_PATH_REL}") _DIRECTORY=$(dirname "${_PATH_TARGET}") - mkdir -p "${_DIRECTORY}" + if [ ! -z "${_OWNER}" ]; then + mkdir_p_for_user "${_OWNER}" "${_DIRECTORY}" + fi cp -av "${_PATH_SOURCE}" "${_PATH_TARGET}" + if [ ! -z "${_OWNER}" ]; then + chown "${_OWNER}:${_OWNER}" "${_PATH_TARGET}" + fi done cd - > /dev/null done diff --git a/bookworm/scripts/lib/ensure_etc_of_tags b/bookworm/scripts/lib/ensure_etc_of_tags index deab16c..410a677 100644 --- a/bookworm/scripts/lib/ensure_etc_of_tags +++ b/bookworm/scripts/lib/ensure_etc_of_tags @@ -1,8 +1,8 @@ . lib/copy_dirtree -. lib/constants_etc # PATH_ETC, PATH_REL_ETC +. lib/constants_etc # PATH_ETC, PATH_REL_ETC . lib/constants_repopaths # PATH_CONF ensure_etc_of_tags() { _PATH_CONF_ETC="${PATH_CONF}/${PATH_REL_ETC}" - copy_dirtree "${_PATH_CONF_ETC}" "${PATH_ETC}" $@ + copy_dirtree '' "${_PATH_CONF_ETC}" "${PATH_ETC}" $@ } diff --git a/bookworm/scripts/lib/ensure_homefiles_of_tags b/bookworm/scripts/lib/ensure_homefiles_of_tags index 4d54843..4726fed 100644 --- a/bookworm/scripts/lib/ensure_homefiles_of_tags +++ b/bookworm/scripts/lib/ensure_homefiles_of_tags @@ -1,10 +1,6 @@ -. lib/chown_to_user -. lib/constants_user # PATH_USER_HOME +. lib/constants_user # PATH_USER_HOME, USERNAME . lib/constants_repopaths # PATH_CONF_HOME ensure_homefiles_of_tags() { - _TO_CHOWN=$(copy_dirtree "${PATH_CONF_HOME}" "${PATH_USER_HOME}" $@ | sed "s/.*' -> '//g" | sed -E "s/'$//g") - echo ${_TO_CHOWN} | while read _LINE; do - chown_to_user "${_LINE}" - done + copy_dirtree "${USERNAME}" "${PATH_CONF_HOME}" "${PATH_USER_HOME}" $@ } diff --git a/bookworm/scripts/lib/mkdir_p_for_user b/bookworm/scripts/lib/mkdir_p_for_user new file mode 100644 index 0000000..0fde79a --- /dev/null +++ b/bookworm/scripts/lib/mkdir_p_for_user @@ -0,0 +1,10 @@ +mkdir_p_for_user() { + _USER="$1" + _TO_SHORTEN=$(mkdir -pv "$1" | sed "s/mkdir: created directory '//g" | head -1) + if [ -z "${_TO_SHORTEN}" ]; then + _LENGTH=$(echo -n "${_TO_SHORTEN}" | wc -c) + _TARGET_LENGTH=$(calc "${_LENGTH} - 1" | cut -f2) + _TARGET_DIR=$(echo "${_TO_SHORTEN}" | cut -c "-${_TARGET_LENGTH}") + chown -R "${_USER}:${_USER}" "${_TARGET_DIR}" + fi +} diff --git a/bookworm/scripts/lib/mkdir_p_print_top b/bookworm/scripts/lib/mkdir_p_print_top deleted file mode 100644 index abacef9..0000000 --- a/bookworm/scripts/lib/mkdir_p_print_top +++ /dev/null @@ -1,10 +0,0 @@ -mkdir_p_print_top() { - _TO_SHORTEN=$(mkdir -pv "$1" | sed "s/mkdir: created directory '//g" | head -1) - if [ -z "${_TO_SHORTEN}" ]; then - echo '' - else - _LENGTH=$(echo -n "${_TO_SHORTEN}" | wc -c) - _TARGET_LENGTH=$(calc "${_LENGTH} - 1" | cut -f2) - echo "${_TO_SHORTEN}" | cut -c "-${_TARGET_LENGTH}" - fi -} diff --git a/bookworm/scripts/lib/setup_users b/bookworm/scripts/lib/setup_users index 59df47f..94f86ff 100644 --- a/bookworm/scripts/lib/setup_users +++ b/bookworm/scripts/lib/setup_users @@ -1,9 +1,8 @@ -. lib/chown_to_user . lib/copy_dirtree . lib/constants_repopaths # PATH_CONF_HOME . lib/constants_user # PATH_USER_HOME, USERNAME . lib/ensure_homefiles_of_tags -. lib/mkdir_p_print_top +. lib/mkdir_p_for_user setup_users() { _MIN_TAGS="$1" @@ -11,16 +10,15 @@ setup_users() { _PATH_USER_BIN="${PATH_USER_HOME}/.local/bin" echo "\nSetting up root user's home directory." - copy_dirtree "${PATH_CONF_HOME}" '/root' ${_MIN_TAGS} root + copy_dirtree 'root' "${PATH_CONF_HOME}" '/root' ${_MIN_TAGS} root echo "\nSetting up user ${USERNAME}." adduser --disabled-password --gecos "" "${USERNAME}" usermod -a -G sudo "${USERNAME}" ensure_homefiles_of_tags ${_MIN_TAGS} ${_TAGS_USER} - copy_dirtree "${PATH_CONF_HOME}" "${PATH_USER_HOME}" ${_MIN_TAGS} ${_TAGS_USER} - _TO_CHOWN=$(mkdir_p_print_top "${_PATH_USER_BIN}") + mkdir_p_for_user "${USERNAME}" "${_PATH_USER_BIN}" cd "${_PATH_USER_BIN}" ln -s ../../.plomlib lib - chown_to_user "${_TO_CHOWN}" + chown "${USERNAME}:${USERNAME}" lib cd - > /dev/null } diff --git a/bookworm/scripts/setup_catgirl.sh b/bookworm/scripts/setup_catgirl.sh index c70655b..dd4b45d 100755 --- a/bookworm/scripts/setup_catgirl.sh +++ b/bookworm/scripts/setup_catgirl.sh @@ -2,14 +2,13 @@ set -e cd $(dirname "$0") . lib/check_finished_marker -. lib/chown_to_user . lib/constants_catgirl # PATH_USER_SHARE_CATGIRL -. lib/constants_user # PATH_USER_HOME +. lib/constants_user # PATH_USER_HOME, USERNAME . lib/ensure_etc_of_tags . lib/ensure_homefiles_of_tags . lib/ensure_packages_of_tags . lib/expect_n_args -. lib/mkdir_p_print_top +. lib/mkdir_p_for_user check_finished_marker 'setup_server' expect_n_args 1 1 'IRC_PASSWORD' $@ @@ -23,13 +22,11 @@ ensure_etc_of_tags catgirl ensure_homefiles_of_tags catgirl echo "\nSetting up ${PATH_USER_SHARE_CATGIRL} so logs can go there." -TO_CHOWN=$(mkdir_p_print_top "${PATH_USER_SHARE_CATGIRL}") -chown_to_user "${TO_CHOWN}" +mkdir_p_for_user "${USERNAME}" "${PATH_USER_SHARE_CATGIRL}" echo "\nWriting provided password into ${PATH_USER_CONF_CATGIRL}." sed -i "s/REPLACE_WITH_IRC_PASSWORD/${IRC_PASSWORD}/g" "${PATH_USER_CONF_CATGIRL}" -chown_to_user "${PATH_USER_SHARE_CATGIRL}" -chown -R plom:plom "${PATH_USER_SHARE_CATGIRL}" +chown -R "${USERNAME}:${USERNAME}" "${PATH_USER_SHARE_CATGIRL}" echo "\nActivating catgirl tmux session service." systemctl enable --now catgirl diff --git a/bookworm/scripts/setup_server.sh b/bookworm/scripts/setup_server.sh index 88687a1..421068b 100755 --- a/bookworm/scripts/setup_server.sh +++ b/bookworm/scripts/setup_server.sh @@ -47,7 +47,7 @@ setup_users "${MIN_TAGS}" '' echo '\nMoving SSH data from root to user.' mkdir -p "${PATH_USER_SSH}" mv "/root/${PATH_REL_SSH}/authorized_keys" "${PATH_USER_SSH}/" -chown_to_user "${PATH_USER_SSH}" +chown -R "${USERNAME}:${USERNAME}" "${PATH_USER_SSH}" echo '\nSetting up minimal borg user.' adduser --system --home "${PATH_BORG_HOME}" --shell /bin/sh borg diff --git a/testing/scripts/lib/chown_to_user b/testing/scripts/lib/chown_to_user deleted file mode 120000 index d23376e..0000000 --- a/testing/scripts/lib/chown_to_user +++ /dev/null @@ -1 +0,0 @@ -../../../bookworm/scripts/lib/chown_to_user \ No newline at end of file diff --git a/testing/scripts/lib/mkdir_p_for_user b/testing/scripts/lib/mkdir_p_for_user new file mode 120000 index 0000000..57cee0e --- /dev/null +++ b/testing/scripts/lib/mkdir_p_for_user @@ -0,0 +1 @@ +../../../bookworm/scripts/lib/mkdir_p_for_user \ No newline at end of file diff --git a/testing/scripts/lib/mkdir_p_print_top b/testing/scripts/lib/mkdir_p_print_top deleted file mode 120000 index ab3ae3b..0000000 --- a/testing/scripts/lib/mkdir_p_print_top +++ /dev/null @@ -1 +0,0 @@ -../../../bookworm/scripts/lib/mkdir_p_print_top \ No newline at end of file diff --git a/testing/scripts/setup_secrets.sh b/testing/scripts/setup_secrets.sh index 68e77ba..67c29e9 100755 --- a/testing/scripts/setup_secrets.sh +++ b/testing/scripts/setup_secrets.sh @@ -3,7 +3,6 @@ set -e cd $(dirname "$0") . lib/abort_if_not_user . lib/check_finished_marker -. lib/chown_to_user . lib/constants_repopaths # PATH_CONF, PATH_SCRIPTS . lib/constants_user # USERNAME . lib/path_tmp_timestamped @@ -16,6 +15,6 @@ PATH_TMP_REPO="$(path_tmp_timestamped configrepo)" echo "Setting up config repo copy for user at ${PATH_TMP_REPO} …" cp -a "${PATH_REPO}" "${PATH_TMP_REPO}" -chown_to_user "${PATH_TMP_REPO}" +chown -R "${USERNAME}:${USERNAME}" "${PATH_TMP_REPO}" su -l "${USERNAME}" -c "/bin/sh ${PATH_TMP_REPO}/${PATH_REL_SETUP_SECRETS_USER} $1" rm -rf "${PATH_TMP_REPO}"