fix(install): sync with release — three-tier binary resolution
Same fix as gyandoot-release: ensure_gyandoot_binary() detects whether we're in source repo, binary repo, or need to clone. install_binary() now takes a path parameter.
This commit is contained in:
106
install.sh
106
install.sh
@@ -259,43 +259,93 @@ install_camoufox_browser() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── Build GyanDoot ──────────────────────────────────────────────────────
|
# ─── Build or Download GyanDoot ───────────────────────────────────────────
|
||||||
build_gyandoot() {
|
# In the source repo (gyandoot-v2): builds from Cargo workspace
|
||||||
|
# In the release repo (gyandoot-release): uses prebuilt binary
|
||||||
|
ensure_gyandoot_binary() {
|
||||||
local root_dir
|
local root_dir
|
||||||
root_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo "$PWD")"
|
root_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo "$PWD")"
|
||||||
|
|
||||||
# Find workspace root (where Cargo.toml with [workspace] is)
|
|
||||||
cd "$root_dir"
|
cd "$root_dir"
|
||||||
while [ "$PWD" != "/" ]; do
|
|
||||||
if [ -f "Cargo.toml" ] && grep -q '\[workspace\]' Cargo.toml 2>/dev/null; then
|
# Check 1: Is there a Cargo workspace? → Build from source
|
||||||
info "Found workspace root at $PWD"
|
local probe="$root_dir"
|
||||||
break
|
while [ "$probe" != "/" ]; do
|
||||||
|
if [ -f "$probe/Cargo.toml" ] && grep -q '\[workspace\]' "$probe/Cargo.toml" 2>/dev/null; then
|
||||||
|
info "Source code found — building GyanDoot from source..."
|
||||||
|
cd "$probe"
|
||||||
|
cargo build --release 2>&1 | tail -5
|
||||||
|
ok "Build complete"
|
||||||
|
echo "$probe/target/release/gyandoot"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
cd ..
|
probe="$(dirname "$probe")"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$PWD" = "/" ]; then
|
# Check 2: Is there a prebuilt binary in the linux/ directory?
|
||||||
err "Could not find Cargo workspace. Make sure you're in the gyandoot-v2 directory."
|
local os
|
||||||
|
os="$(uname -s)"
|
||||||
|
local arch
|
||||||
|
arch="$(uname -m)"
|
||||||
|
|
||||||
|
# Map platform names
|
||||||
|
local os_dir
|
||||||
|
case "$os" in
|
||||||
|
Darwin) os_dir="macos" ;;
|
||||||
|
Linux) os_dir="linux" ;;
|
||||||
|
CYGWIN*|MINGW*|MSYS*) os_dir="windows" ;;
|
||||||
|
*) err "Unsupported OS: $os" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
local prebuilt="$root_dir/$os_dir/gyandoot"
|
||||||
|
if [ -f "$prebuilt" ]; then
|
||||||
|
info "Prebuilt binary found at $prebuilt"
|
||||||
|
echo "$prebuilt"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Building GyanDoot v2.0 (release mode)..."
|
# Check 3: Download from source repo (clone and build)
|
||||||
|
info "No prebuilt binary found for $os/$arch"
|
||||||
|
info "Cloning source repository to build from scratch..."
|
||||||
|
local clone_dir
|
||||||
|
clone_dir="$(mktemp -d 2>/dev/null || echo "/tmp/gyandoot-build-$$")"
|
||||||
|
|
||||||
|
if command -v git &>/dev/null; then
|
||||||
|
git clone --depth=1 https://git.gyannetra.in/gnpl_admin/gyandoot-v2.git "$clone_dir" 2>&1 | tail -5
|
||||||
|
cd "$clone_dir"
|
||||||
cargo build --release 2>&1 | tail -5
|
cargo build --release 2>&1 | tail -5
|
||||||
ok "Build complete ($(du -sh target/release/gyandoot* 2>/dev/null | cut -f1))"
|
if [ -f "target/release/gyandoot" ]; then
|
||||||
|
ok "Built from source"
|
||||||
|
echo "$clone_dir/target/release/gyandoot"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [ -f "target/release/gyandoot.exe" ]; then
|
||||||
|
ok "Built from source"
|
||||||
|
echo "$clone_dir/target/release/gyandoot.exe"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
err "Could not find or build GyanDoot binary.
|
||||||
|
1. Clone the source repo: git clone https://git.gyannetra.in/gnpl_admin/gyandoot-v2.git
|
||||||
|
2. cd gyandoot-v2 && cargo build --release
|
||||||
|
3. Then run: ./target/release/gyandoot"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── Install Binary ──────────────────────────────────────────────────────
|
# ─── Install Binary ──────────────────────────────────────────────────────
|
||||||
install_binary() {
|
install_binary() {
|
||||||
local target_dir="$PWD/target/release"
|
local binary_path="$1"
|
||||||
local bin_name="gyandoot"
|
local bin_name
|
||||||
|
|
||||||
if [ -f "$target_dir/gyandoot.exe" ]; then
|
if [ -z "$binary_path" ]; then
|
||||||
bin_name="gyandoot.exe"
|
err "No binary path provided to install_binary"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$target_dir/$bin_name" ]; then
|
if [ ! -f "$binary_path" ]; then
|
||||||
err "Binary not found at $target_dir/$bin_name"
|
err "Binary not found at $binary_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
bin_name="$(basename "$binary_path")"
|
||||||
|
|
||||||
local os
|
local os
|
||||||
os="$(uname -s)"
|
os="$(uname -s)"
|
||||||
local install_dir=""
|
local install_dir=""
|
||||||
@@ -311,7 +361,7 @@ install_binary() {
|
|||||||
install_dir="/usr/local/bin"
|
install_dir="/usr/local/bin"
|
||||||
else
|
else
|
||||||
info "Need sudo to install to /usr/local/bin"
|
info "Need sudo to install to /usr/local/bin"
|
||||||
sudo cp "$target_dir/$bin_name" "/usr/local/bin/$bin_name"
|
sudo cp "$binary_path" "/usr/local/bin/$bin_name"
|
||||||
sudo chmod +x "/usr/local/bin/$bin_name"
|
sudo chmod +x "/usr/local/bin/$bin_name"
|
||||||
install_dir="/usr/local/bin"
|
install_dir="/usr/local/bin"
|
||||||
fi
|
fi
|
||||||
@@ -327,14 +377,14 @@ install_binary() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$install_dir" ]; then
|
if [ -n "$install_dir" ]; then
|
||||||
cp "$target_dir/$bin_name" "$install_dir/$bin_name"
|
cp "$binary_path" "$install_dir/$bin_name"
|
||||||
chmod +x "$install_dir/$bin_name"
|
chmod +x "$install_dir/$bin_name"
|
||||||
installed_to="$install_dir/$bin_name"
|
installed_to="$install_dir/$bin_name"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
CYGWIN*|MINGW*|MSYS*)
|
CYGWIN*|MINGW*|MSYS*)
|
||||||
install_dir="/usr/local/bin"
|
install_dir="/usr/local/bin"
|
||||||
cp "$target_dir/$bin_name" "$install_dir/$bin_name"
|
cp "$binary_path" "$install_dir/$bin_name"
|
||||||
chmod +x "$install_dir/$bin_name"
|
chmod +x "$install_dir/$bin_name"
|
||||||
installed_to="$install_dir/$bin_name"
|
installed_to="$install_dir/$bin_name"
|
||||||
;;
|
;;
|
||||||
@@ -441,13 +491,15 @@ main() {
|
|||||||
info "Phase 2: Installing Camoufox browser..."
|
info "Phase 2: Installing Camoufox browser..."
|
||||||
install_camoufox_browser
|
install_camoufox_browser
|
||||||
|
|
||||||
# ── Build from source ──────────────────────────────────────────────
|
# ── Build or download binary ─────────────────────────────────────
|
||||||
info "Phase 3: Building GyanDoot..."
|
info "Phase 3: Preparing GyanDoot binary..."
|
||||||
build_gyandoot
|
local gyandoot_binary
|
||||||
|
gyandoot_binary="$(ensure_gyandoot_binary)"
|
||||||
|
ok "Binary ready: $gyandoot_binary ($(du -sh "$gyandoot_binary" 2>/dev/null | cut -f1))"
|
||||||
|
|
||||||
# ── Install binary ─────────────────────────────────────────────────
|
# ── Install binary ────────────────────────────────────────────────
|
||||||
info "Phase 4: Installing binary..."
|
info "Phase 4: Installing binary..."
|
||||||
install_binary
|
install_binary "$gyandoot_binary"
|
||||||
|
|
||||||
# ── Optional: system service ───────────────────────────────────────
|
# ── Optional: system service ───────────────────────────────────────
|
||||||
info "Phase 5: Service setup..."
|
info "Phase 5: Service setup..."
|
||||||
|
|||||||
106
release/install.sh
Normal file → Executable file
106
release/install.sh
Normal file → Executable file
@@ -259,43 +259,93 @@ install_camoufox_browser() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── Build GyanDoot ──────────────────────────────────────────────────────
|
# ─── Build or Download GyanDoot ───────────────────────────────────────────
|
||||||
build_gyandoot() {
|
# In the source repo (gyandoot-v2): builds from Cargo workspace
|
||||||
|
# In the release repo (gyandoot-release): uses prebuilt binary
|
||||||
|
ensure_gyandoot_binary() {
|
||||||
local root_dir
|
local root_dir
|
||||||
root_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo "$PWD")"
|
root_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo "$PWD")"
|
||||||
|
|
||||||
# Find workspace root (where Cargo.toml with [workspace] is)
|
|
||||||
cd "$root_dir"
|
cd "$root_dir"
|
||||||
while [ "$PWD" != "/" ]; do
|
|
||||||
if [ -f "Cargo.toml" ] && grep -q '\[workspace\]' Cargo.toml 2>/dev/null; then
|
# Check 1: Is there a Cargo workspace? → Build from source
|
||||||
info "Found workspace root at $PWD"
|
local probe="$root_dir"
|
||||||
break
|
while [ "$probe" != "/" ]; do
|
||||||
|
if [ -f "$probe/Cargo.toml" ] && grep -q '\[workspace\]' "$probe/Cargo.toml" 2>/dev/null; then
|
||||||
|
info "Source code found — building GyanDoot from source..."
|
||||||
|
cd "$probe"
|
||||||
|
cargo build --release 2>&1 | tail -5
|
||||||
|
ok "Build complete"
|
||||||
|
echo "$probe/target/release/gyandoot"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
cd ..
|
probe="$(dirname "$probe")"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$PWD" = "/" ]; then
|
# Check 2: Is there a prebuilt binary in the linux/ directory?
|
||||||
err "Could not find Cargo workspace. Make sure you're in the gyandoot-v2 directory."
|
local os
|
||||||
|
os="$(uname -s)"
|
||||||
|
local arch
|
||||||
|
arch="$(uname -m)"
|
||||||
|
|
||||||
|
# Map platform names
|
||||||
|
local os_dir
|
||||||
|
case "$os" in
|
||||||
|
Darwin) os_dir="macos" ;;
|
||||||
|
Linux) os_dir="linux" ;;
|
||||||
|
CYGWIN*|MINGW*|MSYS*) os_dir="windows" ;;
|
||||||
|
*) err "Unsupported OS: $os" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
local prebuilt="$root_dir/$os_dir/gyandoot"
|
||||||
|
if [ -f "$prebuilt" ]; then
|
||||||
|
info "Prebuilt binary found at $prebuilt"
|
||||||
|
echo "$prebuilt"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Building GyanDoot v2.0 (release mode)..."
|
# Check 3: Download from source repo (clone and build)
|
||||||
|
info "No prebuilt binary found for $os/$arch"
|
||||||
|
info "Cloning source repository to build from scratch..."
|
||||||
|
local clone_dir
|
||||||
|
clone_dir="$(mktemp -d 2>/dev/null || echo "/tmp/gyandoot-build-$$")"
|
||||||
|
|
||||||
|
if command -v git &>/dev/null; then
|
||||||
|
git clone --depth=1 https://git.gyannetra.in/gnpl_admin/gyandoot-v2.git "$clone_dir" 2>&1 | tail -5
|
||||||
|
cd "$clone_dir"
|
||||||
cargo build --release 2>&1 | tail -5
|
cargo build --release 2>&1 | tail -5
|
||||||
ok "Build complete ($(du -sh target/release/gyandoot* 2>/dev/null | cut -f1))"
|
if [ -f "target/release/gyandoot" ]; then
|
||||||
|
ok "Built from source"
|
||||||
|
echo "$clone_dir/target/release/gyandoot"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [ -f "target/release/gyandoot.exe" ]; then
|
||||||
|
ok "Built from source"
|
||||||
|
echo "$clone_dir/target/release/gyandoot.exe"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
err "Could not find or build GyanDoot binary.
|
||||||
|
1. Clone the source repo: git clone https://git.gyannetra.in/gnpl_admin/gyandoot-v2.git
|
||||||
|
2. cd gyandoot-v2 && cargo build --release
|
||||||
|
3. Then run: ./target/release/gyandoot"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── Install Binary ──────────────────────────────────────────────────────
|
# ─── Install Binary ──────────────────────────────────────────────────────
|
||||||
install_binary() {
|
install_binary() {
|
||||||
local target_dir="$PWD/target/release"
|
local binary_path="$1"
|
||||||
local bin_name="gyandoot"
|
local bin_name
|
||||||
|
|
||||||
if [ -f "$target_dir/gyandoot.exe" ]; then
|
if [ -z "$binary_path" ]; then
|
||||||
bin_name="gyandoot.exe"
|
err "No binary path provided to install_binary"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$target_dir/$bin_name" ]; then
|
if [ ! -f "$binary_path" ]; then
|
||||||
err "Binary not found at $target_dir/$bin_name"
|
err "Binary not found at $binary_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
bin_name="$(basename "$binary_path")"
|
||||||
|
|
||||||
local os
|
local os
|
||||||
os="$(uname -s)"
|
os="$(uname -s)"
|
||||||
local install_dir=""
|
local install_dir=""
|
||||||
@@ -311,7 +361,7 @@ install_binary() {
|
|||||||
install_dir="/usr/local/bin"
|
install_dir="/usr/local/bin"
|
||||||
else
|
else
|
||||||
info "Need sudo to install to /usr/local/bin"
|
info "Need sudo to install to /usr/local/bin"
|
||||||
sudo cp "$target_dir/$bin_name" "/usr/local/bin/$bin_name"
|
sudo cp "$binary_path" "/usr/local/bin/$bin_name"
|
||||||
sudo chmod +x "/usr/local/bin/$bin_name"
|
sudo chmod +x "/usr/local/bin/$bin_name"
|
||||||
install_dir="/usr/local/bin"
|
install_dir="/usr/local/bin"
|
||||||
fi
|
fi
|
||||||
@@ -327,14 +377,14 @@ install_binary() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$install_dir" ]; then
|
if [ -n "$install_dir" ]; then
|
||||||
cp "$target_dir/$bin_name" "$install_dir/$bin_name"
|
cp "$binary_path" "$install_dir/$bin_name"
|
||||||
chmod +x "$install_dir/$bin_name"
|
chmod +x "$install_dir/$bin_name"
|
||||||
installed_to="$install_dir/$bin_name"
|
installed_to="$install_dir/$bin_name"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
CYGWIN*|MINGW*|MSYS*)
|
CYGWIN*|MINGW*|MSYS*)
|
||||||
install_dir="/usr/local/bin"
|
install_dir="/usr/local/bin"
|
||||||
cp "$target_dir/$bin_name" "$install_dir/$bin_name"
|
cp "$binary_path" "$install_dir/$bin_name"
|
||||||
chmod +x "$install_dir/$bin_name"
|
chmod +x "$install_dir/$bin_name"
|
||||||
installed_to="$install_dir/$bin_name"
|
installed_to="$install_dir/$bin_name"
|
||||||
;;
|
;;
|
||||||
@@ -441,13 +491,15 @@ main() {
|
|||||||
info "Phase 2: Installing Camoufox browser..."
|
info "Phase 2: Installing Camoufox browser..."
|
||||||
install_camoufox_browser
|
install_camoufox_browser
|
||||||
|
|
||||||
# ── Build from source ──────────────────────────────────────────────
|
# ── Build or download binary ─────────────────────────────────────
|
||||||
info "Phase 3: Building GyanDoot..."
|
info "Phase 3: Preparing GyanDoot binary..."
|
||||||
build_gyandoot
|
local gyandoot_binary
|
||||||
|
gyandoot_binary="$(ensure_gyandoot_binary)"
|
||||||
|
ok "Binary ready: $gyandoot_binary ($(du -sh "$gyandoot_binary" 2>/dev/null | cut -f1))"
|
||||||
|
|
||||||
# ── Install binary ─────────────────────────────────────────────────
|
# ── Install binary ────────────────────────────────────────────────
|
||||||
info "Phase 4: Installing binary..."
|
info "Phase 4: Installing binary..."
|
||||||
install_binary
|
install_binary "$gyandoot_binary"
|
||||||
|
|
||||||
# ── Optional: system service ───────────────────────────────────────
|
# ── Optional: system service ───────────────────────────────────────
|
||||||
info "Phase 5: Service setup..."
|
info "Phase 5: Service setup..."
|
||||||
|
|||||||
Reference in New Issue
Block a user