Created
June 7, 2023 12:40
-
-
Save NNdroid/0afc81ce62365b69dce9f197309787fa to your computer and use it in GitHub Desktop.
sniproxy installer
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 | |
| RELEASE_API="https://api.github.com/repos/XIU2/SNIProxy/releases/latest" | |
| BIN_DST_DIR=/usr/local/bin | |
| RESOURCE_DST_DIR=/usr/local/etc/sniproxy | |
| 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="https://github.com/XIU2/SNIProxy/releases/download/v1.0.0/sniproxy_linux_amd64.tar.gz" | |
| echo $assetDownloadUrl | |
| wget -O /tmp/sniproxy.tar.gz $assetDownloadUrl | |
| check_error "download binary error!" | |
| tar -zxvf /tmp/sniproxy.tar.gz -C /tmp | |
| check_error "uncompression error!" | |
| mv /tmp/sniproxy ${BIN_DST_DIR}/sniproxy | |
| chmod +x ${BIN_DST_DIR}/sniproxy | |
| mkdir $RESOURCE_DST_DIR | |
| mv /tmp/config.yaml $RESOURCE_DST_DIR | |
| cat << EOT > ${RESOURCE_DST_DIR}/config.yaml | |
| # 监听端口 | |
| listen_addr: :443 | |
| # 可选:启用 Socks5 代理(访客 <=> SNIProxy <=> Socks5 <=> 目标网站) | |
| enable_socks5: true | |
| # 可选:配置 Socks5 代理地址 | |
| socks_addr: 10.9.3.1:9050 | |
| # 可选:允许所有域名(会忽略下面的 rules 列表) | |
| allow_all_hosts: true | |
| # 仅允许指定域名 | |
| # 指定域名后,则代表允许域名自身及其所有子域名访问该服务(以下方两个为例 example.com、a.example.com 与 b.example2.com、c.> | |
| rules: | |
| - example.com | |
| - b.example2.com | |
| EOT | |
| cat << EOT > /etc/systemd/system/sniproxy.service | |
| [unit] | |
| Description=sniproxy | |
| Wants=network.target | |
| After=syslog.target network-online.target | |
| [Service] | |
| User=root | |
| Type=simple | |
| Environment=GOGC=20 | |
| ExecStart=${BIN_DST_DIR}/sniproxy -c ${RESOURCE_DST_DIR}/config.yaml | |
| Restart=on-failure | |
| RestartSec=10 | |
| KillMode=process | |
| LimitNOFILE=65536 | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOT | |
| systemctl enable --now sniproxy | |
| clear | |
| echo -e "config.yaml in ${RESOURCE_DST_DIR}/config.yaml" | |
| echo "finished" | |
| } | |
| function remove() { | |
| systemctl stop sniproxy | |
| systemctl disable sniproxy | |
| rm -rf /etc/systemd/system/sniproxy.service | |
| rm -rf ${BIN_DST_DIR}/sniproxy | |
| rm -rf $RESOURCE_DST_DIR | |
| clear | |
| echo "remove finished!" | |
| } | |
| function help() { | |
| cat << EOF | |
| sniproxy install helper!!! | |
| usage: | |
| ./sniproxy.sh menu | |
| install: install sniproxy | |
| remove: remove sniproxy | |
| 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