summarylogtreecommitdiffstats
path: root/update-aria2-tracker
blob: acf3337e98fdbbc07b95cffe89598ad555453f72 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash

set -e

function get_aria2_home(){
    if [[ "$1" == "--systemd" ]]
    then
        echo /etc/aria2cd
        return 0
    fi
    for path in "${HOME}/.aria2" "${XDG_CONFIG_HOME:-${HOME}/.config}/aria2"
    do
        if [[ -f ${path}/aria2.conf ]]
        then
            echo "${path}"
            return 0
        fi
    done
    echo "${HOME}/.aria2"
    return 0
}

ARIA2_CONFIG_HOME=$(get_aria2_home "$1")
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
ENABLED=${ENABLED:-false}
if $ENABLED
then
    if [[ -z $TRACKER ]]
    then
        exit 1
    fi
    if grep -q 'bt-tracker=' "${ARIA2_CONFIG_HOME}/aria2.conf"
    then
        echo "Replacing tracker line"
        sed -i "s@bt-tracker=.*@bt-tracker=$TRACKER@" "${ARIA2_CONFIG_HOME}/aria2.conf"
    else
        echo "Adding tracker line"
        echo "bt-tracker=$TRACKER" >> "${ARIA2_CONFIG_HOME}/aria2.conf"
    fi
fi