76 lines
2.4 KiB
Bash
76 lines
2.4 KiB
Bash
#!/data/data/com.termux/files/usr/bin/bash
|
|
# install.sh - Install mdns-termux scripts to ~/.local/bin
|
|
# Usage: bash install.sh [--dry-run]
|
|
set -euo pipefail
|
|
|
|
DRY_RUN=0
|
|
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=1
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
BIN_DIR="$HOME/.local/bin"
|
|
|
|
run() {
|
|
if [[ $DRY_RUN -eq 1 ]]; then
|
|
echo "[dry-run] $*"
|
|
else
|
|
eval "$@"
|
|
fi
|
|
}
|
|
|
|
step() { echo ""; echo ">>> Step $1: $2"; }
|
|
|
|
# 1. Verify Termux
|
|
step 1 "Verifying Termux environment..."
|
|
if [[ -z "${PREFIX:-}" || "$PREFIX" != *"com.termux"* ]]; then
|
|
echo "ERROR: This installer targets Termux. \$PREFIX not set as expected." >&2
|
|
exit 1
|
|
fi
|
|
echo " Termux detected: $PREFIX"
|
|
|
|
# 2. Base packages
|
|
step 2 "Installing required packages (pkg + pip)..."
|
|
run "pkg install -y python proot"
|
|
run "pip install --upgrade zeroconf"
|
|
|
|
# 3. Symlink CLI scripts (bin/) and library (lib/) — symlinks keep git-pull updates live
|
|
step 3 "Linking scripts into $BIN_DIR..."
|
|
run "mkdir -p '$BIN_DIR'"
|
|
for script in mdns mdns-resolve mdns-publish.py ssh-mdns-proxy ssh-fallback resolve; do
|
|
run "ln -sf '$SCRIPT_DIR/bin/$script' '$BIN_DIR/$script'"
|
|
done
|
|
|
|
# 4. Sample services config
|
|
step 4 "Sample services config for `mdns publish`..."
|
|
CFG_DIR="$HOME/.config/mdns"
|
|
run "mkdir -p '$CFG_DIR'"
|
|
if [[ ! -f "$CFG_DIR/services.json" ]]; then
|
|
run "cp '$SCRIPT_DIR/config/services.example.json' '$CFG_DIR/services.json'"
|
|
echo " Wrote $CFG_DIR/services.json (edit before running mdns publish)."
|
|
else
|
|
echo " $CFG_DIR/services.json already exists, keeping it."
|
|
fi
|
|
|
|
# 5. Reminders
|
|
step 5 "Manual steps remaining:"
|
|
cat <<EOF
|
|
|
|
a) Append aliases to ~/.bashrc:
|
|
cat $SCRIPT_DIR/config/bashrc.snippet >> ~/.bashrc
|
|
Then edit TAILSCALE_DOMAIN inside your ~/.bashrc.
|
|
|
|
b) (Optional) Merge SSH config for .local + short-name resolution:
|
|
cat $SCRIPT_DIR/config/ssh_config.example >> ~/.ssh/config
|
|
Adjust User and hostnames.
|
|
|
|
c) Try it:
|
|
mdns browse --list-types # discover service types on the LAN
|
|
mdns browse --type _ssh._tcp.local. # list SSH hosts
|
|
mdns resolve <host> # host -> IP (v4 by default)
|
|
mdns resolve <host> --family v6 # IPv6
|
|
mdns reverse <ip> # IP -> hostname
|
|
mdns publish # advertise this device + services
|
|
resolve <host> # bash wrapper (any command)
|
|
|
|
EOF
|
|
echo "Done."
|