fix install phase when xray is already installed

This commit is contained in:
Evgeny Nerush 2023-10-26 13:51:34 +03:00
parent 1aa212b482
commit 7604952e36
2 changed files with 31 additions and 28 deletions

View file

@ -45,7 +45,9 @@ For Windows, MacOS or Android you can try Nekobox, v2rayNG or ? (TODO): tests an
### Acknowledgements ### Acknowledgements
[This article (in Russian)](https://habr.com/ru/articles/731608/) helped me to install *XRay* for the first time. [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. [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. [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... (TODO) logging, choose domain names or geoip, configs for phone...

57
ex.sh
View file

@ -7,28 +7,27 @@ green='\033[0;32m'
yellow='\033[0;33m' yellow='\033[0;33m'
normal='\033[0m' normal='\033[0m'
xray_version="None"
if command -v xray > /dev/null if command -v xray > /dev/null
then then
xray_version=$(xray --version | head -n 1 | cut -c 6-10) xray_version=$(xray --version | head -n 1 | cut -c 6-10)
echo -e "${yellow}xray ${xray_version} detected${normal}" echo -e "${yellow}xray ${xray_version} detected${normal}"
fi fi
jq_installed=1
if command -v jq > /dev/null if command -v jq > /dev/null
then then
jq_installed=0 jq_installed=true
echo -e "${green}jq found${normal}" echo -e "${green}jq found${normal}"
else else
jq_installed=false
echo -e "${red}Warning: jq not installed but needed for operations with configs${normal}" echo -e "${red}Warning: jq not installed but needed for operations with configs${normal}"
fi fi
is_root=1
if [ $(id -u) -eq 0 ] if [ $(id -u) -eq 0 ]
then then
is_root=0 is_root=true
echo -e "${green}running as root${normal}" echo -e "${green}running as root${normal}"
else else
is_root=false
echo -e "${red}Warning: you should be root to install xray${normal}" echo -e "${red}Warning: you should be root to install xray${normal}"
fi fi
@ -45,25 +44,30 @@ then
read answer read answer
if [ -v $answer ] || [ $(echo $answer | cut -c 1) != "n" ] if [ -v $answer ] || [ $(echo $answer | cut -c 1) != "n" ]
then then
if [ xray_version != "None" ] install_xray=true
if command -v xray > /dev/null
then then
echo -e "xray ${version} detected, install anyway? (y/N)" echo -e "xray ${version} detected, install anyway? (y/N)"
read answer 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 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 then
echo -e "${red}You should be root, or run this script with sudo echo -e "${green}xray installed${normal}"
to install xray${normal}"
exit 1
else else
if bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install echo -e "${red}xray not installed, something goes wrong${normal}"
then
echo -e "${green}xray installed${normal}"
else
echo -e "${red}xray not installed, something goes wrong${normal}"
fi
fi fi
else
echo -e "${red}You should be root, or run this script with sudo
to install xray${normal}"
exit 1
fi fi
fi fi
fi fi
@ -72,15 +76,12 @@ to install xray${normal}"
read answer read answer
if [ -v $answer ] || [ $(echo $answer | cut -c 1) != "n" ] if [ -v $answer ] || [ $(echo $answer | cut -c 1) != "n" ]
then then
if command -v xray > /dev/null if ! $(command -v xray > /dev/null)
then
xray_version=$(xray --version | head -n 1 | cut -c 6-10)
fi
if [ $xray_version = "None" ]
then then
echo -e "${red}xray not installed, can't generate configs" echo -e "${red}xray not installed, can't generate configs"
exit 1 exit 1
elif [ ! $jq_installed ] fi
if ! $jq_installed
then then
echo -e "${red}jq not installed, can't generate configs" echo -e "${red}jq not installed, can't generate configs"
exit 1 exit 1
@ -222,12 +223,8 @@ then
read answer read answer
if [ ! -v $answer ] && ([ $answer = "YES" ] || [ $answer = "yes" ]) if [ ! -v $answer ] && ([ $answer = "YES" ] || [ $answer = "yes" ])
then then
if [ $is_root -ne 0 ] if $is_root
then 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 if bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove --purge
then then
echo -e " echo -e "
@ -236,6 +233,10 @@ ${green}xray removed${normal}"
echo -e " echo -e "
${red}xray not removed${normal}" ${red}xray not removed${normal}"
fi fi
else
echo -e "${red}You should be root, or run this script with sudo
to remove xray${normal}"
exit 1
fi fi
fi fi
fi fi