From 07bd32d7b1b6e93fe25499826e78b186ac55f89d Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 6 May 2025 11:34:20 +0200 Subject: [PATCH] Fix. --- .../desktop/home/plom/.local/bin/make_secrets | 14 +++-- .../plom/.plomlib/copy_and_unmount_secrets | 1 + .../copy/desktop/home/plom/.profile.desktop | 2 +- testing/scripts/_setup_secrets_user.sh | 7 +-- testing/scripts/init_server_access.sh | 2 +- testing/scripts/lib/copy_and_unmount_secrets | 18 +++++++ testing/scripts/lib/mount_secrets | 53 +++++++------------ testing/scripts/setup_desktop.sh | 3 +- 8 files changed, 57 insertions(+), 43 deletions(-) create mode 120000 testing/copy/desktop/home/plom/.plomlib/copy_and_unmount_secrets create mode 100644 testing/scripts/lib/copy_and_unmount_secrets diff --git a/testing/copy/desktop/home/plom/.local/bin/make_secrets b/testing/copy/desktop/home/plom/.local/bin/make_secrets index 344214e..c03c315 100755 --- a/testing/copy/desktop/home/plom/.local/bin/make_secrets +++ b/testing/copy/desktop/home/plom/.local/bin/make_secrets @@ -7,22 +7,28 @@ cd $(dirname "$0") . lib/constants_secrets # PATH_REL_SECRETS, PATH_SECRETS, PATH_SECRETS_BORGKEYS . lib/constants_ssh # PATH_USER_SSH . lib/constants_user # USERNAME -. lib/mount_secrets # mount_secrets, copy_and_unmount_secrets +. lib/copy_and_unmount_secrets +. lib/mount_secrets +. lib/prefixed_msg + +prefixed_msg_init abort_if_exists "${PATH_SECRETS}" -echo "Collecting new ${PATH_REL_SECRETS}." +prefixed_msg "Collecting new ${PATH_REL_SECRETS}." mkdir "${PATH_SECRETS}" "${NAME_BORGAPP}" backup_keys "${PATH_SECRETS_BORGKEYS}" cp -a "${PATH_USER_SSH}" "${PATH_SECRETS_SSH}" -echo "secrets file, last update: $(whoami)/$(hostname) at $(date)" > "${PATH_SECRETS}/info" +prefixed_msg "secrets file, last update: $(whoami)/$(hostname) at $(date)" > "${PATH_SECRETS}/info" mount_secrets "$1" # sets PATH_MOUNTED_SECRETS SUFFIX_OLD=.old PATH_REL_SECRETS_OLD="${PATH_REL_SECRETS}${SUFFIX_OLD}" PATH_MOUNTED_SECRETS_OLD="${PATH_MOUNTED_SECRETS}${SUFFIX_OLD}" if [ -d "${PATH_MOUNTED_SECRETS}" ]; then - echo "Drive already has ${PATH_REL_SECRETS}, moving to ${PATH_REL_SECRETS_OLD}." + prefixed_msg "Drive already has ${PATH_REL_SECRETS}, moving to ${PATH_REL_SECRETS_OLD}." rm -rf "${PATH_MOUNTED_SECRETS_OLD}" mv "${PATH_MOUNTED_SECRETS}" "${PATH_MOUNTED_SECRETS_OLD}" fi copy_and_unmount_secrets 'out' + +prefixed_msg_exit diff --git a/testing/copy/desktop/home/plom/.plomlib/copy_and_unmount_secrets b/testing/copy/desktop/home/plom/.plomlib/copy_and_unmount_secrets new file mode 120000 index 0000000..c215403 --- /dev/null +++ b/testing/copy/desktop/home/plom/.plomlib/copy_and_unmount_secrets @@ -0,0 +1 @@ +../../../../../scripts/lib/copy_and_unmount_secrets \ No newline at end of file diff --git a/testing/copy/desktop/home/plom/.profile.desktop b/testing/copy/desktop/home/plom/.profile.desktop index 57a42bd..47a2d90 100644 --- a/testing/copy/desktop/home/plom/.profile.desktop +++ b/testing/copy/desktop/home/plom/.profile.desktop @@ -1,5 +1,5 @@ # so we don't have to enter our SSH key password all the time -eval $(ssh-agent) && ssh-add +eval $(ssh-agent) && ssh-add -q # zero audio volume (rather than "just" mute) vol 0 diff --git a/testing/scripts/_setup_secrets_user.sh b/testing/scripts/_setup_secrets_user.sh index a2556b9..3302968 100644 --- a/testing/scripts/_setup_secrets_user.sh +++ b/testing/scripts/_setup_secrets_user.sh @@ -9,7 +9,8 @@ cd $(dirname "$0") . lib/constants_ssh # PATH_USER_SSH . lib/constants_user # USERNAME . lib/constants_borg # NAME_BORGAPP -. lib/mount_secrets # mount_secrets, copy_and_unmount_secrets +. lib/copy_and_unmount_secrets +. lib/mount_secrets . lib/prefixed_msg . lib/retry_until . lib/trapp @@ -43,11 +44,11 @@ REPOS_SITE_LOGIN="${USERNAME}@${REPOS_SITE_DOMAIN}" mkdir "${PATH_REPOS}" cd "${PATH_REPOS}" ssh ${REPOS_SITE_LOGIN} "cd ${REMOTE_PATH_REPOS} && ls -1" | while read REPO_NAME; do - git clone --recurse "${REPOS_SITE_LOGIN}:${REMOTE_PATH_REPOS}/${REPO_NAME}" + git clone --quiet --recurse "${REPOS_SITE_LOGIN}:${REMOTE_PATH_REPOS}/${REPO_NAME}" done cd - > /dev/null -prefixed_msg '# Setting up borg and pull in ~/org …' +prefixed_msg 'Setting up borg and pull in ~/org …' cd "${PATH_SECRETS_BORGKEYS}" ls -1 | while read _FILENAME; do "${NAME_BORGAPP}" claim "${_FILENAME}" diff --git a/testing/scripts/init_server_access.sh b/testing/scripts/init_server_access.sh index 94219ce..d20ccab 100755 --- a/testing/scripts/init_server_access.sh +++ b/testing/scripts/init_server_access.sh @@ -24,7 +24,7 @@ if [ ! -z "${OLD_ROOT_PW}" ]; then fi prefixed_msg "In ${PATH_KNOWN_HOSTS}, removing previous entry for ${SERVER} if found …" -ssh-keygen -f "${PATH_KNOWN_HOSTS}" -R "${SERVER}" > /dev/null +ssh-keygen -q -f "${PATH_KNOWN_HOSTS}" -R "${SERVER}" prefixed_msg 'Scanning server for new key to add to file …' PATH_LOG_KEYSCAN_STDERR=$(path_tmp_timestamped) diff --git a/testing/scripts/lib/copy_and_unmount_secrets b/testing/scripts/lib/copy_and_unmount_secrets new file mode 100644 index 0000000..8d203c9 --- /dev/null +++ b/testing/scripts/lib/copy_and_unmount_secrets @@ -0,0 +1,18 @@ +. lib/constants_secrets # PATH_REL_SECRETS, PATH_SECRETS + +copy_and_unmount_secrets() { +prefixed_msg_init copy_and_unmount_secrets + +prefixed_msg "Copying over ${PATH_REL_SECRETS}." +if [ "$1" = "out" ]; then + cp -a "${PATH_SECRETS}" "${PATH_MOUNTED_SECRETS}" +elif [ "$1" = "in" ]; then + cp -a "${PATH_MOUNTED_SECRETS}" "${PATH_SECRETS}" +else + abort "Illegal argument to unmount_secrets." +fi +pumount "${SECRETS_DEV}" +prefixed_msg "You can remove device ${SECRETS_DEV} now." + +prefixed_msg_exit +} diff --git a/testing/scripts/lib/mount_secrets b/testing/scripts/lib/mount_secrets index 8e44c4a..934b0a6 100644 --- a/testing/scripts/lib/mount_secrets +++ b/testing/scripts/lib/mount_secrets @@ -6,38 +6,25 @@ . lib/retry_until mount_secrets() { - prefixed_msg_init mount_secrets - expect_n_args 1 1 "(device name, e.g. 'sda')" $@ - SECRETS_DEV=$1 - if [ -z "${SECRETS_DEV}" ]; then - abort "Aborting due to empty device argument." - fi - PATH_MOUNTED_SECRETS="${PATH_MEDIA}/${SECRETS_DEV}/${PATH_REL_SECRETS}" - PATH_DEV="/dev/${SECRETS_DEV}" - PATH_PMOUNT_ERR="$(path_tmp_timestamped 'err_mount')" - prefixed_msg "Put secrets drive into slot for ${PATH_DEV}." - while [ ! -e "${PATH_DEV}" ]; do - sleep 0.1 - done - _ON_LOOP_START='prefixed_msg_no_nl "Passphrase: "; PASSPHRASE=$(get_passphrase); echo ""' - _TO_TEST='echo "${PASSPHRASE}" | pmount "${PATH_DEV}" 2>&1' - _ON_FAIL='prefixed_msg "Aborting due to pmount error:"' - retry_until 100 "${_ON_LOOP_START}" "${_TO_TEST}" "${_ON_FAIL}" - prefixed_msg "${_OUTPUT}" - prefixed_msg_exit -} +prefixed_msg_init mount_secrets + +expect_n_args 1 1 "(device name, e.g. 'sda')" $@ +SECRETS_DEV=$1 +if [ -z "${SECRETS_DEV}" ]; then + abort "Aborting due to empty device argument." +fi +PATH_MOUNTED_SECRETS="${PATH_MEDIA}/${SECRETS_DEV}/${PATH_REL_SECRETS}" +PATH_DEV="/dev/${SECRETS_DEV}" +PATH_PMOUNT_ERR="$(path_tmp_timestamped 'err_mount')" +prefixed_msg "Put secrets drive into slot for ${PATH_DEV}." +while [ ! -e "${PATH_DEV}" ]; do + sleep 0.1 +done +_ON_LOOP_START='prefixed_msg_no_nl "Passphrase: "; PASSPHRASE=$(get_passphrase); echo ""' +_TO_TEST='echo "${PASSPHRASE}" | pmount "${PATH_DEV}" 2>&1' +_ON_FAIL='prefixed_msg "Aborting due to pmount error:"' +retry_until 100 "${_ON_LOOP_START}" "${_TO_TEST}" "${_ON_FAIL}" +prefixed_msg "${_OUTPUT}" -copy_and_unmount_secrets() { - prefixed_msg_init copy_and_unmount_secrets - prefixed_msg "Copying over ${PATH_REL_SECRETS}." - if [ "$1" = "out" ]; then - cp -a "${PATH_SECRETS}" "${PATH_MOUNTED_SECRETS}" - elif [ "$1" = "in" ]; then - cp -a "${PATH_MOUNTED_SECRETS}" "${PATH_SECRETS}" - else - abort "Illegal argument to unmount_secrets." - fi - pumount "${SECRETS_DEV}" - prefixed_msg "You can remove device ${SECRETS_DEV} now." - prefixed_msg_exit +prefixed_msg_exit } diff --git a/testing/scripts/setup_desktop.sh b/testing/scripts/setup_desktop.sh index 8b88503..7820dff 100755 --- a/testing/scripts/setup_desktop.sh +++ b/testing/scripts/setup_desktop.sh @@ -13,6 +13,7 @@ cd $(dirname "$0") . lib/put_finished_marker prefixed_msg_init +prefixed_msg 'starting …' PATH_NETWORK_INTERFACES="${PATH_ETC}/network/interfaces" THINKPAD_NAMES="x220 w530 t490s" @@ -52,7 +53,7 @@ adopt_wifi_connection() { WLAN_SSID=$(get_network_interfaces_last_wpa_value 'ssid') WLAN_PSK=$(get_network_interfaces_last_wpa_value 'psk') if [ ! -z "${WLAN_SSID}" ]; then - prefixed_msg "Found, adding to NetworkManager." + prefixed_msg_no_nl "Found, adding to NetworkManager: " if [ -z "${WLAN_PSK}" ]; then nmcli connection add type wifi wifi.ssid "${WLAN_SSID}" else # NB: assumes last (collected with tail -1) wpa-psk that of last wlan-ssid -- 2.30.2