diff --git a/.env.scripts b/.env.scripts index 5599c56..9a241ae 100644 --- a/.env.scripts +++ b/.env.scripts @@ -42,7 +42,7 @@ ENV_DISTRO_TAG="${IMAGE_VERSION}" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Env SERVICE_PORT="80" -EXPOSE_PORTS="6800" +EXPOSE_PORTS="6800 6888" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Versions PHP_VERSION="system" diff --git a/rootfs/tmp/etc/aria2/aria2.conf b/rootfs/tmp/etc/aria2/aria2.conf index ab717c3..fe62102 100644 --- a/rootfs/tmp/etc/aria2/aria2.conf +++ b/rootfs/tmp/etc/aria2/aria2.conf @@ -23,14 +23,14 @@ file-allocation=prealloc console-log-level=error save-session-interval=10 max-upload-limit=0 - follow-torrent=true -listen-port=6881 +listen-port=6888 +dht-listen-port=6888 user-agent=Transmission/2.77 seed-ratio=0 bt-seed-unverified=false bt-save-metadata=true - -bt-tracker=udp://62.138.0.158:6969/announce,udp://188.241.58.209:6969/announce,udp://151.80.120.112:2710/announce,udp://151.80.120.114:2710/announce,udp://93.158.213.92:1337/announce,udp://185.19.107.254:80/announce,udp://185.225.17.100:1337/announce,udp://208.83.20.20:6969/announce,udp://5.206.19.247:6969/announce,udp://37.235.174.46:2710/announce,udp://142.44.243.4:1337/announce,udp://195.154.52.99:80/announce,udp://54.37.235.149:6969/announce,udp://212.1.226.176:2710/announce,udp://89.234.156.205:451/announce,udp://159.100.245.181:6969/announce,udp://45.56.74.11:6969/announce,udp://51.15.226.113:6969/announce,udp://176.113.71.19:6961/announce,udp://51.15.40.114:80/announce on-download-error=/etc/aria2/scripts/post-hook.sh on-download-complete=/etc/aria2/scripts/post-hook.sh + +bt-tracker=udp://62.138.0.158:6969/announce,udp://188.241.58.209:6969/announce,udp://151.80.120.112:2710/announce,udp://151.80.120.114:2710/announce,udp://93.158.213.92:1337/announce,udp://185.19.107.254:80/announce,udp://185.225.17.100:1337/announce,udp://208.83.20.20:6969/announce,udp://5.206.19.247:6969/announce,udp://37.235.174.46:2710/announce,udp://142.44.243.4:1337/announce,udp://195.154.52.99:80/announce,udp://54.37.235.149:6969/announce,udp://212.1.226.176:2710/announce,udp://89.234.156.205:451/announce,udp://159.100.245.181:6969/announce,udp://45.56.74.11:6969/announce,udp://51.15.226.113:6969/announce,udp://176.113.71.19:6961/announce,udp://51.15.40.114:80/announce diff --git a/rootfs/usr/local/bin/tracker.sh b/rootfs/usr/local/bin/tracker.sh new file mode 100755 index 0000000..a69cba5 --- /dev/null +++ b/rootfs/usr/local/bin/tracker.sh @@ -0,0 +1,155 @@ +#!/usr/bin/env bash +# +# https://github.com/P3TERX/aria2.conf +# File name:tracker.sh +# Description: Get BT trackers and add to Aria2 +# Version: 3.1 +# +# Copyright (c) 2018-2021 P3TERX +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# BT tracker is provided by the following project. +# https://github.com/XIU2/TrackersListCollection +# +CUSTOM_TRACKER_URL="$2" +ARIA2_CONF="${1:-/config/aria2/aria2.conf}" +DOWNLOADER="curl -fsSL --connect-timeout 3 --max-time 3 --retry 2" + +RED_FONT_PREFIX="\033[31m" +FONT_COLOR_SUFFIX="\033[0m" +GREEN_FONT_PREFIX="\033[32m" +YELLOW_FONT_PREFIX="\033[1;33m" +LIGHT_PURPLE_FONT_PREFIX="\033[1;35m" +INFO="[${GREEN_FONT_PREFIX}INFO${FONT_COLOR_SUFFIX}]" +ERROR="[${RED_FONT_PREFIX}ERROR${FONT_COLOR_SUFFIX}]" +NL=$'\n' + +DATE_TIME() { + date +"%m/%d %H:%M:%S" +} + +GET_TRACKERS() { + + if [[ -z "${CUSTOM_TRACKER_URL}" ]]; then + echo && echo -e "$(DATE_TIME) ${INFO} Get BT trackers..." + TRACKER=$( + ${DOWNLOADER} https://trackerslist.com/all_aria2.txt || + ${DOWNLOADER} https://cdn.statically.io/gh/XIU2/TrackersListCollection/master/all_aria2.txt || + ${DOWNLOADER} https://trackers.p3terx.com/all_aria2.txt + ) + else + echo && echo -e "$(DATE_TIME) ${INFO} Get BT trackers from url(s):${CUSTOM_TRACKER_URL} ..." + URLS=$(echo ${CUSTOM_TRACKER_URL} | tr "," "$NL") + for URL in $URLS; do + TRACKER+="$(${DOWNLOADER} ${URL} | tr "," "\n")$NL" + done + TRACKER="$(echo "$TRACKER" | awk NF | sort -u | sed 'H;1h;$!d;x;y/\n/,/')" + fi + + [[ -z "${TRACKER}" ]] && { + echo + echo -e "$(DATE_TIME) ${ERROR} Unable to get trackers, network failure or invalid links." && exit 1 + } +} + +ECHO_TRACKERS() { + echo -e " +--------------------[BitTorrent Trackers]-------------------- +${TRACKER} +--------------------[BitTorrent Trackers]-------------------- +" +} + +ADD_TRACKERS() { + echo -e "$(DATE_TIME) ${INFO} Adding BT trackers to Aria2 configuration file ${LIGHT_PURPLE_FONT_PREFIX}${ARIA2_CONF}${FONT_COLOR_SUFFIX} ..." && echo + if [ ! -f ${ARIA2_CONF} ]; then + echo -e "$(DATE_TIME) ${ERROR} '${ARIA2_CONF}' does not exist." + exit 1 + else + [ -z $(grep "bt-tracker=" ${ARIA2_CONF}) ] && echo "bt-tracker=" >>${ARIA2_CONF} + sed -i "s@^\(bt-tracker=\).*@\1${TRACKER}@" ${ARIA2_CONF} && echo -e "$(DATE_TIME) ${INFO} BT trackers successfully added to Aria2 configuration file !" + fi +} + +ADD_TRACKERS_RPC() { + if [[ "${RPC_SECRET}" ]]; then + RPC_PAYLOAD='{"jsonrpc":"2.0","method":"aria2.changeGlobalOption","id":"P3TERX","params":["token:'${RPC_SECRET}'",{"bt-tracker":"'${TRACKER}'"}]}' + else + RPC_PAYLOAD='{"jsonrpc":"2.0","method":"aria2.changeGlobalOption","id":"P3TERX","params":[{"bt-tracker":"'${TRACKER}'"}]}' + fi + curl "${RPC_ADDRESS}" -fsSd "${RPC_PAYLOAD}" || curl "https://${RPC_ADDRESS}" -kfsSd "${RPC_PAYLOAD}" +} + +ADD_TRACKERS_RPC_STATUS() { + RPC_RESULT=$(ADD_TRACKERS_RPC) + [[ $(echo ${RPC_RESULT} | grep OK) ]] && + echo -e "$(DATE_TIME) ${INFO} BT trackers successfully added to Aria2 !" || + echo -e "$(DATE_TIME) ${ERROR} Network failure or Aria2 RPC interface error!" +} + +ADD_TRACKERS_REMOTE_RPC() { + echo -e "$(DATE_TIME) ${INFO} Adding BT trackers to remote Aria2: ${LIGHT_PURPLE_FONT_PREFIX}${RPC_ADDRESS%/*}${FONT_COLOR_SUFFIX} ..." && echo + ADD_TRACKERS_RPC_STATUS +} + +ADD_TRACKERS_LOCAL_RPC() { + if [ ! -f ${ARIA2_CONF} ]; then + echo -e "$(DATE_TIME) ${ERROR} '${ARIA2_CONF}' does not exist." + exit 1 + else + RPC_PORT=$(grep ^rpc-listen-port ${ARIA2_CONF} | cut -d= -f2-) + RPC_SECRET=$(grep ^rpc-secret ${ARIA2_CONF} | cut -d= -f2-) + [[ ${RPC_PORT} ]] || { + echo -e "$(DATE_TIME) ${ERROR} Aria2 configuration file incomplete." + exit 1 + } + RPC_ADDRESS="localhost:${RPC_PORT}/jsonrpc" + echo -e "$(DATE_TIME) ${INFO} Adding BT trackers to Aria2 ..." && echo + ADD_TRACKERS_RPC_STATUS + fi +} + +[ $(command -v curl) ] || { + echo -e "$(DATE_TIME) ${ERROR} curl is not installed." + exit 1 +} + +if [ "$1" = "cat" ]; then + GET_TRACKERS + ECHO_TRACKERS +elif [ "$1" = "RPC" ]; then + RPC_ADDRESS="$2/jsonrpc" + RPC_SECRET="$3" + GET_TRACKERS + ECHO_TRACKERS + ADD_TRACKERS_REMOTE_RPC +elif [ "$2" = "RPC" ]; then + GET_TRACKERS + ECHO_TRACKERS + ADD_TRACKERS + echo + ADD_TRACKERS_LOCAL_RPC +else + GET_TRACKERS + ECHO_TRACKERS + ADD_TRACKERS +fi + +exit 0 diff --git a/rootfs/usr/local/etc/docker/init.d/00-aria2c.sh b/rootfs/usr/local/etc/docker/init.d/00-aria2c.sh index 7f271cf..fbb4aee 100755 --- a/rootfs/usr/local/etc/docker/init.d/00-aria2c.sh +++ b/rootfs/usr/local/etc/docker/init.d/00-aria2c.sh @@ -224,6 +224,7 @@ __update_conf_files() { local get_data_dir="$(grep -Rs 'dir=' "/config/aria2/aria2.conf" | awk -F'=' '{print $2}')" local get_config="$(find "$WWW_ROOT_DIR/js" -name 'aria-ng-*.min.js' | grep -v 'f1dd57abb9.min' | head -n1)" local get_session_file="$(grep -Rs 'aria2.session' "/config/aria2/aria2.conf" | awk -F'=' '{print $2}' | head -n1)" + local dht_port="$DHT_LISTEN_PORT" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # delete files #__rm "" @@ -249,6 +250,15 @@ __update_conf_files() { __replace "rpc-secret=" "#rpc-secret=" "$CONF_DIR/aria2.conf" __replace "REPLACE_RPC_SECRET" "" "$CONF_DIR/aria-ng.config.js" fi + if [ -n "$dht_port" ]; then + sed -i "s@^\(listen-port=\).*@\1$dht_port@" "$CONF_DIR/aria2.conf" + sed -i "s@^\(dht-listen-port=\).*@\1$dht_port@" "$CONF_DIR/aria2.conf" + fi + sed -i "s@\(move-log=\).*@\1$LOG_DIR/move.log@" "$CONF_DIR/aria2.conf" + sed -i "s@\(upload-log=\).*@\1$LOG_DIR/upload.log@" "$CONF_DIR/aria2.conf" + if [ -n "$FILE_ALLOCATION" ]; then + sed -i "s@^\(file-allocation=\).*@\1${FILE_ALLOCATION}@" "$CONF_DIR/aria2.conf" + fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # define actions [ -n "$get_session_file" ] && touch "$get_session_file" @@ -262,6 +272,7 @@ __update_conf_files() { fi cp -Rf "$CONF_DIR/aria-ng.config.js" "$WWW_ROOT_DIR/js/aria-ng-f1dd57abb9.min.js" fi + /usr/local/bin/tracker.sh "$CONF_DIR/aria2.conf" "$CUSTOM_TRACKER_URL" # allow custom functions if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi # exit function