fix jq commands

This commit is contained in:
Evgeny Nerush
2023-10-20 22:39:22 +03:00
parent 33b5cdb60b
commit 47e8cf323d

122
ex.sh
View File

@@ -85,26 +85,27 @@ to install xray${normal}"
echo -e "${red}jq not installed, can't generate configs" echo -e "${red}jq not installed, can't generate configs"
exit 1 exit 1
else else
if curl -L https://raw.githubusercontent.com/XTLS/Xray-examples/main/VLESS-gRPC-REALITY/config_server.json > template_config_server.json if curl -L https://raw.githubusercontent.com/XTLS/Xray-examples/main/VLESS-gRPC-REALITY/config_server.json > tmpconfig
then then
cat tmpconfig > template_config_server.json
echo -e "${green}template server config downloaded${normal}" echo -e "${green}template server config downloaded${normal}"
else else
echo -e "${red}can't download template server config, try again later${normal}" echo -e "${red}can't download template server config, trying to use that have been downloaded before${normal}"
exit 1
fi fi
if curl -L https://raw.githubusercontent.com/XTLS/Xray-examples/main/VLESS-gRPC-REALITY/config_client.json > template_config_client.json if curl -L https://raw.githubusercontent.com/XTLS/Xray-examples/main/VLESS-gRPC-REALITY/config_client.json > tmpconfig
then then
cat tmpconfig > template_config_client.json
echo -e "${green}template client config downloaded${normal}" echo -e "${green}template client config downloaded${normal}"
else else
echo -e "${red}can't download template client config, try again later${normal}" echo -e "${red}can't download template client config, trying to use that have been downloaded before${normal}"
exit 1
fi fi
echo -e "Enter domain name, IPv4 or IPv6 address of your xray server:" rm tmpconfig
echo -e "${bold}Enter domain name, IPv4 or IPv6 address of your xray server:${normal}"
read address read address
id=$(xray uuid) id=$(xray uuid)
keys=$(xray x25519) keys=$(xray x25519)
private_key=$(echo $keys | head -n 1 | cut -c 13-) private_key=$(echo $keys | cut -d " " -f 3)
public_key=$(echo $keys | tail -n 1 | cut -c 12-) public_key=$(echo $keys | cut -d " " -f 6)
if command -v openssl > /dev/null if command -v openssl > /dev/null
then then
short_id=$(openssl rand -hex 8) short_id=$(openssl rand -hex 8)
@@ -115,7 +116,7 @@ containing only digits 0-9 and letters a-f, for instance
read short_id read short_id
if [ -v $short_id ] if [ -v $short_id ]
then then
echo -e "${red}shortId not set${normal}" echo -e "${red}short id not set${normal}"
exit 1 exit 1
fi fi
fi fi
@@ -155,69 +156,74 @@ or is in the same country. Better if it is popular.
then then
fake_site="www.yahoo.com" fake_site="www.yahoo.com"
fi fi
else
fake_site="www.yahoo.com"
fi fi
else else
fake_site="www.yahoo.com" fake_site="www.yahoo.com"
fi fi
echo -e "${green}mimic ${fake_site}${normal}" echo -e "${green}mimic ${fake_site}${normal}"
port=443 port=443
clients=' [ clients=" [
{ {
"id": "${id}", \"id\": \"${id}\",
"email": "love@xray.com", \"email\": \"love@xray.com\",
"flow": "xtls-rprx-vision" \"flow\": \"xtls-rprx-vision\"
} }
]' ]"
serverRealitySettings=' { serverRealitySettings=" {
"show": false, \"show\": false,
"dest": "${fake_site}:${port}", \"dest\": \"${fake_site}:${port}\",
"xver": 0, \"xver\": 0,
"serverNames": [ "${fake_site}" ], \"serverNames\": [ \"${fake_site}\" ],
"privateKey": "${private_key}", \"privateKey\": \"${private_key}\",
"shortIds": [ "${shortId}" ] \"shortIds\": [ \"${short_id}\" ]
}' }"
# make server config # make server config
cat template_config_server.json | jd '.inbounds[].port=${port} | .settings.clients=${clients} | .inbounds[].streamSettings.realitySettings=${serverRealitySettings}' > config_server.json cat template_config_server.json | jq ".inbounds[].port=${port} | .settings.clients=${clients} | .inbounds[].streamSettings.realitySettings=${serverRealitySettings}" > config_server.json
vnext=' [ vnext=" [
{ {
"address": "${address}", \"address\": \"${address}\",
"port": ${port}, \"port\": ${port},
"users": [ \"users\": [
{ {
"id": "${id}", \"id\": \"${id}\",
"alterId": 0, \"alterId\": 0,
"email": "love@xray.com", \"email\": \"love@xray.com\",
"security": "auto", \"security\": \"auto\",
"encryption": "none", \"encryption\": \"none\",
"flow": "xtls-rprx-vision" \"flow\": \"xtls-rprx-vision\"
} }
] ]
} }
]' ]"
clientRealitySettings=' { clientRealitySettings=" {
"serverName": "${serverName}", \"serverName\": \"${serverName}\",
"fingerprint": "chrome", \"fingerprint\": \"chrome\",
"show": false, \"show\": false,
"publicKey": "${publicKey}", \"publicKey\": \"${publicKey}\",
"shortId": "${shortId}", \"shortId\": \"${short_id}\",
"spiderX": "" \"spiderX\": \"\"
}' }"
rules=' [ rules=" [
{ {
"type": "field", \"type\": \"field\",
"domain": [ "domain:localhost", "domain:ru", "domain:su", "domain:by", "domain:cn", "domain:vk.com" ], \"domain\": [ \"domain:localhost\", \"domain:ru\", \"domain:su\", \"domain:by\", \"domain:cn\", \"domain:vk.com\" ],
"outboundTag": "direct" \"outboundTag\": \"direct\"
} },
{ {
"type": "field", \"type\": \"field\",
"inboundTag": ["api"], \"inboundTag\": [\"api\"],
"outboundTag": "api", \"outboundTag\": \"api\",
"enabled": true \"enabled\": true
} }
]' ]"
# make main client config # make main client config
cat template_config_client.json | jd '.outbounds[].settings.vnext=${vnext} | .outbounds[].streamSettings.realitySettings=${clientRealitySettings} | .routing.rules=${rules}' > config_client.json #cat template_config_client.json | grep -v "\/\/ Server IPv4" | jq ".outbounds[].settings.vnext=${vnext} | .outbounds[].streamSettings.realitySettings=${clientRealitySettings} | .routing.rules=${rules}" > config_client.json
#cat template_config_client.json | grep -v "\/\/ Server IPv4" | jq "if .outbounds[].settings.vnext? then .outbounds[].settings.vnext=${vnext} else . end | if .outbounds[].streamSettings.realitySettings? then .outbounds[].streamSettings.realitySettings=${clientRealitySettings} else . end" > config_client.json
#cat template_config_client.json | grep -v "\/\/ Server IPv4" | jq ".outbounds[].settings=(if .settings.vnext? then ${vnext} else .settings end)" > config_client.json
cat template_config_client.json | grep -v "\/\/ Server IPv4" | jq ".outbounds |= map(if .settings.vnext then .settings.vnext=${vnext} else . end) | .outbounds[].streamSettings.realitySettings=${clientRealitySettings} | .routing.rules=${rules}" > config_client.json
fi fi
fi fi
@@ -229,6 +235,14 @@ elif [ $command = "del" ]
then then
echo -e "TODO" echo -e "TODO"
elif [ $command = "mimic" ]
then
echo -e "TODO"
elif [ $command = "upgrade" ]
then
echo -e "TODO"
elif [ $command = "remove" ] elif [ $command = "remove" ]
then then
echo -e "Remove xray? (y/N)" echo -e "Remove xray? (y/N)"