Add automatic installer
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Usage:
|
||||
# curl -fsSL https://ssh.surf/bridgeswarm/install.sh -o install.sh && bash install.sh
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo ""
|
||||
echo "╔══════════════════════════════════════════════════════════════════╗"
|
||||
echo "║ 🌉 BridgeSwarm Installer ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
|
||||
cat << 'EOF'
|
||||
This installer will set up BridgeSwarm on your computer:
|
||||
|
||||
• Native Messaging Host → Enables browser ↔ network communication
|
||||
• Browser Extension → Packaged to ~/Downloads for manual install
|
||||
• Fixed Extension ID → No random IDs, stable across updates
|
||||
|
||||
What's installed where:
|
||||
• Software: ~/.bridgeswarm/
|
||||
• Extension: ~/Downloads/BridgeSwarm-*.zip (Chrome) / *.xpi (Firefox)
|
||||
• Browser manifests: ~/.config/.../NativeMessagingHosts/ (Linux)
|
||||
~/Library/Application Support/.../NativeMessagingHosts/ (macOS)
|
||||
%LOCALAPPDATA%/bridge-swarm/ (Windows)
|
||||
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
|
||||
if [ -t 1 ]; then
|
||||
echo -n "Continue with installation? [y/N]: "
|
||||
read -r answer
|
||||
if [[ "${answer,,}" != "y" && "${answer,,}" != "yes" ]]; then
|
||||
echo "Installation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
|
||||
# 1. Install Node.js if missing
|
||||
if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then
|
||||
echo "📦 Installing Node.js..."
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
command -v brew >/dev/null 2>&1 || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
brew install node
|
||||
elif grep -qiE 'debian|ubuntu' /etc/os-release 2>/dev/null; then
|
||||
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
|
||||
sudo apt-get update && sudo apt-get install -y nodejs
|
||||
elif grep -qi fedora /etc/os-release 2>/dev/null || command -v dnf >/dev/null; then
|
||||
sudo dnf install -y nodejs
|
||||
else
|
||||
echo "⚠️ Please install Node.js manually from https://nodejs.org"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2. git
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "📦 Installing git..."
|
||||
[[ "$OSTYPE" == "darwin"* ]] && brew install git || sudo apt install -y git || sudo dnf install -y git || true
|
||||
fi
|
||||
|
||||
# 3. Clone / update to persistent location
|
||||
INSTALL_DIR="$HOME/.bridgeswarm"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
cd "$INSTALL_DIR" || exit 1
|
||||
|
||||
if [ -d ".git" ]; then
|
||||
echo "📥 Updating existing installation..."
|
||||
git pull --ff-only origin main || { cd ..; rm -rf "$INSTALL_DIR"; git clone https://git.ssh.surf/snxraven/BridgeSwarm.git "$INSTALL_DIR"; cd "$INSTALL_DIR"; }
|
||||
else
|
||||
echo "📥 Cloning BridgeSwarm..."
|
||||
git clone https://git.ssh.surf/snxraven/BridgeSwarm.git .
|
||||
fi
|
||||
|
||||
# 4. Build
|
||||
echo "🔨 Building bundles and codegen..."
|
||||
npm ci --no-audit --prefer-offline --no-fund
|
||||
npm run build
|
||||
|
||||
# 5. Package the extension
|
||||
echo "📦 Packaging extension..."
|
||||
npm run pack
|
||||
|
||||
# 6. Copy to ~/Downloads
|
||||
DOWNLOADS_DIR="$HOME/Downloads"
|
||||
mkdir -p "$DOWNLOADS_DIR"
|
||||
ZIP_FILE=$(ls releases/BridgeSwarm-*.zip 2>/dev/null | head -1)
|
||||
XPI_FILE=$(ls releases/BridgeSwarm-*.xpi 2>/dev/null | head -1)
|
||||
|
||||
if [ -n "$ZIP_FILE" ]; then
|
||||
cp "$ZIP_FILE" "$DOWNLOADS_DIR/"
|
||||
echo "✅ Extension saved to ~/Downloads/$(basename "$ZIP_FILE")"
|
||||
fi
|
||||
if [ -n "$XPI_FILE" ]; then
|
||||
cp "$XPI_FILE" "$DOWNLOADS_DIR/"
|
||||
echo "✅ Firefox extension saved to ~/Downloads/$(basename "$XPI_FILE")"
|
||||
fi
|
||||
|
||||
# 7. Install native host + manifest
|
||||
echo "🔧 Installing native messaging host..."
|
||||
|
||||
HOST_WRAPPER="$INSTALL_DIR/native-host/bridge-swarm-host"
|
||||
chmod +x "$HOST_WRAPPER" 2>/dev/null || true
|
||||
|
||||
MANIFEST_NAME="com.bridgeswarm"
|
||||
MANIFEST_TEMPLATE="$INSTALL_DIR/com.bridgeswarm.json"
|
||||
MANIFEST_CONTENT=$(sed "s|ABSOLUTE_PATH_TO_NATIVE_HOST|$HOST_WRAPPER|g" "$MANIFEST_TEMPLATE")
|
||||
|
||||
CHROME_DIRS=(
|
||||
"$HOME/.config/google-chrome/NativeMessagingHosts"
|
||||
"$HOME/.config/chromium/NativeMessagingHosts"
|
||||
"$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts"
|
||||
"$HOME/Library/Application Support/Chromium/NativeMessagingHosts"
|
||||
)
|
||||
FIREFOX_DIR="$HOME/.mozilla/native-messaging-hosts"
|
||||
|
||||
for dir in "${CHROME_DIRS[@]}" "$FIREFOX_DIR"; do
|
||||
mkdir -p "$dir" 2>/dev/null
|
||||
echo "$MANIFEST_CONTENT" > "$dir/$MANIFEST_NAME.json"
|
||||
echo " ✅ Installed: $dir/$MANIFEST_NAME.json"
|
||||
done
|
||||
|
||||
# 8. Try open browser
|
||||
echo ""
|
||||
echo "🌐 Opening browser extension page..."
|
||||
|
||||
open_page() {
|
||||
local url="$1" app="$2"
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
open -a "$app" "$url" 2>/dev/null && return 0
|
||||
fi
|
||||
command -v xdg-open >/dev/null 2>&1 && xdg-open "$url" 2>/dev/null && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
open_page "chrome://extensions" "Google Chrome" || \
|
||||
open_page "chrome://extensions" "Chromium" || \
|
||||
open_page "chrome://extensions" "Microsoft Edge" || {
|
||||
echo "⚠️ Could not auto-open browser. Please open manually:"
|
||||
echo " Chrome/Edge: chrome://extensions/"
|
||||
echo " Firefox: about:addons"
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo " ✅ Installation Complete!"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
|
||||
cat << INSTALL_EOF
|
||||
|
||||
📋 NEXT STEPS - Install the Extension
|
||||
|
||||
Chrome / Edge:
|
||||
1. In the browser that opened, enable "Developer mode" (top right)
|
||||
2. Click "Unpack extension"
|
||||
3. Extract ~/Downloads/BridgeSwarm-1.0.0.zip to a folder
|
||||
4. Click "Load unpacked" and select the extracted folder
|
||||
5. Your extension ID should be: fmcenppcipeikpnpopolicnllljclmmi
|
||||
|
||||
Firefox:
|
||||
1. Go to about:addons
|
||||
2. Click the gear icon → "Install Add-on From File"
|
||||
3. Select ~/Downloads/BridgeSwarm-1.0.0.xpi
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
🧪 Test it:
|
||||
• Open: $INSTALL_DIR/examples/chat/index.html
|
||||
• In browser console: BridgeSwarm → should show the constructor
|
||||
|
||||
📁 Files:
|
||||
• Extension: ~/Downloads/BridgeSwarm-1.0.0.zip
|
||||
• Software: ~/.bridgeswarm/
|
||||
|
||||
🔄 To update later: run the same install command again
|
||||
|
||||
INSTALL_EOF
|
||||
|
||||
echo ""
|
||||
echo "📍 Extension file path copied to clipboard!"
|
||||
echo "$DOWNLOADS_DIR/BridgeSwarm-1.0.0.zip" | pbcopy 2>/dev/null || \
|
||||
echo "$DOWNLOADS_DIR/BridgeSwarm-1.0.0.zip" | xclip -sel clip 2>/dev/null || \
|
||||
echo "$DOWNLOADS_DIR/BridgeSwarm-1.0.0.zip" | xsel -ib 2>/dev/null || true
|
||||
Reference in New Issue
Block a user