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:
108
install.sh
108
install.sh
@@ -259,43 +259,93 @@ install_camoufox_browser() {
|
||||
fi
|
||||
}
|
||||
|
||||
# ─── Build GyanDoot ──────────────────────────────────────────────────────
|
||||
build_gyandoot() {
|
||||
# ─── Build or Download 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
|
||||
root_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo "$PWD")"
|
||||
|
||||
# Find workspace root (where Cargo.toml with [workspace] is)
|
||||
cd "$root_dir"
|
||||
while [ "$PWD" != "/" ]; do
|
||||
if [ -f "Cargo.toml" ] && grep -q '\[workspace\]' Cargo.toml 2>/dev/null; then
|
||||
info "Found workspace root at $PWD"
|
||||
break
|
||||
|
||||
# Check 1: Is there a Cargo workspace? → Build from source
|
||||
local probe="$root_dir"
|
||||
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
|
||||
cd ..
|
||||
probe="$(dirname "$probe")"
|
||||
done
|
||||
|
||||
if [ "$PWD" = "/" ]; then
|
||||
err "Could not find Cargo workspace. Make sure you're in the gyandoot-v2 directory."
|
||||
# Check 2: Is there a prebuilt binary in the linux/ 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
|
||||
|
||||
info "Building GyanDoot v2.0 (release mode)..."
|
||||
cargo build --release 2>&1 | tail -5
|
||||
ok "Build complete ($(du -sh target/release/gyandoot* 2>/dev/null | cut -f1))"
|
||||
# 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
|
||||
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() {
|
||||
local target_dir="$PWD/target/release"
|
||||
local bin_name="gyandoot"
|
||||
local binary_path="$1"
|
||||
local bin_name
|
||||
|
||||
if [ -f "$target_dir/gyandoot.exe" ]; then
|
||||
bin_name="gyandoot.exe"
|
||||
if [ -z "$binary_path" ]; then
|
||||
err "No binary path provided to install_binary"
|
||||
fi
|
||||
|
||||
if [ ! -f "$target_dir/$bin_name" ]; then
|
||||
err "Binary not found at $target_dir/$bin_name"
|
||||
if [ ! -f "$binary_path" ]; then
|
||||
err "Binary not found at $binary_path"
|
||||
fi
|
||||
|
||||
bin_name="$(basename "$binary_path")"
|
||||
|
||||
local os
|
||||
os="$(uname -s)"
|
||||
local install_dir=""
|
||||
@@ -311,7 +361,7 @@ install_binary() {
|
||||
install_dir="/usr/local/bin"
|
||||
else
|
||||
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"
|
||||
install_dir="/usr/local/bin"
|
||||
fi
|
||||
@@ -327,14 +377,14 @@ install_binary() {
|
||||
fi
|
||||
|
||||
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"
|
||||
installed_to="$install_dir/$bin_name"
|
||||
fi
|
||||
;;
|
||||
CYGWIN*|MINGW*|MSYS*)
|
||||
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"
|
||||
installed_to="$install_dir/$bin_name"
|
||||
;;
|
||||
@@ -441,13 +491,15 @@ main() {
|
||||
info "Phase 2: Installing Camoufox browser..."
|
||||
install_camoufox_browser
|
||||
|
||||
# ── Build from source ──────────────────────────────────────────────
|
||||
info "Phase 3: Building GyanDoot..."
|
||||
build_gyandoot
|
||||
# ── Build or download binary ─────────────────────────────────────
|
||||
info "Phase 3: Preparing GyanDoot binary..."
|
||||
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..."
|
||||
install_binary
|
||||
install_binary "$gyandoot_binary"
|
||||
|
||||
# ── Optional: system service ───────────────────────────────────────
|
||||
info "Phase 5: Service setup..."
|
||||
|
||||
108
release/install.sh
Normal file → Executable file
108
release/install.sh
Normal file → Executable file
@@ -259,43 +259,93 @@ install_camoufox_browser() {
|
||||
fi
|
||||
}
|
||||
|
||||
# ─── Build GyanDoot ──────────────────────────────────────────────────────
|
||||
build_gyandoot() {
|
||||
# ─── Build or Download 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
|
||||
root_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo "$PWD")"
|
||||
|
||||
# Find workspace root (where Cargo.toml with [workspace] is)
|
||||
cd "$root_dir"
|
||||
while [ "$PWD" != "/" ]; do
|
||||
if [ -f "Cargo.toml" ] && grep -q '\[workspace\]' Cargo.toml 2>/dev/null; then
|
||||
info "Found workspace root at $PWD"
|
||||
break
|
||||
|
||||
# Check 1: Is there a Cargo workspace? → Build from source
|
||||
local probe="$root_dir"
|
||||
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
|
||||
cd ..
|
||||
probe="$(dirname "$probe")"
|
||||
done
|
||||
|
||||
if [ "$PWD" = "/" ]; then
|
||||
err "Could not find Cargo workspace. Make sure you're in the gyandoot-v2 directory."
|
||||
# Check 2: Is there a prebuilt binary in the linux/ 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
|
||||
|
||||
info "Building GyanDoot v2.0 (release mode)..."
|
||||
cargo build --release 2>&1 | tail -5
|
||||
ok "Build complete ($(du -sh target/release/gyandoot* 2>/dev/null | cut -f1))"
|
||||
# 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
|
||||
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() {
|
||||
local target_dir="$PWD/target/release"
|
||||
local bin_name="gyandoot"
|
||||
local binary_path="$1"
|
||||
local bin_name
|
||||
|
||||
if [ -f "$target_dir/gyandoot.exe" ]; then
|
||||
bin_name="gyandoot.exe"
|
||||
if [ -z "$binary_path" ]; then
|
||||
err "No binary path provided to install_binary"
|
||||
fi
|
||||
|
||||
if [ ! -f "$target_dir/$bin_name" ]; then
|
||||
err "Binary not found at $target_dir/$bin_name"
|
||||
if [ ! -f "$binary_path" ]; then
|
||||
err "Binary not found at $binary_path"
|
||||
fi
|
||||
|
||||
bin_name="$(basename "$binary_path")"
|
||||
|
||||
local os
|
||||
os="$(uname -s)"
|
||||
local install_dir=""
|
||||
@@ -311,7 +361,7 @@ install_binary() {
|
||||
install_dir="/usr/local/bin"
|
||||
else
|
||||
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"
|
||||
install_dir="/usr/local/bin"
|
||||
fi
|
||||
@@ -327,14 +377,14 @@ install_binary() {
|
||||
fi
|
||||
|
||||
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"
|
||||
installed_to="$install_dir/$bin_name"
|
||||
fi
|
||||
;;
|
||||
CYGWIN*|MINGW*|MSYS*)
|
||||
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"
|
||||
installed_to="$install_dir/$bin_name"
|
||||
;;
|
||||
@@ -441,13 +491,15 @@ main() {
|
||||
info "Phase 2: Installing Camoufox browser..."
|
||||
install_camoufox_browser
|
||||
|
||||
# ── Build from source ──────────────────────────────────────────────
|
||||
info "Phase 3: Building GyanDoot..."
|
||||
build_gyandoot
|
||||
# ── Build or download binary ─────────────────────────────────────
|
||||
info "Phase 3: Preparing GyanDoot binary..."
|
||||
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..."
|
||||
install_binary
|
||||
install_binary "$gyandoot_binary"
|
||||
|
||||
# ── Optional: system service ───────────────────────────────────────
|
||||
info "Phase 5: Service setup..."
|
||||
|
||||
Reference in New Issue
Block a user