From 7604952e36e3c29a6db13d88cb43eb5c61016c59 Mon Sep 17 00:00:00 2001 From: Evgeny Nerush Date: Thu, 26 Oct 2023 13:51:34 +0300 Subject: [PATCH] fix install phase when xray is already installed --- README.md | 2 ++ ex.sh | 57 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index b1c5fcd..d099fab 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ For Windows, MacOS or Android you can try Nekobox, v2rayNG or ? (TODO): tests an ### Acknowledgements [This article (in Russian)](https://habr.com/ru/articles/731608/) helped me to install *XRay* for the first time. + [XRay config reference](https://xtls.github.io/en/config/) is brilliant and helped me much. + [Configs](https://github.com/XTLS/Xray-examples/tree/main/VLESS-gRPC-REALITY) on which the template configs are based. (TODO) logging, choose domain names or geoip, configs for phone... diff --git a/ex.sh b/ex.sh index e01a683..4b7d4e9 100755 --- a/ex.sh +++ b/ex.sh @@ -7,28 +7,27 @@ green='\033[0;32m' yellow='\033[0;33m' normal='\033[0m' -xray_version="None" if command -v xray > /dev/null then xray_version=$(xray --version | head -n 1 | cut -c 6-10) echo -e "${yellow}xray ${xray_version} detected${normal}" fi -jq_installed=1 if command -v jq > /dev/null then - jq_installed=0 + jq_installed=true echo -e "${green}jq found${normal}" else + jq_installed=false echo -e "${red}Warning: jq not installed but needed for operations with configs${normal}" fi -is_root=1 if [ $(id -u) -eq 0 ] then - is_root=0 + is_root=true echo -e "${green}running as root${normal}" else + is_root=false echo -e "${red}Warning: you should be root to install xray${normal}" fi @@ -45,25 +44,30 @@ then read answer if [ -v $answer ] || [ $(echo $answer | cut -c 1) != "n" ] then - if [ xray_version != "None" ] + install_xray=true + if command -v xray > /dev/null then echo -e "xray ${version} detected, install anyway? (y/N)" read answer - if [ ! -v $answer ] && ([ $(echo $answer | cut -c 1) = "y" ] || [ $(echo $answer | cut -c 1) = "Y" ]) + if [ -v $answer ] || ([ $(echo $answer | cut -c 1) != "y" ] && [ $(echo $answer | cut -c 1) != "Y" ]) then - if [ $is_root -ne 0 ] + install_xray=false + fi + fi + if $install_xray + then + if $is_root + then + if bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install then - echo -e "${red}You should be root, or run this script with sudo -to install xray${normal}" - exit 1 + echo -e "${green}xray installed${normal}" else - if bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install - then - echo -e "${green}xray installed${normal}" - else - echo -e "${red}xray not installed, something goes wrong${normal}" - fi + echo -e "${red}xray not installed, something goes wrong${normal}" fi + else + echo -e "${red}You should be root, or run this script with sudo +to install xray${normal}" + exit 1 fi fi fi @@ -72,15 +76,12 @@ to install xray${normal}" read answer if [ -v $answer ] || [ $(echo $answer | cut -c 1) != "n" ] then - if command -v xray > /dev/null - then - xray_version=$(xray --version | head -n 1 | cut -c 6-10) - fi - if [ $xray_version = "None" ] + if ! $(command -v xray > /dev/null) then echo -e "${red}xray not installed, can't generate configs" exit 1 - elif [ ! $jq_installed ] + fi + if ! $jq_installed then echo -e "${red}jq not installed, can't generate configs" exit 1 @@ -222,12 +223,8 @@ then read answer if [ ! -v $answer ] && ([ $answer = "YES" ] || [ $answer = "yes" ]) then - if [ $is_root -ne 0 ] + if $is_root then - echo -e "${red}You should be root, or run this script with sudo -to remove xray${normal}" - exit 1 - else if bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove --purge then echo -e " @@ -236,6 +233,10 @@ ${green}xray removed${normal}" echo -e " ${red}xray not removed${normal}" fi + else + echo -e "${red}You should be root, or run this script with sudo +to remove xray${normal}" + exit 1 fi fi fi