home · contact · privacy
Fix.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 16 Apr 2025 05:02:31 +0000 (07:02 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 16 Apr 2025 05:02:31 +0000 (07:02 +0200)
14 files changed:
bookworm/aptmark/all
bookworm/scripts/lib/chown_to_user [deleted file]
bookworm/scripts/lib/copy_dirtree
bookworm/scripts/lib/ensure_etc_of_tags
bookworm/scripts/lib/ensure_homefiles_of_tags
bookworm/scripts/lib/mkdir_p_for_user [new file with mode: 0644]
bookworm/scripts/lib/mkdir_p_print_top [deleted file]
bookworm/scripts/lib/setup_users
bookworm/scripts/setup_catgirl.sh
bookworm/scripts/setup_server.sh
testing/scripts/lib/chown_to_user [deleted symlink]
testing/scripts/lib/mkdir_p_for_user [new symlink]
testing/scripts/lib/mkdir_p_print_top [deleted symlink]
testing/scripts/setup_secrets.sh

index 68791c82487853ba0d49268b1dd130d534b359ae..e56c358383f1b2e771444acb4ce76ba2529c6039 100644 (file)
@@ -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 (file)
index 2463d76..0000000
+++ /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
-}
index 44b9f2bc3fde20d004c41d137740558f27ed0463..5c7a2273c90249721c74f2ecca1169146ed5b6f0 100644 (file)
@@ -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
index deab16c2b5c4188435513e876f5cef10e987066f..410a6770c1e742ad5e97fcfbef37f2644cefe22c 100644 (file)
@@ -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}" $@
 }
index 4d548433e01f994206cacefcdbd4261be5cc8304..4726fed8aac2c63cf147364faa4384f0385a0759 100644 (file)
@@ -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 (file)
index 0000000..0fde79a
--- /dev/null
@@ -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 (file)
index abacef9..0000000
+++ /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
-}
index 59df47fb913d4a290f3f1627d207a56970a55b59..94f86ff30b075cad75a67e287aeab893d4525a04 100644 (file)
@@ -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
 }
index c70655b1aa220170a41257441e688b9ad5b1cb66..dd4b45ded40b6f52ebadf7d5921b71b81963becb 100755 (executable)
@@ -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
index 88687a1de09ff7691dfd20d3ab1f16fadfeea81b..421068bde19abd7d654a51a5c0c2bd98eca74530 100755 (executable)
@@ -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 (symlink)
index d23376e..0000000
+++ /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 (symlink)
index 0000000..57cee0e
--- /dev/null
@@ -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 (symlink)
index ab3ae3b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../../bookworm/scripts/lib/mkdir_p_print_top
\ No newline at end of file
index 68e77bae1f3d4d128ee19a1bf6f47cd9d88ca405..67c29e9b4173917cee90587a2d5c499964b68a54 100755 (executable)
@@ -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}"