mirror of https://github.com/v2ray/v2ray-core
Merge branch 'master' into 5
commit
72e61b3370
11
policy.go
11
policy.go
|
@ -91,6 +91,17 @@ func (m *syncPolicyManager) ForLevel(level uint32) Policy {
|
||||||
return m.PolicyManager.ForLevel(level)
|
return m.PolicyManager.ForLevel(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *syncPolicyManager) ForSystem() SystemPolicy {
|
||||||
|
m.RLock()
|
||||||
|
defer m.RUnlock()
|
||||||
|
|
||||||
|
if m.PolicyManager == nil {
|
||||||
|
return SystemPolicy{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.PolicyManager.ForSystem()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *syncPolicyManager) Start() error {
|
func (m *syncPolicyManager) Start() error {
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
# This file is accessible as https://install.direct/go.sh
|
# This file is accessible as https://install.direct/go.sh
|
||||||
# Original source is located at github.com/v2ray/v2ray-core/release/install-release.sh
|
# Original source is located at github.com/v2ray/v2ray-core/release/install-release.sh
|
||||||
|
|
||||||
|
# If not specify, default meaning of return value:
|
||||||
|
# 1: System error
|
||||||
|
# 2: Application error
|
||||||
|
# 3: Network error
|
||||||
|
|
||||||
CUR_VER=""
|
CUR_VER=""
|
||||||
NEW_VER=""
|
NEW_VER=""
|
||||||
ARCH=""
|
ARCH=""
|
||||||
|
@ -156,19 +161,22 @@ extract(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# 1: new V2Ray. 0: no
|
# 1: new V2Ray. 0: no. 2: not installed. 3: check failed. 4: don't check.
|
||||||
getVersion(){
|
getVersion(){
|
||||||
if [[ -n "$VERSION" ]]; then
|
if [[ -n "$VERSION" ]]; then
|
||||||
NEW_VER="$VERSION"
|
NEW_VER="$VERSION"
|
||||||
return 1
|
return 4
|
||||||
else
|
else
|
||||||
CUR_VER=`/usr/bin/v2ray/v2ray -version 2>/dev/null | head -n 1 | cut -d " " -f2`
|
VER=`/usr/bin/v2ray/v2ray -version 2>/dev/null`
|
||||||
|
RETVAL="$?"
|
||||||
|
CUR_VER=`echo $VER | head -n 1 | cut -d " " -f2`
|
||||||
TAG_URL="https://api.github.com/repos/v2ray/v2ray-core/releases/latest"
|
TAG_URL="https://api.github.com/repos/v2ray/v2ray-core/releases/latest"
|
||||||
NEW_VER=`curl ${PROXY} -s ${TAG_URL} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4`
|
NEW_VER=`curl ${PROXY} -s ${TAG_URL} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4`
|
||||||
|
|
||||||
if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then
|
if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then
|
||||||
colorEcho ${RED} "Network error! Please check your network or try again."
|
colorEcho ${RED} "Network error! Please check your network or try again."
|
||||||
exit
|
return 3
|
||||||
|
elif [[ $RETVAL -ne 0 ]];then
|
||||||
|
return 2
|
||||||
elif [[ "$NEW_VER" != "$CUR_VER" ]];then
|
elif [[ "$NEW_VER" != "$CUR_VER" ]];then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -186,6 +194,10 @@ stopV2ray(){
|
||||||
elif [[ -n "${SERVICE_CMD}" ]] || [[ -f "/etc/init.d/v2ray" ]]; then
|
elif [[ -n "${SERVICE_CMD}" ]] || [[ -f "/etc/init.d/v2ray" ]]; then
|
||||||
${SERVICE_CMD} v2ray stop
|
${SERVICE_CMD} v2ray stop
|
||||||
fi
|
fi
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
colorEcho ${RED} "Failed to shutdown V2Ray service."
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,19 +212,21 @@ startV2ray(){
|
||||||
elif [ -n "${SERVICE_CMD}" ] && [ -f "/etc/init.d/v2ray" ]; then
|
elif [ -n "${SERVICE_CMD}" ] && [ -f "/etc/init.d/v2ray" ]; then
|
||||||
${SERVICE_CMD} v2ray start
|
${SERVICE_CMD} v2ray start
|
||||||
fi
|
fi
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
colorEcho ${RED} "Failed to start V2Ray service."
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
copyFile() {
|
copyFile() {
|
||||||
NAME=$1
|
NAME=$1
|
||||||
MANDATE=$2
|
|
||||||
ERROR=`cp "/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}/${NAME}" "/usr/bin/v2ray/${NAME}" 2>&1`
|
ERROR=`cp "/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}/${NAME}" "/usr/bin/v2ray/${NAME}" 2>&1`
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
colorEcho ${YELLOW} "${ERROR}"
|
colorEcho ${YELLOW} "${ERROR}"
|
||||||
if [ "$MANDATE" = true ]; then
|
return 2
|
||||||
exit
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
makeExecutable() {
|
makeExecutable() {
|
||||||
|
@ -222,16 +236,16 @@ makeExecutable() {
|
||||||
installV2Ray(){
|
installV2Ray(){
|
||||||
# Install V2Ray binary to /usr/bin/v2ray
|
# Install V2Ray binary to /usr/bin/v2ray
|
||||||
mkdir -p /usr/bin/v2ray
|
mkdir -p /usr/bin/v2ray
|
||||||
copyFile v2ray true
|
copyFile v2ray || return $?
|
||||||
makeExecutable v2ray
|
makeExecutable v2ray
|
||||||
copyFile v2ctl false
|
copyFile v2ctl
|
||||||
makeExecutable v2ctl
|
makeExecutable v2ctl
|
||||||
copyFile geoip.dat false
|
copyFile geoip.dat
|
||||||
copyFile geosite.dat false
|
copyFile geosite.dat
|
||||||
|
|
||||||
# Install V2Ray server config to /etc/v2ray
|
# Install V2Ray server config to /etc/v2ray
|
||||||
mkdir -p /etc/v2ray
|
|
||||||
if [[ ! -f "/etc/v2ray/config.json" ]]; then
|
if [[ ! -f "/etc/v2ray/config.json" ]]; then
|
||||||
|
mkdir -p /etc/v2ray
|
||||||
cp "/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
|
cp "/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
colorEcho ${YELLOW} "Create V2Ray configuration file error, pleases create it manually."
|
colorEcho ${YELLOW} "Create V2Ray configuration file error, pleases create it manually."
|
||||||
|
@ -277,7 +291,7 @@ Help(){
|
||||||
echo " -h, --help Show help"
|
echo " -h, --help Show help"
|
||||||
echo " -p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc"
|
echo " -p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc"
|
||||||
echo " -f, --force Force install"
|
echo " -f, --force Force install"
|
||||||
echo " --version Install a particular version"
|
echo " --version Install a particular version, use --version v3.15"
|
||||||
echo " -l, --local Install from a local file"
|
echo " -l, --local Install from a local file"
|
||||||
echo " --remove Remove installed V2Ray"
|
echo " --remove Remove installed V2Ray"
|
||||||
echo " -c, --check Check for update"
|
echo " -c, --check Check for update"
|
||||||
|
@ -336,14 +350,18 @@ remove(){
|
||||||
|
|
||||||
checkUpdate(){
|
checkUpdate(){
|
||||||
echo "Checking for update."
|
echo "Checking for update."
|
||||||
|
VERSION=""
|
||||||
getVersion
|
getVersion
|
||||||
if [[ $? -eq 1 ]]; then
|
RETVAL="$?"
|
||||||
colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray."
|
if [[ $RETVAL -eq 1 ]]; then
|
||||||
exit
|
colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)"
|
||||||
else
|
elif [[ $RETVAL -eq 0 ]]; then
|
||||||
colorEcho ${GREEN} "No new version."
|
colorEcho ${GREEN} "No new version. Current version is ${NEW_VER}."
|
||||||
exit
|
elif [[ $RETVAL -eq 2 ]]; then
|
||||||
|
colorEcho ${RED} "No V2Ray installed."
|
||||||
|
colorEcho ${GREEN} "The newest version for V2Ray is ${NEW_VER}."
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
main(){
|
main(){
|
||||||
|
@ -374,9 +392,14 @@ main(){
|
||||||
# download via network and extract
|
# download via network and extract
|
||||||
installSoftware "curl" || return $?
|
installSoftware "curl" || return $?
|
||||||
getVersion
|
getVersion
|
||||||
if [[ $? == 0 ]] && [[ "$FORCE" != "1" ]]; then
|
RETVAL="$?"
|
||||||
|
if [[ $RETVAL == 0 ]] && [[ "$FORCE" != "1" ]]; then
|
||||||
colorEcho ${GREEN} "Latest version ${NEW_VER} is already installed."
|
colorEcho ${GREEN} "Latest version ${NEW_VER} is already installed."
|
||||||
exit
|
return
|
||||||
|
elif [[ $RETVAL == 3 ]]; then
|
||||||
|
return 3
|
||||||
|
elif [[ $RETVAL == 1 ]]; then
|
||||||
|
colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)"
|
||||||
else
|
else
|
||||||
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}"
|
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}"
|
||||||
downloadV2Ray || return $?
|
downloadV2Ray || return $?
|
||||||
|
@ -388,7 +411,7 @@ main(){
|
||||||
V2RAY_RUNNING=1
|
V2RAY_RUNNING=1
|
||||||
stopV2ray
|
stopV2ray
|
||||||
fi
|
fi
|
||||||
installV2Ray
|
installV2Ray || return $?
|
||||||
installInitScript || return $?
|
installInitScript || return $?
|
||||||
if [[ ${V2RAY_RUNNING} -eq 1 ]];then
|
if [[ ${V2RAY_RUNNING} -eq 1 ]];then
|
||||||
colorEcho ${BLUE} "Restarting V2Ray service."
|
colorEcho ${BLUE} "Restarting V2Ray service."
|
||||||
|
|
Loading…
Reference in New Issue