From 5bcd49565e3f890fa32501344a0a358255e58af6 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 14 May 2025 03:00:56 +0200 Subject: [PATCH] Fix. --- bookworm/aptmark/server | 4 +- .../home/plom/.local/bin/print_torrents | 39 +++++++++++++ testing/scripts/lib/abort_if_exists | 2 +- testing/scripts/sync_rtorrent_download.sh | 56 +++++++++++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100755 bookworm/copy/seedbox/home/plom/.local/bin/print_torrents create mode 100755 testing/scripts/sync_rtorrent_download.sh diff --git a/bookworm/aptmark/server b/bookworm/aptmark/server index dc1715e..1c5d46c 100644 --- a/bookworm/aptmark/server +++ b/bookworm/aptmark/server @@ -6,9 +6,9 @@ nftables borgbackup # so every server can serve some webspace caddy -# for playing nicely with ssh sessions via the foot terminal -foot-terminfo # necessary on _some_ vservers net-tools quota +# for playing nicely with ssh sessions via the foot terminal +foot-terminfo # diff --git a/bookworm/copy/seedbox/home/plom/.local/bin/print_torrents b/bookworm/copy/seedbox/home/plom/.local/bin/print_torrents new file mode 100755 index 0000000..0e04b98 --- /dev/null +++ b/bookworm/copy/seedbox/home/plom/.local/bin/print_torrents @@ -0,0 +1,39 @@ +#!/bin/sh +set -e +cd $(dirname "$0") + +PATTERN_TORRENTNAME=".*e4:name[0-9]+:(.+)12:piece length.*" +PATTERN_DU_NONSUMMARY="^[[:graph:]]+[[:blank:]]+\.\/" +PATTERN_DU_SIZE_NAME="^([[:graph:]]+)\t\.\/(.+)$" + +cd "${HOME}/session" +HASHED_TITLES= +FILENAMES_TORRENTS=$(ls *.torrent) +for _FILENAME in ${FILENAMES_TORRENTS}; do + _HASH=$(printf '%s' "${_FILENAME}" | cut -d '.' -f 1) + _TITLE=$(cat -v "${_FILENAME}" | head -1 | sed -E "s/${PATTERN_TORRENTNAME}/\1/g") + HASHED_TITLES="${_HASH}:${_TITLE}\n${HASHED_TITLES}" +done + +cd "${HOME}/downloads" +SIZED_DOWNLOADS=$(du -ad1 -bh | grep -E "${PATTERN_DU_NONSUMMARY}" | sed -E "s/${PATTERN_DU_SIZE_NAME}/\1:\2/g") +for _LINE in $(echo "${SIZED_DOWNLOADS}" | sed 's/ /REPLACED_WHITESPACE/g'); do + _LINE=$(printf '%s' "${_LINE}" | sed 's/REPLACED_WHITESPACE/ /g') + _SIZE=$(printf '%s' "${_LINE}" | cut -d':' -f 1) + _DOWNLOAD=$(printf '%s' "${_LINE}" | cut -d':' -f 2-) + _FOUND= + for _LINE in $(echo "${HASHED_TITLES}" | sed 's/ /REPLACED_WHITESPACE/g'); do + _LINE=$(printf '%s' "${_LINE}" | sed 's/REPLACED_WHITESPACE/ /g') + _HASH=$(printf '%s' "${_LINE}" | cut -d':' -f 1) + _TITLE=$(printf '%s' "${_LINE}" | cut -d':' -f 2-) + if [ "${_TITLE}" = "${_DOWNLOAD}" ]; then + _FOUND=1 + printf '%s' "${_HASH}" + break + fi + done + if [ -z "${_FOUND}" ]; then + printf 'no_torrent_files' + fi + printf ' %s %s\n' "${_SIZE}" "${_DOWNLOAD}" +done diff --git a/testing/scripts/lib/abort_if_exists b/testing/scripts/lib/abort_if_exists index 7c4d62d..33f49d5 100644 --- a/testing/scripts/lib/abort_if_exists +++ b/testing/scripts/lib/abort_if_exists @@ -2,6 +2,6 @@ abort_if_exists() { if [ -e "$1" ]; then - abort "$1 already exists." + abort "Aborting since $1 already exists." fi } diff --git a/testing/scripts/sync_rtorrent_download.sh b/testing/scripts/sync_rtorrent_download.sh new file mode 100755 index 0000000..9ac2994 --- /dev/null +++ b/testing/scripts/sync_rtorrent_download.sh @@ -0,0 +1,56 @@ +#!/bin/sh +set -e +cd $(dirname "$0") +. lib/abort +. lib/abort_if_exists +. lib/abort_if_offline +. lib/expect_n_args +. lib/path_tmp_timestamped + +prefixed_msg_init +abort_if_offline + +BACKUPS_DIR="${HOME}/del/torrentexp" + +expect_n_args 1 2 'SERVER [SELECTION]' $@ +SERVER="$1" +SELECTION="$2" + +OVERVIEW=$(ssh -t -q "${SERVER}" './print_torrents' | tr -d "\r") +if [ -z "${SELECTION}" ]; then + prefixed_msg 'Available:' + for _LINE in $(echo "${OVERVIEW}" | sed 's/ /REPLACED_WHITESPACE/g'); do + _LINE=$(printf '%s' "${_LINE}" | sed 's/REPLACED_WHITESPACE/ /g') + prefixed_msg "- ${_LINE}" + done + exit 0 +fi +LEN_SELECTION=$(printf '%s' "${SELECTION}" | wc -c) +FOUND= +for _LINE in $(echo "${OVERVIEW}" | sed 's/ /REPLACED_WHITESPACE/g'); do + _LINE=$(printf '%s' "${_LINE}" | sed 's/REPLACED_WHITESPACE/ /g') + _LINE_START=$(printf '%s' "${_LINE}" | cut -c -${LEN_SELECTION}) + if [ "${_LINE_START}" = "${SELECTION}" ]; then + HASH=$(printf '%s' "${_LINE}" | cut -d' ' -f 1) + TITLE=$(printf '%s' "${_LINE}" | cut -d' ' -f 3-) + FOUND=1 + break + fi +done +if [ -z "${FOUND}" ]; then + abort "No known hash starting with: ${SELECTION}" +fi +TARGET_DIR="${BACKUPS_DIR}/${TITLE}" +abort_if_exists "${TARGET_DIR}" +prefixed_msg "Downloading torrent files and content for: ${HASH} ${TITLE}" +TMP_DIR=$(path_tmp_timestamped "${TITLE}") +SESSION_DIR="${TMP_DIR}/session" +DOWNLOAD_DIR="${TMP_DIR}/download" +mkdir -p "${SESSION_DIR}" +mkdir -p "${DOWNLOAD_DIR}" +scp "${SERVER}:~/session/${HASH}"* "${SESSION_DIR}/" +scp -r "${SERVER}:~/downloads/${TITLE}" "${DOWNLOAD_DIR}/" +prefixed_msg "Storing in: ${TARGET_DIR}" +mv "${TMP_DIR}" "${TARGET_DIR}" + +prefixed_msg_exit -- 2.30.2