summaryrefslogtreecommitdiff
path: root/yams
blob: 762313e7142cea4b6913b2cdad9a6cdbda158bd1 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
set -euo pipefail


dc="docker-compose -f <filename> -f <custom_file_filename>"
install_location="<install_location>"

option=${1:-"--help"}

help() {
   echo "yams - Yet Another Media Server"
   echo
   echo "Usage: yams [--help|restart|stop|start|status]"
   echo "options:"
   echo "--help     displays this help message"
   echo "restart    restarts yams services"
   echo "stop       stops all yams services"
   echo "start      starts yams services"
   echo "destroy    destroy yams services so you can start from scratch"
   echo "check-vpn  checks if the VPN is working as expected"
   echo "update     updates YAMS"
}

send_success_message() {
    echo -e "$(printf "\e[32m$1\e[0m")"
}

send_error_message() {
    echo -e "$(printf "\e[31m$1\e[0m")"
    exit 255
}

if [ "$option" == "--help" ]; then
    help
    exit 0
fi

if [ "$option" == "restart" ]; then
    $dc stop && $dc up -d
    echo "YAMS is starting. Wait 1 min until all the services are up and running..."
    exit 0
fi

if [ "$option" == "stop" ]; then
    $dc stop
    exit 0
fi

if [ "$option" == "start" ]; then
    $dc up -d
    echo "YAMS is starting. Wait 1 min until all the services are up and running..."
    exit 0
fi

if [ "$option" == "check-vpn" ]; then
    echo "Getting your IP..."
    your_ip=$(curl -s api.ipify.org)
    echo "$your_ip"
    echo "Your local IP country is $(curl -s https://am.i.mullvad.net/country)"
    echo
    echo
    echo "Getting your qBittorrent IP..."

    qbittorrent_ip=$(docker exec qbittorrent sh -c "curl -s api.ipify.org");
    if [ -n "$qbittorrent_ip" ]; then
        echo "$qbittorrent_ip"
        echo "Your country in qBittorrent is $(docker exec -it qbittorrent sh -c 'curl -s https://am.i.mullvad.net/country')"
        if [ "$qbittorrent_ip" == "$your_ip" ]; then
            send_error_message "Your IPs are the same! qBittorrent is exposing your IP! ⚠️"
        else
            send_success_message "Your IPs are different. qBittorrent is masking your IP! ✅ "
        fi
    else
        send_error_message "Failed to retrieve qBittorrent IP. Please check your setup. ⚠️"
    fi
fi

if [ "$option" == "destroy" ]; then
    echo
    echo
    read -p "Are you sure you want to destroy all your yams services? THIS IS NOT RECOVERABLE! ⚠️ ️🚨 [y/N]: " destroy_now
    destroy_now=${destroy_now:-"n"}
    if [ "$destroy_now" == "y" ]; then
        $dc down
        echo
        echo
        echo "yams services were destroyed. To restart, run: "
        echo "\$ yams start"
    fi
fi

if [ "$option" == "update" ]; then
    echo "Updating YAMS..."
    $dc stop
    rm -rf /tmp/yams && mkdir /tmp/yams
    wget https://gitlab.com/rogs/yams/-/raw/master/docker-compose.example.yaml -O /tmp/yams/docker-compose.example.yml > /dev/null 2>&1
    source $install_location/.env

    filename="$install_location/docker-compose.yaml"

    cp /tmp/yams/docker-compose.example.yml $filename


    sed -i -e "s;<media_service>;$MEDIA_SERVICE;g" "$filename"
    if [ "$MEDIA_SERVICE" == "plex" ]; then
        sed -i -e "s;#network_mode: host # plex;network_mode: host # plex;g" "$filename"
    fi

    if [ "$VPN_ENABLED" == "y" ]; then
        sed -i -e "s;#network_mode: \"service:gluetun\";network_mode: \"service:gluetun\";g" "$filename" \
            -e "s;ports: # qbittorrent;#port: # qbittorrent;g" "$filename" \
            -e "s;- 8080:8080 # qbittorrent;#- 8080:8080 # qbittorrent;g" "$filename" \
            -e "s;#- 8080:8080/tcp # gluetun;- 8080:8080/tcp # gluetun;g" "$filename"
    fi

    $dc up -d
    echo "YAMS was updated and it is starting. Wait 1 min until all the services are up and running..."
fi