summarylogtreecommitdiffstats
path: root/update-aria2-tracker
blob: 9d60011b1c3aabc8dfd639c5ae284c2e3fcfeea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env bash

set -e

function get_aria2_home(){
    [[ $(id -nu) == "aria2cd" ]] && echo /etc/aria2cd && return 0
    for path in ${HOME}/.aria2 ${XDG_CONFIG_HOME:-${HOME}/.config}/aria2
    do
        [[ -f ${path}/aria2.conf ]] && echo ${path} && return 0
    done
    echo ${HOME}/.aria2 && return 0
}

ARIA2_CONFIG_HOME=$(get_aria2_home)
echo "Aria2 config is placing at ${ARIA2_CONFIG_HOME}"
if [[ -f "${ARIA2_CONFIG_HOME}/tracker-config.sh" ]]
then
    echo "Loading config from ${ARIA2_CONFIG_HOME}/tracker-config.sh"
    source "${ARIA2_CONFIG_HOME}/tracker-config.sh"
fi
[[ -z $ENABLED ]] && ENABLED=false
$ENABLED || exit 0
[[ -z $TRACKER ]] && \
    TRACKER=$(curl -Ls https://cdn.staticaly.com/gh/XIU2/TrackersListCollection/master/best_aria2.txt)
grep -q 'bt-tracker=' "${ARIA2_CONFIG_HOME}/aria2.conf" && \
    sed -i "s@bt-tracker=.*@bt-tracker=$TRACKER@" "${ARIA2_CONFIG_HOME}/aria2.conf" || \
    sed -i "\$a bt-tracker=$TRACKER" "${ARIA2_CONFIG_HOME}/aria2.conf"