#!/bin/bash
SERVER_IP=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`
# update & upgrade
apt update && apt upgrade -y
# install shadowsocks
apt install -y shadowsocks
# write shadowsocks config
cat > /root/config.json <<EOF
{
"server":"$SERVER_IP",
"server_port":8388,
"local_address":"127.0.0.1",
"local_port":1080,
"password":"password++--",
"method":"aes-256-cfb"
}
EOF
# set autostart
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
cat > /etc/systemd/system/rc-local.service <<EOF
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
EOF
cat > /etc/rc.local <<EOF
#!/bin/bash
/usr/bin/ssserver -c /root/config.json -d start
EOF
chmod 755 /etc/rc.local
# turn on bbr
wget https://gist.githubusercontent.com/xinali/a738fe13a5483fb40d7d727c617b7da3/raw/da273105c6f12cfd2b23508da0663d9c2a2cdb46/ubuntu_enable_bbr.sh
bash ubuntu_enable_bbr.sh