|
| 1 | +#!/usr/bin/env bash |
| 2 | +# DroidTether — One-line installer for Apple Silicon macOS |
| 3 | +# Usage: curl -sL https://raw.githubusercontent.com/HelloPrincePal/DroidTether/main/install.sh | bash |
| 4 | + |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +# 1. Platform Check |
| 8 | +ARCH="$(uname -m)" |
| 9 | +OS="$(uname -s)" |
| 10 | + |
| 11 | +if [[ "$OS" != "Darwin" || "$ARCH" != "arm64" ]]; then |
| 12 | + echo "error: DroidTether currently only supports Apple Silicon macOS (arm64)." >&2 |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +echo "🚀 Installing DroidTether for Apple Silicon..." |
| 17 | + |
| 18 | +# 2. Dependency Check (libusb) |
| 19 | +if ! command -v brew >/dev/null 2>&1; then |
| 20 | + echo "error: Homebrew not found. Please install Homebrew first: https://brew.sh" >&2 |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +if ! brew list libusb >/dev/null 2>&1; then |
| 25 | + echo "→ Installing dependency: libusb" |
| 26 | + brew install libusb |
| 27 | +fi |
| 28 | + |
| 29 | +# 3. Fetch Latest Release from GitHub API |
| 30 | +REPO="HelloPrincePal/DroidTether" |
| 31 | +LATEST_RELEASE=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') |
| 32 | + |
| 33 | +if [[ -z "$LATEST_RELEASE" ]]; then |
| 34 | + echo "error: could not find latest release for $REPO" >&2 |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +echo "→ Downloading DroidTether $LATEST_RELEASE" |
| 39 | +URL="https://github.com/HelloPrincePal/DroidTether/releases/download/$LATEST_RELEASE/droidtether-darwin-arm64.tar.gz" |
| 40 | +TMP_DIR=$(mktemp -d) |
| 41 | +curl -sL "$URL" -o "$TMP_DIR/droidtether.tar.gz" |
| 42 | + |
| 43 | +# 4. Extract and Install Binary |
| 44 | +tar -xzf "$TMP_DIR/droidtether.tar.gz" -C "$TMP_DIR" |
| 45 | + |
| 46 | +if [[ ! -f "$TMP_DIR/droidtether" ]]; then |
| 47 | + echo "error: Could not find droidtether binary in $LATEST_RELEASE archive." >&2 |
| 48 | + ls -R "$TMP_DIR" |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +echo "→ Installing binary to /usr/local/bin (requires password)" |
| 53 | +sudo mkdir -p /usr/local/bin |
| 54 | +sudo mv "$TMP_DIR/droidtether" /usr/local/bin/droidtether |
| 55 | +sudo chmod +x /usr/local/bin/droidtether |
| 56 | + |
| 57 | +# 5. Config Setup |
| 58 | +CONFIG_DIR="/etc/droidtether" |
| 59 | +if [[ ! -d "$CONFIG_DIR" ]]; then |
| 60 | + echo "→ Creating config directory at $CONFIG_DIR" |
| 61 | + sudo mkdir -p "$CONFIG_DIR" |
| 62 | +fi |
| 63 | + |
| 64 | +# Download default config if not exists |
| 65 | +if [[ ! -f "$CONFIG_DIR/droidtether.toml" ]]; then |
| 66 | + echo "→ Installing default configuration" |
| 67 | + CONFIG_URL="https://raw.githubusercontent.com/HelloPrincePal/DroidTether/main/config/default.toml" |
| 68 | + sudo curl -sL "$CONFIG_URL" -o "$CONFIG_DIR/droidtether.toml" |
| 69 | +fi |
| 70 | + |
| 71 | +# 6. Launchd Service Setup |
| 72 | +PLIST_NAME="com.princePal.droidtether.plist" |
| 73 | +PLIST_DEST="/Library/LaunchDaemons/$PLIST_NAME" |
| 74 | +PLIST_URL="https://raw.githubusercontent.com/HelloPrincePal/DroidTether/main/launchd/$PLIST_NAME" |
| 75 | + |
| 76 | +echo "→ Installing background service (launchd)" |
| 77 | +sudo curl -sL "$PLIST_URL" -o "$PLIST_DEST" |
| 78 | +sudo chown root:wheel "$PLIST_DEST" |
| 79 | +sudo chmod 644 "$PLIST_DEST" |
| 80 | + |
| 81 | +# 7. Start the Service |
| 82 | +echo "→ Starting DroidTether service" |
| 83 | +sudo launchctl bootout system "$PLIST_DEST" 2>/dev/null || true |
| 84 | +sudo launchctl bootstrap system "$PLIST_DEST" |
| 85 | + |
| 86 | +# Cleanup |
| 87 | +rm -rf "$TMP_DIR" |
| 88 | + |
| 89 | +echo "" |
| 90 | +echo "✨ DroidTether successfully installed!" |
| 91 | +echo "📡 Plug in your Android phone and enable USB Tethering to begin." |
| 92 | +echo "📜 Logs: tail -f /var/log/droidtether.log" |
| 93 | +echo "❌ To uninstall: curl -sL https://raw.githubusercontent.com/HelloPrincePal/DroidTether/main/uninstall.sh | bash" |
0 commit comments