| … | … | @@ -41,7 +41,8 @@ |
| 41 | 41 | # --bin-name <name> rename pgh's bin (sidecar follows as <name>-sidecar) |
| 42 | 42 | # --base <url> download base (default: $PGH_DOWNLOAD_BASE or |
| 43 | 43 | # https://7rnx.net/git/bootstrap) |
| 44 | | # --no-path-warn skip the PATH-not-set warning |
| 44 | # --no-modify-path don't add <prefix>/bin to your shell rc |
| 45 | # --no-path-warn skip the PATH-not-set warning (implies --no-modify-path) |
| 45 | 46 | # |
| 46 | 47 | # Nothing here requires root. |
| 47 | 48 | |
| … | … | @@ -57,7 +58,13 @@ FROM_DIR="" # --from-dir: local dir of tarballs |
| 57 | 58 | ONLY_APP="" # --app: install just one |
| 58 | 59 | BASE="$DEFAULT_BASE" |
| 59 | 60 | SKIP_PATH_WARN=0 |
| 61 | MODIFY_PATH=1 # append BIN_DIR to the login shell's rc when it's missing |
| 60 | 62 | FORCE_MODE="" # --recover | --fresh | "" (auto-detect) |
| 63 | |
| 64 | # Idempotency markers for the block we manage in the user's shell rc. Never |
| 65 | # change these — a rerun finds its own previous block by exact match. |
| 66 | PATH_MARKER_BEGIN='# >>> pgh PATH >>>' |
| 67 | PATH_MARKER_END='# <<< pgh PATH <<<' |
| 61 | 68 | BIN_NAME_SET=0 # did the caller pass --bin-name explicitly? |
| 62 | 69 | |
| 63 | 70 | # Managed-peer recovery targets the pgh-managed tree store, not the fresh- |
| … | … | @@ -76,8 +83,11 @@ while [ $# -gt 0 ]; do |
| 76 | 83 | --base) BASE="$2"; shift 2 ;; |
| 77 | 84 | --recover) FORCE_MODE="recover"; shift ;; |
| 78 | 85 | --fresh) FORCE_MODE="fresh"; shift ;; |
| 79 | | --no-path-warn) SKIP_PATH_WARN=1; shift ;; |
| 80 | | -h|--help) sed -n '2,46p' "$0"; exit 0 ;; |
| 86 | --no-modify-path) MODIFY_PATH=0; shift ;; |
| 87 | # Historically the only "leave my PATH alone" flag, so it keeps that |
| 88 | # meaning in full: suppress the warning AND touch no rc file. |
| 89 | --no-path-warn) SKIP_PATH_WARN=1; MODIFY_PATH=0; shift ;; |
| 90 | -h|--help) sed -n '2,47p' "$0"; exit 0 ;; |
| 81 | 91 | *) echo "unknown flag: $1" >&2; exit 1 ;; |
| 82 | 92 | esac |
| 83 | 93 | done |
| … | … | @@ -272,17 +282,55 @@ else |
| 272 | 282 | install_one pgh-sidecar "${BIN_NAME}-sidecar" |
| 273 | 283 | fi |
| 274 | 284 | |
| 275 | | # ── PATH check ──────────────────────────────────────────────── |
| 276 | | if [ "$SKIP_PATH_WARN" -ne 1 ]; then |
| 277 | | case ":$PATH:" in |
| 278 | | *":${BIN_DIR}:"*) : ;; |
| 279 | | *) |
| 280 | | echo |
| 281 | | echo "WARNING: ${BIN_DIR} is not on your PATH. Add to your shell rc:" |
| 282 | | echo " export PATH=\"${BIN_DIR}:\$PATH\"" |
| 283 | | echo |
| 284 | | ;; |
| 285 | # ── PATH ────────────────────────────────────────────────────── |
| 286 | # The launchers we just linked live in BIN_DIR. If it isn't on PATH then the |
| 287 | # next command of every documented quick start — `pgh init` — is "command not |
| 288 | # found", and `pgh init` CANNOT be the place that fixes it: you can't invoke |
| 289 | # what isn't found. So the installer owns PATH (rustup's model), unless |
| 290 | # --no-modify-path / --no-path-warn. |
| 291 | # |
| 292 | # Why this bites on a machine that looks fine: Debian/Ubuntu's stock ~/.profile |
| 293 | # adds ~/.local/bin only `if [ -d ... ]`, evaluated at LOGIN. We create that |
| 294 | # directory here (mkdir -p above), so a first-ever install on such a box has |
| 295 | # the dir but not the PATH entry until the next login. |
| 296 | # |
| 297 | # An rc edit never affects the ALREADY-RUNNING shell, so when PATH is missing |
| 298 | # the next-steps below print absolute paths — the sequence works verbatim |
| 299 | # either way. |
| 300 | PATH_OK=0 |
| 301 | case ":$PATH:" in *":${BIN_DIR}:"*) PATH_OK=1 ;; esac |
| 302 | |
| 303 | PATH_RC="" # rc file we appended to (empty = none) |
| 304 | if [ "$PATH_OK" -eq 0 ] && [ "$MODIFY_PATH" -eq 1 ] && [ "$MANAGED" -ne 1 ]; then |
| 305 | # Target the rc of the user's LOGIN shell, not whatever is running us (curl |
| 306 | # | sh means $0's shell is always sh). |
| 307 | case "$(basename "${SHELL:-/bin/sh}")" in |
| 308 | zsh) rc="${ZDOTDIR:-$HOME}/.zshrc" ;; |
| 309 | bash) rc="${HOME}/.bashrc" ;; |
| 310 | fish) rc="${HOME}/.config/fish/config.fish" ;; |
| 311 | *) rc="${HOME}/.profile" ;; |
| 285 | 312 | esac |
| 313 | |
| 314 | if [ -f "$rc" ] && grep -qF "$PATH_MARKER_BEGIN" "$rc" 2>/dev/null; then |
| 315 | PATH_RC="$rc" # already managed by a previous run — idempotent, no-op |
| 316 | echo " PATH block already present in ${rc}" |
| 317 | else |
| 318 | mkdir -p "$(dirname "$rc")" |
| 319 | # The appended line is itself guarded, so re-sourcing the rc (or a login |
| 320 | # shell that already has BIN_DIR from elsewhere) never duplicates the entry. |
| 321 | { |
| 322 | echo "" |
| 323 | echo "$PATH_MARKER_BEGIN" |
| 324 | if [ "$(basename "${SHELL:-/bin/sh}")" = "fish" ]; then |
| 325 | echo "fish_add_path \"${BIN_DIR}\"" |
| 326 | else |
| 327 | echo "case \":\$PATH:\" in *\":${BIN_DIR}:\"*) ;; *) export PATH=\"${BIN_DIR}:\$PATH\" ;; esac" |
| 328 | fi |
| 329 | echo "$PATH_MARKER_END" |
| 330 | } >> "$rc" |
| 331 | PATH_RC="$rc" |
| 332 | echo " added ${BIN_DIR} to PATH in ${rc}" |
| 333 | fi |
| 286 | 334 | fi |
| 287 | 335 | |
| 288 | 336 | echo |
| … | … | @@ -293,12 +341,27 @@ if [ "$MANAGED" -eq 1 ]; then |
| 293 | 341 | echo |
| 294 | 342 | echo "Verify: ${BIN_NAME} app status" |
| 295 | 343 | else |
| 344 | # Absolute paths whenever PATH is missing in THIS shell — including right |
| 345 | # after we edited an rc file, which only takes effect in new shells. |
| 346 | if [ "$PATH_OK" -eq 1 ]; then PGH_CMD="$BIN_NAME"; else PGH_CMD="${BIN_DIR}/${BIN_NAME}"; fi |
| 347 | |
| 296 | 348 | echo "pgh installed. Next steps:" |
| 297 | 349 | echo |
| 298 | | echo " ${BIN_NAME} init # identity + tree store + local registries" |
| 299 | | echo " ${BIN_NAME} app boot # start pgh-sidecar (and any autostart apps)" |
| 350 | echo " ${PGH_CMD} init # identity + tree store + local registries" |
| 351 | echo " ${PGH_CMD} app boot # start pgh-sidecar (and any autostart apps)" |
| 300 | 352 | echo |
| 301 | 353 | echo "init sets things up but does NOT start the sidecar — 'app boot' does." |
| 354 | |
| 355 | if [ "$PATH_OK" -eq 0 ] && [ "$SKIP_PATH_WARN" -ne 1 ]; then |
| 356 | echo |
| 357 | if [ -n "$PATH_RC" ]; then |
| 358 | echo "PATH: ${BIN_DIR} added to ${PATH_RC} — applies to NEW shells." |
| 359 | echo " For this one: export PATH=\"${BIN_DIR}:\$PATH\"" |
| 360 | else |
| 361 | echo "WARNING: ${BIN_DIR} is not on your PATH. Add to your shell rc:" |
| 362 | echo " export PATH=\"${BIN_DIR}:\$PATH\"" |
| 363 | fi |
| 364 | fi |
| 302 | 365 | fi |
| 303 | 366 | echo |
| 304 | 367 | |