-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivate
More file actions
86 lines (73 loc) · 3.85 KB
/
Copy pathactivate
File metadata and controls
86 lines (73 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# hackbox — source this and start hacking. (bash/zsh, macOS+Linux)
# source /path/to/hackbox/activate
# First run: fetches uv, runs `uv sync` (python tools) and downloads the native
# tools into .tools/. Later runs: instant. Everything stays inside the repo;
# nothing touches the system. Run `deactivate` to leave.
#
# Env knobs:
# HACKBOX_NO_SYNC=1 source the env only; don't fetch anything
# HACKBOX_RESYNC=1 force a re-sync this time
# HACKBOX_NO_PROMPT=1 don't add the (hackbox) prompt marker
if [ -n "${BASH_SOURCE:-}" ]; then _hb_src="${BASH_SOURCE[0]}"
elif [ -n "${ZSH_VERSION:-}" ]; then _hb_src="${(%):-%N}"
else _hb_src="$0"; fi
HACKBOX_ROOT="$(cd "$(dirname "$_hb_src")" && pwd)"; unset _hb_src
export HACKBOX_ROOT
. "$HACKBOX_ROOT/lib/common.sh"
hb_setup_env
. "$HACKBOX_ROOT/versions.env"
. "$HACKBOX_ROOT/lib/recipes.sh"
. "$HACKBOX_ROOT/lib/engine.sh"
if [ -n "${HACKBOX_ACTIVE:-}" ]; then
hb_warn "hackbox already active — run 'deactivate' first"; return 0 2>/dev/null || exit 0
fi
# --- one-command sync (this is the "uv sync and we're ready" step) ----------
if [ -z "${HACKBOX_NO_SYNC:-}" ]; then
if [ ! -f "$HB_TOOLS/.synced" ] || [ -n "${HACKBOX_RESYNC:-}" ]; then
[ -n "${HACKBOX_RESYNC:-}" ] && export HB_FORCE=1
hb_log "first-time setup — fetching tools into .tools/ and .venv/ ..."
hb_sync_all
unset HB_FORCE
else
# cheap: reconcile python deps if the lock changed; offline-fast otherwise
hb_uv_sync >/dev/null 2>&1 || true
fi
fi
# --- save state for a clean deactivate --------------------------------------
_HB_OLD_PATH="$PATH"; _HB_OLD_PS1="${PS1:-}"
_HB_OLD_PSMODULEPATH="${PSModulePath:-}"; _HB_OLD_JAVA_HOME="${JAVA_HOME:-}"
# --- PATH: repo tools first -------------------------------------------------
export PATH="$HB_BIN:$HACKBOX_VENV/bin:$HACKBOX_ROOT/bin:$PATH"
export VIRTUAL_ENV="$HACKBOX_VENV"
[ -x "$HACKBOX_VENV/bin/python" ] && export HACKBOX_PY="$HACKBOX_VENV/bin/python"
[ -d "$HB_PKG/jre/current" ] && export JAVA_HOME="$HB_PKG/jre/current"
# --- contain all tool config/creds inside the repo (nothing in $HOME) -------
export CLOUDSDK_CONFIG="$HACKBOX_ROOT/state/gcloud"
export AWS_CONFIG_FILE="$HACKBOX_ROOT/state/aws/config"
export AWS_SHARED_CREDENTIALS_FILE="$HACKBOX_ROOT/state/aws/credentials"
export GAU_CONFIG="$HACKBOX_ROOT/state/gau.toml"
mkdir -p "$HACKBOX_ROOT/state/gcloud" "$HACKBOX_ROOT/state/aws" 2>/dev/null
# --- PowerShell / AD modules (your CRTE kit etc.) via repo-local path -------
export PSModulePath="$HACKBOX_ROOT/vendor/psmodules${PSModulePath:+:$PSModulePath}"
# --- licensed drop-in tools (jeb) -------------------------------------------
[ -d "$HACKBOX_ROOT/vendor/jeb" ] && export PATH="$HACKBOX_ROOT/vendor/jeb:$PATH"
# --- commands ---------------------------------------------------------------
hackbox() { "$HACKBOX_ROOT/bootstrap.sh" "$@"; } # fetch/update tools
hackbox-tools() { ls -1 "$HB_BIN" 2>/dev/null; } # what's on PATH
deactivate() {
export PATH="$_HB_OLD_PATH"
[ -n "$_HB_OLD_JAVA_HOME" ] && export JAVA_HOME="$_HB_OLD_JAVA_HOME" || unset JAVA_HOME
export PSModulePath="$_HB_OLD_PSMODULEPATH"
[ -n "$_HB_OLD_PS1" ] && PS1="$_HB_OLD_PS1"
unset HACKBOX_ACTIVE HACKBOX_PY VIRTUAL_ENV HB_OS HB_ARCH HB_TOOLS HB_BIN HB_PKG HACKBOX_VENV
unset UV_PYTHON_INSTALL_DIR UV_CACHE_DIR UV_TOOL_DIR UV_TOOL_BIN_DIR UV_PROJECT_ENVIRONMENT UV_PYTHON_PREFERENCE
unset CLOUDSDK_CONFIG AWS_CONFIG_FILE AWS_SHARED_CREDENTIALS_FILE GAU_CONFIG
unset _HB_OLD_PATH _HB_OLD_PS1 _HB_OLD_PSMODULEPATH _HB_OLD_JAVA_HOME
unset -f hackbox hackbox-tools deactivate 2>/dev/null
hb_ok "hackbox deactivated"
}
export HACKBOX_ACTIVE=1
[ "${HACKBOX_NO_PROMPT:-}" = "1" ] || PS1="(hackbox) ${PS1:-}"
_hb_n=$(ls -1 "$HB_BIN" 2>/dev/null | wc -l | tr -d ' ')
hb_ok "hackbox active — ${HB_OS}-${HB_ARCH}, ${_hb_n} tool(s) on PATH (\`hackbox --list\`, \`deactivate\`)"
unset _hb_n