119 lines
3.8 KiB
Bash
Executable File
119 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# install_local.sh — Build sovereign_browser from local source and install to
|
|
# /usr/local/bin (or $INSTALL_PREFIX/bin).
|
|
#
|
|
# This is a lightweight alternative to install.sh for developers who already
|
|
# have the build environment set up. It does NOT install apt dependencies,
|
|
# FIPS, or Tor — it just runs `cargo build --release` and copies the binary.
|
|
#
|
|
# Usage:
|
|
# ./install_local.sh # build + install to /usr/local
|
|
# INSTALL_PREFIX=/opt ./install_local.sh # install elsewhere
|
|
# ./install_local.sh --prefix /opt # same
|
|
# ./install_local.sh --help # show help
|
|
|
|
set -euo pipefail
|
|
|
|
INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"
|
|
|
|
# --- Output helpers ------------------------------------------------------
|
|
|
|
if [[ -t 2 && -z "${NO_COLOR:-}" ]]; then
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
else
|
|
RED='' GREEN='' YELLOW='' BLUE='' NC=''
|
|
fi
|
|
|
|
print_info() { echo -e "${BLUE}[INFO]${NC} $*" >&2; }
|
|
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $*" >&2; }
|
|
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $*" >&2; }
|
|
print_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
|
|
die() { print_error "$*"; exit 1; }
|
|
|
|
# --- Privilege helper ----------------------------------------------------
|
|
# Returns "sudo" if the target path is not user-writable, else "".
|
|
sudo_for() {
|
|
local target="$1"
|
|
if [[ -w "$target" ]]; then
|
|
echo ""
|
|
else
|
|
command -v sudo >/dev/null 2>&1 || die "sudo is required to write to $target but is not available."
|
|
echo "sudo"
|
|
fi
|
|
}
|
|
|
|
# --- Usage ---------------------------------------------------------------
|
|
|
|
show_usage() {
|
|
cat <<'EOF'
|
|
install_local.sh — Build sovereign_browser from local source and install
|
|
|
|
Usage: ./install_local.sh [options]
|
|
|
|
Options:
|
|
--prefix <dir> Install prefix (default: /usr/local)
|
|
-h, --help Show this help
|
|
|
|
Environment:
|
|
INSTALL_PREFIX Alternative to --prefix (default: /usr/local)
|
|
EOF
|
|
}
|
|
|
|
# --- Args ----------------------------------------------------------------
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--prefix) INSTALL_PREFIX="${2:-}"; shift 2 ;;
|
|
-h|--help) show_usage; exit 0 ;;
|
|
*) die "Unknown option: $1 (try --help)" ;;
|
|
esac
|
|
done
|
|
|
|
# --- Config --------------------------------------------------------------
|
|
# Resolve the project root as the directory containing this script.
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
BIN_NAME="sovereign_browser"
|
|
BUILT_BIN="target/release/${BIN_NAME}"
|
|
|
|
# --- Build ---------------------------------------------------------------
|
|
|
|
print_info "Building ${BIN_NAME} from local source (release)..."
|
|
if ! cargo build --release; then
|
|
die "Build failed. Ensure build dependencies are installed (see README)."
|
|
fi
|
|
|
|
[[ -x "$BUILT_BIN" ]] || die "Build finished but ${BUILT_BIN} was not produced."
|
|
|
|
print_success "Build complete."
|
|
|
|
# --- Install binary ------------------------------------------------------
|
|
|
|
prefix_bin="$INSTALL_PREFIX/bin"
|
|
SUDO="$(sudo_for "$INSTALL_PREFIX")"
|
|
|
|
print_info "Installing binary to $prefix_bin/${BIN_NAME}"
|
|
$SUDO mkdir -p "$prefix_bin"
|
|
$SUDO cp -f "$BUILT_BIN" "$prefix_bin/${BIN_NAME}"
|
|
$SUDO chmod +x "$prefix_bin/${BIN_NAME}"
|
|
print_success "Binary installed: $prefix_bin/${BIN_NAME}"
|
|
|
|
# --- Done ----------------------------------------------------------------
|
|
|
|
print_success "${BIN_NAME} installed to $prefix_bin"
|
|
if [[ ":${PATH}:" != *":$prefix_bin:"* ]]; then
|
|
print_warning "$prefix_bin is not in your PATH. Add it: export PATH=\"$prefix_bin:\$PATH\""
|
|
fi
|
|
|
|
cat >&2 <<EOF
|
|
${GREEN}[SUCCESS]${NC} Next steps:
|
|
Run: ${BIN_NAME}
|
|
Or: ${BIN_NAME} --login-method generate
|
|
Or: ${BIN_NAME} --login-method generate --url https://example.com
|
|
EOF
|