Last active
June 28, 2024 23:10
-
-
Save NNdroid/776373ae6151d909899cd40733ed2269 to your computer and use it in GitHub Desktop.
ss-rust 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GITHUB_API="https://api.github.com/repos/shadowsocks/shadowsocks-rust/releases" | |
BIN_PATH="/usr/local/bin" | |
CFG_PATH="/usr/local/etc/ss-rust" | |
TEMP_PATH="/tmp/ss-rust" | |
SS_LISTEN="::" | |
SS_PORT="2022" | |
SS_PWD="GbqAZCWgm8bE0uVnYYCaEA==" | |
SS_METHOD="2022-blake3-aes-128-gcm" | |
function check_error() { | |
if [ $? == 1 ]; then | |
echo $1 | |
exit 1 | |
fi | |
} | |
function install_pkgs() { | |
apt install jq curl wget xz-utils -y | |
} | |
function get_arch() { | |
arch=$(uname -m) | |
echo $arch | |
return | |
if [ "$arch" == "x86_64" ]; then | |
echo "amd64" | |
elif [ "$arch" == "aarch64" ]; then | |
echo "arm64" | |
else | |
echo "null" | |
fi | |
} | |
function install_binary() { | |
arch=$(get_arch) | |
echo "OS arch: ${arch}" | |
download_url=$(curl "${GITHUB_API}" | jq -r --arg arch "$arch" '.[0].assets[] | select(.name | test("^shadowsocks-v[0-9]+\\.[0-9]+\\.[0-9]+\\.\($arch)-unknown-linux-gnu.tar.xz$")) | .browser_download_url') | |
check_error "get download url error." | |
if [ -z "$download_url" ]; then | |
echo "get download url error." | |
exit 1 | |
else | |
echo "download bin from: ${download_url}" | |
wget -O ${TEMP_PATH}/ss.tar.xz "${download_url}" | |
check_error "a error for download bin." | |
tar -Jxvf ${TEMP_PATH}/ss.tar.xz -C ${TEMP_PATH} | |
mv ${TEMP_PATH}/ss* ${BIN_PATH} | |
fi | |
} | |
function install_config() { | |
mkdir $CFG_PATH | |
if [ -f "${CFG_PATH}/config.json" ]; then | |
echo "config.json was exists, skip create." | |
else | |
echo "config.json no found, create it." | |
cat <<EOF > ${CFG_PATH}/config.json | |
{ | |
"servers": [ | |
{ | |
"server": "${SS_LISTEN}", | |
"server_port": ${SS_PORT}, | |
"password": "${SS_PWD}", | |
"method": "${SS_METHOD}", | |
"timeout": 300, | |
"ipv6_first": true, | |
"nameserver": "8.8.8.8", | |
"mode": "tcp_only", | |
"acl": "${CFG_PATH}/chnroute.acl" | |
} | |
], | |
"log": { | |
"level": 0 | |
} | |
} | |
EOF | |
fi | |
} | |
function install_service() { | |
if [ -f "/etc/systemd/system/ss-rust.service" ]; then | |
echo "service was exists, skip create." | |
else | |
echo "service no found, create it." | |
cat <<EOF > /etc/systemd/system/ss-rust.service | |
[Unit] | |
Description=ss-rust | |
Wants=network.target | |
After=syslog.target network-online.target | |
[Service] | |
Type=simple | |
Environment=GOGC=20 | |
ExecStart=${BIN_PATH}/ssserver -c ${CFG_PATH}/config.json | |
Restart=always | |
RestartSec=10 | |
KillMode=process | |
LimitNOFILE=65536 | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
fi | |
systemctl enable --now ss-rust | |
} | |
function install_dict() { | |
wget -O ${TEMP_PATH}/chnroute.txt "https://raw.githubusercontent.com/ym/chnroutes2/master/chnroutes.txt" | |
check_error "download chnroute error." | |
grep -v '^#' ${TEMP_PATH}/chnroute.txt > ${TEMP_PATH}/chnroute_filtered.txt | |
echo "[outbound_block_list]" | cat - ${TEMP_PATH}/chnroute_filtered.txt > ${TEMP_PATH}/chnroute.acl | |
mv ${TEMP_PATH}/chnroute.acl ${CFG_PATH} | |
} | |
function main() { | |
mkdir ${TEMP_PATH} | |
install_pkgs | |
install_binary | |
install_config | |
install_dict | |
install_service | |
rm -rf ${TEMP_PATH} | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment