mirror of https://github.com/XTLS/Xray-install
Merge 75c9580145
into 652637b1eb
commit
ef816156b9
|
@ -117,71 +117,93 @@ systemd_cat_config() {
|
||||||
|
|
||||||
check_if_running_as_root() {
|
check_if_running_as_root() {
|
||||||
# If you want to run as another user, please modify $EUID to be owned by this user
|
# If you want to run as another user, please modify $EUID to be owned by this user
|
||||||
if [[ "$EUID" -ne '0' ]]; then
|
if [[ "$(id -u)" -eq 0 ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
echo "error: You must run this script as root!"
|
echo "error: You must run this script as root!"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
identify_the_operating_system_and_architecture() {
|
identify_the_operating_system_and_architecture() {
|
||||||
if [[ "$(uname)" != 'Linux' ]]; then
|
if [[ "$(uname)" != 'Linux' ]]; then
|
||||||
echo "error: This operating system is not supported."
|
echo "error: This operating system is not supported."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Add OpenWrt detection
|
||||||
|
if grep -q -i 'openwrt' /etc/openwrt_release 2>/dev/null; then
|
||||||
|
echo "info: OpenWrt system detected."
|
||||||
|
OPENWRT=1
|
||||||
|
else
|
||||||
|
OPENWRT=0
|
||||||
|
fi
|
||||||
|
|
||||||
case "$(uname -m)" in
|
case "$(uname -m)" in
|
||||||
'i386' | 'i686')
|
'i386' | 'i686')
|
||||||
MACHINE='32'
|
MACHINE='32'
|
||||||
;;
|
;;
|
||||||
'amd64' | 'x86_64')
|
'amd64' | 'x86_64')
|
||||||
MACHINE='64'
|
MACHINE='64'
|
||||||
;;
|
;;
|
||||||
'armv5tel')
|
'armv5tel')
|
||||||
MACHINE='arm32-v5'
|
MACHINE='arm32-v5'
|
||||||
;;
|
;;
|
||||||
'armv6l')
|
'armv6l')
|
||||||
MACHINE='arm32-v6'
|
MACHINE='arm32-v6'
|
||||||
grep Features /proc/cpuinfo | grep -qw 'vfp' || MACHINE='arm32-v5'
|
grep Features /proc/cpuinfo | grep -qw 'vfp' || MACHINE='arm32-v5'
|
||||||
;;
|
;;
|
||||||
'armv7' | 'armv7l')
|
'armv7' | 'armv7l')
|
||||||
MACHINE='arm32-v7a'
|
MACHINE='arm32-v7a'
|
||||||
grep Features /proc/cpuinfo | grep -qw 'vfp' || MACHINE='arm32-v5'
|
grep Features /proc/cpuinfo | grep -qw 'vfp' || MACHINE='arm32-v5'
|
||||||
;;
|
;;
|
||||||
'armv8' | 'aarch64')
|
'armv8' | 'aarch64')
|
||||||
MACHINE='arm64-v8a'
|
MACHINE='arm64-v8a'
|
||||||
;;
|
;;
|
||||||
'mips')
|
'mips')
|
||||||
MACHINE='mips32'
|
MACHINE='mips32'
|
||||||
;;
|
;;
|
||||||
'mipsle')
|
'mipsle')
|
||||||
MACHINE='mips32le'
|
MACHINE='mips32le'
|
||||||
;;
|
;;
|
||||||
'mips64')
|
'mips64')
|
||||||
MACHINE='mips64'
|
MACHINE='mips64'
|
||||||
lscpu | grep -q "Little Endian" && MACHINE='mips64le'
|
lscpu | grep -q "Little Endian" && MACHINE='mips64le'
|
||||||
;;
|
;;
|
||||||
'mips64le')
|
'mips64le')
|
||||||
MACHINE='mips64le'
|
MACHINE='mips64le'
|
||||||
;;
|
;;
|
||||||
'ppc64')
|
'ppc64')
|
||||||
MACHINE='ppc64'
|
MACHINE='ppc64'
|
||||||
;;
|
;;
|
||||||
'ppc64le')
|
'ppc64le')
|
||||||
MACHINE='ppc64le'
|
MACHINE='ppc64le'
|
||||||
;;
|
;;
|
||||||
'riscv64')
|
'riscv64')
|
||||||
MACHINE='riscv64'
|
MACHINE='riscv64'
|
||||||
;;
|
;;
|
||||||
's390x')
|
's390x')
|
||||||
MACHINE='s390x'
|
MACHINE='s390x'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "error: The architecture is not supported."
|
echo "error: The architecture is not supported."
|
||||||
exit 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if [[ "$OPENWRT" -eq '1' ]]; then
|
||||||
|
if [[ ! -f '/etc/openwrt_release' ]]; then
|
||||||
|
echo "error: Not a supported OpenWrt system."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
PACKAGE_MANAGEMENT_INSTALL='opkg update; opkg install'
|
||||||
|
PACKAGE_MANAGEMENT_REMOVE='opkg remove'
|
||||||
|
package_provide_tput='ncurses-utils'
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
if [[ ! -f '/etc/os-release' ]]; then
|
if [[ ! -f '/etc/os-release' ]]; then
|
||||||
echo "error: Don't use outdated Linux distributions."
|
echo "error: Don't use outdated Linux distributions."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Do not combine this judgment condition with the following judgment condition.
|
# Do not combine this judgment condition with the following judgment condition.
|
||||||
## Be aware of Linux distribution like Gentoo, which kernel supports switch between Systemd and OpenRC.
|
## Be aware of Linux distribution like Gentoo, which kernel supports switch between Systemd and OpenRC.
|
||||||
|
@ -191,7 +213,7 @@ identify_the_operating_system_and_architecture() {
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
echo "error: Only Linux distributions using systemd are supported."
|
echo "error: Only Linux distributions using systemd are supported."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [[ "$(type -P apt)" ]]; then
|
if [[ "$(type -P apt)" ]]; then
|
||||||
PACKAGE_MANAGEMENT_INSTALL='apt -y --no-install-recommends install'
|
PACKAGE_MANAGEMENT_INSTALL='apt -y --no-install-recommends install'
|
||||||
|
@ -213,13 +235,13 @@ identify_the_operating_system_and_architecture() {
|
||||||
PACKAGE_MANAGEMENT_INSTALL='pacman -Syy --noconfirm'
|
PACKAGE_MANAGEMENT_INSTALL='pacman -Syy --noconfirm'
|
||||||
PACKAGE_MANAGEMENT_REMOVE='pacman -Rsn'
|
PACKAGE_MANAGEMENT_REMOVE='pacman -Rsn'
|
||||||
package_provide_tput='ncurses'
|
package_provide_tput='ncurses'
|
||||||
elif [[ "$(type -P emerge)" ]]; then
|
elif [[ "$(type -P emerge)" ]]; then
|
||||||
PACKAGE_MANAGEMENT_INSTALL='emerge -qv'
|
PACKAGE_MANAGEMENT_INSTALL='emerge -qv'
|
||||||
PACKAGE_MANAGEMENT_REMOVE='emerge -Cv'
|
PACKAGE_MANAGEMENT_REMOVE='emerge -Cv'
|
||||||
package_provide_tput='ncurses'
|
package_provide_tput='ncurses'
|
||||||
else
|
else
|
||||||
echo "error: The script does not support the package manager in this operating system."
|
echo "error: The script does not support the package manager in this operating system."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,89 +251,89 @@ judgment_parameters() {
|
||||||
local temp_version='0'
|
local temp_version='0'
|
||||||
while [[ "$#" -gt '0' ]]; do
|
while [[ "$#" -gt '0' ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'install')
|
'install')
|
||||||
INSTALL='1'
|
INSTALL='1'
|
||||||
;;
|
;;
|
||||||
'install-geodata')
|
'install-geodata')
|
||||||
INSTALL_GEODATA='1'
|
INSTALL_GEODATA='1'
|
||||||
;;
|
;;
|
||||||
'remove')
|
'remove')
|
||||||
REMOVE='1'
|
REMOVE='1'
|
||||||
;;
|
;;
|
||||||
'help')
|
'help')
|
||||||
HELP='1'
|
HELP='1'
|
||||||
;;
|
;;
|
||||||
'check')
|
'check')
|
||||||
CHECK='1'
|
CHECK='1'
|
||||||
;;
|
;;
|
||||||
'--without-geodata')
|
'--without-geodata')
|
||||||
NO_GEODATA='1'
|
NO_GEODATA='1'
|
||||||
;;
|
;;
|
||||||
'--without-logfiles')
|
'--without-logfiles')
|
||||||
NO_LOGFILES='1'
|
NO_LOGFILES='1'
|
||||||
;;
|
;;
|
||||||
'--purge')
|
'--purge')
|
||||||
PURGE='1'
|
PURGE='1'
|
||||||
;;
|
;;
|
||||||
'--version')
|
'--version')
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
echo "error: Please specify the correct version."
|
echo "error: Please specify the correct version."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
temp_version='1'
|
temp_version='1'
|
||||||
SPECIFIED_VERSION="$2"
|
SPECIFIED_VERSION="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
'-f' | '--force')
|
'-f' | '--force')
|
||||||
FORCE='1'
|
FORCE='1'
|
||||||
;;
|
;;
|
||||||
'--beta')
|
'--beta')
|
||||||
BETA='1'
|
BETA='1'
|
||||||
;;
|
;;
|
||||||
'-l' | '--local')
|
'-l' | '--local')
|
||||||
local_install='1'
|
local_install='1'
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
echo "error: Please specify the correct local file."
|
echo "error: Please specify the correct local file."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
LOCAL_FILE="$2"
|
LOCAL_FILE="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
'-p' | '--proxy')
|
'-p' | '--proxy')
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
echo "error: Please specify the proxy server address."
|
echo "error: Please specify the proxy server address."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
PROXY="$2"
|
PROXY="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
'-u' | '--install-user')
|
'-u' | '--install-user')
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
echo "error: Please specify the install user.}"
|
echo "error: Please specify the install user.}"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
INSTALL_USER="$2"
|
INSTALL_USER="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
'--reinstall')
|
'--reinstall')
|
||||||
REINSTALL='1'
|
REINSTALL='1'
|
||||||
;;
|
;;
|
||||||
'--no-update-service')
|
'--no-update-service')
|
||||||
N_UP_SERVICE='1'
|
N_UP_SERVICE='1'
|
||||||
;;
|
;;
|
||||||
'--logrotate')
|
'--logrotate')
|
||||||
if ! grep -qE '\b([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\b' <<< "$2";then
|
if ! grep -qE '\b([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\b' <<< "$2";then
|
||||||
echo "error: Wrong format of time, it should be in the format of 12:34:56, under 10:00:00 should be start with 0, e.g. 01:23:45."
|
echo "error: Wrong format of time, it should be in the format of 12:34:56, under 10:00:00 should be start with 0, e.g. 01:23:45."
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
LOGROTATE='1'
|
|
||||||
LOGROTATE_TIME="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "$0: unknown option -- -"
|
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
fi
|
||||||
|
LOGROTATE='1'
|
||||||
|
LOGROTATE_TIME="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "$0: unknown option -- -"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
@ -319,11 +341,11 @@ judgment_parameters() {
|
||||||
INSTALL='1'
|
INSTALL='1'
|
||||||
elif ((INSTALL+INSTALL_GEODATA+HELP+CHECK+REMOVE>1)); then
|
elif ((INSTALL+INSTALL_GEODATA+HELP+CHECK+REMOVE>1)); then
|
||||||
echo 'You can only choose one action.'
|
echo 'You can only choose one action.'
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [[ "$INSTALL" -eq '1' ]] && ((temp_version+local_install+REINSTALL+BETA>1)); then
|
if [[ "$INSTALL" -eq '1' ]] && ((temp_version+local_install+REINSTALL+BETA>1)); then
|
||||||
echo "--version,--reinstall,--beta and --local can't be used together."
|
echo "--version,--reinstall,--beta and --local can't be used together."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +394,10 @@ get_latest_version() {
|
||||||
# Get Xray latest release version number
|
# Get Xray latest release version number
|
||||||
local tmp_file
|
local tmp_file
|
||||||
tmp_file="$(mktemp)"
|
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
|
local url='https://api.github.com/repos/XTLS/Xray-core/releases/latest'
|
||||||
|
if curl -x "${PROXY}" -sSfLo "$tmp_file" -H "Accept: application/vnd.github.v3+json" "$url"; then
|
||||||
|
echo "get release list success"
|
||||||
|
else
|
||||||
"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
|
||||||
|
@ -390,14 +415,16 @@ get_latest_version() {
|
||||||
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}" -sSfLo "$tmp_file" -H "Accept: application/vnd.github.v3+json" "$url"; then
|
||||||
|
echo "get release list success"
|
||||||
|
else
|
||||||
"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
|
local releases_list
|
||||||
releases_list=($(sed 'y/,/\n/' "$tmp_file" | grep 'tag_name' | awk -F '"' '{print $4}'))
|
readarray -t releases_list < <(sed 'y/,/\n/' "$tmp_file" | grep 'tag_name' | awk -F '"' '{print $4}')
|
||||||
if [[ "${#releases_list[@]}" -eq '0' ]]; then
|
if [[ "${#releases_list[@]}" -eq 0 ]]; 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
|
||||||
|
@ -407,14 +434,16 @@ get_latest_version() {
|
||||||
"rm" "$tmp_file"
|
"rm" "$tmp_file"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
local i
|
local i url_zip
|
||||||
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
|
url_zip="https://github.com/XTLS/Xray-core/releases/download/${releases_list[$i]}/Xray-linux-$MACHINE.zip"
|
||||||
|
if grep -q "$url_zip" "$tmp_file"; then
|
||||||
|
PRE_RELEASE_LATEST="${releases_list[$i]}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
"rm" "$tmp_file"
|
"rm" "$tmp_file"
|
||||||
PRE_RELEASE_LATEST="${releases_list[$i]}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
version_gt() {
|
version_gt() {
|
||||||
|
@ -422,7 +451,7 @@ version_gt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
download_xray() {
|
download_xray() {
|
||||||
DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/download/${INSTALL_VERSION}/Xray-linux-${MACHINE}.zip"
|
local DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/download/${INSTALL_VERSION}/Xray-linux-${MACHINE}.zip"
|
||||||
echo "Downloading Xray archive: $DOWNLOAD_LINK"
|
echo "Downloading Xray archive: $DOWNLOAD_LINK"
|
||||||
if curl -f -x "${PROXY}" -R -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then
|
if curl -f -x "${PROXY}" -R -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then
|
||||||
echo "ok."
|
echo "ok."
|
||||||
|
@ -471,6 +500,27 @@ install_file() {
|
||||||
}
|
}
|
||||||
|
|
||||||
install_xray() {
|
install_xray() {
|
||||||
|
# Install Xray binary to /usr/bin/ and /etc/xray (OpenWrt)
|
||||||
|
if [[ "$OPENWRT" -eq '1' ]]; then
|
||||||
|
cp "${TMP_DIRECTORY}/xray" "/usr/bin/xray"
|
||||||
|
chmod 755 "/usr/bin/xray"
|
||||||
|
mkdir -p /etc/xray
|
||||||
|
if [[ ! -f /etc/xray/config.json ]]; then
|
||||||
|
echo "{}" >"/etc/xray/config.json"
|
||||||
|
CONFIG_NEW='1'
|
||||||
|
fi
|
||||||
|
mkdir -p "/usr/share/xray"
|
||||||
|
cp "${TMP_DIRECTORY}/geoip.dat" "/usr/share/xray/geoip.dat"
|
||||||
|
cp "${TMP_DIRECTORY}/geosite.dat" "/usr/share/xray/geosite.dat"
|
||||||
|
mkdir -p /var/log/xray
|
||||||
|
chown -R "$INSTALL_USER_UID:$INSTALL_USER_GID" /var/log/xray
|
||||||
|
if [[ ! -f /var/log/xray/access.log ]]; then
|
||||||
|
touch /var/log/xray/access.log
|
||||||
|
touch /var/log/xray/error.log
|
||||||
|
LOG=1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
# Install Xray binary to /usr/local/bin/ and $DAT_PATH
|
# Install Xray binary to /usr/local/bin/ and $DAT_PATH
|
||||||
install_file xray
|
install_file xray
|
||||||
# If the file exists, geoip.dat and geosite.dat will not be installed or updated
|
# If the file exists, geoip.dat and geosite.dat will not be installed or updated
|
||||||
|
@ -512,6 +562,74 @@ install_xray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
install_startup_service_file() {
|
install_startup_service_file() {
|
||||||
|
if [[ "$OPENWRT" -eq '1' ]]; then
|
||||||
|
[[ -f /etc/init.d/xray ]] && return 0
|
||||||
|
# Create OpenWrt init script
|
||||||
|
cat >/etc/init.d/xray <<'EOF'
|
||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
|
USE_PROCD=1
|
||||||
|
START=99
|
||||||
|
|
||||||
|
CONF="xray"
|
||||||
|
PROG="/usr/bin/xray"
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
config_load "$CONF"
|
||||||
|
|
||||||
|
local enabled
|
||||||
|
config_get_bool enabled "enabled" "enabled" "0"
|
||||||
|
[ "$enabled" -eq "1" ] || return 1
|
||||||
|
|
||||||
|
local confdir
|
||||||
|
local conffiles
|
||||||
|
local datadir
|
||||||
|
local dialer
|
||||||
|
local format
|
||||||
|
|
||||||
|
config_get confdir "config" "confdir"
|
||||||
|
config_get conffiles "config" "conffiles"
|
||||||
|
config_get datadir "config" "datadir" "/usr/share/xray"
|
||||||
|
config_get dialer "config" "dialer"
|
||||||
|
config_get format "config" "format" "json"
|
||||||
|
|
||||||
|
procd_open_instance "$CONF"
|
||||||
|
procd_set_param command "$PROG" run
|
||||||
|
[ -n "$confdir" ] && procd_append_param command -confdir "$confdir"
|
||||||
|
[ -n "$conffiles" ] && {
|
||||||
|
for i in $conffiles
|
||||||
|
do
|
||||||
|
procd_append_param command -config "$i"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
[ -n "$format" ] && procd_append_param command -format "$format"
|
||||||
|
[ -n "$dialer" ] && procd_set_param env XRAY_BROWSER_DIALER="$dialer"
|
||||||
|
procd_set_param env XRAY_LOCATION_ASSET="$datadir"
|
||||||
|
procd_set_param file $conffiles
|
||||||
|
|
||||||
|
procd_set_param limits core="unlimited"
|
||||||
|
procd_set_param limits nofile="1000000 1000000"
|
||||||
|
procd_set_param stdout 1
|
||||||
|
procd_set_param stderr 1
|
||||||
|
procd_set_param respawn
|
||||||
|
|
||||||
|
procd_close_instance
|
||||||
|
}
|
||||||
|
|
||||||
|
reload_service() {
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
}
|
||||||
|
|
||||||
|
service_triggers() {
|
||||||
|
procd_add_reload_trigger "$CONF"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x /etc/init.d/xray
|
||||||
|
/etc/init.d/xray enable
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
mkdir -p '/etc/systemd/system/xray.service.d'
|
mkdir -p '/etc/systemd/system/xray.service.d'
|
||||||
mkdir -p '/etc/systemd/system/xray@.service.d/'
|
mkdir -p '/etc/systemd/system/xray@.service.d/'
|
||||||
local temp_CapabilityBoundingSet="CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE"
|
local temp_CapabilityBoundingSet="CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE"
|
||||||
|
@ -604,6 +722,15 @@ ExecStart=/usr/local/bin/xray run -config ${JSON_PATH}/%i.json" > \
|
||||||
}
|
}
|
||||||
|
|
||||||
start_xray() {
|
start_xray() {
|
||||||
|
if [[ "$OPENWRT" -eq 1 ]]; then
|
||||||
|
if /etc/init.d/xray start; then
|
||||||
|
echo 'info: Start the Xray service.'
|
||||||
|
else
|
||||||
|
echo 'error: Failed to start Xray service.'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
if [[ -f '/etc/systemd/system/xray.service' ]]; then
|
if [[ -f '/etc/systemd/system/xray.service' ]]; then
|
||||||
systemctl start "${XRAY_CUSTOMIZE:-xray}"
|
systemctl start "${XRAY_CUSTOMIZE:-xray}"
|
||||||
sleep 1s
|
sleep 1s
|
||||||
|
@ -617,6 +744,11 @@ start_xray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_xray() {
|
stop_xray() {
|
||||||
|
if [[ "$OPENWRT" -eq '1' ]]; then
|
||||||
|
/etc/init.d/xray stop
|
||||||
|
echo 'info: Stop the Xray service.'
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
XRAY_CUSTOMIZE="$(systemctl list-units | grep 'xray@' | awk -F ' ' '{print $1}')"
|
XRAY_CUSTOMIZE="$(systemctl list-units | grep 'xray@' | awk -F ' ' '{print $1}')"
|
||||||
if [[ -z "$XRAY_CUSTOMIZE" ]]; then
|
if [[ -z "$XRAY_CUSTOMIZE" ]]; then
|
||||||
local xray_daemon_to_stop='xray.service'
|
local xray_daemon_to_stop='xray.service'
|
||||||
|
@ -633,7 +765,7 @@ stop_xray() {
|
||||||
install_with_logrotate() {
|
install_with_logrotate() {
|
||||||
install_software 'logrotate' 'logrotate'
|
install_software 'logrotate' 'logrotate'
|
||||||
if [[ -z "$LOGROTATE_TIME" ]]; then
|
if [[ -z "$LOGROTATE_TIME" ]]; then
|
||||||
LOGROTATE_TIME="00:00:00"
|
LOGROTATE_TIME="00:00:00"
|
||||||
fi
|
fi
|
||||||
cat <<EOF > /etc/systemd/system/logrotate@.service
|
cat <<EOF > /etc/systemd/system/logrotate@.service
|
||||||
[Unit]
|
[Unit]
|
||||||
|
@ -656,8 +788,8 @@ Persistent=true
|
||||||
WantedBy=timers.target
|
WantedBy=timers.target
|
||||||
EOF
|
EOF
|
||||||
if [[ ! -d '/etc/logrotate.d/' ]]; then
|
if [[ ! -d '/etc/logrotate.d/' ]]; then
|
||||||
install -d -m 700 -o "$INSTALL_USER_UID" -g "$INSTALL_USER_GID" /etc/logrotate.d/
|
install -d -m 700 -o "$INSTALL_USER_UID" -g "$INSTALL_USER_GID" /etc/logrotate.d/
|
||||||
LOGROTATE_DIR='1'
|
LOGROTATE_DIR='1'
|
||||||
fi
|
fi
|
||||||
cat << EOF > /etc/logrotate.d/xray
|
cat << EOF > /etc/logrotate.d/xray
|
||||||
/var/log/xray/*.log {
|
/var/log/xray/*.log {
|
||||||
|
@ -811,9 +943,9 @@ show_help() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
check_if_running_as_root
|
check_if_running_as_root || return 1
|
||||||
identify_the_operating_system_and_architecture
|
identify_the_operating_system_and_architecture || return 1
|
||||||
judgment_parameters "$@"
|
judgment_parameters "$@" || return 1
|
||||||
|
|
||||||
install_software "$package_provide_tput" 'tput'
|
install_software "$package_provide_tput" 'tput'
|
||||||
red=$(tput setaf 1)
|
red=$(tput setaf 1)
|
||||||
|
@ -924,7 +1056,7 @@ main() {
|
||||||
echo 'installed: /etc/systemd/system/logrotate@.service'
|
echo 'installed: /etc/systemd/system/logrotate@.service'
|
||||||
echo 'installed: /etc/systemd/system/logrotate@.timer'
|
echo 'installed: /etc/systemd/system/logrotate@.timer'
|
||||||
if [[ "$LOGROTATE_DIR" -eq '1' ]]; then
|
if [[ "$LOGROTATE_DIR" -eq '1' ]]; then
|
||||||
echo 'installed: /etc/logrotate.d/'
|
echo 'installed: /etc/logrotate.d/'
|
||||||
fi
|
fi
|
||||||
echo 'installed: /etc/logrotate.d/xray'
|
echo 'installed: /etc/logrotate.d/xray'
|
||||||
systemctl start logrotate@xray.timer
|
systemctl start logrotate@xray.timer
|
||||||
|
|
Loading…
Reference in New Issue