fix jq detect

pull/171/head
233boy 6 years ago
parent 57fe6e6914
commit 5c76c0d3aa
  1. 49
      install.sh
  2. 61
      src/install.sh
  3. 43
      src/jqcmd.sh
  4. 1
      v2ray.sh

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
red='\e[91m' red='\e[91m'
green='\e[92m' green='\e[92m'
@ -760,51 +761,9 @@ caddy_config() {
} }
install_v2ray() { install_v2ray() {
echo ## install
echo _load install.sh
echo -e "$yellow 同步系统仓库并安装必须组件,请骚吼~~~~~~~~~ $none" _do_install
echo
echo
if [[ $cmd == "apt-get" ]]; then
$cmd update -y
$cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap2-bin patch diffutils jq dbus
else
# $cmd install -y lrzsz git zip unzip curl wget qrencode libcap iptables-services
$cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap patch diffutils
fi
_disableselinux
_sys_timezone
_sys_time
echo
echo
[ -d /etc/v2ray ] && rm -rf /etc/v2ray
if [[ $local_install ]]; then
if [[ ! -d $(pwd)/config ]]; then
echo
echo -e "$red 哎呀呀...安装失败了咯...$none"
echo
echo -e " 请确保你有完整的上传 $author 的 V2Ray 一键安装脚本 & 管理脚本到当前 ${green}$(pwd) $none目录下"
echo
exit 1
fi
mkdir -p /etc/v2ray/233boy/v2ray
cp -rf $(pwd) /etc/v2ray/233boy/v2ray/
else
pushd /tmp
git clone --depth=1 https://github.com/233boy/v2ray -b "$_gitbranch" /etc/v2ray/233boy/v2ray
popd
fi
if [[ ! -d /etc/v2ray/233boy/v2ray ]]; then
echo
echo -e "$red 哎呀呀...克隆脚本仓库出错了...$none"
echo
echo -e " 温馨提示..... 请尝试自行安装 Git: ${green}$cmd install -y git $none 之后再安装此脚本"
echo
exit 1
fi
# download v2ray file then install # download v2ray file then install
_load download-v2ray.sh _load download-v2ray.sh

@ -0,0 +1,61 @@
_do_install() {
echo
echo
echo -e "$yellow 同步系统仓库并安装必须组件,请骚吼~~~~~~~~~ $none"
echo
echo
if [[ $cmd == "apt-get" ]]; then
$cmd update -y
$cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap2-bin patch diffutils jq dbus
else
# $cmd install -y lrzsz git zip unzip curl wget qrencode libcap iptables-services
$cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap patch diffutils
if [[ ! $(command -v jq) ]]; then
pushd /tmp
if curl -sL -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-${_jqArch}; then
install -m 755 jq /usr/local/bin/
rm -f jq
else
echo
_red "安装 jq 失败..."
echo
exit 1
fi
popd
fi
fi
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
_disableselinux
_sys_timezone
_sys_time
echo
echo
[ -d /etc/v2ray ] && rm -rf /etc/v2ray
if [[ $local_install ]]; then
if [[ ! -d $(pwd)/config ]]; then
echo
echo -e "$red 哎呀呀...安装失败了咯...$none"
echo
echo -e " 请确保你有完整的上传 $author 的 V2Ray 一键安装脚本 & 管理脚本到当前 ${green}$(pwd) $none目录下"
echo
exit 1
fi
mkdir -p /etc/v2ray/233boy/v2ray
cp -rf $(pwd) /etc/v2ray/233boy/v2ray/
else
pushd /tmp
git clone --depth=1 https://github.com/233boy/v2ray -b "$_gitbranch" /etc/v2ray/233boy/v2ray
popd
fi
if [[ ! -d /etc/v2ray/233boy/v2ray ]]; then
echo
echo -e "$red 哎呀呀...克隆脚本仓库出错了...$none"
echo
echo -e " 温馨提示..... 请尝试自行安装 Git: ${green}$cmd install -y git $none 之后再安装此脚本"
echo
exit 1
fi
}

@ -7,30 +7,39 @@ if [[ $sys_bit == "x86_64" ]]; then
_jqArch="linux64" _jqArch="linux64"
fi fi
if ! ( command -v jq 2>&1>/dev/null ) ; then if [[ ! $(command -v jq) ]]; then
echo
_green "检测到没有 jq 命令,正在自动安装..." _green "检测到没有 jq 命令,正在自动安装..."
echo
if command -v apt-get 2>&1>/dev/null; then if [[ $cmd == "apt-get" ]]; then
apt-get install -y jq $cmd install -y jq
elif command -v dnf 2>&1>/dev/null; then
dnf install -y jq
else else
pushd /tmp pushd /tmp
if curl -L -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-${_jqArch}; then if curl -sL -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-${_jqArch}; then
install -m 755 jq /usr/local/bin/ install -m 755 jq /usr/local/bin/
rm -f jq rm -f jq
else
echo
_red "安装 jq 失败..."
echo
exit 1
fi fi
popd popd
fi fi
fi fi
if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; then if [[ ! $(command -v patch) && $(command -v diff) ]]; then
echo
_green "检测到没有patch命令,正在自动安装..." _green "检测到没有patch命令,正在自动安装..."
$cmd install -y patch diff echo
$cmd install -y patch diffutils
fi fi
if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; then if [[ ! $(command -v patch) && $(command -v diff) ]]; then
echo
_red "diff/patch not found" _red "diff/patch not found"
echo
exit 1 exit 1
fi fi
@ -39,19 +48,19 @@ TMP_UPDT_JSON=$(mktemp --suffix=.json)
CMPATCH=$(mktemp --suffix=.patch) CMPATCH=$(mktemp --suffix=.patch)
jq_gen_json() { jq_gen_json() {
sed '/ *\/\//d' $v2ray_server_config > $TMP_ORIG_JSON sed '/ *\/\//d' $v2ray_server_config >$TMP_ORIG_JSON
} }
jq_gen_jsonpatch() { jq_gen_jsonpatch() {
jq_gen_json jq_gen_json
diff -u $TMP_ORIG_JSON $v2ray_server_config > $CMPATCH diff -u $TMP_ORIG_JSON $v2ray_server_config >$CMPATCH
} }
jq_clear_tmp() { jq_clear_tmp() {
rm -f $TMP_ORIG_JSON $TMP_UPDT_JSON $CMPATCH rm -f $TMP_ORIG_JSON $TMP_UPDT_JSON $CMPATCH
} }
jq_vmess_adduser () { jq_vmess_adduser() {
local uuid=$1 local uuid=$1
local alterId=${2:-64} local alterId=${2:-64}
local email=${3:-${uuid:30}@233} local email=${3:-${uuid:30}@233}
@ -70,11 +79,11 @@ jq_vmess_adduser () {
return 1 return 1
fi fi
jq --tab ".inbounds[${_IDX}].settings.clients += [${client}]" $TMP_ORIG_JSON > $TMP_UPDT_JSON jq --tab ".inbounds[${_IDX}].settings.clients += [${client}]" $TMP_ORIG_JSON >$TMP_UPDT_JSON
} }
jq_patchback () { jq_patchback() {
if patch --ignore-whitespace $TMP_UPDT_JSON < $CMPATCH; then if patch --ignore-whitespace $TMP_UPDT_JSON <$CMPATCH; then
mv $v2ray_server_config "${v2ray_server_config}.bak.${RANDOM}" mv $v2ray_server_config "${v2ray_server_config}.bak.${RANDOM}"
install -m 644 $TMP_UPDT_JSON $v2ray_server_config install -m 644 $TMP_UPDT_JSON $v2ray_server_config
fi fi
@ -106,7 +115,7 @@ jq_printvmess() {
_HOST='.streamSettings.wsSettings.headers.Host' _HOST='.streamSettings.wsSettings.headers.Host'
_PATH='.streamSettings.wsSettings.path' _PATH='.streamSettings.wsSettings.path'
;; ;;
h2|http) h2 | http)
_HOST='.streamSettings.httpSettings.host|join(,)' _HOST='.streamSettings.httpSettings.host|join(,)'
_PATH='.streamSettings.httpSettings.path' _PATH='.streamSettings.httpSettings.path'
_TLS="tls" _TLS="tls"
@ -121,7 +130,7 @@ jq_printvmess() {
;; ;;
esac esac
local CLTLEN=$(echo $IN | jq '.settings.clients|length - 1') local CLTLEN=$(echo $IN | jq '.settings.clients|length - 1')
for CLINTIDX in $( seq 0 $CLTLEN ); do for CLINTIDX in $(seq 0 $CLTLEN); do
local EMAIL=$(echo $IN | jq 'if .settings.clients['${CLINTIDX}'].email then .settings.clients['${CLINTIDX}'].email else "DEFAULT" end') local EMAIL=$(echo $IN | jq 'if .settings.clients['${CLINTIDX}'].email then .settings.clients['${CLINTIDX}'].email else "DEFAULT" end')
local _ps="${_MAKPREFIX}${ADDRESS}/${_NETTRIM}" local _ps="${_MAKPREFIX}${ADDRESS}/${_NETTRIM}"
local _VMESS=$(echo "vmess://"$(echo $IN | jq -c '{"v":"2","ps":"'${_ps}'","add":"'${ADDRESS}'","port":.port,"id":.settings.clients['${CLINTIDX}'].id,"aid":.settings.clients['${CLINTIDX}'].alterId,"net":.streamSettings.network|"tcp","type":'${_TYPE}',"host":'${_HOST}',"path":'${_PATH}',"tls":'${_TLS}'}' | base64 -w0)) local _VMESS=$(echo "vmess://"$(echo $IN | jq -c '{"v":"2","ps":"'${_ps}'","add":"'${ADDRESS}'","port":.port,"id":.settings.clients['${CLINTIDX}'].id,"aid":.settings.clients['${CLINTIDX}'].alterId,"net":.streamSettings.network|"tcp","type":'${_TYPE}',"host":'${_HOST}',"path":'${_PATH}',"tls":'${_TLS}'}' | base64 -w0))

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
red='\e[91m' red='\e[91m'
green='\e[92m' green='\e[92m'

Loading…
Cancel
Save