mirror of
https://github.com/XTLS/Xray-install.git
synced 2024-11-21 14:51:27 +00:00
一些更新 (#19)
Co-authored-by: RPRX <63339210+rprx@users.noreply.github.com>
This commit is contained in:
parent
090bb04f97
commit
c394a9f050
|
@ -5,6 +5,9 @@ Bash script for installing Xray in operating systems such as CentOS / Debian / O
|
||||||
[Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)
|
[Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
installed: /etc/systemd/system/xray.service
|
||||||
|
installed: /etc/systemd/system/xray@.service
|
||||||
|
|
||||||
installed: /usr/local/bin/xray
|
installed: /usr/local/bin/xray
|
||||||
installed: /usr/local/etc/xray/*.json
|
installed: /usr/local/etc/xray/*.json
|
||||||
|
|
||||||
|
@ -13,11 +16,10 @@ installed: /usr/local/share/xray/geosite.dat
|
||||||
|
|
||||||
installed: /var/log/xray/access.log
|
installed: /var/log/xray/access.log
|
||||||
installed: /var/log/xray/error.log
|
installed: /var/log/xray/error.log
|
||||||
|
|
||||||
installed: /etc/systemd/system/xray.service
|
|
||||||
installed: /etc/systemd/system/xray@.service
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Notice: Xray will NOT log to `/var/log/xray/*.log` by default. Configure `"log"` to specify log files.
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
|
|
||||||
**Install & Upgrade Xray-core and geodata with User nobody, but will NOT overwrite User in existing service files**
|
**Install & Upgrade Xray-core and geodata with User nobody, but will NOT overwrite User in existing service files**
|
||||||
|
|
|
@ -27,40 +27,64 @@ JSON_PATH=${JSON_PATH:-/usr/local/etc/xray}
|
||||||
# export check_all_service_files='yes'
|
# export check_all_service_files='yes'
|
||||||
|
|
||||||
# Gobal verbals
|
# Gobal verbals
|
||||||
|
|
||||||
# Xray current version
|
# Xray current version
|
||||||
CURRENT_VERSION=""
|
CURRENT_VERSION=''
|
||||||
|
|
||||||
# Xray latest release version
|
# Xray latest release version
|
||||||
RELEASE_LATEST=""
|
RELEASE_LATEST=''
|
||||||
|
|
||||||
|
# Xray latest prerelease/release version
|
||||||
|
PRE_RELEASE_LATEST=''
|
||||||
|
|
||||||
# Xray version will be installed
|
# Xray version will be installed
|
||||||
INSTALL_VERSION=""
|
INSTALL_VERSION=''
|
||||||
|
|
||||||
# install
|
# install
|
||||||
INSTALL='0'
|
INSTALL='0'
|
||||||
|
|
||||||
# install-geodata
|
# install-geodata
|
||||||
INSTALL_GEODATA='0'
|
INSTALL_GEODATA='0'
|
||||||
|
|
||||||
# remove
|
# remove
|
||||||
REMOVE='0'
|
REMOVE='0'
|
||||||
|
|
||||||
# help
|
# help
|
||||||
HELP='0'
|
HELP='0'
|
||||||
|
|
||||||
# check
|
# check
|
||||||
CHECK='0'
|
CHECK='0'
|
||||||
|
|
||||||
# --force
|
# --force
|
||||||
FORCE='0'
|
FORCE='0'
|
||||||
|
|
||||||
# --beta
|
# --beta
|
||||||
BETA='0'
|
BETA='0'
|
||||||
|
|
||||||
# --install-user ?
|
# --install-user ?
|
||||||
INSTALL_USER=""
|
INSTALL_USER=''
|
||||||
|
|
||||||
# --without-geodata
|
# --without-geodata
|
||||||
NO_GEODATA='0'
|
NO_GEODATA='0'
|
||||||
# --not-update-service
|
|
||||||
|
# --without-logfiles
|
||||||
|
NO_LOGFILES='0'
|
||||||
|
|
||||||
|
# --no-update-service
|
||||||
N_UP_SERVICE='0'
|
N_UP_SERVICE='0'
|
||||||
|
|
||||||
# --reinstall
|
# --reinstall
|
||||||
REINSTALL='0'
|
REINSTALL='0'
|
||||||
|
|
||||||
# --version ?
|
# --version ?
|
||||||
SPECIFIED_VERSION=""
|
SPECIFIED_VERSION=''
|
||||||
|
|
||||||
# --local ?
|
# --local ?
|
||||||
LOCAL_FILE=""
|
LOCAL_FILE=''
|
||||||
|
|
||||||
# --proxy ?
|
# --proxy ?
|
||||||
PROXY=""
|
PROXY=''
|
||||||
|
|
||||||
# --purge
|
# --purge
|
||||||
PURGE='0'
|
PURGE='0'
|
||||||
|
|
||||||
|
@ -198,7 +222,7 @@ judgment_parameters() {
|
||||||
'install-geodata')
|
'install-geodata')
|
||||||
INSTALL_GEODATA='1'
|
INSTALL_GEODATA='1'
|
||||||
;;
|
;;
|
||||||
'remove' | '--remove')
|
'remove')
|
||||||
REMOVE='1'
|
REMOVE='1'
|
||||||
;;
|
;;
|
||||||
'help')
|
'help')
|
||||||
|
@ -210,6 +234,9 @@ judgment_parameters() {
|
||||||
'--without-geodata')
|
'--without-geodata')
|
||||||
NO_GEODATA='1'
|
NO_GEODATA='1'
|
||||||
;;
|
;;
|
||||||
|
'--without-logfiles')
|
||||||
|
NO_LOGFILES='1'
|
||||||
|
;;
|
||||||
'--purge')
|
'--purge')
|
||||||
PURGE='1'
|
PURGE='1'
|
||||||
;;
|
;;
|
||||||
|
@ -256,7 +283,7 @@ judgment_parameters() {
|
||||||
'--reinstall')
|
'--reinstall')
|
||||||
REINSTALL='1'
|
REINSTALL='1'
|
||||||
;;
|
;;
|
||||||
'--not-update-service')
|
'--no-update-service')
|
||||||
N_UP_SERVICE='1'
|
N_UP_SERVICE='1'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -321,48 +348,50 @@ get_current_version() {
|
||||||
|
|
||||||
get_latest_version() {
|
get_latest_version() {
|
||||||
# Get Xray latest release version number
|
# Get Xray latest release version number
|
||||||
TMP_FILE="$(mktemp)"
|
local tmp_file
|
||||||
if ! curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/XTLS/Xray-core/releases/latest'; then
|
tmp_file="$(mktemp)"
|
||||||
"rm" "$TMP_FILE"
|
if ! curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" -o "$tmp_file" 'https://api.github.com/repos/XTLS/Xray-core/releases/latest'; then
|
||||||
|
"rm" "$tmp_file"
|
||||||
echo 'error: Failed to get release list, please check your network.'
|
echo 'error: Failed to get release list, please check your network.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
RELEASE_LATEST="$(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}')"
|
RELEASE_LATEST="$(sed 'y/,/\n/' "$tmp_file" | grep 'tag_name' | awk -F '"' '{print $4}')"
|
||||||
if [[ -z "$RELEASE_LATEST" ]]; then
|
if [[ -z "$RELEASE_LATEST" ]]; then
|
||||||
if grep -q "API rate limit exceeded" "$TMP_FILE"; then
|
if grep -q "API rate limit exceeded" "$tmp_file"; then
|
||||||
echo "error: github API rate limit exceeded"
|
echo "error: github API rate limit exceeded"
|
||||||
else
|
else
|
||||||
echo "error: Failed to get the latest release version."
|
echo "error: Failed to get the latest release version."
|
||||||
echo "Welcome bug report:https://github.com/XTLS/Xray-install/issues"
|
echo "Welcome bug report:https://github.com/XTLS/Xray-install/issues"
|
||||||
fi
|
fi
|
||||||
"rm" "$TMP_FILE"
|
"rm" "$tmp_file"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
"rm" "$TMP_FILE"
|
"rm" "$tmp_file"
|
||||||
RELEASE_LATEST="v${RELEASE_LATEST#v}"
|
RELEASE_LATEST="v${RELEASE_LATEST#v}"
|
||||||
if ! curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/XTLS/Xray-core/releases'; then
|
if ! curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" -o "$tmp_file" 'https://api.github.com/repos/XTLS/Xray-core/releases'; then
|
||||||
"rm" "$TMP_FILE"
|
"rm" "$tmp_file"
|
||||||
echo 'error: Failed to get release list, please check your network.'
|
echo 'error: Failed to get release list, please check your network.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
local releases_list=($(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}'))
|
local releases_list
|
||||||
if [[ -z "${releases_list[@]}" ]]; then
|
releases_list=($(sed 'y/,/\n/' "$tmp_file" | grep 'tag_name' | awk -F '"' '{print $4}'))
|
||||||
if grep -q "API rate limit exceeded" "$TMP_FILE"; then
|
if [[ "${#releases_list[@]}" -eq '0' ]]; then
|
||||||
|
if grep -q "API rate limit exceeded" "$tmp_file"; then
|
||||||
echo "error: github API rate limit exceeded"
|
echo "error: github API rate limit exceeded"
|
||||||
else
|
else
|
||||||
echo "error: Failed to get the latest release version."
|
echo "error: Failed to get the latest release version."
|
||||||
echo "Welcome bug report:https://github.com/XTLS/Xray-install/issues"
|
echo "Welcome bug report:https://github.com/XTLS/Xray-install/issues"
|
||||||
fi
|
fi
|
||||||
"rm" "$TMP_FILE"
|
"rm" "$tmp_file"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
local i
|
local i
|
||||||
for i in ${!releases_list[@]}
|
for i in ${!releases_list[@]}
|
||||||
do
|
do
|
||||||
releases_list[$i]="v${releases_list[$i]#v}"
|
releases_list[$i]="v${releases_list[$i]#v}"
|
||||||
grep -q "https://github.com/XTLS/Xray-core/releases/download/${releases_list[$i]}/Xray-linux-$MACHINE.zip" "$TMP_FILE" && break
|
grep -q "https://github.com/XTLS/Xray-core/releases/download/${releases_list[$i]}/Xray-linux-$MACHINE.zip" "$tmp_file" && break
|
||||||
done
|
done
|
||||||
"rm" "$TMP_FILE"
|
"rm" "$tmp_file"
|
||||||
PRE_RELEASE_LATEST="${releases_list[$i]}"
|
PRE_RELEASE_LATEST="${releases_list[$i]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,12 +403,14 @@ version_gt() {
|
||||||
if [[ "$1" != "$2" ]]; then
|
if [[ "$1" != "$2" ]]; then
|
||||||
local temp_1_version_number="${1#v}"
|
local temp_1_version_number="${1#v}"
|
||||||
local temp_1_major_version_number="${temp_1_version_number%%.*}"
|
local temp_1_major_version_number="${temp_1_version_number%%.*}"
|
||||||
local temp_1_minor_version_number="$(echo "$temp_1_version_number" | awk -F '.' '{print $2}')"
|
local temp_1_minor_version_number
|
||||||
|
temp_1_minor_version_number="$(echo "$temp_1_version_number" | awk -F '.' '{print $2}')"
|
||||||
local temp_1_minimunm_version_number="${temp_1_version_number##*.}"
|
local temp_1_minimunm_version_number="${temp_1_version_number##*.}"
|
||||||
# shellcheck disable=SC2001
|
# shellcheck disable=SC2001
|
||||||
local temp_2_version_number="${2#v}"
|
local temp_2_version_number="${2#v}"
|
||||||
local temp_2_major_version_number="${temp_2_version_number%%.*}"
|
local temp_2_major_version_number="${temp_2_version_number%%.*}"
|
||||||
local temp_2_minor_version_number="$(echo "$temp_2_version_number" | awk -F '.' '{print $2}')"
|
local temp_2_minor_version_number
|
||||||
|
temp_2_minor_version_number="$(echo "$temp_2_version_number" | awk -F '.' '{print $2}')"
|
||||||
local temp_2_minimunm_version_number="${temp_2_version_number##*.}"
|
local temp_2_minimunm_version_number="${temp_2_version_number##*.}"
|
||||||
if [[ "$temp_1_major_version_number" -gt "$temp_2_major_version_number" ]]; then
|
if [[ "$temp_1_major_version_number" -gt "$temp_2_major_version_number" ]]; then
|
||||||
return 0
|
return 0
|
||||||
|
@ -480,13 +511,15 @@ install_xray() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Used to store Xray log files
|
# Used to store Xray log files
|
||||||
if [[ ! -d '/var/log/xray/' ]]; then
|
if [[ "$NO_LOGFILES" -eq '0' ]]; then
|
||||||
install -d -m 700 -o $INSTALL_USER_UID -g $INSTALL_USER_GID /var/log/xray/
|
if [[ ! -d '/var/log/xray/' ]]; then
|
||||||
install -m 600 -o $INSTALL_USER_UID -g $INSTALL_USER_GID /dev/null /var/log/xray/access.log
|
install -d -m 700 -o "$INSTALL_USER_UID" -g "$INSTALL_USER_GID" /var/log/xray/
|
||||||
install -m 600 -o $INSTALL_USER_UID -g $INSTALL_USER_GID /dev/null /var/log/xray/error.log
|
install -m 600 -o "$INSTALL_USER_UID" -g "$INSTALL_USER_GID" /dev/null /var/log/xray/access.log
|
||||||
LOG='1'
|
install -m 600 -o "$INSTALL_USER_UID" -g "$INSTALL_USER_GID" /dev/null /var/log/xray/error.log
|
||||||
else
|
LOG='1'
|
||||||
chown -R $INSTALL_USER_UID:$INSTALL_USER_GID /var/log/xray/
|
else
|
||||||
|
chown -R "$INSTALL_USER_UID:$INSTALL_USER_GID" /var/log/xray/
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,7 +617,9 @@ ExecStart=/usr/local/bin/xray run -config ${JSON_PATH}/%i.json" > \
|
||||||
|
|
||||||
start_xray() {
|
start_xray() {
|
||||||
if [[ -f '/etc/systemd/system/xray.service' ]]; then
|
if [[ -f '/etc/systemd/system/xray.service' ]]; then
|
||||||
if systemctl start "${XRAY_CUSTOMIZE:-xray}"; then
|
systemctl start "${XRAY_CUSTOMIZE:-xray}"
|
||||||
|
sleep 1s
|
||||||
|
if systemctl -q is-active "${XRAY_CUSTOMIZE:-xray}"; then
|
||||||
echo 'info: Start the Xray service.'
|
echo 'info: Start the Xray service.'
|
||||||
else
|
else
|
||||||
echo 'error: Failed to start Xray service.'
|
echo 'error: Failed to start Xray service.'
|
||||||
|
@ -623,7 +658,8 @@ install_geodata() {
|
||||||
local file_ip='geoip.dat'
|
local file_ip='geoip.dat'
|
||||||
local file_dlc='dlc.dat'
|
local file_dlc='dlc.dat'
|
||||||
local file_site='geosite.dat'
|
local file_site='geosite.dat'
|
||||||
local dir_tmp="$(mktemp -d)"
|
local dir_tmp
|
||||||
|
dir_tmp="$(mktemp -d)"
|
||||||
[[ ! -f '/usr/local/bin/xray' ]] && echo "warning: Xray was not installed"
|
[[ ! -f '/usr/local/bin/xray' ]] && echo "warning: Xray was not installed"
|
||||||
download_geodata $download_link_geoip $file_ip
|
download_geodata $download_link_geoip $file_ip
|
||||||
download_geodata $download_link_geosite $file_dlc
|
download_geodata $download_link_geosite $file_dlc
|
||||||
|
@ -668,7 +704,7 @@ remove_xray() {
|
||||||
else
|
else
|
||||||
delete_files+=("$JSONS_PATH")
|
delete_files+=("$JSONS_PATH")
|
||||||
fi
|
fi
|
||||||
delete_files+=('/var/log/xray')
|
[[ -d '/var/log/xray' ]] && delete_files+=('/var/log/xray')
|
||||||
fi
|
fi
|
||||||
systemctl disable xray
|
systemctl disable xray
|
||||||
if ! ("rm" -r "${delete_files[@]}"); then
|
if ! ("rm" -r "${delete_files[@]}"); then
|
||||||
|
@ -719,8 +755,9 @@ show_help() {
|
||||||
echo ' -p, --proxy Download through a proxy server, e.g., -p http://127.0.0.1:8118 or -p socks5://127.0.0.1:1080'
|
echo ' -p, --proxy Download through a proxy server, e.g., -p http://127.0.0.1:8118 or -p socks5://127.0.0.1:1080'
|
||||||
echo ' -u, --install-user Install Xray in specified user, e.g, -u root'
|
echo ' -u, --install-user Install Xray in specified user, e.g, -u root'
|
||||||
echo ' --reinstall Reinstall current Xray version'
|
echo ' --reinstall Reinstall current Xray version'
|
||||||
echo " --not-update-service Don't change service files if they are exist"
|
echo " --no-update-service Don't change service files if they are exist"
|
||||||
echo " --without-geodata Don't install/update geoip.dat and geosite.dat"
|
echo " --without-geodata Don't install/update geoip.dat and geosite.dat"
|
||||||
|
echo " --without-logfiles Don't install /var/log/xray"
|
||||||
echo ' install-geodata:'
|
echo ' install-geodata:'
|
||||||
echo ' -p, --proxy Download through a proxy server'
|
echo ' -p, --proxy Download through a proxy server'
|
||||||
echo ' remove:'
|
echo ' remove:'
|
||||||
|
@ -786,9 +823,7 @@ main() {
|
||||||
else
|
else
|
||||||
INSTALL_VERSION="$PRE_RELEASE_LATEST"
|
INSTALL_VERSION="$PRE_RELEASE_LATEST"
|
||||||
fi
|
fi
|
||||||
version_gt $INSTALL_VERSION $CURRENT_VERSION
|
if ! version_gt "$INSTALL_VERSION" "$CURRENT_VERSION" && [[ "$FORCE" -eq '0' ]]; then
|
||||||
local temp_number=$?
|
|
||||||
if [[ "$temp_number" -eq '1' ]] && [[ "$FORCE" -eq '0' ]]; then
|
|
||||||
echo "info: No new version. The current version of Xray is $CURRENT_VERSION ."
|
echo "info: No new version. The current version of Xray is $CURRENT_VERSION ."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -796,8 +831,7 @@ main() {
|
||||||
fi
|
fi
|
||||||
install_software 'curl' 'curl'
|
install_software 'curl' 'curl'
|
||||||
install_software 'unzip' 'unzip'
|
install_software 'unzip' 'unzip'
|
||||||
download_xray
|
if ! download_xray; then
|
||||||
if [[ "$?" -eq '1' ]]; then
|
|
||||||
"rm" -r "$TMP_DIRECTORY"
|
"rm" -r "$TMP_DIRECTORY"
|
||||||
echo "removed: $TMP_DIRECTORY"
|
echo "removed: $TMP_DIRECTORY"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -853,7 +887,8 @@ main() {
|
||||||
start_xray
|
start_xray
|
||||||
else
|
else
|
||||||
systemctl --now enable xray
|
systemctl --now enable xray
|
||||||
if [[ "$?" -eq 0 ]]; then
|
sleep 1s
|
||||||
|
if systemctl -q is-active xray; then
|
||||||
echo "info: Enable and start the Xray service"
|
echo "info: Enable and start the Xray service"
|
||||||
else
|
else
|
||||||
echo "warning: Failed to enable and start the Xray service"
|
echo "warning: Failed to enable and start the Xray service"
|
||||||
|
|
Loading…
Reference in a new issue