diff --git a/README.md b/README.md index 2a4967bb..26ddf8df 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ source <(curl -sL https://git.io/fNgqx) --remove 所有命令行参数支持**Tab**补全 ```bash v2ray -h 查看帮助 + v2ray -v 查看版本信息 v2ray start 启动 V2Ray v2ray stop 停止 V2Ray v2ray restart 重启 V2Ray @@ -127,7 +128,7 @@ source <(curl -sL https://git.io/fNgqx) --remove **不支持Centos 6** ## 更新日志 -**2018.11.29** +[**2018.11.29**](https://github.com/Jrohy/multi-v2ray/tree/v2.4) 加入更新v2ray到特定版本的指令 **2018.11.28** @@ -136,14 +137,14 @@ source <(curl -sL https://git.io/fNgqx) --remove **2018.11.25** 加入Flask Web接口 -**2018.11.19** +[**2018.11.19**](https://github.com/Jrohy/multi-v2ray/tree/v2.2) 加入禁止BT -**2018.11.18** +[**2018.11.18**](https://github.com/Jrohy/multi-v2ray/tree/v2.1) 支持新版v2ray配置文件格式(v4.1+), 升级脚本自动转换格式为新版 支持范围端口修改 -**2018.10.9** +[**2018.10.9**](https://github.com/Jrohy/multi-v2ray/tree/v2.0) 面向对象 来重构代码 加入json文件缓存(利用序列化实现) diff --git a/multi-v2ray.sh b/multi-v2ray.sh index 7b470f79..3713ca32 100644 --- a/multi-v2ray.sh +++ b/multi-v2ray.sh @@ -12,12 +12,14 @@ BEGIN_PATH=$(pwd) INSTARLL_WAY=0 #定义操作变量, 0为否, 1为是 -DEV_MODE=0 - HELP=0 REMOVE=0 +FORCE=0 + +UPDATE_VERSION="" + APP_PATH="/usr/local/multi-v2ray" #Centos 临时取消别名 @@ -44,6 +46,13 @@ while [[ $# > 0 ]];do -h|--help) HELP=1 ;; + -f|--force) + FORCE=1 + ;; + -v|--version) + UPDATE_VERSION="$2" + shift + ;; -k|--keep) INSTARLL_WAY=1 colorEcho ${BLUE} "当前以keep保留配置文件形式更新, 若失败请用全新安装\n" @@ -52,10 +61,6 @@ while [[ $# > 0 ]];do INSTARLL_WAY=2 colorEcho ${BLUE} "当前仅更新multi-v2ray源码\n" ;; - -d|--dev) - DEV_MODE=1 - colorEcho ${BLUE} "当前为开发模式, 用dev分支来更新\n" - ;; *) # unknown option ;; @@ -64,12 +69,30 @@ while [[ $# > 0 ]];do done ############################# +checkUpdate(){ + LASTEST_VERSION=$(curl -H 'Cache-Control: no-cache' -s "https://api.github.com/repos/Jrohy/multi-v2ray/releases/latest" | grep 'tag_name' | cut -d\" -f4) + + if [[ -e /usr/local/bin/v2ray ]];then + VERSION_TEMP_VALUE=$(cat /usr/local/bin/v2ray|grep SHELL_V2RAY|awk 'NR==1') + if [[ ! -z $VERSION_TEMP_VALUE ]]; then + CURRENT_VERSION=${VERSION_TEMP_VALUE/*=} + if [[ $LASTEST_VERSION == $CURRENT_VERSION ]]; then + colorEcho $GREEN "脚本已为最新!!" + exit + fi + fi + fi + + [[ -z $UPDATE_VERSION ]] && UPDATE_VERSION=$LASTEST_VERSION +} + help(){ - echo "source multi-v2ray.sh [-h|--help] [-k|--keep] [-d|--dev][-c|--code][--remove]" + echo "source multi-v2ray.sh [-h|--help] [-k|--keep] [-c|--code] [-f|--force] [--remove]" echo " -h, --help Show help" echo " -k, --keep keep the v2ray config.json to update" - echo " -d, --dev update from dev branch" echo " -c, --code only update multi-v2ray code" + echo " -f, --force force to update multi-v2ray lastest code" + echo " -v, --version update multi-v2ray to special version" echo " --remove remove v2ray && multi-v2ray" echo " no params to new install" return 0 @@ -191,21 +214,18 @@ updateProject() { DOMAIN=${TEMP_VALUE/*=} fi - [[ $DEV_MODE == 1 ]] && BRANCH="dev" || BRANCH="master" - cd /usr/local/ if [[ -e multi-v2ray && -e multi-v2ray/.git ]];then cd multi-v2ray FIR_COMMIT_AUTHOR=$(git log --reverse | awk 'NR==2'| awk '{print $2}') if [[ $FIR_COMMIT_AUTHOR == 'Jrohy' ]];then - git reset --hard HEAD && git clean -d -f - if [[ $DEV_MODE == 1 ]];then - git checkout dev >/dev/null 2>&1 - else - git checkout master >/dev/null 2>&1 + git reset --hard HEAD && git clean -d -f && git checkout master >/dev/null 2>&1 + if [[ $FORCE == 1 ]]; then + git pull + else + git fetch origin && git checkout $UPDATE_VERSION fi - git pull else cd /usr/local/ rm -rf multi-v2ray @@ -244,7 +264,7 @@ timeSync() { profileInit() { #配置V2ray初始环境 - cp $APP_PATH/v2ray /usr/local/bin + cp -f $APP_PATH/v2ray /usr/local/bin chmod +x /usr/local/bin/v2ray #加入multi-v2ray模块搜索路径 @@ -302,6 +322,8 @@ main() { [[ ${REMOVE} == 1 ]] && removeV2Ray && return + checkUpdate + [[ ${INSTARLL_WAY} == 0 ]] && colorEcho ${BLUE} "当前为全新安装\n" if [[ ${INSTARLL_WAY} != 2 ]];then diff --git a/v2ray b/v2ray index e4fb460e..59d4a23a 100755 --- a/v2ray +++ b/v2ray @@ -1,5 +1,7 @@ #!/bin/bash +SHELL_V2RAY="v2.5.0" + #######color code######## RED="31m" # Error message GREEN="32m" # Success message @@ -13,6 +15,12 @@ colorEcho(){ echo -e "\033[${COLOR}${@:2}\033[0m" } +showVersion(){ + echo -e "multi-v2ray: $(colorEcho $GREEN $SHELL_V2RAY)\n" + V2RAY_VERSION=$(/usr/bin/v2ray/v2ray -version | head -n 1 | cut -d " " -f2-4) + echo -e "v2ray: $(colorEcho $GREEN $V2RAY_VERSION)\n" +} + cleanLog() { cat /dev/null > /var/log/v2ray/access.log cat /dev/null > /var/log/v2ray/error.log @@ -23,8 +31,9 @@ cleanLog() { [ $(id -u) != "0" ] && { colorEcho ${RED} "Error: You must be root to run this script"; exit 1; } help(){ - echo "v2ray [-h|--help] [options]" + echo "v2ray [-h|--help] [-v|--version] [options]" echo " -h, --help 查看帮助" + echo " -v, --version 查看版本信息" echo " start 启动 V2Ray" echo " stop 停止 V2Ray" echo " restart 重启 V2Ray" @@ -56,6 +65,9 @@ while [[ $# > 0 ]];do -h|--help) help ;; + -v|--version) + showVersion + ;; start) service v2ray start colorEcho ${GREEN} "v2ray启动成功!" @@ -127,6 +139,7 @@ while [[ $# > 0 ]];do ;; *) colorEcho ${YELLOW} "传参有误! 输入-h 或者--help查看帮助" # unknown option + ;; esac shift # past argument or value done diff --git a/v2ray.bash b/v2ray.bash index 66c61ea4..13fd3861 100644 --- a/v2ray.bash +++ b/v2ray.bash @@ -1,6 +1,6 @@ # bash completion for v2ray -*- shell-script -*- function _auto_tab() { - local options_array=("start" "stop" "restart" "status" "log" "update" "update.sh" "add" "del" "info" "port" "tls" "tfo" "stream" "stats" "clean" "-h") + local options_array=("start" "stop" "restart" "status" "log" "update" "update.sh" "add" "del" "info" "port" "tls" "tfo" "stream" "stats" "clean" "-h" "-v") local add_array=("wechat" "utp" "srtp" "dtls" "wireguard" "socks" "mtproto" "ss") local cur pre