Merge pull request #147 from cutelua/adduser

install jq package
pull/156/head
233boy 6 years ago committed by GitHub
commit 0db7396bd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      bin/jq-linux32
  2. BIN
      bin/jq-linux64
  3. 4
      install.sh
  4. 45
      src/jqcmd.sh
  5. 3
      v2ray.sh

Binary file not shown.

Binary file not shown.

@ -733,10 +733,10 @@ install_v2ray() {
echo
if [[ $cmd == "apt-get" ]]; then
$cmd update -y
$cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap2-bin patch
$cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap2-bin patch diff jq
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
$cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap patch diff
fi
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[ -d /etc/v2ray ] && rm -rf /etc/v2ray

@ -6,12 +6,22 @@ _jqArch="linux32"
if [[ $sys_bit == "x86_64" ]]; then
_jqArch="linux64"
fi
_jqbin=${__dir}/../bin/jq-${_jqArch}
[[ -e $_jqbin && ! -x $_jqbin ]] && chmod 755 $_jqbin
if [[ ! -x $_jqbin ]]; then
_red "jq not found"
exit 1
if ! ( command -v jq 2>&1>/dev/null ) ; then
_green "检测到没有 jq 命令,正在自动安装..."
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
else
pushd /tmp
if curl -L -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
fi
popd
fi
fi
if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; then
@ -24,10 +34,6 @@ if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; the
exit 1
fi
_jq () {
$_jqbin "$@" < /dev/stdin
}
TMP_ORIG_JSON=$(mktemp --suffix=.json)
TMP_UPDT_JSON=$(mktemp --suffix=.json)
CMPATCH=$(mktemp --suffix=.patch)
@ -51,20 +57,20 @@ jq_vmess_adduser () {
local email=${3:-${uuid:30}@233}
local level=1
local client='{"id":"'${uuid}'","level":'${level}',"alterId":'${alterId}',"email":"'${email}'"}'
local len_inbounds=$(_jq '(.inbounds|length) - 1' $TMP_ORIG_JSON)
local len_inbounds=$(jq '(.inbounds|length) - 1' $TMP_ORIG_JSON)
local _IDX
for _IDX in $(seq 0 ${len_inbounds}); do
if [[ $(_jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) == '"vmess"' ]]; then
if [[ $(jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) == '"vmess"' ]]; then
break
fi
done
if [[ $(_jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) != '"vmess"' ]]; then
if [[ $(jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) != '"vmess"' ]]; then
_red "vmess not found"
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 () {
@ -80,15 +86,14 @@ jq_printvmess() {
local INPUT=$TMP_ORIG_JSON
[[ -s $TMP_UPDT_JSON ]] && INPUT=$TMP_UPDT_JSON
local INBS=$(_jq -c '.inbounds[] | select(.protocol == "vmess" )' $INPUT)
local INBS=$(jq -c '.inbounds[] | select(.protocol == "vmess" )' $INPUT)
for IN in $INBS; do
# echo $IN | _jq
local _TYPE="\"none\""
local _HOST=\"\"
local _PATH=\"\"
local _TLS=\"\"
local _NET=$(echo $IN | _jq '.streamSettings.network')
local _PORT=$(echo $IN | _jq '.port')
local _NET=$(echo $IN | jq '.streamSettings.network')
local _PORT=$(echo $IN | jq '.port')
local _NETTRIM=${_NET//\"/}
echo
echo "-------------------------- Server: ${ADDRESS}:${_PORT}/${_NETTRIM} --------------------------"
@ -110,12 +115,12 @@ jq_printvmess() {
_TYPE='if .streamSettings.tcpSettings.header.type then .streamSettings.tcpSettings.header.type else "none" end'
;;
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
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}"
_green "${EMAIL//\"/} -- ${_ps}"
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,"type":'${_TYPE}',"host":'${_HOST}',"path":'${_PATH}',"tls":'${_TLS}'}' | base64 -w0)
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,"type":'${_TYPE}',"host":'${_HOST}',"path":'${_PATH}',"tls":'${_TLS}'}' | base64 -w0)
echo
done
done

@ -1033,8 +1033,9 @@ change_vmess_user () {
echo
echo
_yellow " ---- 搞定了。"
restart_v2ray
_yellow " ---- 翻查多用户的vmess link请用v2ray url查看。"
echo
_yellow " ---- 翻查各个用户的流量,可用v2ray traffic查看(重启v2ray后会清空)。"
echo
}

Loading…
Cancel
Save