-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtermux.txt
More file actions
81 lines (67 loc) · 2.38 KB
/
Copy pathtermux.txt
File metadata and controls
81 lines (67 loc) · 2.38 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
#!/data/data/com.termux/files/usr/bin/bash
# Copied from: https://github.com/iiab/iiab-android/blob/main/termux.txt
set -euo pipefail
# iiab Termux chained bootstrap launcher
# Intended usage:
# curl iiab.io/termux.txt | bash
# curl iiab.io/termux.txt | bash -s -- --help
# curl iiab.io/termux.txt | bash -s -- --all --debug
log() { printf "[iiab] %s\n" "$*"; }
warn() { printf "[iiab] WARNING: %s\n" "$*" >&2; }
die() { printf "[iiab] ERROR: %s\n" "$*" >&2; exit 1; }
need() { command -v "$1" >/dev/null 2>&1; }
# ---- hard requirement: curl, if not exit ----
need curl || die "Missing 'curl'. Please run first: pkg install -y curl"
CURL=(curl -fsSL --retry 5 --retry-connrefused --retry-delay 2)
PREFIX="${PREFIX:-/data/data/com.termux/files/usr}"
DEST="$PREFIX/bin/iiab-termux"
STATE_DIR="${HOME}/.iiab-android"
BACKUP_DIR="${STATE_DIR}/termux"
BUNDLE_PRIMARY="https://raw.githubusercontent.com/iiab/iiab-android/main/iiab-termux"
mkdir -p "$BACKUP_DIR"
# Migrate pre-existing backups that were left in $PREFIX (old behavior).
shopt -s nullglob
for f in "${PREFIX}/bin/iiab-termux.old."*; do
mv -f -- "$f" "$BACKUP_DIR/" 2>/dev/null || true
done
shopt -u nullglob
# Temporary file
mkdir -p "${DEST%/*}"
tmp="${DEST}.tmp.$$"
cleanup() { rm -f "$tmp" >/dev/null 2>&1 || true; }
trap cleanup EXIT INT TERM
log "Downloading iiab-termux bundle..."
"${CURL[@]}" "$BUNDLE_PRIMARY" -o "$tmp" || die "Unable to download bundle from URL."
# Sanity check: first line must be a shebang mentioning bash
first_line=""
IFS= read -r first_line < "$tmp" || true
if [[ "$first_line" != \#!*bash* ]]; then
warn "Downloaded file first line: ${first_line:-<empty>}"
die "Downloaded content doesn't look like a bash script (wrong URL or HTML error page)."
fi
# Backup existing installed command
if [[ -f "$DEST" ]]; then
ts="$(date +%Y%m%d-%H%M%S)"
mv -f "$DEST" "${BACKUP_DIR}/iiab-termux.old.${ts}" 2>/dev/null || true
fi
chmod 0755 "$tmp"
mv -f -- "$tmp" "$DEST"
log "Installed: $DEST"
# Run installed command:
# - If launcher received args -> pass through
# - Else -> default to --all
if [[ $# -gt 0 ]]; then
# Normalize arguments: if they don't have '--', add them
FINAL_ARGS=()
for arg in "$@"; do
if [[ "$arg" != -* ]]; then
FINAL_ARGS+=("--$arg")
else
FINAL_ARGS+=("$arg")
fi
done
log "Running with: ${FINAL_ARGS[*]}"
exec "$DEST" "${FINAL_ARGS[@]}"
else
exec "$DEST" --all
fi