Skip to content

Instantly share code, notes, and snippets.

@akaxxi
Created October 11, 2016 12:21
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save akaxxi/15f421d00f17447b94f90fbd5d44bf72 to your computer and use it in GitHub Desktop.
Save akaxxi/15f421d00f17447b94f90fbd5d44bf72 to your computer and use it in GitHub Desktop.
Install Aria2 and webui on Raspberry Pi with one simple script.
#!/bin/sh
DOWNLOAD_DIR="${HOME}/MiniDLNA"
CONFIG_DIR="${HOME}/.aria2"
RPC_TOKEN="changeIt"
RPC_PORT="6800"
change_apt_source(){
if [ -f /etc/apt/sources.list ]; then
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
fi
sudo sed -i '/^deb.*/s/^/# /g' /etc/apt/sources.list
sudo chmod 666 /etc/apt/sources.list
sudo echo "deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ jessie main non-free contrib" >> /etc/apt/sources.list
sudo echo "deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ jessie main non-free contrib" >> /etc/apt/sources.list
sudo chmod 644 /etc/apt/sources.list
}
# change_apt_source
sudo apt-get update
sudo apt-get install -y aria2 ca-certificates
if [ ! -d ${DOWNLOAD_DIR} ]; then
mkdir -p ${DOWNLOAD_DIR}
fi
if [ ! -d ${CONFIG_DIR} ]; then
mkdir -p ${CONFIG_DIR}
fi
if [ ! -f ${CONFIG_DIR}/aria2.session ]; then
touch ${CONFIG_DIR}/aria2.session
fi
if [ ! -f ${CONFIG_DIR}/aria2.log ]; then
touch ${CONFIG_DIR}/aria2.log
fi
if [ -f ${CONFIG_DIR}/aria2.conf ];then
mv ${CONFIG_DIR}/aria2.conf ${CONFIG_DIR}/aria2.conf.bak
fi
# Generate cfg file
cat > ${CONFIG_DIR}/aria2.conf <<-EOCFG
# For full reference:
# https://aria2.github.io/manual/en/html/aria2c.html
##
dir=${DOWNLOAD_DIR}
file-allocation=trunc
continue=true
# daemon=true
##
log=${CONFIG_DIR}/aria2.log
console-log-level=warn
log-level=notice
##
max-concurrent-downloads=5
max-connection-per-server=10
min-split-size=5M
split=10
disable-ipv6=true
##
input-file=${CONFIG_DIR}/aria2.session
save-session=${CONFIG_DIR}/aria2.session
save-session-interval=30
##
enable-rpc=true
rpc-allow-origin-all=true
rpc-listen-all=true
rpc-listen-port=${RPC_PORT}
rpc-secret=${RPC_TOKEN}
##
follow-torrent=mem
follow-metalink=mem
enable-dht6=false
peer-id-prefix=-TR2770-
user-agent=Transmission/2.77
seed-time=0
#seed-ratio=1.0
bt-seed-unverified=true
bt-save-metadata=true
EOCFG
# MiniDLNA
sudo apt-get install -y minidlna
sudo cp /etc/minidlna.conf /etc/minidlna.conf.origin
sudo sed -i 's#^media_dir=/.*#media_dir='${DOWNLOAD_DIR}'#g' /etc/minidlna.conf
sudo sed -i '/#inotify=yes/s/#//g' minidlna.conf #Enable media auto discover
sudo sed -i '$a fs.inotify.max_user_watches=65536' /etc/sysctl.conf
# aria2-webui on lighttpd
sudo apt-get install -y lighttpd unzip
wget https://github.com/ziahamza/webui-aria2/archive/master.zip
unzip -qu master.zip
cd webui-aria2-master/
change_token(){
sed -i '/token:/s/\/\///g' configuration.js
sed -i 's/\$YOUR_SECRET_TOKEN\$/'${RPC_TOKEN}'/g' configuration.js
}
# change_token
sudo cp -Rfu . /var/www/html/
cd ..
rm -rf webui-aria2-master master.zip
echo "Done!"
echo "Your Aria2 configuration and log file are in : ${CONFIG_DIR}"
echo "Your RPC token is: ${RPC_TOKEN}"
echo "Start aria2 with 'aria2c -D' and enjoy!"
@yarciapaul
Copy link

a little documentation would help a lot

@hukumdar
Copy link

hukumdar commented Oct 8, 2017

it is works indeed but i should give a little info to noobs like me

after finish message in order to start webui service use this commands
sudo openssl rand -base64 32
it will give you a long key
copy it and use it in this command
aria2c --enable-rpc --rpc-listen-all --rpc-secret="paste here your key and delete quotes" --daemon
after that you can login into webui by typing your raspberry lan ip (192.168.xxx.xxx)
after that in order to use webui open Settings-->Connection Settings
paste your key into "Enter the secret token (optional):" area and hit Save Connection configuration.
You are ready to go :)

@yarciapaul
Copy link

will the web ui open when i type 192.168.xxx.xxx:6800 in my browser? if it will, then this script would be very useful.

I'll give it a try right now.

@yarciapaul
Copy link

it worked! i typed the local ip address of my raspberry pi server and it displayed the aria2 web ui. But it looks like an unfinished html webpage. Attached is the print screen of the web ui

fix

@yarciapaul
Copy link

how can I completely reverse the changes made by this script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment