#!/bin/bash
# Instalar o aria2
sudo apt-get update
sudo apt-get install aria2 -y
# Instalar o Node.js (se necessário)
# sudo apt-get install curl -y
# curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
# sudo apt-get install nodejs -y
# Instalar o AriaNg
mkdir ariang
cd ariang
wget https://github.com/mayswind/AriaNg/releases/download/1.2.2/AriaNg-1.2.2.zip
unzip AriaNg-1.2.2.zip
cd ..
# Instalar o http-server
sudo npm install -g http-server
# Instalar o localtunnel
sudo npm install -g localtunnel
# Iniciar o servidor aria2c
aria2c --enable-rpc \
--rpc-listen-port=6800 \
-D "fr" \
-d {OUTPUT_DIR} \
-j 20 \
-c \
$(if [ res.ok ]; then echo "--bt-tracker=${res.text}"; fi) \
--bt-request-peer-speed-limit=0 \
--bt-max-peers=0 \
--seed-ratio=0.0 \
--max-connection-per-server=10 \
--min-split-size=10M \
--follow-torrent=mem \
--disable-ipv6=true \
--user-agent=Transmission/2.77 \
--peer-agent=Transmission/2.77 \
--peer-id-prefix=-TR2770- \
--split=20
# Aguardar alguns segundos para garantir que o servidor aria2c tenha iniciado completamente
sleep 5
# Obter o hostname do sistema
HOST=$(hostname)
# Porta para WebSocket
PORT="80"
# Caminho para o arquivo index.html do AriaNg
INDEX_FILE="ariang/index.html"
# Atualizar as configurações no arquivo index.html do AriaNg
sed -i "s/rpcHost:\"[^\"]\+./rpcHost:\"$HOST\"/" $INDEX_FILE
sed -i "s/protocol:\"\\w+./protocol:\"ws\"/" $INDEX_FILE
sed -i "s/rpcPort:\"\\d+./rpcPort:\"$PORT\"/" $INDEX_FILE
# Iniciar o http-server para servir o AriaNg
http-server /content/ariang --port 8080 &
# Iniciar o LocalTunnel para encaminhar as solicitações HTTP
lt --port 8080
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}