Skip to content

Instantly share code, notes, and snippets.

@jianyun8023
Last active July 7, 2022 07:49
Show Gist options
  • Save jianyun8023/0bf7fabbbe7574da03bd7514d2f0a4fd to your computer and use it in GitHub Desktop.
Save jianyun8023/0bf7fabbbe7574da03bd7514d2f0a4fd to your computer and use it in GitHub Desktop.
#!/bin/bash
#fonts color
yellow(){
echo -e "\033[33m\033[01m$1\033[0m"
}
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
#copy from 秋水逸冰 ss scripts
if [[ -f /etc/redhat-release ]]; then
release="centos"
systemPackage="yum"
systempwd="/usr/lib/systemd/system/"
elif cat /etc/issue | grep -Eqi "debian"; then
release="debian"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
release="ubuntu"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
release="centos"
systemPackage="yum"
systempwd="/usr/lib/systemd/system/"
elif cat /proc/version | grep -Eqi "debian"; then
release="debian"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /proc/version | grep -Eqi "ubuntu"; then
release="ubuntu"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
release="centos"
systemPackage="yum"
systempwd="/usr/lib/systemd/system/"
fi
function install_v2ray(){
CHECK=$(grep SELINUX= /etc/selinux/config | grep -v "#")
if [ "$CHECK" == "SELINUX=enforcing" ]; then
red "======================================================================="
red "检测到SELinux为开启状态,为防止申请证书失败,请先重启VPS后,再执行本脚本"
red "======================================================================="
read -p "是否现在重启 ?请输入 [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "VPS 重启中..."
reboot
fi
exit
fi
if [ "$CHECK" == "SELINUX=permissive" ]; then
red "======================================================================="
red "检测到SELinux为宽容状态,为防止申请证书失败,请先重启VPS后,再执行本脚本"
red "======================================================================="
read -p "是否现在重启 ?请输入 [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "VPS 重启中..."
reboot
fi
exit
fi
if [ "$release" == "centos" ]; then
if [ -n "$(grep ' 6\.' /etc/redhat-release)" ] ;then
red "==============="
red "当前系统不受支持"
red "==============="
exit
fi
if [ -n "$(grep ' 5\.' /etc/redhat-release)" ] ;then
red "==============="
red "当前系统不受支持"
red "==============="
exit
fi
systemctl stop firewalld
systemctl disable firewalld
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
elif [ "$release" == "ubuntu" ]; then
if [ -n "$(grep ' 14\.' /etc/os-release)" ] ;then
red "==============="
red "当前系统不受支持"
red "==============="
exit
fi
if [ -n "$(grep ' 12\.' /etc/os-release)" ] ;then
red "==============="
red "当前系统不受支持"
red "==============="
exit
fi
systemctl stop ufw
systemctl disable ufw
apt-get update
fi
$systemPackage -y install nginx wget unzip zip curl tar >/dev/null 2>&1
systemctl enable nginx.service
green "======================="
yellow "请输入绑定到本VPS的域名"
green "======================="
read your_domain
real_addr=`ping ${your_domain} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'`
local_addr=`curl ipv4.icanhazip.com`
if [ $real_addr == $local_addr ] ; then
green "=========================================="
green " 域名解析正常,开始安装v2ray"
green "=========================================="
sleep 1s
#设置伪装站
rm -rf /usr/share/nginx/html/*
cd /usr/share/nginx/html/
## 站点内容
wget https://github.com/V2RaySSR/Trojan/raw/master/web.zip
unzip web.zip
systemctl restart nginx.service
#申请https证书
mkdir -p /usr/local/etc/xray/cert
chmod 755 /usr/local/etc/xray/cert
green "======================="
yellow "请输入申请HTTPS证书的邮箱"
green "======================="
read your_email
curl https://get.acme.sh | sh -s email=$your_email
~/.acme.sh/acme.sh --issue -d $your_domain --webroot /usr/share/nginx/html/
~/.acme.sh/acme.sh --installcert -d $your_domain \
--key-file /usr/local/etc/xray/cert/private.key \
--fullchain-file /usr/local/etc/xray/cert/fullchain.crt \
--reloadcmd "systemctl restart xray.service"
if test -s /usr/local/etc/xray/cert/fullchain.crt; then
chmod 644 /usr/local/etc/xray/cert/private.key
chmod 644 /usr/local/etc/xray/cert/fullchain.crt
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
v2ray_id=$(uuidgen)
cat > /usr/local/etc/xray/config.json <<-EOF
{
"log": {
"access": "/var/log/xray/access.log",
"error": "/var/log/xray/error.log",
"loglevel": "warning"
},
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$v2ray_id",
"flow": "xtls-rprx-direct",
"level": 0,
"email": "love@v2fly.org"
}
],
"decryption": "none",
"fallbacks": [
{
"dest": 80
},
{
"path": "/wss",
"dest": 1234,
"xver": 1
}
]
},
"streamSettings": {
"network": "tcp",
"security": "xtls",
"xtlsSettings": {
"alpn": [
"http/1.1"
],
"certificates": [
{
"certificateFile": "/usr/local/etc/xray/cert/fullchain.crt",
"keyFile": "/usr/local/etc/xray/cert/private.key"
}
]
}
}
},
{
"port": 1234,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$v2ray_id",
"level": 0,
"email": "love@v2fly.org"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/wss"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"rules": [
{
"type": "field",
"ip": [
"geoip:private"
],
"outboundTag": "blocked"
}
]
}
}
EOF
systemctl enable xray.service
systemctl start xray.service
green "======================================================================"
green "va2ay已安装完成,请使用下面配置"
green "domain ${your_domain} id ${v2ray_id}"
green "======================================================================"
else
red "================================"
red "https证书没有申请成果,本次安装失败"
red "================================"
fi
else
red "================================"
red "域名解析地址与本VPS IP地址不一致"
red "本次安装失败,请确保域名解析正常"
red "================================"
fi
}
function remove_v2ray(){
red "================================"
red "即将卸载Xray"
red "同时卸载安装的nginx"
red "================================"
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove
if [ "$release" == "centos" ]; then
yum remove -y nginx
else
apt autoremove -y nginx
fi
green "=============="
green "Xray删除完毕"
green "=============="
}
function bbr_boost_sh(){
bash -c $(curl -L -s -k "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh")
}
start_menu(){
clear
green " ===================================="
green " Xray 一键安装自动脚本 "
green " 系统:centos7+/debian9+/ubuntu16.04+"
green " ===================================="
echo
red " ===================================="
yellow " 1. 一键安装 Xray"
red " ===================================="
yellow " 2. 安装 4 IN 1 BBRPLUS加速脚本"
red " ===================================="
yellow " 3. 一键卸载 Xray"
red " ===================================="
yellow " 0. 退出脚本"
red " ===================================="
echo
read -p "请输入数字:" num
case "$num" in
1)
install_v2ray
;;
2)
bbr_boost_sh
;;
3)
remove_v2ray
;;
0)
exit 1
;;
*)
clear
red "请输入正确数字"
sleep 1s
start_menu
;;
esac
}
start_menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment