Created
November 20, 2020 06:06
-
-
Save biaocy/a404608ea3ae91f12e6fcd121e1f6e8b to your computer and use it in GitHub Desktop.
Switch v2ray configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# fail fast | |
set -e | |
# Symbolic file | |
LINK_CONF="config.json" | |
if [ ! -h "$LINK_CONF" ] | |
then | |
echo "'$LINK_CONF' is not a symbolic file or not exist" | |
exit 1 | |
fi | |
# Find target config file | |
CURR_CONF=$(readlink $LINK_CONF) | |
echo "Current config file: $CURR_CONF" | |
# This filename | |
FILE=$(basename $0) | |
# Other config file | |
CONFS=$(ls -1 -I $CURR_CONF -I $LINK_CONF -I $FILE) | |
NUM_OF_CONF=${#CONFS[*]} | |
echo | |
echo "Available options:" | |
PS3="Select new config: " | |
select conf in $CONFS | |
do | |
if [ "$REPLY" -lt 1 -o "$REPLY" -gt "$NUM_OF_CONF" ] | |
then | |
echo | |
echo "Invalid option $REPLY" | |
else | |
echo | |
echo "Selected $conf, now link new config to selection" | |
sudo ln -f -s $conf $LINK_CONF | |
echo "Restart service..." | |
sudo systemctl restart v2ray | |
break | |
fi | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment