-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·193 lines (173 loc) · 7.79 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·193 lines (173 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env bash
# ═══════════════════════════════════════════════════════════════
# XrayMOD — One-Click Open Source Installer
#
# Linux / macOS / Git Bash / WSL:
# bash <(curl -fsSL https://raw.githubusercontent.com/askarniroomand/XRayMOD/main/install.sh)
#
# Windows PowerShell:
# irm https://raw.githubusercontent.com/askarniroomand/XRayMOD/main/install.ps1 | iex
#
# Windows CMD:
# powershell -NoProfile -ExecutionPolicy Bypass -Command "iex (iwr -UseBasicParsing 'https://raw.githubusercontent.com/askarniroomand/XRayMOD/main/install.ps1').Content"
#
# Flow for end users:
# 1) Cloudflare API Token
# 2) Account (auto if only one)
# 3) Panel username
# 4) Panel password
# 5) Automatic deploy + print login / sub links
#
# Support: https://t.me/MRROBOT_DT
# ═══════════════════════════════════════════════════════════════
set -euo pipefail
# Windows Git Bash / MSYS: ensure common Node/Git paths
if [[ "${OSTYPE:-}" == msys* || "${OSTYPE:-}" == cygwin* || -n "${MSYSTEM:-}" ]]; then
export PATH="/c/Program Files/nodejs:/c/Program Files/Git/cmd:${PATH}"
fi
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
INSTALLER_DIR="${HOME}/.xraymod"
REPO_URL="${XRAYMOD_REPO:-https://github.com/askarniroomand/XRayMOD.git}"
BRANCH="${XRAYMOD_BRANCH:-main}"
clear 2>/dev/null || true
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║${BOLD} XrayMOD · نصب کاملاً خودکار ${NC}${GREEN}║${NC}"
echo -e "${GREEN}║${DIM} فقط توکن · یوزر · رمز → پنل آماده ${NC}${GREEN}║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════╝${NC}"
echo ""
echo -e " ${CYAN}پشتیبانی:${NC} https://t.me/MRROBOT_DT"
echo ""
die() { echo -e "${RED}✗${NC} $*" >&2; exit 1; }
step() { echo -e "${YELLOW}→${NC} $*"; }
ok() { echo -e "${GREEN}✓${NC} $*"; }
# ── prerequisites (auto where possible) ─────────────────────
command -v curl >/dev/null || die "curl لازم است"
ensure_node() {
if command -v node >/dev/null; then
local major
major="$(node -v | sed 's/v//' | cut -d. -f1)"
if [ "${major}" -ge 18 ] 2>/dev/null; then
ok "Node $(node -v)"
return 0
fi
fi
step "نصب خودکار Node.js..."
if command -v brew >/dev/null; then
brew install node@20 >/dev/null 2>&1 || brew install node >/dev/null 2>&1 || true
elif command -v apt-get >/dev/null && [ "$(id -u)" -eq 0 ]; then
apt-get update -qq && apt-get install -y -qq nodejs npm >/dev/null 2>&1 || true
elif command -v dnf >/dev/null && [ "$(id -u)" -eq 0 ]; then
dnf install -y nodejs npm >/dev/null 2>&1 || true
elif command -v pacman >/dev/null && [ "$(id -u)" -eq 0 ]; then
pacman -Sy --noconfirm nodejs npm >/dev/null 2>&1 || true
fi
# nvm fallback
if ! command -v node >/dev/null; then
export NVM_DIR="${HOME}/.nvm"
if [ ! -s "${NVM_DIR}/nvm.sh" ]; then
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash >/dev/null 2>&1 || true
fi
# shellcheck disable=SC1091
[ -s "${NVM_DIR}/nvm.sh" ] && . "${NVM_DIR}/nvm.sh"
command -v nvm >/dev/null 2>&1 && nvm install --lts >/dev/null 2>&1 || true
fi
command -v node >/dev/null || die "Node.js 18+ لازم است — از https://nodejs.org نصب کن و دوباره همین دستور را بزن"
local major
major="$(node -v | sed 's/v//' | cut -d. -f1)"
[ "${major}" -ge 18 ] 2>/dev/null || die "Node.js 18+ لازم است (الان: $(node -v))"
ok "Node $(node -v)"
}
ensure_node
command -v npm >/dev/null || die "npm پیدا نشد"
HAS_GIT=0
if command -v git >/dev/null; then
HAS_GIT=1
ok "git پیدا شد"
else
echo -e " ${DIM}git نیست — از دانلود ZIP استفاده میشود${NC}"
fi
# Python runner
export PATH="${HOME}/.local/bin:${HOME}/.cargo/bin:${PATH}"
if ! command -v uv >/dev/null; then
step "نصب uv (ابزار پایتون)..."
curl -LsSf https://astral.sh/uv/install.sh | sh >/dev/null 2>&1 || true
export PATH="${HOME}/.local/bin:${HOME}/.cargo/bin:${PATH}"
fi
github_zip_url() {
# https://github.com/owner/repo.git → archive zip
local url="$1" branch="$2"
if [[ "$url" =~ github\.com[:/]([^/]+)/([^/.]+) ]]; then
local owner="${BASH_REMATCH[1]}"
local repo="${BASH_REMATCH[2]%.git}"
echo "https://github.com/${owner}/${repo}/archive/refs/heads/${branch}.zip"
return 0
fi
return 1
}
fetch_zip() {
local zip_url
zip_url="$(github_zip_url "${REPO_URL}" "${BRANCH}")" \
|| die "بدون git فقط ریپوهای GitHub پشتیبانی میشوند — git را نصب کن"
step "دانلود سورس (بدون git)..."
local zip_path="${INSTALLER_DIR}/xraymod-src.zip"
local extract_dir="${INSTALLER_DIR}/_extract"
rm -rf "${extract_dir}" "${INSTALLER_DIR}/XRayMOD"
mkdir -p "${extract_dir}"
curl -fsSL -o "${zip_path}" "${zip_url}" \
|| die "دانلود ZIP ناموفق — اینترنت / فیلتر GitHub را چک کن"
if command -v unzip >/dev/null; then
unzip -q "${zip_path}" -d "${extract_dir}"
elif command -v tar >/dev/null; then
# bsdtar / GNU tar with libarchive can open zip
tar -xf "${zip_path}" -C "${extract_dir}" 2>/dev/null \
|| die "unzip لازم است (apt install unzip / brew install unzip)"
else
die "unzip لازم است"
fi
rm -f "${zip_path}"
local inner
inner="$(find "${extract_dir}" -mindepth 1 -maxdepth 1 -type d | head -1)"
[ -n "${inner}" ] || die "استخراج ZIP خالی بود"
mv "${inner}" "${INSTALLER_DIR}/XRayMOD"
rm -rf "${extract_dir}"
}
# ── fetch source ────────────────────────────────────────────
mkdir -p "${INSTALLER_DIR}"
if [ "${HAS_GIT}" -eq 1 ] && [ -d "${INSTALLER_DIR}/XRayMOD/.git" ]; then
step "بهروزرسانی مخزن..."
git -C "${INSTALLER_DIR}/XRayMOD" remote set-url origin "${REPO_URL}" 2>/dev/null || true
git -C "${INSTALLER_DIR}/XRayMOD" fetch --depth 1 origin "${BRANCH}" --quiet 2>/dev/null || true
git -C "${INSTALLER_DIR}/XRayMOD" checkout -f "${BRANCH}" --quiet 2>/dev/null || true
git -C "${INSTALLER_DIR}/XRayMOD" reset --hard "origin/${BRANCH}" --quiet 2>/dev/null || \
git -C "${INSTALLER_DIR}/XRayMOD" pull --ff-only --quiet 2>/dev/null || true
elif [ "${HAS_GIT}" -eq 1 ]; then
step "دانلود XrayMOD..."
rm -rf "${INSTALLER_DIR}/XRayMOD"
if ! git clone --depth 1 -b "${BRANCH}" "${REPO_URL}" "${INSTALLER_DIR}/XRayMOD" 2>/dev/null; then
echo -e " ${DIM}git clone ناموفق — سوییچ به ZIP...${NC}"
fetch_zip
fi
else
fetch_zip
fi
cd "${INSTALLER_DIR}/XRayMOD"
[ -f installer/cli_deploy.py ] || die "installer/cli_deploy.py در مخزن نیست — main را push کردی؟"
ok "سورس آماده است"
echo ""
# ── run interactive deploy ──────────────────────────────────
if command -v uv >/dev/null; then
exec uv run --with httpx python installer/cli_deploy.py "$@"
fi
# fallback: system python
if command -v python3 >/dev/null; then
python3 -m pip install --user -q httpx 2>/dev/null || true
exec python3 installer/cli_deploy.py "$@"
fi
die "python3 یا uv لازم است"