Files
gyandoot-v2/install.sh
Tara Menon b2650a569c feat: system service management (gyandoot service install|remove|status)
- Create systemd + launchd service templates in resources/
- Add gyandoot-core/src/service.rs module with full lifecycle
  - systemd: user service, daemon-reload, enable, start, stop, disable
  - launchd: macOS plist, load/unload, start/stop (launchctl)
- Add 'gyandoot service install|remove|status' CLI subcommand
- Update setup wizard: prompts 'Install system service? [y/N]'
- Update install.sh: prompts user for service install after binary
- Browser auto-starts at runtime (browser_manager), no separate service needed
- Camoufox installed via npm, auto-started by GyanDoot agent loop
2026-06-11 23:23:49 +05:30

193 lines
6.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# GyanDoot v2.0 — Cross-platform installer
# Detects OS, architecture, and installs the gyandoot binary + camofox-browser.
# For full documentation, visit: https://git.gyannetra.in/gnpl_admin/gyandoot-v2
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${BLUE}[INFO]${NC} $*"; }
ok() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
err() { echo -e "${RED}[ERR]${NC} $*" >&2; exit 1; }
detect_architecture() {
local arch
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) echo "x86_64" ;;
aarch64|arm64) echo "aarch64" ;;
*) err "Unsupported architecture: $arch" ;;
esac
}
detect_os() {
local os
os="$(uname -s)"
case "$os" in
Linux) echo "linux" ;;
Darwin) echo "darwin" ;;
CYGWIN*|MINGW*|MSYS*) echo "windows" ;;
*) err "Unsupported OS: $os" ;;
esac
}
install_rust_if_needed() {
if ! command -v cargo &>/dev/null; then
info "Rust toolchain not found. Installing..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
ok "Rust installed"
else
ok "Rust already installed ($(cargo --version))"
fi
}
install_node_if_needed() {
if ! command -v node &>/dev/null; then
info "Node.js not found. Installing via nvm..."
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
[ -s "$HOME/.nvm/nvm.sh" ] && \. "$HOME/.nvm/nvm.sh"
nvm install 22
ok "Node.js installed ($(node --version))"
else
ok "Node.js already installed ($(node --version))"
fi
}
install_camofox_browser() {
info "Installing camofox-browser (anti-detection browser)..."
if command -v npx &>/dev/null; then
info "Installing via npm..."
npm install -g camoufox-browser 2>&1 | tail -5
npx camoufox-browser@latest install 2>&1 | tail -5
ok "Camoufox browser installed (npx camoufox-browser start)"
elif command -v docker &>/dev/null; then
info "Installing via Docker..."
docker run -d --name camoufox -p 9377:9377 \
-e CAMOUFOX_WS_PORT=9377 \
--restart unless-stopped \
ghcr.io/nousresearch/camoufox-browser:latest 2>&1 | tail -3
ok "Camoufox browser installed (Docker)"
else
warn "Neither npm nor docker found. Install manually: npm install -g camoufox-browser"
fi
}
build_release() {
local root_dir
root_dir="$(cd "$(dirname "$0")" && pwd)"
info "Building GyanDoot v2.0 in release mode..."
cd "$root_dir"
if [ ! -f "$root_dir/Cargo.toml" ]; then
local probe
probe="$(pwd)"
while [ "$probe" != "/" ]; do
if [ -f "$probe/Cargo.toml" ] && grep -q '\[workspace\]' "$probe/Cargo.toml" 2>/dev/null; then
root_dir="$probe"
cd "$root_dir"
info "Found workspace root at $root_dir"
break
fi
probe="$(dirname "$probe")"
done
fi
cargo build --release
ok "Build complete ($(du -sh target/release/gyandoot | cut -f1))"
}
install_binary() {
local root_dir
root_dir="$(cd "$(dirname "$0")" && pwd)"
local target_dir="$root_dir/target/release"
local bin_name="gyandoot"
if [ ! -f "$target_dir/$bin_name" ]; then
err "Binary not found at $target_dir/$bin_name"
fi
local install_dir="/usr/local/bin"
if [ ! -w "$install_dir" ]; then
info "Need sudo to install to $install_dir"
sudo cp "$target_dir/$bin_name" "$install_dir/$bin_name"
sudo chmod +x "$install_dir/$bin_name"
else
cp "$target_dir/$bin_name" "$install_dir/$bin_name"
chmod +x "$install_dir/$bin_name"
fi
ok "Installed to $install_dir/$bin_name"
}
print_post_install() {
echo ""
ok "GyanDoot v2.0 installed successfully!"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Quick Start:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " gyandoot --help Show all commands"
echo " gyandoot init Create config"
echo " gyandoot setup Interactive setup wizard"
echo " gyandoot run Start interactive agent"
echo ""
echo " Browser Tools (anti-detection browsing):"
echo " gyandoot browser health Check camofox status"
echo " gyandoot browser search <query>"
echo " gyandoot browser browse <url>"
echo ""
echo " Service Management:"
echo " gyandoot service install Auto-start on boot"
echo " gyandoot service remove Remove system service"
echo " gyandoot service status Check service status"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
}
prompt_service_install() {
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Optional: Auto-start GyanDoot on Boot?"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " GyanDoot can run as a system service and"
echo " start automatically when your computer boots."
echo " This keeps the gateway server running in the background."
echo ""
echo " (You can also do this later with: gyandoot service install)"
echo ""
read -r -p " Install system service? [y/N]: " response
}
main() {
local os arch
os=$(detect_os)
arch=$(detect_architecture)
info "Detected: $os / $arch"
install_rust_if_needed
install_node_if_needed
install_camofox_browser
build_release
install_binary
# Optional: install GyanDoot system service (auto-start on boot)
prompt_service_install
case "$response" in
[yY]|[yY][eE][sS])
info "Installing GyanDoot system service..."
gyandoot service install 2>&1 || warn "Service install failed (run 'gyandoot service install' later)"
;;
*)
info "Skipping service install (use 'gyandoot service install' later)"
;;
esac
print_post_install
}
main "$@"