torrent complete qbittorrent inside docker
This commit is contained in:
1 parent
366c26f581
commit
b92bdbea7d
1 file changed
+95
-95
@@ -32,7 +32,6 @@
|
||||
set -u
|
||||
|
||||
SCRIPT_NAME="$(basename "$0")"
|
||||
LOG_DIR="/home/lucas/.LOG"
|
||||
|
||||
###############################################################################
|
||||
# Usage
|
||||
@@ -58,8 +57,6 @@ Example:
|
||||
qBittorrent:
|
||||
$SCRIPT_NAME "%N" "%R" "%L"
|
||||
|
||||
Log directory:
|
||||
$LOG_DIR
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -76,99 +73,102 @@ TORRENT_NAME="$1"
|
||||
ROOT_PATH="$2"
|
||||
CATEGORY="$3"
|
||||
|
||||
###############################################################################
|
||||
# Logging
|
||||
###############################################################################
|
||||
if [[ "$CATEGORY" != *arr* ]]; then
|
||||
###############################################################################
|
||||
# Start
|
||||
###############################################################################
|
||||
|
||||
echo "=================================================="
|
||||
echo "Torrent transfer started"
|
||||
echo "Date: $(date)"
|
||||
echo "Script: $SCRIPT_NAME"
|
||||
echo "Torrent name: $TORRENT_NAME"
|
||||
echo "Root path: $ROOT_PATH"
|
||||
echo "Category: $CATEGORY"
|
||||
echo "=================================================="
|
||||
|
||||
###############################################################################
|
||||
# Send torrent name to MQTT script
|
||||
###############################################################################
|
||||
|
||||
echo
|
||||
echo "--- Sending torrent name to torrent_mqtt.py ---"
|
||||
|
||||
/config/.venv/bin/python3 /config/torrent_mqtt.py "$TORRENT_NAME"
|
||||
|
||||
MQTT_STATUS=$?
|
||||
|
||||
echo "torrent_mqtt.py exit status: $MQTT_STATUS"
|
||||
|
||||
###############################################################################
|
||||
# Check root path
|
||||
###############################################################################
|
||||
|
||||
echo
|
||||
echo "--- Checking root path ---"
|
||||
|
||||
if [[ ! -d "$ROOT_PATH" ]]; then
|
||||
echo "ERROR: Root path does not exist or is not a directory:"
|
||||
echo " $ROOT_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Root path exists."
|
||||
|
||||
###############################################################################
|
||||
# Copy torrent to mediahost
|
||||
###############################################################################
|
||||
|
||||
basename_root=$(basename "$ROOT_PATH")
|
||||
echo $basename_root
|
||||
if [ "$basename_root" = "downloads" ]; then
|
||||
remote_dir="$TORRENT_NAME"
|
||||
else
|
||||
remote_dir="$basename_root"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "--- Copying torrent to mediahost ---"
|
||||
echo "Source: $ROOT_PATH"
|
||||
echo "Destination: mediahost:/torrent/qbittorrent/mediahost/"
|
||||
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
LOG_FILE="$LOG_DIR/log_torrent_name_$(date '+%Y-%m-%d_%H-%M-%S').log"
|
||||
|
||||
# Redirect all stdout and stderr to the logfile
|
||||
exec >> "$LOG_FILE" 2>&1
|
||||
|
||||
###############################################################################
|
||||
# Start
|
||||
###############################################################################
|
||||
|
||||
echo "=================================================="
|
||||
echo "Torrent transfer started"
|
||||
echo "Date: $(date)"
|
||||
echo "Script: $SCRIPT_NAME"
|
||||
echo "Torrent name: $TORRENT_NAME"
|
||||
echo "Root path: $ROOT_PATH"
|
||||
echo "Category: $CATEGORY"
|
||||
echo "Log file: $LOG_FILE"
|
||||
echo "=================================================="
|
||||
|
||||
###############################################################################
|
||||
# Send torrent name to MQTT script
|
||||
###############################################################################
|
||||
|
||||
echo
|
||||
echo "--- Sending torrent name to torrent_mqtt.py ---"
|
||||
|
||||
if [[ ! -x "/home/lucas/scripts/serverhost/torrent_mqtt.py" ]]; then
|
||||
echo "WARNING: torrent_mqtt.py is not executable."
|
||||
echo "Attempting to run it through Python..."
|
||||
python3 "/home/lucas/scripts/serverhost/torrent_mqtt.py" "$TORRENT_NAME"
|
||||
ssh -i /config/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
lucas@mediahost "mkdir -p \"/torrent/qbittorrent/mediahost/$remote_dir\""
|
||||
SSH_STATUS=$?
|
||||
scp -i /config/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
-r "$ROOT_PATH"/. lucas@mediahost:/torrent/qbittorrent/mediahost/
|
||||
SCP_STATUS=$?
|
||||
|
||||
echo "scp exit status: $SCP_STATUS"
|
||||
|
||||
###############################################################################
|
||||
# Result
|
||||
###############################################################################
|
||||
|
||||
echo
|
||||
echo "=================================================="
|
||||
|
||||
if [[ $MQTT_STATUS -ne 0 ]]; then
|
||||
echo "WARNING: torrent_mqtt.py failed."
|
||||
fi
|
||||
if [[ $SSH_STATUS -eq 0 ]]; then
|
||||
echo "Target Dir generated"
|
||||
else
|
||||
echo "ERROR: Target dir generation failed."
|
||||
fi
|
||||
|
||||
if [[ $SCP_STATUS -eq 0 ]]; then
|
||||
echo "Torrent transfer completed successfully."
|
||||
else
|
||||
echo "ERROR: Torrent transfer failed."
|
||||
fi
|
||||
|
||||
echo "Finished: $(date +'%y%m%d %H%M%Sr')"
|
||||
echo "=================================================="
|
||||
else
|
||||
"/home/lucas/scripts/serverhost/torrent_mqtt.py" "$TORRENT_NAME"
|
||||
fi
|
||||
|
||||
MQTT_STATUS=$?
|
||||
|
||||
echo "torrent_mqtt.py exit status: $MQTT_STATUS"
|
||||
|
||||
###############################################################################
|
||||
# Check root path
|
||||
###############################################################################
|
||||
|
||||
echo
|
||||
echo "--- Checking root path ---"
|
||||
|
||||
if [[ ! -d "$ROOT_PATH" ]]; then
|
||||
echo "ERROR: Root path does not exist or is not a directory:"
|
||||
echo " $ROOT_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Root path exists."
|
||||
|
||||
###############################################################################
|
||||
# Copy torrent to mediahost
|
||||
###############################################################################
|
||||
|
||||
echo
|
||||
echo "--- Copying torrent to mediahost ---"
|
||||
echo "Source: $ROOT_PATH"
|
||||
echo "Destination: mediahost:/torrent/qbittorrent/mediahost/"
|
||||
|
||||
scp -r "$ROOT_PATH"/. mediahost:/torrent/qbittorrent/mediahost/
|
||||
SCP_STATUS=$?
|
||||
|
||||
echo "scp exit status: $SCP_STATUS"
|
||||
|
||||
###############################################################################
|
||||
# Result
|
||||
###############################################################################
|
||||
|
||||
echo
|
||||
echo "=================================================="
|
||||
|
||||
if [[ $MQTT_STATUS -ne 0 ]]; then
|
||||
echo "WARNING: torrent_mqtt.py failed."
|
||||
fi
|
||||
|
||||
if [[ $SCP_STATUS -eq 0 ]]; then
|
||||
echo "Torrent transfer completed successfully."
|
||||
else
|
||||
echo "ERROR: Torrent transfer failed."
|
||||
fi
|
||||
|
||||
echo "Finished: $(date)"
|
||||
echo "=================================================="
|
||||
echo "ARR handled torrent: $(date +'%y%m%d %H%M%S'): $TORRENT_NAME"
|
||||
fi
|
||||
|
||||
# Return SCP's exit status to qBittorrent
|
||||
exit "$SCP_STATUS"
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in new issue
Block a user