-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmobile-install.sh
More file actions
executable file
·311 lines (283 loc) · 10.2 KB
/
mobile-install.sh
File metadata and controls
executable file
·311 lines (283 loc) · 10.2 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
# Sarab Mobile Install Script
# Supports: Termux (Android), iSH (iOS), a-Shell (iOS)
set -e
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m'
# Detect Environment
detect_environment() {
if [ -n "$TERMUX_VERSION" ]; then
ENV_TYPE="termux"
PKG_MANAGER="pkg"
INSTALL_DIR="$HOME/.local/bin"
BINARY_DEST="$INSTALL_DIR/sarab"
elif [ -f "/etc/alpine-release" ] && [ -d "/proc/ish" ]; then
ENV_TYPE="ish"
PKG_MANAGER="apk"
INSTALL_DIR="$HOME/.local/bin"
BINARY_DEST="$INSTALL_DIR/sarab"
elif [ -n "$ASHELL_VERSION" ] || command -v pickFolder &> /dev/null; then
ENV_TYPE="ashell"
PKG_MANAGER="none"
INSTALL_DIR="$HOME/Documents"
BINARY_DEST="$INSTALL_DIR/sarab"
else
# Fallback detection for Alpine (iSH without proc/ish)
if [ -f "/etc/alpine-release" ]; then
ENV_TYPE="ish"
PKG_MANAGER="apk"
INSTALL_DIR="$HOME/.local/bin"
BINARY_DEST="$INSTALL_DIR/sarab"
else
ENV_TYPE="unknown"
PKG_MANAGER="unknown"
INSTALL_DIR="$HOME/.local/bin"
BINARY_DEST="$INSTALL_DIR/sarab"
fi
fi
}
# Detect Architecture
detect_arch() {
ARCH="$(uname -m)"
case "$ARCH" in
aarch64|arm64)
RID="linux-arm64"
;;
armv7*|armv8l)
RID="linux-arm"
;;
x86_64|amd64)
RID="linux-x64"
;;
i*86|x86)
RID="linux-x86"
;;
*)
echo -e "${RED}Unsupported architecture: $ARCH${NC}"
exit 1
;;
esac
}
# Install dependencies
install_deps_termux() {
echo -e "${BLUE}Installing dependencies via pkg...${NC}"
pkg update -y
pkg install -y curl wget git
}
install_deps_ish() {
echo -e "${BLUE}Installing dependencies via apk...${NC}"
apk update
apk add curl wget git bash gcompat libstdc++
}
install_deps_ashell() {
echo -e "${YELLOW}a-Shell has limited package support.${NC}"
echo -e "${YELLOW}Ensure 'curl' command is available.${NC}"
}
install_dependencies() {
case "$ENV_TYPE" in
termux)
install_deps_termux
;;
ish)
install_deps_ish
;;
ashell)
install_deps_ashell
;;
*)
echo -e "${YELLOW}Unknown environment. Skipping dependency install.${NC}"
;;
esac
}
# Download and install Sarab binary
download_release() {
ASSET_NAME="sarab-${RID}.tar.gz"
DOWNLOAD_URL="https://github.com/meedoomostafa/sarab/releases/latest/download/${ASSET_NAME}"
echo -e "${BLUE}Downloading Sarab for ${RID}...${NC}"
echo -e "${BLUE}URL: $DOWNLOAD_URL${NC}"
TEMP_DIR=$(mktemp -d)
if curl -sL -f -o "$TEMP_DIR/$ASSET_NAME" "$DOWNLOAD_URL"; then
echo -e "${GREEN}Download successful.${NC}"
echo -e "${BLUE}Extracting...${NC}"
tar -xzf "$TEMP_DIR/$ASSET_NAME" -C "$TEMP_DIR"
# Find the binary
if [ -f "$TEMP_DIR/sarab" ]; then
SOURCE_BIN="$TEMP_DIR/sarab"
elif [ -f "$TEMP_DIR/Sarab.Cli" ]; then
SOURCE_BIN="$TEMP_DIR/Sarab.Cli"
else
echo -e "${RED}Binary not found in archive.${NC}"
rm -rf "$TEMP_DIR"
return 1
fi
echo -e "${BLUE}Installing to $INSTALL_DIR...${NC}"
mkdir -p "$INSTALL_DIR"
cp "$SOURCE_BIN" "$BINARY_DEST"
chmod +x "$BINARY_DEST"
rm -rf "$TEMP_DIR"
return 0
else
echo -e "${RED}Download failed. Release may not exist for $RID.${NC}"
rm -rf "$TEMP_DIR"
return 1
fi
}
# Setup PATH
setup_path() {
case "$ENV_TYPE" in
termux)
# Termux uses .bashrc or .zshrc
if [ -f "$HOME/.bashrc" ]; then
if ! grep -q "\.local/bin" "$HOME/.bashrc"; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc"
echo -e "${GREEN}✔ Added to .bashrc${NC}"
fi
fi
if [ -f "$HOME/.zshrc" ]; then
if ! grep -q "\.local/bin" "$HOME/.zshrc"; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.zshrc"
echo -e "${GREEN}✔ Added to .zshrc${NC}"
fi
fi
# Also add to current session
export PATH="$HOME/.local/bin:$PATH"
;;
ish)
# iSH uses ash/bash
PROFILE="$HOME/.profile"
if ! grep -q "\.local/bin" "$PROFILE" 2>/dev/null; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$PROFILE"
echo -e "${GREEN}✔ Added to .profile${NC}"
fi
export PATH="$HOME/.local/bin:$PATH"
;;
ashell)
echo -e "${YELLOW}a-Shell: Binary installed to $INSTALL_DIR${NC}"
echo -e "${YELLOW}Run with: ~/Documents/sarab${NC}"
;;
*)
export PATH="$INSTALL_DIR:$PATH"
;;
esac
}
# Initialize Sarab
initialize_sarab() {
echo -e "${BLUE}Initializing Sarab...${NC}"
if "$BINARY_DEST" init 2>/dev/null; then
echo -e "${GREEN}✔ Sarab initialized.${NC}"
else
echo -e "${YELLOW}Note: Run 'sarab init' manually if needed.${NC}"
fi
}
# Print environment-specific notes
print_notes() {
echo ""
echo -e "${GREEN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN} Sarab installed successfully!${NC}"
echo -e "${GREEN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
case "$ENV_TYPE" in
termux)
echo -e "${BLUE}Termux Notes:${NC}"
echo -e " • Restart Termux or run: source ~/.bashrc"
echo -e " • To expose port 8080: sarab expose 8080"
echo -e " • For SSH tunneling: sarab expose 22 --scheme ssh"
echo ""
echo -e "${YELLOW}Tip: Install openssh to expose your phone's terminal:${NC}"
echo -e " pkg install openssh"
echo -e " sshd # Starts SSH server on port 8022"
echo -e " sarab expose 8022 --scheme ssh"
;;
ish)
echo -e "${BLUE}iSH Notes:${NC}"
echo -e " • iSH emulates x86, performance may be limited"
echo -e " • Restart iSH or run: source ~/.profile"
echo -e " • To expose port 8080: sarab expose 8080"
echo ""
echo -e "${YELLOW}Limitations:${NC}"
echo -e " • iSH runs in user-space emulation (slow)"
echo -e " • Consider using Sarab on a desktop for better performance"
;;
ashell)
echo -e "${BLUE}a-Shell Notes:${NC}"
echo -e " • Run Sarab with: ~/Documents/sarab"
echo -e " • a-Shell has limited networking capabilities"
echo ""
echo -e "${YELLOW}Recommendation:${NC}"
echo -e " • a-Shell is best for the 'connect' command (client-side)"
echo -e " • Example: ~/Documents/sarab connect user@tunnel.trycloudflare.com"
;;
*)
echo -e " • Run 'sarab --version' to verify installation"
echo -e " • Run 'sarab --help' for usage"
;;
esac
echo ""
}
# Alternative: Client-only mode for limited environments
print_client_only_instructions() {
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${YELLOW} Alternative: SSH Client Without Sarab${NC}"
echo -e "${YELLOW}═══════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e "If Sarab doesn't work on your device, you can still connect to"
echo -e "exposed SSH servers using cloudflared directly:"
echo ""
echo -e "${BLUE}1. Install cloudflared:${NC}"
case "$ENV_TYPE" in
termux)
echo -e " pkg install cloudflared"
;;
ish)
echo -e " apk add cloudflared"
;;
*)
echo -e " # Download from: https://github.com/cloudflare/cloudflared/releases"
;;
esac
echo ""
echo -e "${BLUE}2. Connect to SSH tunnel:${NC}"
echo -e " ssh -o ProxyCommand='cloudflared access tcp --hostname %h' user@tunnel.trycloudflare.com"
echo ""
}
# ------------------------ Main Script ------------------------
echo ""
echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} Sarab Mobile Installer${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
echo ""
# Detect environment and architecture
detect_environment
detect_arch
echo -e "${GREEN}Environment:${NC} $ENV_TYPE"
echo -e "${GREEN}Architecture:${NC} $ARCH → $RID"
echo ""
# Confirm with user
if [ "$1" != "-y" ] && [ "$1" != "--yes" ]; then
read -p "Continue with installation? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo -e "${YELLOW}Installation cancelled.${NC}"
exit 0
fi
fi
# Install dependencies
install_dependencies
# Download and install
if download_release; then
setup_path
initialize_sarab
print_notes
else
echo ""
echo -e "${RED}Failed to download pre-built binary.${NC}"
echo -e "${YELLOW}This likely means no release exists for $RID yet.${NC}"
echo ""
print_client_only_instructions
exit 1
fi