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