From: Christian Heller Date: Mon, 19 May 2025 21:44:03 +0000 (+0200) Subject: Fix. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bprefix%7D%7D/ledger?a=commitdiff_plain;h=f8643fce52d8d39b0b916b01cdac688b76644d78;p=config Fix. --- diff --git a/bookworm/copy/seedbox/home/plom/.local/bin/print_torrents b/bookworm/copy/seedbox/home/plom/.local/bin/print_torrents index 18814bd..6426431 100755 --- a/bookworm/copy/seedbox/home/plom/.local/bin/print_torrents +++ b/bookworm/copy/seedbox/home/plom/.local/bin/print_torrents @@ -25,9 +25,9 @@ hash_titles() { return fi done - printf '? ? %s\n' "${FILENAME}" + printf '? %s %s %s\n' "${PLACEHOLDER_HASH}" "${PLACEHOLDER_SIZE}" "${FILENAME}" else - echo "${ALREADY_COLLECTED}" | grep "${HASH}" > /dev/null && continue + echo "${ALREADY_COLLECTED}" | grep "^${HASH}\$" > /dev/null && return ALREADY_COLLECTED=$(printf '%s\n%s' "${HASH}" "${ALREADY_COLLECTED}") local TITLE=$(cat -v "${FILENAME}" | head -1 | sed -E "s/${PATTERN_TORRENTNAME}/\1/g") HASHED_TITLES=$(printf '%s:%s\n%s' "${HASH}" "${TITLE}" "${HASHED_TITLES}") @@ -37,10 +37,11 @@ for_line_in "$(ls -1)" hash_titles cd "${PATH_DOWNLOADS}" SIZED_DOWNLOADS=$(du -ad1 -bh | grep -E "${PATTERN_DU_NONSUMMARY}" | sed -E "s/${PATTERN_DU_SIZE_NAME}/\1:\2/g") +HASHES_WITH_DOWNLOAD= print_entry() { local LINE=$1 - local STATUS='?' - local HASH='?' + local STATUS='D' + local HASH=${PLACEHOLDER_HASH} local SIZE=$(printf '%s' "${LINE}" | cut -d':' -f 1) local TITLE_DOWNLOADED=$(printf '%s' "${LINE}" | cut -d':' -f 2-) local FOUND= @@ -51,6 +52,7 @@ print_entry() { if [ "${TITLE_HASHED}" = "${TITLE_DOWNLOADED}" ]; then HASH=${MAYBE_HASH} FOUND=1 + HASHES_WITH_DOWNLOAD=$(printf '%s\n%s' "${HASH}" "${HASHES_WITH_DOWNLOAD}") break fi } @@ -64,3 +66,12 @@ print_entry() { printf '%s %s %s %s\n' "${STATUS}" "${HASH}" "${SIZE}" "${TITLE_DOWNLOADED}" } for_line_in "${SIZED_DOWNLOADS}" print_entry + +print_if_without_download() { + local LINE=$1 + local HASH=$(printf '%s' "${LINE}" | cut -d':' -f 1) + echo "${HASHES_WITH_DOWNLOAD}" | grep "^${HASH}\$" > /dev/null && return + local TITLE=$(printf '%s' "${LINE}" | cut -d':' -f 2-) + printf 'S %s %s %s\n' "${HASH}" "${PLACEHOLDER_SIZE}" "${TITLE}" +} +for_line_in "${HASHED_TITLES}" print_if_without_download diff --git a/bookworm/scripts/lib/constants_seedbox b/bookworm/scripts/lib/constants_seedbox index 3b659d8..c171a26 100644 --- a/bookworm/scripts/lib/constants_seedbox +++ b/bookworm/scripts/lib/constants_seedbox @@ -1,6 +1,6 @@ EXT_TORRENT='.torrent' -PATTERN_HASH_CHAR='[A-Z0-9]' -PATTERN_HASH="${PATTERN_HASH_CHAR}{40}" -PATTERN_HASH_ONLY="^${PATTERN_HASH}\$" +PATTERN_HASH_ONLY="^[A-Z0-9]{40}\$" DIRNAME_DOWNLOADS='downloads' DIRNAME_SESSION='session' +PLACEHOLDER_HASH='????????????????????????????????????????' +PLACEHOLDER_SIZE='????' diff --git a/bookworm/scripts/lib/path_tmp_timestamped b/bookworm/scripts/lib/path_tmp_timestamped deleted file mode 100644 index 7ae63cd..0000000 --- a/bookworm/scripts/lib/path_tmp_timestamped +++ /dev/null @@ -1,3 +0,0 @@ -path_tmp_timestamped () { - printf "/tmp/${1}_$(date +'%s')" -} diff --git a/bookworm/scripts/setup_server.sh b/bookworm/scripts/setup_server.sh index 4316596..8b66f3e 100755 --- a/bookworm/scripts/setup_server.sh +++ b/bookworm/scripts/setup_server.sh @@ -4,12 +4,13 @@ cd $(dirname "$0") . lib/apt_get_digested . lib/constants_etc # PATH_ETC . lib/constants_ssh # PATH_REL_SSH, PATH_USER_SSH +. lib/constants_user # USERNAME . lib/copy_dirtrees_of_tags . lib/core_setup . lib/expect_n_args -. lib/path_tmp_timestamped . lib/prefixed_msg . lib/put_finished_marker +. lib/trapp prefixed_msg_init prefixed_msg 'starting (setting up basics of standard server)' @@ -50,7 +51,9 @@ fi prefixed_msg 'Ensure we have curl and gpg (for caddy installation preparation) …' apt_get_digested '-q -q install curl gpg' -PATH_CURL_ERROR="$(path_tmp_timestamped curl_error)" +PATH_CURL_ERROR=$(mktemp) +CMD_RM_CURL_ERROR="rm ${PATH_CURL_ERROR}" +trapp "${CDM_RM_CURL_ERROR}" prefixed_msg 'Retrieve caddy repo key …' set +e curl -1Lf "${PATH_CADDY_REPO}/gpg.key" 2> "${PATH_CURL_ERROR}" | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg @@ -60,6 +63,8 @@ if [ "${RESULT}" != '0' ]; then cat "${PATH_CURL_ERROR}" exit 1 fi +${CMD_RM_CURL_ERROR} +trapp PATH_APT_CADDY_REPO='/etc/apt/sources.list.d/caddy-stable.list' prefixed_msg "Adding caddy repo to ${PATH_APT_CADDY_REPO} …" curl -1LfsS "${PATH_CADDY_REPO}/debian.deb.txt" > "${PATH_APT_CADDY_REPO}" @@ -95,5 +100,8 @@ sed -i 's/REPLACE_WITH_FQDN/'"${ADDRESS_TO_CADDY}"'/g' "${PATH_CADDYFILE}" prefixed_msg "Restarting caddy …" systemctl reload caddy +prefixed_msg "Asking for user pw so they can sudo …" +passwd "${USERNAME}" + put_finished_marker 'setup_server' prefixed_msg_exit diff --git a/testing/scripts/lib/path_tmp_timestamped b/testing/scripts/lib/path_tmp_timestamped deleted file mode 120000 index a7ae07c..0000000 --- a/testing/scripts/lib/path_tmp_timestamped +++ /dev/null @@ -1 +0,0 @@ -../../../trixie/scripts/lib/path_tmp_timestamped \ No newline at end of file diff --git a/testing/scripts/lib/path_tmp_timestamped b/testing/scripts/lib/path_tmp_timestamped new file mode 100644 index 0000000..7ae63cd --- /dev/null +++ b/testing/scripts/lib/path_tmp_timestamped @@ -0,0 +1,3 @@ +path_tmp_timestamped () { + printf "/tmp/${1}_$(date +'%s')" +} diff --git a/testing/scripts/sync_rtorrent_download.sh b/testing/scripts/sync_rtorrent_download.sh index a9b86eb..1a16167 100755 --- a/testing/scripts/sync_rtorrent_download.sh +++ b/testing/scripts/sync_rtorrent_download.sh @@ -24,41 +24,45 @@ SELECTION="$3" if [ ! -d "${LOCAL_STORE}" ]; then abort "Aborting, no local storage directory at ${LOCAL_STORE}." fi -if echo "${SELECTION}" | grep -v "^${PATTERN_HASH_CHAR}*\$" > /dev/null; then - abort "Bad SELECTION format: ${SELECTION}" -fi + + prefixed_msg 'Collecting known media …' OVERVIEW_LOCAL= cd "${LOCAL_STORE}" parse_line() { local TITLE="$1" - local HASH='?' - local SIZE='?' + local HASH=${PLACEHOLDER_HASH} + local SIZE=${PLACEHOLDER_SIZE} local STATUS='?' local PATH_DOWNLOAD="${TITLE}/${DIRNAME_DOWNLOAD}" local PATH_SESSION="${TITLE}/${DIRNAME_SESSION}" if [ -d "${PATH_DOWNLOAD}" ]; then - SIZE=$(du --bytes --human-readable --summarize "${PATH_DOWNLOAD}" | cut -f 1) + SIZE=$(du --bytes --human-readable --summarize "${PATH_DOWNLOAD}" | cut -f 1) + STATUS='D' fi if [ -d "${PATH_SESSION}" ]; then local SESSION_FILES_LISTING=$(ls -1 "${PATH_SESSION}") if [ $(echo "${SESSION_FILES_LISTING}" | wc -l) -eq 3 ]; then local MAYBE_HASH=$(basename $(echo "${SESSION_FILES_LISTING}" | head -1) "${EXT_TORRENT}" | grep -E "${PATTERN_HASH_ONLY}") - if [ ! -z "${MAYBE_HASH}" ] && expected_rtorrent_files "${PATH_SESSION}/${MAYBE_HASH}${EXT_TORRENT}"; then + if [ ! -z "${MAYBE_HASH}" ] \ + && expected_rtorrent_files "${PATH_SESSION}/${MAYBE_HASH}${EXT_TORRENT}" + then HASH="${MAYBE_HASH}" + test "${STATUS}" = '?'&& STATUS='S' + test "${STATUS}" = 'D'&& STATUS='+' fi fi fi - if [ "${SIZE}" != "?" -a "${HASH}" != "?" ]; then - STATUS='+' - fi OVERVIEW_LOCAL=$(printf '%s %s %s %s\n%s' "${STATUS}" "${HASH}" "${SIZE}" "${TITLE}" "${OVERVIEW_LOCAL}") } for_line_in "$(ls -1)" parse_line cd - > /dev/null OVERVIEW_REMOTE=$(ssh -t -q "${SERVER}" "sh -cl ${CMD_PRINT_TORRENTS}") + + +prefixed_msg 'Comparing presence here vs there …' OVERVIEW_BOTH= OVERVIEW_ONLY_REMOTE= OVERVIEW_ONLY_LOCAL="${OVERVIEW_LOCAL}" @@ -82,11 +86,10 @@ compare_overviews() { OVERVIEW_ONLY_LOCAL="${NEXT_UNUSED}" } for_line_in "${OVERVIEW_REMOTE}" compare_overviews - if [ -z "${SELECTION}" ]; then list_overview() { - local MSG="$1" - local OVERVIEW="$2" + local MSG=$1 + local OVERVIEW=$(echo "$2" | sort -k 4) prefixed_msg "${MSG}" if [ -z "${OVERVIEW}" ]; then prefixed_msg '(none)' @@ -100,65 +103,148 @@ if [ -z "${SELECTION}" ]; then exit 0 fi -FOUND= + + +prefixed_msg "Analyzing selection: ${SELECTION}" find_match() { - local LINE_CUT=$(printf '%s' "$1" | cut -c 3-) - local HASH_START=$(printf '%s' "${LINE_CUT}" | cut -c -${#SELECTION}) - if [ "${HASH_START}" = "${SELECTION}" ]; then - if [ ! -z "${FOUND}" ]; then - abort "Ambiguous selection, more than one hash starting with: ${SELECTION}" + local LINE=$1 + local LOCAL_HASH=$(echo "${LINE}" | cut -d' ' -f 2) + local LOCAL_TITLE=$(echo "${LINE}" | cut -d' ' -f 4) + if $(echo "${LOCAL_HASH}" | grep -iqv "${SELECTION}")\ + && $(echo "${LOCAL_TITLE}" | grep -iqv "${SELECTION}") + then + return + fi + local MSG_AMBIGUITY='Ambiguous selection, more than one selectable match found.' + if [ ! -z "${TITLE}" ] && [ "${LOCAL_TITLE}" != "${TITLE}" ]; then + abort "${MSG_AMBIGUITY}" + fi + TITLE="${LOCAL_TITLE}" + if [ "${LOCAL_HASH}" != "${PLACEHOLDER_HASH}" ]; then + if [ -z "${HASH}" ]; then + HASH="${LOCAL_HASH}" + elif [ "${LOCAL_HASH}" != "${HASH}" ]; then + abort "${MSG_AMBIGUITY}" fi - FOUND=1 - HASH=$(printf '%s' "${LINE_CUT}" | cut -d' ' -f 1) - TITLE=$(printf '%s' "${LINE_CUT}" | cut -d' ' -f 3-) fi + STATUS=$(echo "${LINE}" | cut -d' ' -f 1) + if [ "${STATUS}" = '?' ]; then + abort "Confounded by status for title: ${TITLE}" + elif [ "${STATUS}" = '+' ]; then + STORING='DS' + elif [ "${STATUS}" = '+' ]; then + STORING=${STATUS} + fi + STORES=$(echo "${STORES}:${STORING}") } -SYNC_DOWN= -BOTHSIDED= -for_line_in "${OVERVIEW_BOTH}" find_match -if [ ! -z "${FOUND}" ]; then - BOTHSIDED=1 -fi +HASH= +TITLE= +STATUS= for_line_in "${OVERVIEW_ONLY_REMOTE}" find_match -if [ ! -z "${FOUND}" ]; then - SYNC_DOWN=1 -fi +STATUS_REMOTE=${STATUS} +STATUS= for_line_in "${OVERVIEW_ONLY_LOCAL}" find_match -if [ -z "${FOUND}" ]; then - abort "No known hash starting with: ${SELECTION}" -elif [ ! -z "${BOTHSIDED}" ]; then - abort 'Target present on both sides, nothing to do.' +STATUS_LOCAL=${STATUS} +if [ -z "${TITLE}" ]; then + abort 'No matching selectable found.' fi -prefixed_msg_no_nl "Hash ${HASH} selected for " -if [ -z "${SYNC_DOWN}" ]; then printf 'LOCAL'; else printf 'REMOTE'; fi -printf ' media: %s\n' "${TITLE}" + + + +prefixed_msg "Selected hash, title: ${HASH} ${TITLE}" +calc_what_to_sync() { + local STATUS_THIS=$1 # S + local STATUS_THAT=$2 # D + local SYNC= + if [ "${STATUS_THIS}" = '' ]; then + SYNC='+' + elif [ "${STATUS_THIS}" = 'D' ]; then + SYNC='S' + elif [ "${STATUS_THIS}" = 'S' ]; then + SYNC='D' + fi + if [ ! -z "${SYNC}" ] && [ '+' != "${STATUS_THAT}" ]; then + if [ -z "${STATUS_THAT}" ] || [ "${STATUS_THAT}" != "${SYNC}" ]; then + abort 'Not enough stored data on both sides for sync.' + fi + fi + echo "${SYNC}" +} +SYNC_UP=$(calc_what_to_sync "${STATUS_REMOTE}" "${STATUS_LOCAL}") +SYNC_DOWN=$(calc_what_to_sync "${STATUS_LOCAL}" "${STATUS_REMOTE}") +prefixed_msg_no_nl 'Task: ' +print_task() { + local SYNC=$1 + local DIRECTION=$2 + local TARGET='nothing' + if [ "${SYNC}" = '+' ]; then + TARGET='ALL' + elif [ "${SYNC}" = 'S' ]; then + TARGET='SESSION' + elif [ "${SYNC}" = 'D' ]; then + TARGET='CONTENT' + fi + printf '%sloading %s' "${DIRECTION}" "${TARGET}" + +} +print_task "${SYNC_UP}" 'up' +printf ', ' +print_task "${SYNC_DOWN}" 'down' +printf '\n' + + TARGET_DIR="${LOCAL_STORE}/${TITLE}" -if [ -z "${SYNC_DOWN}" ]; then +if [ ! -z "${SYNC_UP}" ]; then prefixed_msg 'Uploading …' TMP_STORE=$(ssh -t -q "${SERVER}" "TMPDIR=~/tmp mktemp -d" | tr -d "\r") -else + handle_subdir() { + local SUBDIR_LOCAL=$1 + local SUBDIR_REMOTE=$2 + local TMP_STORE_SUBDIR="${TMP_STORE}/${SUBDIR_LOCAL}" + + local SUBDIR=$1 + local TMP_STORE_SUBDIR="${TMP_STORE}/${SUBDIR}" + scp -r "${TARGET_DIR}/${SUBDIR_LOCAL}" "${SERVER}:${TMP_STORE}/" + ssh -t -q "${SERVER}" "mv -i ${TMP_STORE_SUBDIR}/* ~/${SUBDIR_REMOTE}/" + ssh -t -q "${SERVER}" "rmdir ${TMP_STORE_SUBDIR}" + } + if [ "${SYNC_UP}" = '+' -o "${SYNC_UP}" = 'D' ]; then + handle_subdir "${DIRNAME_DOWNLOAD}" "${DIRNAME_DOWNLOADS}" + fi + if [ "${SYNC_UP}" = '+' -o "${SYNC_UP}" = 'S' ]; then + handle_subdir "${DIRNAME_SESSION}" "${DIRNAME_SESSION}" + fi + ssh -t -q "${SERVER}" "rmdir ${TMP_STORE}" + ssh -t -q "${SERVER}" 'sh -cl kill_rtorrent' +fi +if [ ! -z "${SYNC_DOWN}" ]; then prefixed_msg 'Downloading …' - abort_if_exists "${TARGET_DIR}" TMP_STORE=$(mktemp -d) trapp "prefixed_msg 'With abortion, removing'${TMP_STORE}; rm -rf ${TMP_STORE}" -fi -TMP_STORE_DOWNLOAD="${TMP_STORE}/${DIRNAME_DOWNLOAD}" -TMP_STORE_SESSION="${TMP_STORE}/${DIRNAME_SESSION}" -if [ -z "${SYNC_DOWN}" ]; then - scp -r "${TARGET_DIR}/"* "${SERVER}:${TMP_STORE}/" - ssh -t -q "${SERVER}" "mv -i ${TMP_STORE_DOWNLOAD}/* ~/${DIRNAME_DOWNLOADS}/" - ssh -t -q "${SERVER}" "mv -i ${TMP_STORE_SESSION}/* ~/${DIRNAME_SESSION}/" - ssh -t -q "${SERVER}" "rmdir ${TMP_STORE_SESSION} && rmdir ${TMP_STORE_DOWNLOAD} && rmdir ${TMP_STORE}" - ssh -t -q "${SERVER}" 'sh -cl kill_rtorrent' -else - mkdir "${TMP_STORE_SESSION}" - mkdir "${TMP_STORE_DOWNLOAD}" - scp "${SERVER}:~/${DIRNAME_SESSION}/${HASH}"* "${TMP_STORE_SESSION}/" - scp -r "${SERVER}:~/${DIRNAME_DOWNLOADS}/${TITLE}" "${TMP_STORE_DOWNLOAD}/" - prefixed_msg "Storing in: ${TARGET_DIR}" - mv -i "${TMP_STORE}" "${TARGET_DIR}" + handle_subdir() { + local SUBDIR_LOCAL=$1 + local SUBDIR_REMOTE=$2 + local TMP_STORE_SUBDIR="${TMP_STORE}/${SUBDIR_LOCAL}" + local TO_COPY_PATTERN=$3 + local GLOB=$4 + mkdir "${TMP_STORE_SUBDIR}" + scp -r "${SERVER}:~/${SUBDIR_REMOTE}/${TO_COPY_PATTERN}"${GLOB} "${TMP_STORE_SUBDIR}/" + if [ "${SYNC_DOWN}" != '+' ]; then + mv -i "${TMP_STORE_SUBDIR}" "${TARGET_DIR}/" + fi + } + if [ "${SYNC_DOWN}" = '+' -o "${SYNC_DOWN}" = 'D' ]; then + handle_subdir "${DIRNAME_DOWNLOAD}" "${DIRNAME_DOWNLOADS}" "${TITLE}" + fi + if [ "${SYNC_DOWN}" = '+' -o "${SYNC_DOWN}" = 'S' ]; then + handle_subdir "${DIRNAME_SESSION}" "${DIRNAME_SESSION}" "${HASH}" '*' + fi + if [ "${SYNC_DOWN}" = '+' ]; then + mv -i "${TMP_STORE}" "${TARGET_DIR}" + fi trapp fi +prefixed_msg 'Success!' prefixed_msg_exit diff --git a/trixie/scripts/lib/path_tmp_timestamped b/trixie/scripts/lib/path_tmp_timestamped deleted file mode 120000 index 2f17d83..0000000 --- a/trixie/scripts/lib/path_tmp_timestamped +++ /dev/null @@ -1 +0,0 @@ -../../../bookworm/scripts/lib/path_tmp_timestamped \ No newline at end of file