Skip to content

Instantly share code, notes, and snippets.

@NNdroid
Created July 6, 2023 07:41
Show Gist options
  • Select an option

  • Save NNdroid/3e7c7e0bef3a3209cb840e1cc59250f2 to your computer and use it in GitHub Desktop.

Select an option

Save NNdroid/3e7c7e0bef3a3209cb840e1cc59250f2 to your computer and use it in GitHub Desktop.
hev-socks5-tunnel installer
#!/bin/bash
RELEASE_API="https://api.github.com/repos/heiher/hev-socks5-tunnel/releases/latest"
BIN_DST_DIR=/usr/local/bin
RESOURCE_DST_DIR=/usr/local/etc/hev-socks5-tunnel
function getReleaseInfo() {
response=$(curl ${RELEASE_API})
if [ $? == 0 ]; then
echo $response
return 0
else
return 1
fi
}
function check_error() {
if [ $? == 1 ]; then
echo $1
exit 1
fi
}
function install() {
assetDownloadUrl=$(curl $RELEASE_API | jq -r ".assets[] | select(.name == \"hev-socks5-tunnel-linux-x86_64\") | .browser_download_url")
echo $assetDownloadUrl
wget -O ${BIN_DST_DIR}/hev-socks5-tunnel $assetDownloadUrl
check_error "download binary error!"
chmod +x ${BIN_DST_DIR}/hev-socks5-tunnel
mkdir $RESOURCE_DST_DIR
cat << EOT > ${RESOURCE_DST_DIR}/config.yml
tunnel:
# Interface name
name: tun0
# Interface MTU
mtu: 8500
# Multi-queue
multi-queue: false
# IPv4 address
ipv4: 198.18.0.1
# IPv6 address
ipv6: 'fc00::1'
socks5:
# Socks5 server port
port: 1080
# Socks5 server address (ipv4/ipv6)
address: 127.0.0.1
# Socks5 UDP relay mode (tcp|udp)
udp: 'udp'
# Socks5 server username
# username: 'username'
# Socks5 server password
# password: 'password'
#misc:
# task stack size (bytes)
# task-stack-size: 20480
# connect timeout (ms)
# connect-timeout: 5000
# read-write timeout (ms)
# read-write-timeout: 60000
# stdout, stderr or file-path
# log-file: stderr
# debug, info, warn or error
# log-level: warn
# If present, run as a daemon with this pid file
# pid-file: /run/hev-socks5-tunnel.pid
# If present, set rlimit nofile; else use default value
# limit-nofile: 65535
EOT
cat << EOT > /etc/systemd/system/hev-socks5-tunnel.service
[unit]
Description=hev-socks5-tunnel
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
Environment=GOGC=20
ExecStart=${BIN_DST_DIR}/hev-socks5-tunnel ${RESOURCE_DST_DIR}/config.yml
Restart=on-failure
RestartSec=10
KillMode=process
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOT
systemctl enable --now hev-socks5-tunnel
clear
echo "finished"
}
function remove() {
systemctl stop hev-socks5-tunnel
systemctl disable hev-socks5-tunnel
rm -rf /etc/systemd/system/hev-socks5-tunnel.service
rm -rf ${BIN_DST_DIR}/hev-socks5-tunnel
rm -rf $RESOURCE_DST_DIR
clear
echo "remove finished!"
}
function help() {
cat << EOF
hev-socks5-server install helper!!!
usage:
./hev-socks5-tunnel.sh menu
install: install hev-socks5-tunnel
remove: remove hev-socks5-tunnel
EOF
}
function main() {
if [ $# -lt 1 ]; then
help
else
case $1 in
install)
install
;;
remove)
remove
;;
*)
echo 'command not found!'
help
;;
esac
fi
exit 0
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment