From 5c76c0d3aa6d2c219c5b86600cfe8a48ec2b3a37 Mon Sep 17 00:00:00 2001 From: 233boy <31657650+233boy@users.noreply.github.com> Date: Mon, 25 Mar 2019 12:39:37 +0800 Subject: [PATCH] fix jq detect --- install.sh | 49 +++-------------------------- src/install.sh | 61 +++++++++++++++++++++++++++++++++++++ src/jqcmd.sh | 83 ++++++++++++++++++++++++++++---------------------- v2ray.sh | 1 + 4 files changed, 112 insertions(+), 82 deletions(-) create mode 100644 src/install.sh diff --git a/install.sh b/install.sh index 92754b6..e43f8e2 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ #!/bin/bash +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin red='\e[91m' green='\e[92m' @@ -760,51 +761,9 @@ caddy_config() { } install_v2ray() { - 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 - 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 + ## install + _load install.sh + _do_install # download v2ray file then install _load download-v2ray.sh diff --git a/src/install.sh b/src/install.sh new file mode 100644 index 0000000..d2ee4ff --- /dev/null +++ b/src/install.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 +} diff --git a/src/jqcmd.sh b/src/jqcmd.sh index caa4175..a8db9db 100644 --- a/src/jqcmd.sh +++ b/src/jqcmd.sh @@ -7,30 +7,39 @@ if [[ $sys_bit == "x86_64" ]]; then _jqArch="linux64" fi -if ! ( command -v jq 2>&1>/dev/null ) ; then +if [[ ! $(command -v jq) ]]; then + echo _green "检测到没有 jq 命令,正在自动安装..." + echo - if command -v apt-get 2>&1>/dev/null; then - apt-get install -y jq - elif command -v dnf 2>&1>/dev/null; then - dnf install -y jq + if [[ $cmd == "apt-get" ]]; then + $cmd install -y jq else 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/ rm -f jq + else + echo + _red "安装 jq 失败..." + echo + exit 1 fi popd 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命令,正在自动安装..." - $cmd install -y patch diff + echo + $cmd install -y patch diffutils 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" + echo exit 1 fi @@ -39,19 +48,19 @@ TMP_UPDT_JSON=$(mktemp --suffix=.json) CMPATCH=$(mktemp --suffix=.patch) jq_gen_json() { - sed '/ *\/\//d' $v2ray_server_config > $TMP_ORIG_JSON + sed '/ *\/\//d' $v2ray_server_config >$TMP_ORIG_JSON } jq_gen_jsonpatch() { jq_gen_json - diff -u $TMP_ORIG_JSON $v2ray_server_config > $CMPATCH + diff -u $TMP_ORIG_JSON $v2ray_server_config >$CMPATCH } jq_clear_tmp() { rm -f $TMP_ORIG_JSON $TMP_UPDT_JSON $CMPATCH } -jq_vmess_adduser () { +jq_vmess_adduser() { local uuid=$1 local alterId=${2:-64} local email=${3:-${uuid:30}@233} @@ -59,7 +68,7 @@ jq_vmess_adduser () { local client='{"id":"'${uuid}'","level":'${level}',"alterId":'${alterId}',"email":"'${email}'"}' local len_inbounds=$(jq '(.inbounds|length) - 1' $TMP_ORIG_JSON) local _IDX - for _IDX in $(seq 0 ${len_inbounds}); do + for _IDX in $(seq 0 ${len_inbounds}); do if [[ $(jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) == '"vmess"' ]]; then break fi @@ -70,11 +79,11 @@ jq_vmess_adduser () { return 1 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 () { - if patch --ignore-whitespace $TMP_UPDT_JSON < $CMPATCH; then +jq_patchback() { + if patch --ignore-whitespace $TMP_UPDT_JSON <$CMPATCH; then mv $v2ray_server_config "${v2ray_server_config}.bak.${RANDOM}" install -m 644 $TMP_UPDT_JSON $v2ray_server_config fi @@ -99,29 +108,29 @@ jq_printvmess() { echo "-------------------------- Server: ${ADDRESS}:${_PORT}/${_NETTRIM} --------------------------" echo case $_NETTRIM in - kcp) - _TYPE='.streamSettings.kcpSettings.header.type' - ;; - ws) - _HOST='.streamSettings.wsSettings.headers.Host' - _PATH='.streamSettings.wsSettings.path' - ;; - h2|http) - _HOST='.streamSettings.httpSettings.host|join(,)' - _PATH='.streamSettings.httpSettings.path' - _TLS="tls" - ;; - tcp) - _TYPE='.streamSettings.tcpSettings.header.type|"none"' - ;; - quic) - _TYPE='.streamSettings.quicSettings.header.type|"none"' - _HOST='.streamSettings.quicSettings.security' - _PATH='.streamSettings.quicSettings.key' - ;; + kcp) + _TYPE='.streamSettings.kcpSettings.header.type' + ;; + ws) + _HOST='.streamSettings.wsSettings.headers.Host' + _PATH='.streamSettings.wsSettings.path' + ;; + h2 | http) + _HOST='.streamSettings.httpSettings.host|join(,)' + _PATH='.streamSettings.httpSettings.path' + _TLS="tls" + ;; + tcp) + _TYPE='.streamSettings.tcpSettings.header.type|"none"' + ;; + quic) + _TYPE='.streamSettings.quicSettings.header.type|"none"' + _HOST='.streamSettings.quicSettings.security' + _PATH='.streamSettings.quicSettings.key' + ;; esac 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 _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)) diff --git a/v2ray.sh b/v2ray.sh index ab6f6e6..3697702 100755 --- a/v2ray.sh +++ b/v2ray.sh @@ -1,4 +1,5 @@ #!/bin/bash +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin red='\e[91m' green='\e[92m'