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)
|
||||
|
||||
```
|
||||
installed: /etc/systemd/system/xray.service
|
||||
installed: /etc/systemd/system/xray@.service
|
||||
|
||||
installed: /usr/local/bin/xray
|
||||
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/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
|
||||
|
||||
**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'
|
||||
|
||||
# Gobal verbals
|
||||
|
||||
# Xray current version
|
||||
CURRENT_VERSION=""
|
||||
CURRENT_VERSION=''
|
||||
|
||||
# Xray latest release version
|
||||
RELEASE_LATEST=""
|
||||
RELEASE_LATEST=''
|
||||
|
||||
# Xray latest prerelease/release version
|
||||
PRE_RELEASE_LATEST=''
|
||||
|
||||
# Xray version will be installed
|
||||
INSTALL_VERSION=""
|
||||
INSTALL_VERSION=''
|
||||
|
||||
# install
|
||||
INSTALL='0'
|
||||
|
||||
# install-geodata
|
||||
INSTALL_GEODATA='0'
|
||||
|
||||
# remove
|
||||
REMOVE='0'
|
||||
|
||||
# help
|
||||
HELP='0'
|
||||
|
||||
# check
|
||||
CHECK='0'
|
||||
|
||||
# --force
|
||||
FORCE='0'
|
||||
|
||||
# --beta
|
||||
BETA='0'
|
||||
|
||||
# --install-user ?
|
||||
INSTALL_USER=""
|
||||
INSTALL_USER=''
|
||||
|
||||
# --without-geodata
|
||||
NO_GEODATA='0'
|
||||
# --not-update-service
|
||||
|
||||
# --without-logfiles
|
||||
NO_LOGFILES='0'
|
||||
|
||||
# --no-update-service
|
||||
N_UP_SERVICE='0'
|
||||
|
||||
# --reinstall
|
||||
REINSTALL='0'
|
||||
|
||||
# --version ?
|
||||
SPECIFIED_VERSION=""
|
||||
SPECIFIED_VERSION=''
|
||||
|
||||
# --local ?
|
||||
LOCAL_FILE=""
|
||||
LOCAL_FILE=''
|
||||
|
||||
# --proxy ?
|
||||
PROXY=""
|
||||
PROXY=''
|
||||
|
||||
# --purge
|
||||
PURGE='0'
|
||||
|
||||
|
@ -198,7 +222,7 @@ judgment_parameters() {
|
|||
'install-geodata')
|
||||
INSTALL_GEODATA='1'
|
||||
;;
|
||||
'remove' | '--remove')
|
||||
'remove')
|
||||
REMOVE='1'
|
||||
;;
|
||||
'help')
|
||||
|
@ -210,6 +234,9 @@ judgment_parameters() {
|
|||
'--without-geodata')
|
||||
NO_GEODATA='1'
|
||||
;;
|
||||
'--without-logfiles')
|
||||
NO_LOGFILES='1'
|
||||
;;
|
||||
'--purge')
|
||||
PURGE='1'
|
||||
;;
|
||||
|
@ -256,7 +283,7 @@ judgment_parameters() {
|
|||
'--reinstall')
|
||||
REINSTALL='1'
|
||||
;;
|
||||
'--not-update-service')
|
||||
'--no-update-service')
|
||||
N_UP_SERVICE='1'
|
||||
;;
|
||||
*)
|
||||
|
@ -321,48 +348,50 @@ get_current_version() {
|
|||
|
||||
get_latest_version() {
|
||||
# Get Xray latest release version number
|
||||
TMP_FILE="$(mktemp)"
|
||||
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"
|
||||
local tmp_file
|
||||
tmp_file="$(mktemp)"
|
||||
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.'
|
||||
exit 1
|
||||
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 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"
|
||||
else
|
||||
echo "error: Failed to get the latest release version."
|
||||
echo "Welcome bug report:https://github.com/XTLS/Xray-install/issues"
|
||||
fi
|
||||
"rm" "$TMP_FILE"
|
||||
"rm" "$tmp_file"
|
||||
exit 1
|
||||
fi
|
||||
"rm" "$TMP_FILE"
|
||||
"rm" "$tmp_file"
|
||||
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
|
||||
"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'; then
|
||||
"rm" "$tmp_file"
|
||||
echo 'error: Failed to get release list, please check your network.'
|
||||
exit 1
|
||||
fi
|
||||
local releases_list=($(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}'))
|
||||
if [[ -z "${releases_list[@]}" ]]; then
|
||||
if grep -q "API rate limit exceeded" "$TMP_FILE"; then
|
||||
local releases_list
|
||||
releases_list=($(sed 'y/,/\n/' "$tmp_file" | grep 'tag_name' | awk -F '"' '{print $4}'))
|
||||
if [[ "${#releases_list[@]}" -eq '0' ]]; then
|
||||
if grep -q "API rate limit exceeded" "$tmp_file"; then
|
||||
echo "error: github API rate limit exceeded"
|
||||
else
|
||||
echo "error: Failed to get the latest release version."
|
||||
echo "Welcome bug report:https://github.com/XTLS/Xray-install/issues"
|
||||
fi
|
||||
"rm" "$TMP_FILE"
|
||||
"rm" "$tmp_file"
|
||||
exit 1
|
||||
fi
|
||||
local i
|
||||
for i in ${!releases_list[@]}
|
||||
do
|
||||
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
|
||||
"rm" "$TMP_FILE"
|
||||
"rm" "$tmp_file"
|
||||
PRE_RELEASE_LATEST="${releases_list[$i]}"
|
||||
}
|
||||
|
||||
|
@ -374,12 +403,14 @@ version_gt() {
|
|||
if [[ "$1" != "$2" ]]; then
|
||||
local temp_1_version_number="${1#v}"
|
||||
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##*.}"
|
||||
# shellcheck disable=SC2001
|
||||
local temp_2_version_number="${2#v}"
|
||||
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##*.}"
|
||||
if [[ "$temp_1_major_version_number" -gt "$temp_2_major_version_number" ]]; then
|
||||
return 0
|
||||
|
@ -480,13 +511,15 @@ install_xray() {
|
|||
fi
|
||||
|
||||
# Used to store Xray log files
|
||||
if [[ "$NO_LOGFILES" -eq '0' ]]; then
|
||||
if [[ ! -d '/var/log/xray/' ]]; then
|
||||
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/access.log
|
||||
install -m 600 -o $INSTALL_USER_UID -g $INSTALL_USER_GID /dev/null /var/log/xray/error.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/access.log
|
||||
install -m 600 -o "$INSTALL_USER_UID" -g "$INSTALL_USER_GID" /dev/null /var/log/xray/error.log
|
||||
LOG='1'
|
||||
else
|
||||
chown -R $INSTALL_USER_UID:$INSTALL_USER_GID /var/log/xray/
|
||||
chown -R "$INSTALL_USER_UID:$INSTALL_USER_GID" /var/log/xray/
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -584,7 +617,9 @@ ExecStart=/usr/local/bin/xray run -config ${JSON_PATH}/%i.json" > \
|
|||
|
||||
start_xray() {
|
||||
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.'
|
||||
else
|
||||
echo 'error: Failed to start Xray service.'
|
||||
|
@ -623,7 +658,8 @@ install_geodata() {
|
|||
local file_ip='geoip.dat'
|
||||
local file_dlc='dlc.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"
|
||||
download_geodata $download_link_geoip $file_ip
|
||||
download_geodata $download_link_geosite $file_dlc
|
||||
|
@ -668,7 +704,7 @@ remove_xray() {
|
|||
else
|
||||
delete_files+=("$JSONS_PATH")
|
||||
fi
|
||||
delete_files+=('/var/log/xray')
|
||||
[[ -d '/var/log/xray' ]] && delete_files+=('/var/log/xray')
|
||||
fi
|
||||
systemctl disable xray
|
||||
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 ' -u, --install-user Install Xray in specified user, e.g, -u root'
|
||||
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-logfiles Don't install /var/log/xray"
|
||||
echo ' install-geodata:'
|
||||
echo ' -p, --proxy Download through a proxy server'
|
||||
echo ' remove:'
|
||||
|
@ -786,9 +823,7 @@ main() {
|
|||
else
|
||||
INSTALL_VERSION="$PRE_RELEASE_LATEST"
|
||||
fi
|
||||
version_gt $INSTALL_VERSION $CURRENT_VERSION
|
||||
local temp_number=$?
|
||||
if [[ "$temp_number" -eq '1' ]] && [[ "$FORCE" -eq '0' ]]; then
|
||||
if ! version_gt "$INSTALL_VERSION" "$CURRENT_VERSION" && [[ "$FORCE" -eq '0' ]]; then
|
||||
echo "info: No new version. The current version of Xray is $CURRENT_VERSION ."
|
||||
exit 0
|
||||
fi
|
||||
|
@ -796,8 +831,7 @@ main() {
|
|||
fi
|
||||
install_software 'curl' 'curl'
|
||||
install_software 'unzip' 'unzip'
|
||||
download_xray
|
||||
if [[ "$?" -eq '1' ]]; then
|
||||
if ! download_xray; then
|
||||
"rm" -r "$TMP_DIRECTORY"
|
||||
echo "removed: $TMP_DIRECTORY"
|
||||
exit 1
|
||||
|
@ -853,7 +887,8 @@ main() {
|
|||
start_xray
|
||||
else
|
||||
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"
|
||||
else
|
||||
echo "warning: Failed to enable and start the Xray service"
|
||||
|
|
Loading…
Reference in a new issue