home · contact · privacy
Fix.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 14 May 2025 01:00:56 +0000 (03:00 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 14 May 2025 01:00:56 +0000 (03:00 +0200)
bookworm/aptmark/server
bookworm/copy/seedbox/home/plom/.local/bin/print_torrents [new file with mode: 0755]
testing/scripts/lib/abort_if_exists
testing/scripts/sync_rtorrent_download.sh [new file with mode: 0755]

index dc1715ecab2f5ed2955361363ec6af0341d2cbc7..1c5d46c068d6c75fc538c7ab22aedb4b014fd1d4 100644 (file)
@@ -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 (executable)
index 0000000..0e04b98
--- /dev/null
@@ -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
index 7c4d62d5a3fe0ac6637afce0d0d26244798422b4..33f49d58bec20899e6861dd87bb57fa4f106c700 100644 (file)
@@ -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 (executable)
index 0000000..9ac2994
--- /dev/null
@@ -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