[termux-adb] add repo selection and other functions from 0_termux-setup.sh
This commit is contained in:
parent
2414e2db9c
commit
ae14a0d3cd
|
|
@ -1,6 +1,20 @@
|
|||
#!/data/data/com.termux/files/usr/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
RED="\033[31m"
|
||||
YEL="\033[33m"
|
||||
GRN="\033[32m"
|
||||
BLU="\033[34m"
|
||||
RST="\033[0m"
|
||||
BOLD="\033[1m"
|
||||
|
||||
log() { printf "${BLU}[iiab]${RST} %s\n" "$*"; }
|
||||
ok() { printf "${GRN}[iiab]${RST} %s\n" "$*"; }
|
||||
warn() { printf "${YEL}[iiab] WARNING:${RST} %s\n" "$*" >&2; }
|
||||
warn_red() { printf "${RED}${BOLD}[iiab] WARNING:${RST} %s\n" "$*" >&2; }
|
||||
|
||||
have() { command -v "$1" >/dev/null 2>&1; }
|
||||
|
||||
HOST="127.0.0.1"
|
||||
CONNECT_PORT=""
|
||||
TIMEOUT_SECS=180
|
||||
|
|
@ -15,13 +29,61 @@ need() { command -v "$1" >/dev/null 2>&1; }
|
|||
die(){ echo "[!] $*" >&2; exit 1; }
|
||||
dbg(){ [[ "$DEBUG" == "1" ]] && echo "[DBG] $*" >&2 || true; }
|
||||
|
||||
# Avoid dpkg conffile prompts (Termux layer)
|
||||
TERMUX_APT_OPTS=(
|
||||
"-y"
|
||||
"-o" "Dpkg::Options::=--force-confdef"
|
||||
"-o" "Dpkg::Options::=--force-confold"
|
||||
)
|
||||
termux_apt() { apt-get "${TERMUX_APT_OPTS[@]}" "$@"; }
|
||||
|
||||
step_termux_repo_select_once() {
|
||||
local stamp="$STATE_DIR/stamp.termux_repo_selected"
|
||||
if [[ -f "$stamp" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! have termux-change-repo; then
|
||||
warn "termux-change-repo not found; skipping mirror selection."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# When running via "curl | bash", stdin is not a TTY.
|
||||
# Try to prompt via /dev/tty if available. If not, skip WITHOUT stamping.
|
||||
if [[ -r /dev/tty ]]; then
|
||||
printf "\n${YEL}[iiab] One-time setup:${RST} Select a nearby Termux repository mirror for faster downloads.\n" >&2
|
||||
|
||||
local ans="Y"
|
||||
if ! read -r -p "[iiab] Launch termux-change-repo now? [Y/n]: " ans < /dev/tty; then
|
||||
warn "No interactive TTY available; skipping mirror selection (run the script directly to be prompted)."
|
||||
return 0
|
||||
fi
|
||||
|
||||
ans="${ans:-Y}"
|
||||
if [[ "$ans" =~ ^[Yy]$ ]]; then
|
||||
termux-change-repo || true
|
||||
ok "Mirror selection completed (or skipped inside the UI)."
|
||||
else
|
||||
warn "Mirror selection skipped by user."
|
||||
fi
|
||||
|
||||
date > "$stamp"
|
||||
return 0
|
||||
fi
|
||||
|
||||
warn "No /dev/tty available; skipping mirror selection (run the script directly to be prompted)."
|
||||
return 0
|
||||
}
|
||||
|
||||
install_if_missing() {
|
||||
local pkgs=()
|
||||
need adb || pkgs+=("android-tools")
|
||||
need termux-notification || pkgs+=("termux-api")
|
||||
termux_apt update || true
|
||||
termux_apt upgrade || true
|
||||
if ((${#pkgs[@]})); then
|
||||
echo "[*] Installing: ${pkgs[*]}"
|
||||
apt-get install -y "${pkgs[@]}" >/dev/null
|
||||
termux_apt install "${pkgs[@]}" >/dev/null
|
||||
fi
|
||||
need adb || die "Missing adb. Install: pkg install android-tools"
|
||||
need termux-notification || die "Missing termux-notification. Install: pkg install termux-api (and install Termux:API app)"
|
||||
|
|
|
|||
Loading…
Reference in New Issue