From 6bc321c03219273dbbc2934f378cc2bf3515451a Mon Sep 17 00:00:00 2001 From: kastov Date: Mon, 11 Aug 2025 18:42:40 +0300 Subject: [PATCH] =?UTF-8?q?=E2=80=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/install-xray.sh | 125 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 scripts/install-xray.sh diff --git a/scripts/install-xray.sh b/scripts/install-xray.sh new file mode 100644 index 0000000..a5c8702 --- /dev/null +++ b/scripts/install-xray.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash + +# Download Xray latest + +RELEASE_TAG="latest" +UPSTREAM_REPO="XTLS" + +if [[ "$1" ]]; then + RELEASE_TAG="$1" +fi + +if [[ "$2" ]]; then + UPSTREAM_REPO="$2" +fi + +check_if_running_as_root() { + # If you want to run as another user, please modify $EUID to be owned by this user + if [[ "$EUID" -ne '0' ]]; then + echo "error: You must run this script as root!" + exit 1 + fi +} + +identify_the_operating_system_and_architecture() { + if [[ "$(uname)" == 'Linux' ]]; then + case "$(uname -m)" in + 'i386' | 'i686') + ARCH='32' + ;; + 'amd64' | 'x86_64') + ARCH='64' + ;; + 'armv5tel') + ARCH='arm32-v5' + ;; + 'armv6l') + ARCH='arm32-v6' + grep Features /proc/cpuinfo | grep -qw 'vfp' || ARCH='arm32-v5' + ;; + 'armv7' | 'armv7l') + ARCH='arm32-v7a' + grep Features /proc/cpuinfo | grep -qw 'vfp' || ARCH='arm32-v5' + ;; + 'armv8' | 'aarch64') + ARCH='arm64-v8a' + ;; + 'mips') + ARCH='mips32' + ;; + 'mipsle') + ARCH='mips32le' + ;; + 'mips64') + ARCH='mips64' + lscpu | grep -q "Little Endian" && ARCH='mips64le' + ;; + 'mips64le') + ARCH='mips64le' + ;; + 'ppc64') + ARCH='ppc64' + ;; + 'ppc64le') + ARCH='ppc64le' + ;; + 'riscv64') + ARCH='riscv64' + ;; + 's390x') + ARCH='s390x' + ;; + *) + echo "error: The architecture is not supported." + exit 1 + ;; + esac + else + echo "error: This operating system is not supported." + exit 1 + fi +} + +download_xray() { + if [[ "$RELEASE_TAG" == "latest" ]]; then + DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-$ARCH.zip" + else + DOWNLOAD_LINK="https://github.com/$UPSTREAM_REPO/Xray-core/releases/download/$RELEASE_TAG/Xray-linux-$ARCH.zip" + fi + + echo "Downloading Xray archive: $DOWNLOAD_LINK" + if ! curl -RL -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then + echo 'error: Download failed! Please check your network or try again.' + return 1 + fi +} + +extract_xray() { + if ! unzip -q "$ZIP_FILE" -d "$TMP_DIRECTORY"; then + echo 'error: Xray decompression failed.' + "rm" -rf "$TMP_DIRECTORY" + echo "removed: $TMP_DIRECTORY" + exit 1 + fi + echo "Extracted Xray archive to $TMP_DIRECTORY" +} + +place_xray() { + install -m 755 "${TMP_DIRECTORY}/xray" "/usr/local/bin/xray" + install -d "/usr/local/share/xray/" + install -m 644 "${TMP_DIRECTORY}/geoip.dat" "/usr/local/share/xray/geoip.dat" + install -m 644 "${TMP_DIRECTORY}/geosite.dat" "/usr/local/share/xray/geosite.dat" + echo "Xray files installed" +} + +check_if_running_as_root +identify_the_operating_system_and_architecture + +TMP_DIRECTORY="$(mktemp -d)" +ZIP_FILE="${TMP_DIRECTORY}/Xray-linux-$ARCH.zip" + +download_xray +extract_xray +place_xray + +"rm" -rf "$TMP_DIRECTORY" \ No newline at end of file