Delete sing-box directory

This commit is contained in:
NewName
2024-06-24 23:33:49 +08:00
parent 8bf065fb33
commit 763bc7318b
11 changed files with 0 additions and 2694 deletions

View File

@@ -1,434 +0,0 @@
#!/bin/bash
author=github
# github=https://github.com/github/sing-box
# bash fonts colors
red='\e[31m'
yellow='\e[33m'
gray='\e[90m'
green='\e[92m'
blue='\e[94m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
_red() { echo -e ${red}$@${none}; }
_blue() { echo -e ${blue}$@${none}; }
_cyan() { echo -e ${cyan}$@${none}; }
_green() { echo -e ${green}$@${none}; }
_yellow() { echo -e ${yellow}$@${none}; }
_magenta() { echo -e ${magenta}$@${none}; }
_red_bg() { echo -e "\e[41m$@${none}"; }
is_err=$(_red_bg 错误!)
is_warn=$(_red_bg 警告!)
err() {
echo -e "\n$is_err $@\n" && exit 1
}
warn() {
echo -e "\n$is_warn $@\n"
}
# root
[[ $EUID != 0 ]] && err "当前非 ${yellow}ROOT用户.${none}"
# yum or apt-get, ubuntu/debian/centos
cmd=$(type -P apt-get || type -P yum)
[[ ! $cmd ]] && err "此脚本仅支持 ${yellow}(Ubuntu or Debian or CentOS)${none}."
# systemd
[[ ! $(type -P systemctl) ]] && {
err "此系统缺少 ${yellow}(systemctl)${none}, 请尝试执行:${yellow} ${cmd} update -y;${cmd} install systemd -y ${none}来修复此错误."
}
# wget installed or none
is_wget=$(type -P wget)
# x64
case $(uname -m) in
amd64 | x86_64)
is_arch=amd64
;;
*aarch64* | *armv8*)
is_arch=arm64
;;
*)
err "此脚本仅支持 64 位系统..."
;;
esac
is_core=sing-box
is_core_name=sing-box
is_core_dir=/etc/$is_core
is_core_bin=$is_core_dir/bin/$is_core
is_core_repo=SagerNet/$is_core
is_conf_dir=$is_core_dir/conf
is_log_dir=/var/log/$is_core
is_sh_bin=/usr/local/bin/$is_core
is_sh_dir=$is_core_dir/sh
is_sh_repo=$author/$is_core
is_pkg="wget tar"
is_config_json=$is_core_dir/config.json
tmp_var_lists=(
tmpcore
tmpsh
tmpjq
is_core_ok
is_sh_ok
is_jq_ok
is_pkg_ok
)
# tmp dir
tmpdir=$(mktemp -u)
[[ ! $tmpdir ]] && {
tmpdir=/tmp/tmp-$RANDOM
}
# set up var
for i in ${tmp_var_lists[*]}; do
export $i=$tmpdir/$i
done
# load bash script.
load() {
. $is_sh_dir/src/$1
}
# wget add --no-check-certificate
_wget() {
[[ $proxy ]] && export https_proxy=$proxy
wget --no-check-certificate $*
}
# print a mesage
msg() {
case $1 in
warn)
local color=$yellow
;;
err)
local color=$red
;;
ok)
local color=$green
;;
esac
echo -e "${color}$(date +'%T')${none}) ${2}"
}
# show help msg
show_help() {
echo -e "Usage: $0 [-f xxx | -l | -p xxx | -v xxx | -h]"
echo -e " -f, --core-file <path> 自定义 $is_core_name 文件路径, e.g., -f /root/$is_core-linux-amd64.tar.gz"
echo -e " -l, --local-install 本地获取安装脚本, 使用当前目录"
echo -e " -p, --proxy <addr> 使用代理下载, e.g., -p http://127.0.0.1:2333 or -p socks5://127.0.0.1:2333"
echo -e " -v, --core-version <ver> 自定义 $is_core_name 版本, e.g., -v v1.8.13"
echo -e " -h, --help 显示此帮助界面\n"
exit 0
}
# install dependent pkg
install_pkg() {
cmd_not_found=
for i in $*; do
[[ ! $(type -P $i) ]] && cmd_not_found="$cmd_not_found,$i"
done
if [[ $cmd_not_found ]]; then
pkg=$(echo $cmd_not_found | sed 's/,/ /g')
msg warn "安装依赖包 >${pkg}"
$cmd install -y $pkg &>/dev/null
if [[ $? != 0 ]]; then
[[ $cmd =~ yum ]] && yum install epel-release -y &>/dev/null
$cmd update -y &>/dev/null
$cmd install -y $pkg &>/dev/null
[[ $? == 0 ]] && >$is_pkg_ok
else
>$is_pkg_ok
fi
else
>$is_pkg_ok
fi
}
# download file
download() {
case $1 in
core)
[[ ! $is_core_ver ]] && is_core_ver=$(_wget -qO- "https://api.github.com/repos/${is_core_repo}/releases/latest?v=$RANDOM" | grep tag_name | egrep -o 'v([0-9.]+)')
[[ $is_core_ver ]] && link="https://github.com/${is_core_repo}/releases/download/${is_core_ver}/${is_core}-${is_core_ver:1}-linux-${is_arch}.tar.gz"
name=$is_core_name
tmpfile=$tmpcore
is_ok=$is_core_ok
;;
sh)
link=https://github.com/${is_sh_repo}/releases/latest/download/code.tar.gz
name="$is_core_name 脚本"
tmpfile=$tmpsh
is_ok=$is_sh_ok
;;
jq)
link=https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-$is_arch
name="jq"
tmpfile=$tmpjq
is_ok=$is_jq_ok
;;
esac
[[ $link ]] && {
msg warn "下载 ${name} > ${link}"
if _wget -t 3 -q -c $link -O $tmpfile; then
mv -f $tmpfile $is_ok
fi
}
}
# get server ip
get_ip() {
export "$(_wget -4 -qO- https://one.one.one.one/cdn-cgi/trace | grep ip=)" &>/dev/null
[[ -z $ip ]] && export "$(_wget -6 -qO- https://one.one.one.one/cdn-cgi/trace | grep ip=)" &>/dev/null
}
# check background tasks status
check_status() {
# dependent pkg install fail
[[ ! -f $is_pkg_ok ]] && {
msg err "安装依赖包失败"
is_fail=1
}
# download file status
if [[ $is_wget ]]; then
[[ ! -f $is_core_ok ]] && {
msg err "下载 ${is_core_name} 失败"
is_fail=1
}
[[ ! -f $is_sh_ok ]] && {
msg err "下载 ${is_core_name} 脚本失败"
is_fail=1
}
[[ ! -f $is_jq_ok ]] && {
msg err "下载 jq 失败"
is_fail=1
}
else
[[ ! $is_fail ]] && {
is_wget=1
[[ ! $is_core_file ]] && download core &
[[ ! $local_install ]] && download sh &
[[ $jq_not_found ]] && download jq &
get_ip
wait
check_status
}
fi
# found fail status, remove tmp dir and exit.
[[ $is_fail ]] && {
exit_and_del_tmpdir
}
}
# parameters check
pass_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-f | --core-file)
[[ -z $2 ]] && {
err "($1) 缺少必需参数, 正确使用示例: [$1 /root/$is_core-linux-amd64.tar.gz]"
} || [[ ! -f $2 ]] && {
err "($2) 不是一个常规的文件."
}
is_core_file=$2
shift 2
;;
-l | --local-install)
[[ ! -f ${PWD}/src/core.sh || ! -f ${PWD}/$is_core.sh ]] && {
err "当前目录 (${PWD}) 非完整的脚本目录."
}
local_install=1
shift 1
;;
-p | --proxy)
[[ -z $2 ]] && {
err "($1) 缺少必需参数, 正确使用示例: [$1 http://127.0.0.1:2333 or -p socks5://127.0.0.1:2333]"
}
proxy=$2
shift 2
;;
-v | --core-version)
[[ -z $2 ]] && {
err "($1) 缺少必需参数, 正确使用示例: [$1 v1.8.13]"
}
is_core_ver=v${2//v/}
shift 2
;;
-h | --help)
show_help
;;
*)
echo -e "\n${is_err} ($@) 为未知参数...\n"
show_help
;;
esac
done
[[ $is_core_ver && $is_core_file ]] && {
err "无法同时自定义 ${is_core_name} 版本和 ${is_core_name} 文件."
}
}
# exit and remove tmpdir
exit_and_del_tmpdir() {
rm -rf $tmpdir
[[ ! $1 ]] && {
msg err "哦豁.."
msg err "安装过程出现错误..."
echo -e "反馈问题) https://github.com/${is_sh_repo}/issues"
echo
exit 1
}
exit
}
# main
main() {
# check old version
[[ -f $is_sh_bin && -d $is_core_dir/bin && -d $is_sh_dir && -d $is_conf_dir ]] && {
err "检测到脚本已安装, 如需重装请使用${green} ${is_core} reinstall ${none}命令."
}
# check parameters
[[ $# -gt 0 ]] && pass_args $@
# show welcome msg
clear
echo
echo "........... $is_core_name script by $author .........."
echo
# start installing...
msg warn "开始安装..."
[[ $is_core_ver ]] && msg warn "${is_core_name} 版本: ${yellow}$is_core_ver${none}"
[[ $proxy ]] && msg warn "使用代理: ${yellow}$proxy${none}"
# create tmpdir
mkdir -p $tmpdir
# if is_core_file, copy file
[[ $is_core_file ]] && {
cp -f $is_core_file $is_core_ok
msg warn "${yellow}${is_core_name} 文件使用 > $is_core_file${none}"
}
# local dir install sh script
[[ $local_install ]] && {
>$is_sh_ok
msg warn "${yellow}本地获取安装脚本 > $PWD ${none}"
}
timedatectl set-ntp true &>/dev/null
[[ $? != 0 ]] && {
is_ntp_on=1
}
# install dependent pkg
install_pkg $is_pkg &
# jq
if [[ $(type -P jq) ]]; then
>$is_jq_ok
else
jq_not_found=1
fi
# if wget installed. download core, sh, jq, get ip
[[ $is_wget ]] && {
[[ ! $is_core_file ]] && download core &
[[ ! $local_install ]] && download sh &
[[ $jq_not_found ]] && download jq &
get_ip
}
# waiting for background tasks is done
wait
# check background tasks status
check_status
# test $is_core_file
if [[ $is_core_file ]]; then
mkdir -p $tmpdir/testzip
tar zxf $is_core_ok --strip-components 1 -C $tmpdir/testzip &>/dev/null
[[ $? != 0 ]] && {
msg err "${is_core_name} 文件无法通过测试."
exit_and_del_tmpdir
}
[[ ! -f $tmpdir/testzip/$is_core ]] && {
msg err "${is_core_name} 文件无法通过测试."
exit_and_del_tmpdir
}
fi
# get server ip.
[[ ! $ip ]] && {
msg err "获取服务器 IP 失败."
exit_and_del_tmpdir
}
# create sh dir...
mkdir -p $is_sh_dir
# copy sh file or unzip sh zip file.
if [[ $local_install ]]; then
cp -rf $PWD/* $is_sh_dir
else
tar zxf $is_sh_ok -C $is_sh_dir
fi
# create core bin dir
mkdir -p $is_core_dir/bin
# copy core file or unzip core zip file
if [[ $is_core_file ]]; then
cp -rf $tmpdir/testzip/* $is_core_dir/bin
else
tar zxf $is_core_ok --strip-components 1 -C $is_core_dir/bin
fi
# add alias
echo "alias sb=$is_sh_bin" >>/root/.bashrc
echo "alias $is_core=$is_sh_bin" >>/root/.bashrc
# core command
ln -sf $is_sh_dir/$is_core.sh $is_sh_bin
ln -sf $is_sh_dir/$is_core.sh ${is_sh_bin/$is_core/sb}
# jq
[[ $jq_not_found ]] && mv -f $is_jq_ok /usr/bin/jq
# chmod
chmod +x $is_core_bin $is_sh_bin /usr/bin/jq ${is_sh_bin/$is_core/sb}
# create log dir
mkdir -p $is_log_dir
# show a tips msg
msg ok "生成配置文件..."
# create systemd service
load systemd.sh
is_new_install=1
install_service $is_core &>/dev/null
# create condf dir
mkdir -p $is_conf_dir
load core.sh
# create a reality config
add reality
# remove tmp dir and exit.
exit_and_del_tmpdir ok
}
# start.
main $@

View File

@@ -1,6 +0,0 @@
#!/bin/bash
args=$@
is_sh_ver=v1.03
. /etc/sing-box/sh/src/init.sh

View File

@@ -1,20 +0,0 @@
_open_bbr() {
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = bbr" >>/etc/sysctl.conf
echo "net.core.default_qdisc = fq" >>/etc/sysctl.conf
sysctl -p &>/dev/null
echo
_green "..已经启用 BBR 优化...."
echo
}
_try_enable_bbr() {
local _test1=$(uname -r | cut -d\. -f1)
local _test2=$(uname -r | cut -d\. -f2)
if [[ $_test1 -eq 4 && $_test2 -ge 9 ]] || [[ $_test1 -ge 5 ]]; then
_open_bbr
else
err "不支持启用 BBR 优化."
fi
}

View File

@@ -1,52 +0,0 @@
caddy_config() {
is_caddy_site_file=$is_caddy_conf/${host}.conf
case $1 in
new)
mkdir -p $is_caddy_dir $is_caddy_dir/sites $is_caddy_conf
cat >$is_caddyfile <<-EOF
{
admin off
http_port $is_http_port
https_port $is_https_port
}
import $is_caddy_conf/*.conf
import $is_caddy_dir/sites/*.conf
EOF
;;
*ws* | *http*)
cat >${is_caddy_site_file} <<<"
${host}:${is_https_port} {
reverse_proxy ${path} 127.0.0.1:${port}
import ${is_caddy_site_file}.add
}"
;;
*h2*)
cat >${is_caddy_site_file} <<<"
${host}:${is_https_port} {
reverse_proxy ${path} h2c://127.0.0.1:${port} {
transport http {
tls_insecure_skip_verify
}
}
import ${is_caddy_site_file}.add
}"
;;
*grpc*)
cat >${is_caddy_site_file} <<<"
${host}:${is_https_port} {
reverse_proxy /${path}/* h2c://127.0.0.1:${port}
import ${is_caddy_site_file}.add
}"
;;
proxy)
cat >${is_caddy_site_file}.add <<<"
reverse_proxy https://$proxy_site {
header_up Host {upstream_hostport}
}"
;;
esac
[[ $1 != "new" && $1 != 'proxy' ]] && {
[[ ! -f ${is_caddy_site_file}.add ]] && echo "# see https://github.com/$is_core/caddy-auto-tls/" >${is_caddy_site_file}.add
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,56 +0,0 @@
is_dns_list=(
1.1.1.1
8.8.8.8
h3://dns.google/dns-query
h3://cloudflare-dns.com/dns-query
h3://family.cloudflare-dns.com/dns-query
set
none
)
dns_set() {
if [[ $1 ]]; then
case ${1,,} in
11 | 1111)
is_dns_use=${is_dns_list[0]}
;;
88 | 8888)
is_dns_use=${is_dns_list[1]}
;;
gg | google)
is_dns_use=${is_dns_list[2]}
;;
cf | cloudflare)
is_dns_use=${is_dns_list[3]}
;;
nosex | family)
is_dns_use=${is_dns_list[4]}
;;
set)
if [[ $2 ]]; then
is_dns_use=${2,,}
else
ask string is_dns_use "请输入 DNS: "
fi
;;
none)
is_dns_use=none
;;
*)
err "无法识别 DNS 参数: $@"
;;
esac
else
is_tmp_list=(${is_dns_list[@]})
ask list is_dns_use null "\n请选择 DNS:\n"
if [[ $is_dns_use == "set" ]]; then
ask string is_dns_use "请输入 DNS: "
fi
fi
if [[ $is_dns_use == "none" ]]; then
cat <<<$(jq '.dns={}' $is_config_json) >$is_config_json
else
cat <<<$(jq '.dns.servers=[{address:"'$is_dns_use'",address_resolver:"local"},{tag:"local",address:"local"}]' $is_config_json) >$is_config_json
fi
manage restart &
msg "\n已更新 DNS 为: $(_green $is_dns_use)\n"
}

View File

@@ -1,67 +0,0 @@
get_latest_version() {
case $1 in
core)
name=$is_core_name
url="https://api.github.com/repos/${is_core_repo}/releases/latest?v=$RANDOM"
;;
sh)
name="$is_core_name 脚本"
url="https://api.github.com/repos/$is_sh_repo/releases/latest?v=$RANDOM"
;;
caddy)
name="Caddy"
url="https://api.github.com/repos/$is_caddy_repo/releases/latest?v=$RANDOM"
;;
esac
latest_ver=$(_wget -qO- $url | grep tag_name | egrep -o 'v([0-9.]+)')
[[ ! $latest_ver ]] && {
err "获取 ${name} 最新版本失败."
}
unset name url
}
download() {
latest_ver=$2
[[ ! $latest_ver ]] && get_latest_version $1
# tmp dir
tmpdir=$(mktemp -u)
[[ ! $tmpdir ]] && {
tmpdir=/tmp/tmp-$RANDOM
}
mkdir -p $tmpdir
case $1 in
core)
name=$is_core_name
tmpfile=$tmpdir/$is_core.tar.gz
link="https://github.com/${is_core_repo}/releases/download/${latest_ver}/${is_core}-${latest_ver:1}-linux-${is_arch}.tar.gz"
download_file
tar zxf $tmpfile --strip-components 1 -C $is_core_dir/bin
chmod +x $is_core_bin
;;
sh)
name="$is_core_name 脚本"
tmpfile=$tmpdir/sh.tar.gz
link="https://github.com/${is_sh_repo}/releases/download/${latest_ver}/code.tar.gz"
download_file
tar zxf $tmpfile -C $is_sh_dir
chmod +x $is_sh_bin ${is_sh_bin/$is_core/sb}
;;
caddy)
name="Caddy"
tmpfile=$tmpdir/caddy.tar.gz
# https://github.com/caddyserver/caddy/releases/download/v2.6.4/caddy_2.6.4_linux_amd64.tar.gz
link="https://github.com/${is_caddy_repo}/releases/download/${latest_ver}/caddy_${latest_ver:1}_linux_${is_arch}.tar.gz"
download_file
tar zxf $tmpfile -C $tmpdir
cp -f $tmpdir/caddy $is_caddy_bin
chmod +x $is_caddy_bin
;;
esac
rm -rf $tmpdir
unset latest_ver
}
download_file() {
if ! _wget -t 5 -c $link -O $tmpfile; then
rm -rf $tmpdir
err "\n下载 ${name} 失败.\n"
fi
}

View File

@@ -1,83 +0,0 @@
show_help() {
case $1 in
api | x25519 | tls | run | uuid | version)
$is_core_bin help $1 ${@:2}
;;
*)
[[ $1 ]] && warn "未知选项 '$1'"
msg "$is_core_name script $is_sh_ver by $author"
msg "Usage: $is_core [options]... [args]... "
msg
help_info=(
"基本:"
" v, version 显示当前版本"
" ip 返回当前主机的 IP"
" pbk 同等于 $is_core generate reality-keypair"
" get-port 返回一个可用的端口"
" ss2022 返回一个可用于 Shadowsocks 2022 的密码\n"
"一般:"
" a, add [protocol] [args... | auto] 添加配置"
" c, change [name] [option] [args... | auto] 更改配置"
" d, del [name] 删除配置**"
" i, info [name] 查看配置"
" qr [name] 二维码信息"
" url [name] URL 信息"
" log 查看日志"
# " logerr 查看错误日志\n"
"更改:"
# " dp, dynamicport [name] [start | auto] [end] 更改动态端口"
" full [name] [...] 更改多个参数"
" id [name] [uuid | auto] 更改 UUID"
" host [name] [domain] 更改域名"
" port [name] [port | auto] 更改端口"
" path [name] [path | auto] 更改路径"
" passwd [name] [password | auto] 更改密码"
" key [name] [Private key | atuo] [Public key] 更改密钥"
# " type [name] [type | auto] 更改伪装类型"
" method [name] [method | auto] 更改加密方式"
" sni [name] [ ip | domain] 更改 serverName"
# " seed [name] [seed | auto] 更改 mKCP seed"
" new [name] [...] 更改协议"
" web [name] [domain] 更改伪装网站\n"
"进阶:"
" dns [...] 设置 DNS"
" dd, ddel [name...] 删除多个配置**"
" fix [name] 修复一个配置"
" fix-all 修复全部配置"
" fix-caddyfile 修复 Caddyfile"
" fix-config.json 修复 config.json"
" import 导入 xray/v2ray 脚本配置\n"
"管理:"
" un, uninstall 卸载"
" u, update [core | sh | caddy] [ver] 更新"
" U, update.sh 更新脚本"
" s, status 运行状态"
" start, stop, restart [caddy] 启动, 停止, 重启"
" t, test 测试运行"
" reinstall 重装脚本\n"
"测试:"
# " client, genc [name] 显示用于客户端 JSON, 仅供参考"
" debug [name] 显示一些 debug 信息, 仅供参考"
" gen [...] 同等于 add, 但只显示 JSON 内容, 不创建文件, 测试使用"
" no-auto-tls [...] 同等于 add, 但禁止自动配置 TLS, 可用于 *TLS 相关协议"
# " xapi [...] 同等于 $is_core api, 但 API 后端使用当前运行的 $is_core_name 服务\n"
"其他:"
" bbr 启用 BBR, 如果支持"
" bin [...] 运行 $is_core_name 命令, 例如: $is_core bin help"
" [...] [...] 兼容绝大多数的 $is_core_name 命令, 例如: $is_core_name generate uuid"
" h, help 显示此帮助界面\n"
)
for v in "${help_info[@]}"; do
msg "$v"
done
msg "谨慎使用 del, ddel, 此选项会直接删除配置; 无需确认"
msg ""
msg ""
;;
esac
}
about() {
}

View File

@@ -1,79 +0,0 @@
is_xray_sh=/etc/xray/sh/src/core.sh
is_v2ray_sh=/etc/v2ray/sh/src/core.sh
is_xray_conf=/etc/xray/conf
is_v2ray_conf=/etc/v2ray/conf
in_conf() {
is_conf_args=$(jq '.inbounds[0]|.protocol,.port,(.settings|(.clients[0]|.id,.password),.method,.password,.port,.address,(.accounts[0]|.user,.pass)),(.streamSettings|.network,.security,.tcpSettings.header.type,(.wsSettings|.path,.headers.Host),(.httpSettings|.path,.host[0]),(.realitySettings|.serverNames[0],.publicKey,.privateKey))' $1)
[[ $? != 0 ]] && warn "无法读取此文件: $1" && return
is_up_var_set=(null is_protocol port uuid trojan_password ss_method ss_password door_port door_addr is_socks_user is_socks_pass net is_reality net_type ws_path ws_host h2_path h2_host is_servername is_public_key is_private_key)
i=0
for v in $(sed 's/""/null/g;s/"//g' <<<"$is_conf_args"); do
((i++))
export ${is_up_var_set[$i]}="${v}"
done
for v in ${is_up_var_set[@]}; do
[[ ${!v} == 'null' ]] && unset $v
done
path="${ws_path}${h2_path}"
host="${ws_host}${h2_host}"
[[ ! $uuid ]] && uuid=$trojan_password
if [[ $host ]]; then
if [[ $is_caddy && -f $is_caddy_conf/$host.conf ]]; then
tmp_tlsport=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
fi
[[ $tmp_tlsport ]] && https_port=$tmp_tlsport
add $is_protocol-$net-tls
else
case $is_protocol in
vmess | vless)
[[ $net_type == "http" ]] && {
net=http
is_tips_msg="新配置文件名: (VMess-HTTP-$port.json)"
}
[[ $is_reality == "reality" ]] && net=reality
add $net
;;
dokodemo-door)
add door
is_tips_msg="新配置文件名: (Direct-$port.json)"
;;
*socks*)
add $is_protocol
;;
*)
is_not_in_conf=1
msg "不支持导入 $1"
;;
esac
fi
[[ ! $is_not_in_conf ]] && msg "导入: $1 $is_tips_msg" && rm $1
}
is_change=1
is_dont_auto_exit=1
is_dont_test_host=1
if [[ -f $is_xray_sh && -d $is_xray_conf ]]; then
is_list=($(ls $is_xray_conf | grep .json | egrep -iv 'kcp|grpc|dynamic|quic' | sed "s#^#$is_xray_conf/#"))
fi
if [[ -f $is_v2ray_sh && -d $is_v2ray_conf ]]; then
is_list+=($(ls $is_v2ray_conf | grep .json | egrep -iv 'kcp|grpc|dynamic|quic' | sed "s#^#$is_v2ray_conf/#"))
fi
[[ ${is_list[@]} =~ "xray" ]] && is_xray_in=1
[[ ${is_list[@]} =~ "v2ray" ]] && is_v2ray_in=1
[[ $is_xray_in ]] && xray stop
[[ $is_v2ray_in ]] && v2ray stop
if [[ ${is_list[@]} ]]; then
msg "开始导入配置..."
for i in ${is_list[@]}; do
in_conf $i &
done
wait
is_dont_auto_exit=
manage restart &
[[ $is_xray_in ]] && xray restart &
[[ $is_v2ray_in ]] && v2ray restart &
[[ ${is_list[@],,} =~ "tls" && $is_caddy ]] && manage restart caddy &
else
err "没有找到可导入的配置..."
fi

View File

@@ -1,141 +0,0 @@
#!/bin/bash
author=github
# github=https://github.com/github/sing-box
# bash fonts colors
red='\e[31m'
yellow='\e[33m'
gray='\e[90m'
green='\e[92m'
blue='\e[94m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
_red() { echo -e ${red}$@${none}; }
_blue() { echo -e ${blue}$@${none}; }
_cyan() { echo -e ${cyan}$@${none}; }
_green() { echo -e ${green}$@${none}; }
_yellow() { echo -e ${yellow}$@${none}; }
_magenta() { echo -e ${magenta}$@${none}; }
_red_bg() { echo -e "\e[41m$@${none}"; }
_rm() {
rm -rf "$@"
}
_cp() {
cp -rf "$@"
}
_sed() {
sed -i "$@"
}
_mkdir() {
mkdir -p "$@"
}
is_err=$(_red_bg 错误!)
is_warn=$(_red_bg 警告!)
err() {
echo -e "\n$is_err $@\n"
[[ $is_dont_auto_exit ]] && return
exit 1
}
warn() {
echo -e "\n$is_warn $@\n"
}
# load bash script.
load() {
. $is_sh_dir/src/$1
}
# wget add --no-check-certificate
_wget() {
# [[ $proxy ]] && export https_proxy=$proxy
wget --no-check-certificate "$@"
}
# yum or apt-get
cmd=$(type -P apt-get || type -P yum)
# x64
case $(arch) in
amd64 | x86_64)
is_arch="amd64"
;;
*aarch64* | *armv8*)
is_arch="arm64"
;;
*)
err "此脚本仅支持 64 位系统..."
;;
esac
is_core=sing-box
is_core_name=sing-box
is_core_dir=/etc/$is_core
is_core_bin=$is_core_dir/bin/$is_core
is_core_repo=SagerNet/$is_core
is_conf_dir=$is_core_dir/conf
is_log_dir=/var/log/$is_core
is_sh_bin=/usr/local/bin/$is_core
is_sh_dir=$is_core_dir/sh
is_sh_repo=$author/$is_core
is_pkg="wget unzip tar qrencode"
is_config_json=$is_core_dir/config.json
is_caddy_bin=/usr/local/bin/caddy
is_caddy_dir=/etc/caddy
is_caddy_repo=caddyserver/caddy
is_caddyfile=$is_caddy_dir/Caddyfile
is_caddy_conf=$is_caddy_dir/$author
is_caddy_service=$(systemctl list-units --full -all | grep caddy.service)
is_http_port=80
is_https_port=443
# core ver
is_core_ver=$($is_core_bin version | head -n1 | cut -d " " -f3)
# tmp tls key
is_tls_cer=$is_core_dir/bin/tls.cer
is_tls_key=$is_core_dir/bin/tls.key
[[ ! -f $is_tls_cer || ! -f $is_tls_key ]] && {
is_tls_tmp=${is_tls_key/key/tmp}
$is_core_bin generate tls-keypair tls -m 456 >$is_tls_tmp
awk '/BEGIN PRIVATE KEY/,/END PRIVATE KEY/' $is_tls_tmp >$is_tls_key
awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' $is_tls_tmp >$is_tls_cer
rm $is_tls_tmp
}
if [[ $(pgrep -f $is_core_bin) ]]; then
is_core_status=$(_green running)
else
is_core_status=$(_red_bg stopped)
is_core_stop=1
fi
if [[ -f $is_caddy_bin && -d $is_caddy_dir && $is_caddy_service ]]; then
is_caddy=1
# fix caddy run; ver >= 2.8.2
[[ ! $(grep '\-\-adapter caddyfile' /lib/systemd/system/caddy.service) ]] && {
load systemd.sh
install_service caddy
systemctl restart caddy &
}
is_caddy_ver=$($is_caddy_bin version | head -n1 | cut -d " " -f1)
is_tmp_http_port=$(egrep '^ {2,}http_port|^http_port' $is_caddyfile | egrep -o [0-9]+)
is_tmp_https_port=$(egrep '^ {2,}https_port|^https_port' $is_caddyfile | egrep -o [0-9]+)
[[ $is_tmp_http_port ]] && is_http_port=$is_tmp_http_port
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
if [[ $(pgrep -f $is_caddy_bin) ]]; then
is_caddy_status=$(_green running)
else
is_caddy_status=$(_red_bg stopped)
is_caddy_stop=1
fi
fi
load core.sh
[[ ! $args ]] && args=main
main $args

View File

@@ -1,58 +0,0 @@
install_service() {
case $1 in
$is_core)
is_doc_site=https://sing-box.sagernet.org/
cat >/lib/systemd/system/$is_core.service <<<"
[Unit]
Description=$is_core_name Service
Documentation=$is_doc_site
After=network.target nss-lookup.target
[Service]
#User=nobody
User=root
NoNewPrivileges=true
ExecStart=$is_core_bin run -c $is_config_json -C $is_conf_dir
Restart=on-failure
RestartPreventExitStatus=23
LimitNPROC=10000
LimitNOFILE=1048576
PrivateTmp=true
ProtectSystem=full
#CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target"
;;
caddy)
cat >/lib/systemd/system/caddy.service <<<"
#https://github.com/caddyserver/dist/blob/master/init/caddy.service
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
User=root
Group=root
ExecStart=$is_caddy_bin run --environ --config $is_caddyfile --adapter caddyfile
ExecReload=$is_caddy_bin reload --config $is_caddyfile --adapter caddyfile
TimeoutStopSec=5s
LimitNPROC=10000
LimitNOFILE=1048576
PrivateTmp=true
ProtectSystem=full
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target"
;;
esac
# enable, reload
systemctl enable $1
systemctl daemon-reload
}