diff --git a/content/aria2/upload.sh b/content/aria2/upload.sh index fbf051a..0a15b2d 100644 --- a/content/aria2/upload.sh +++ b/content/aria2/upload.sh @@ -65,10 +65,10 @@ DEFINITION_PATH() { LOCAL_PATH="${TASK_PATH}" D_PATH="$(echo ${ARIA2_DOWNLOAD_DIR} | sed 's/\r$//')" PATH_SUFFIX="${DOWNLOAD_DIR#"${D_PATH}"}" - if [[ -f "${TASK_PATH}" ]]; then - REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${PATH_SUFFIX}" + if [[ "${ARIA_DRIVE_DIR}" =~ :/ ]]; then + REMOTE_PATH="${ARIA_DRIVE_DIR}${PATH_SUFFIX}" else - REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${PATH_SUFFIX}/${TASK_FILE_NAME}" + REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${PATH_SUFFIX}" fi } @@ -96,7 +96,7 @@ UPLOAD_FILE() { if [ -f "${LOCAL_PATH}" ]; then JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${DOWNLOAD_DIR}"'","srcRemote":"'"${TASK_FILE_NAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${TASK_FILE_NAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" else - JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${LOCAL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${LOCAL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'/'"${TASK_FILE_NAME}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" fi if [ "${JOB_ID}" != "" ]; then UPLOAD_LOG="$(DATE_TIME) ${INFO} Successfully send job to rclone: ${LOCAL_PATH} -> ${REMOTE_PATH}" diff --git a/content/gdltorclone.sh b/content/gdltorclone.sh index 4bea4f8..c2d39c0 100644 --- a/content/gdltorclone.sh +++ b/content/gdltorclone.sh @@ -1,46 +1,40 @@ #!/bin/bash - -DATE_TIME() { - date +"%m/%d %H:%M:%S" +# +# Created by wy580477 for customized container +# + +LOCAL_PATH="$1" +source /workdir/script_core.sh + +DEFINITION_PATH() { + UPLOAD_MODE="$(grep ^gallery-dl-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" + DOWNLOAD_DIR="$(jq '."base-directory"' /mnt/data/config/gallery-dl.conf | sed 's/\"//g;s/\r$//')" + GDL_DRIVE_DIR="$(grep ^gdl-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" + BASE_PATH="${LOCAL_PATH#"${DOWNLOAD_DIR%/}"}" + if [[ "${GDL_DRIVE_DIR}" =~ :/ ]]; then + REMOTE_PATH="${GDL_DRIVE_DIR}${BASE_PATH}" + else + if [ "${GDL_DRIVE_DIR}" = "" ]; then + DRIVE_DIR=${GLOBAL_DRIVE_DIR}/gallery-dl + else + DRIVE_DIR=${GDL_DRIVE_DIR} + fi + REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${BASE_PATH}" + fi } -UPLOAD_MODE="$(grep ^gallery-dl-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" -DELETE_EMPTY_DIR="$(grep ^delete-empty-dir /mnt/data/config/script.conf | cut -d= -f2-)" -DRIVE_NAME="$(grep ^drive-name /mnt/data/config/script.conf | cut -d= -f2-)" -DOWNLOAD_DIR="$(jq '."base-directory"' /mnt/data/config/gallery-dl.conf | sed 's/\"//g;s/\r$//')" - -DRIVE_NAME_AUTO="$(sed -n '1p' /mnt/data/config/rclone.conf | sed "s/.*\[//g;s/\].*//g;s/\r$//")" -if [ "${DRIVE_NAME}" = "auto" ]; then - DRIVENAME=${DRIVE_NAME_AUTO} -else - DRIVENAME=${DRIVE_NAME} -fi - -GLOBAL_DRIVE_DIR="$(grep ^drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" -GDL_DRIVE_DIR="$(grep ^gdl-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" - -if [ "${GDL_DRIVE_DIR}" = "" ]; then - DRIVE_DIR=${GLOBAL_DRIVE_DIR}/gallery-dl -else - DRIVE_DIR=${GDL_DRIVE_DIR} -fi - -DL_PATH="$1" -BASE_PATH="${DL_PATH#"${DOWNLOAD_DIR%/}"}" -REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${BASE_PATH}" - -if [ "${UPLOAD_MODE}" = "disable" ]; then - echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" -else - JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${DL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" - if [ "${JOB_ID}" != "" ]; then - echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' +UPLOAD_TASK() { + if [ "${UPLOAD_MODE}" = "disable" ]; then + echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $1" + UPLOAD_FOLDER fi -fi + if [ "${JOB_ID}" = "" ]; then + exit 1 + fi +} -if [[ "${DELETE_EMPTY_DIR}" = "true" ]]; then - find ${DOWNLOAD_DIR} -depth -mindepth 1 -type d -empty -exec rm -vrf {} \; 2>/dev/null -fi +GET_PATH +DEFINITION_PATH +UPLOAD_TASK +CLEAN_EMPTY_DIR diff --git a/content/pyload_to_rclone.sh b/content/pyload_to_rclone.sh index d4ae982..b1d3bc6 100644 --- a/content/pyload_to_rclone.sh +++ b/content/pyload_to_rclone.sh @@ -1,46 +1,39 @@ -#!/bin/sh - -DATE_TIME() { - date +"%m/%d %H:%M:%S" +#!/bin/bash +# +# Created by wy580477 for customized container +# + +LOCAL_PATH="$3" +FILE_NAME="$2" +source /workdir/script_core.sh + +DEFINITION_PATH() { + UPLOAD_MODE="$(grep ^pyload-download-finished-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" + DOWNLOAD_DIR="$(grep ^'.*folder storage_folder' /workdir/.pyload/settings/pyload.cfg | cut -d= -f2- | sed "s/\r$//")" + PYLOAD_DRIVE_DIR="$(grep ^pyload-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" + FILE_PATH=$(echo ${LOCAL_PATH} | sed 's:[^/]*$::') + DEST_PATH_SUFFIX="${FILE_PATH#"${DOWNLOAD_DIR%/}"}" + if [[ "${PYLOAD_DRIVE_DIR}" =~ :/ ]]; then + REMOTE_PATH="${PYLOAD_DRIVE_DIR}${DEST_PATH_SUFFIX}" + else + if [ "${PYLOAD_DRIVE_DIR}" = "" ]; then + DRIVE_DIR=${GLOBAL_DRIVE_DIR}/pyload + else + DRIVE_DIR=${PYLOAD_DRIVE_DIR} + fi + REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${DEST_PATH_SUFFIX}" + fi } -UPLOAD_MODE="$(grep ^pyload-download-finished-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" -DELETE_EMPTY_DIR="$(grep ^delete-empty-dir /mnt/data/config/script.conf | cut -d= -f2-)" -DRIVE_NAME="$(grep ^drive-name /mnt/data/config/script.conf | cut -d= -f2-)" -PYLOAD_DOWNLOAD_DIR="$(grep ^'.*folder storage_folder' /workdir/.pyload/settings/pyload.cfg | cut -d= -f2- | sed "s/\r$//")" - -DRIVE_NAME_AUTO="$(sed -n '1p' /mnt/data/config/rclone.conf | sed "s/.*\[//g;s/\].*//g;s/\r$//")" -if [ "${DRIVE_NAME}" = "auto" ]; then - DRIVENAME=${DRIVE_NAME_AUTO} -else - DRIVENAME=${DRIVE_NAME} -fi - -GLOBAL_DRIVE_DIR="$(grep ^drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" -PYLOAD_DRIVE_DIR="$(grep ^pyload-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" - -if [ "${PYLOAD_DRIVE_DIR}" = "" ]; then - DRIVE_DIR=${GLOBAL_DRIVE_DIR}/pyload -else - DRIVE_DIR=${PYLOAD_DRIVE_DIR} -fi - -FILE_PATH=$(echo $3 | sed 's:[^/]*$::') -DEST_PATH_SUFFIX="${FILE_PATH#"${PYLOAD_DOWNLOAD_DIR%/}"}" -REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${DEST_PATH_SUFFIX}" - -if [ "${UPLOAD_MODE}" = "disable" ]; then - echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" -else - JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILE_PATH}"'","srcRemote":"'"$2"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"$2"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" - if [ "${JOB_ID}" != "" ]; then - echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $3 -> ${REMOTE_PATH}" - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' +UPLOAD_TASK() { + if [ "${UPLOAD_MODE}" = "disable" ]; then + echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $3" + UPLOAD_FILE fi -fi +} -if [[ "${DELETE_EMPTY_DIR}" = "true" ]]; then - find ${PYLOAD_DOWNLOAD_DIR} -depth -mindepth 1 -type d -empty -exec rm -vrf {} \; 2>/dev/null -fi \ No newline at end of file +GET_PATH +DEFINITION_PATH +UPLOAD_TASK +CLEAN_EMPTY_DIR diff --git a/content/pyload_to_rclone_package_extracted.sh b/content/pyload_to_rclone_package_extracted.sh index 3b8c644..99f045a 100644 --- a/content/pyload_to_rclone_package_extracted.sh +++ b/content/pyload_to_rclone_package_extracted.sh @@ -1,44 +1,37 @@ -#!/bin/sh - -DATE_TIME() { - date +"%m/%d %H:%M:%S" +#!/bin/bash +# +# Created by wy580477 for customized container +# + +LOCAL_PATH="$3" +PACKAGE_NAME="$2" +source /workdir/script_core.sh + +DEFINITION_PATH() { + UPLOAD_MODE="$(grep ^pyload-package-extracted-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" + DOWNLOAD_DIR="$(grep ^'.*folder storage_folder' /workdir/.pyload/settings/pyload.cfg | cut -d= -f2- | sed "s/\r$//")" + PYLOAD_DRIVE_DIR="$(grep ^pyload-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" + if [[ "${PYLOAD_DRIVE_DIR}" =~ :/ ]]; then + REMOTE_PATH="${PYLOAD_DRIVE_DIR}/${PACKAGE_NAME}" + else + if [ "${PYLOAD_DRIVE_DIR}" = "" ]; then + DRIVE_DIR=${GLOBAL_DRIVE_DIR}/pyload + else + DRIVE_DIR=${PYLOAD_DRIVE_DIR} + fi + REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}/${PACKAGE_NAME}" + fi } -UPLOAD_MODE="$(grep ^pyload-package-extracted-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" -DELETE_EMPTY_DIR="$(grep ^delete-empty-dir /mnt/data/config/script.conf | cut -d= -f2-)" -DRIVE_NAME="$(grep ^drive-name /mnt/data/config/script.conf | cut -d= -f2-)" -PYLOAD_DOWNLOAD_DIR="$(grep ^'.*folder storage_folder' /workdir/.pyload/settings/pyload.cfg | cut -d= -f2- | sed "s/\r$//")" - -DRIVE_NAME_AUTO="$(sed -n '1p' /mnt/data/config/rclone.conf | sed "s/.*\[//g;s/\].*//g;s/\r$//")" -if [ "${DRIVE_NAME}" = "auto" ]; then - DRIVENAME=${DRIVE_NAME_AUTO} -else - DRIVENAME=${DRIVE_NAME} -fi - -GLOBAL_DRIVE_DIR="$(grep ^drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" -PYLOAD_DRIVE_DIR="$(grep ^pyload-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" - -if [ "${PYLOAD_DRIVE_DIR}" = "" ]; then - DRIVE_DIR=${GLOBAL_DRIVE_DIR}/pyload -else - DRIVE_DIR=${PYLOAD_DRIVE_DIR} -fi - -REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}" - -if [ "${UPLOAD_MODE}" = "disable" ]; then - echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" -else - JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"$3"'","dstFs":"'"${REMOTE_PATH}"'/'"$2"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" - if [ "${JOB_ID}" != "" ]; then - echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $3 -> ${REMOTE_PATH}" - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' +UPLOAD_TASK() { + if [ "${UPLOAD_MODE}" = "disable" ]; then + echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $3" + UPLOAD_FOLDER fi -fi +} -if [[ "${DELETE_EMPTY_DIR}" = "true" ]]; then - find ${PYLOAD_DOWNLOAD_DIR} -depth -mindepth 1 -type d -empty -exec rm -vrf {} \; 2>/dev/null -fi \ No newline at end of file +GET_PATH +DEFINITION_PATH +UPLOAD_TASK +CLEAN_EMPTY_DIR diff --git a/content/qbittorclone.sh b/content/qbittorclone.sh index 4ea9932..39518b1 100644 --- a/content/qbittorclone.sh +++ b/content/qbittorclone.sh @@ -1,51 +1,46 @@ -#!/bin/sh +#!/bin/bash +# +# Created by wy580477 for customized container +# -UPLOAD_MODE="$(grep ^qbit-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" -DELETE_EMPTY_DIR="$(grep ^delete-empty-dir /mnt/data/config/script.conf | cut -d= -f2-)" -DRIVE_NAME="$(grep ^drive-name /mnt/data/config/script.conf | cut -d= -f2-)" -QBIT_DOWNLOAD_DIR="$(grep ^'Session\\\DefaultSavePath' /mnt/data/config/qBittorrent/config/qBittorrent.conf | cut -d= -f2- | sed "s/\r$//")" +LOCAL_PATH="$1" +source /workdir/script_core.sh -DRIVE_NAME_AUTO="$(sed -n '1p' /mnt/data/config/rclone.conf | sed "s/.*\[//g;s/\].*//g;s/\r$//")" -if [ "${DRIVE_NAME}" = "auto" ]; then - DRIVENAME=${DRIVE_NAME_AUTO} -else - DRIVENAME=${DRIVE_NAME} -fi - -GLOBAL_DRIVE_DIR="$(grep ^drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" -QBIT_DRIVE_DIR="$(grep ^qbit-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" - -if [ "${QBIT_DRIVE_DIR}" = "" ]; then - DRIVE_DIR=${GLOBAL_DRIVE_DIR}/qBittorrent -else - DRIVE_DIR=${QBIT_DRIVE_DIR} -fi - -FILE_NAME="$(basename "$1")" -FILE_PATH="$(echo $1 | sed 's:[^/]*$::')" -DEST_PATH_SUFFIX="${FILE_PATH#"${QBIT_DOWNLOAD_DIR%/}"}" -REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}${DEST_PATH_SUFFIX}" - -if [ "${UPLOAD_MODE}" = "disable" ]; then - echo "[INFO] Auto-upload to Rclone remote disabled" -elif [ -f "$1" ]; then - JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILE_PATH}"'","srcRemote":"'"${FILE_NAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${FILE_NAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" - if [ "${JOB_ID}" != "" ]; then - echo "[INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' +DEFINITION_PATH() { + UPLOAD_MODE="$(grep ^qbit-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" + DOWNLOAD_DIR="$(grep ^'Session\\\DefaultSavePath' /mnt/data/config/qBittorrent/config/qBittorrent.conf | cut -d= -f2- | sed "s/\r$//")" + QBIT_DRIVE_DIR="$(grep ^qbit-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" + FILE_NAME="$(basename "${LOCAL_PATH}")" + FILE_PATH="$(echo ${LOCAL_PATH} | sed 's:[^/]*$::')" + DEST_PATH_SUFFIX="${FILE_PATH#"${DOWNLOAD_DIR%/}"}" + if [[ "${QBIT_DRIVE_DIR}" =~ :/ ]]; then + REMOTE_PATH_PREFIX="${QBIT_DRIVE_DIR}" else - echo "[ERROR] Failed to send job to rclone: $1" + if [ "${QBIT_DRIVE_DIR}" = "" ]; then + DRIVE_DIR=${GLOBAL_DRIVE_DIR}/qBittorrent + else + DRIVE_DIR=${QBIT_DRIVE_DIR} + fi + REMOTE_PATH_PREFIX="${DRIVENAME}:${DRIVE_DIR}" fi -else - JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"$1"'","dstFs":"'"${REMOTE_PATH}"'/'"$2"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" - if [ "${JOB_ID}" != "" ]; then - echo "[INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' + if [ -f "${LOCAL_PATH}" ]; then + REMOTE_PATH="${REMOTE_PATH_PREFIX}${DEST_PATH_SUFFIX}" + else + REMOTE_PATH="${REMOTE_PATH_PREFIX}${DEST_PATH_SUFFIX}/${FILE_NAME}" + fi +} + +UPLOAD_TASK() { + if [ "${UPLOAD_MODE}" = "disable" ]; then + echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" + elif [ -f "${LOCAL_PATH}" ]; then + UPLOAD_FILE else - echo "[ERROR] Failed to send job to rclone: $1" + UPLOAD_FOLDER fi -fi +} -if [[ "${DELETE_EMPTY_DIR}" = "true" ]]; then - find ${QBIT_DOWNLOAD_DIR} -depth -mindepth 1 -type d -empty -exec rm -vrf {} \; 2>/dev/null -fi +GET_PATH +DEFINITION_PATH +UPLOAD_TASK +CLEAN_EMPTY_DIR diff --git a/content/script.conf b/content/script.conf index ddbe902..fddfa68 100644 --- a/content/script.conf +++ b/content/script.conf @@ -34,32 +34,27 @@ pyload-download-finished-upload-mode=disable # pyLoad auto-upload mode after package extracted. move | copy | disable pyload-package-extracted-upload-mode=disable -# 网盘名称(RCLONE 配置时填写的 name)。默认值auto将从配置文件第一行中提取。 -# Rclone remote name. If set to auto, Remote name will be extracted from the first line of rclone config file. +# 默认上传网盘名称(RCLONE 配置时填写的 name)。默认值auto将从配置文件第一行中提取。 +# Default Rclone remote name. If set to auto, Remote name will be extracted from the first line of rclone config file. drive-name=auto # 全局上传目标目录,网盘中的文件夹路径。末尾不要有斜杠。 # global Rclone remote upload path. drive-dir=/upload -# Aria2 上传目标目录,网盘中的文件夹路径。末尾不要有斜杠。留空则采用全局上传目标目录。 -# Aria2 Rclone remote upload path. If set to empty, global upload path will be used. +## 自定义下载工具独立上传路径。支持 Remote:/path 和 /path 两种写法,前者可自定义上传目的网盘名称,后者上传到默认网盘名称。## +## 末尾不要有斜杠。留空则采用全局上传目标目录。## +## Per downloader Rclone remote upload path. If set to empty, default Rclone remote name and global upload path will be used.## +## Support "Remote:/path" and "/path" format. The former can customize Rclone remote name, the latter will upload to default Rclone remote name.## +# Aria2 上传路径 | Aria2 Rclone remote upload path aria2-drive-dir= - -# qBittorrent 上传目标目录,网盘中的文件夹路径)。末尾不要有斜杠。留空则采用全局上传目标目录。 -# qBittorrent Rclone remote upload path. If set to empty, global upload path will be used. +# qBittorrent 上传路径 | qBittorrent Rclone remote upload path qbit-drive-dir= - -# yt-dlp 上传目标目录,网盘中的文件夹路径)。末尾不要有斜杠。留空则采用全局上传目标目录。 -# yt-dlp Rclone remote upload path. If set to empty, global upload path will be used. +# yt-dlp 上传路径 | yt-dlp Rclone remote upload path ytdlp-drive-dir= - -# gallery-dl 上传目标目录,网盘中的文件夹路径)。末尾不要有斜杠。留空则采用全局上传目标目录。 -# gallery-dl Rclone remote upload path. If set to empty, global upload path will be used. +# gallery-dl 上传路径 | gallery-dl Rclone remote upload path gdl-drive-dir= - -# pyLoad 上传目标目录,网盘中的文件夹路径)。末尾不要有斜杠。留空则采用全局上传目标目录。 -# pyLoad Rclone remote upload path. If set to empty, global upload path will be used. +# pyLoad 上传路径 | pyLoad Rclone remote upload path pyload-drive-dir= # 自动删除空目录。 diff --git a/content/script_core.sh b/content/script_core.sh new file mode 100644 index 0000000..3723805 --- /dev/null +++ b/content/script_core.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# Created by wy580477 for customized container +# + +DATE_TIME() { + date +"%m/%d %H:%M:%S" +} + +GET_PATH() { + DELETE_EMPTY_DIR="$(grep ^delete-empty-dir /mnt/data/config/script.conf | cut -d= -f2-)" + DRIVE_NAME="$(grep ^drive-name /mnt/data/config/script.conf | cut -d= -f2-)" + GLOBAL_DRIVE_DIR="$(grep ^drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" + DRIVE_NAME_AUTO="$(sed -n '1p' /mnt/data/config/rclone.conf | sed "s/.*\[//g;s/\].*//g;s/\r$//")" + if [ "${DRIVE_NAME}" = "auto" ]; then + DRIVENAME=${DRIVE_NAME_AUTO} + else + DRIVENAME=${DRIVE_NAME} + fi +} + +UPLOAD_FILE() { + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILE_PATH}"'","srcRemote":"'"${FILE_NAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${FILE_NAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then + echo "[INFO] Successfully send job to rclone: ${FILE_PATH}${FILE_NAME} -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' + else + echo "[ERROR] Failed to send job to rclone: ${FILE_PATH}${FILE_NAME}" + fi +} + +UPLOAD_FOLDER() { + JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${LOCAL_PATH}"'","dstFs":"'"${REMOTE_PATH}"'","_async":"true"}' 'localhost:61802/sync/'${UPLOAD_MODE}'' | jq .jobid | sed 's/\"//g')" + if [ "${JOB_ID}" != "" ]; then + echo "$(DATE_TIME) [INFO] Successfully send job to rclone: ${LOCAL_PATH} -> ${REMOTE_PATH}" + curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' + else + echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: ${LOCAL_PATH}" + fi +} + +CLEAN_EMPTY_DIR() { + if [ "${DELETE_EMPTY_DIR}" = "true" ]; then + find ${DOWNLOAD_DIR} -depth -mindepth 1 -type d -empty -exec rm -vrf {} \; 2>/dev/null + fi +} diff --git a/content/ytdlptorclone.sh b/content/ytdlptorclone.sh index 9b09da9..a1768dd 100644 --- a/content/ytdlptorclone.sh +++ b/content/ytdlptorclone.sh @@ -1,41 +1,40 @@ -#!/bin/sh +#!/bin/bash +# +# Created by wy580477 for customized container +# -DATE_TIME() { - date +"%m/%d %H:%M:%S" -} - -UPLOAD_MODE="$(grep ^ytdlp-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" -DRIVE_NAME="$(grep ^drive-name /mnt/data/config/script.conf | cut -d= -f2-)" - -DRIVE_NAME_AUTO="$(sed -n '1p' /mnt/data/config/rclone.conf | sed "s/.*\[//g;s/\].*//g;s/\r$//")" -if [ "${DRIVE_NAME}" = "auto" ]; then - DRIVENAME=${DRIVE_NAME_AUTO} -else - DRIVENAME=${DRIVE_NAME} -fi +LOCAL_PATH="$1" +source /workdir/script_core.sh -GLOBAL_DRIVE_DIR="$(grep ^drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" -YTDLP_DRIVE_DIR="$(grep ^ytdlp-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" - -if [ "${YTDLP_DRIVE_DIR}" = "" ]; then - DRIVE_DIR=${GLOBAL_DRIVE_DIR}/yt-dlp -else - DRIVE_DIR=${YTDLP_DRIVE_DIR} -fi - -REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}" -FILEPATH=$(echo $1 | sed 's:[^/]*$::') -FILENAME=$(basename "$1") -mv "$1" "${FILEPATH}""${FILENAME}" +DEFINITION_PATH() { + UPLOAD_MODE="$(grep ^ytdlp-upload-mode /mnt/data/config/script.conf | cut -d= -f2-)" + YTDLP_DRIVE_DIR="$(grep ^ytdlp-drive-dir /mnt/data/config/script.conf | cut -d= -f2-)" + FILE_PATH=$(echo ${LOCAL_PATH} | sed 's:[^/]*$::') + FILE_NAME=$(basename "${LOCAL_PATH}") + mv "${LOCAL_PATH}" "${FILE_PATH}""${FILE_NAME}" + if [[ "${YTDLP_DRIVE_DIR}" =~ :/ ]]; then + REMOTE_PATH="${YTDLP_DRIVE_DIR}" + else + if [ "${YTDLP_DRIVE_DIR}" = "" ]; then + DRIVE_DIR=${GLOBAL_DRIVE_DIR}/yt-dlp + else + DRIVE_DIR=${YTDLP_DRIVE_DIR} + fi + REMOTE_PATH="${DRIVENAME}:${DRIVE_DIR}" + fi +} -if [ "${UPLOAD_MODE}" = "disable" ]; then - echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" -else - JOB_ID="$(curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"srcFs":"'"${FILEPATH}"'","srcRemote":"'"${FILENAME}"'","dstFs":"'"${REMOTE_PATH}"'","dstRemote":"'"${FILENAME}"'","_async":"true"}' 'localhost:61802/operations/'${UPLOAD_MODE}'file' | jq .jobid | sed 's/\"//g')" - if [ "${JOB_ID}" != "" ]; then - echo "$(DATE_TIME) [INFO] Successfully send job to rclone: $1 -> ${REMOTE_PATH}" - curl -s -u ${GLOBAL_USER}:${GLOBAL_PASSWORD} -H "Content-Type: application/json" -f -X POST -d '{"jobid":"'"${JOB_ID}"'"}' 'localhost:61802/job/status' +UPLOAD_TASK() { + if [ "${UPLOAD_MODE}" = "disable" ]; then + echo "$(DATE_TIME) [INFO] Auto-upload to Rclone remote disabled" else - echo "$(DATE_TIME) [ERROR] Failed to send job to rclone: $1" + UPLOAD_FILE + fi + if [ "${JOB_ID}" = "" ]; then + exit 1 fi -fi +} + +GET_PATH +DEFINITION_PATH +UPLOAD_TASK