Skip to content

Instantly share code, notes, and snippets.

@biaocy
Created November 20, 2020 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biaocy/a404608ea3ae91f12e6fcd121e1f6e8b to your computer and use it in GitHub Desktop.
Save biaocy/a404608ea3ae91f12e6fcd121e1f6e8b to your computer and use it in GitHub Desktop.
Switch v2ray configuration
#!/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