merve HF Staff commited on
Commit
164e59e
·
verified ·
1 Parent(s): 9f020c3

Patch ~/.local/bin/hermes to default HERMES_HOME — no shell sourcing needed

Browse files
Files changed (1) hide show
  1. bootstrap.sh +32 -16
bootstrap.sh CHANGED
@@ -215,38 +215,53 @@ chmod 600 "$SECRETS"
215
  ok "Secrets saved to $SECRETS (mode 600)"
216
 
217
  # ----------------------------------------------------------------------------
218
- # 10. Persistent HERMES_HOME export in your shell rc
219
  # ----------------------------------------------------------------------------
220
- # Aliases were unreliable across shells. Exporting the env var instead means
221
- # every plain `hermes` / `hermes gateway` / `hermes cron` invocation in any new
222
- # shell uses the shadow dir automatically no special command names.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  SHELL_NAME="${SHELL##*/}"
224
  case "$SHELL_NAME" in
225
  zsh) SHELL_RC="$HOME/.zshrc" ;;
226
  bash) SHELL_RC="$HOME/.bashrc" ;;
227
  *) SHELL_RC="$HOME/.profile" ;;
228
  esac
229
-
230
- # Remove any prior block we added (old alias-based version or earlier export)
231
  if [ -f "$SHELL_RC" ] && grep -q "# hermes-bucket" "$SHELL_RC"; then
232
  python3 - "$SHELL_RC" <<'PY'
233
  import sys, pathlib, re
234
  p = pathlib.Path(sys.argv[1])
235
  text = p.read_text()
236
- # Strip every block we previously injected, identified by the marker comment
237
  new = re.sub(r"\n*# hermes-bucket[^\n]*\n(?:[^\n]*\n)*?(?=\n|\Z)", "\n", text)
238
  p.write_text(new)
239
  PY
 
240
  fi
241
 
242
- cat >> "$SHELL_RC" <<EOF
243
-
244
- # hermes-bucket: export HERMES_HOME so 'hermes', 'hermes gateway', 'hermes cron'
245
- # all use the bucket-backed shadow dir. Remove this if you'd rather manage it yourself.
246
- export HERMES_HOME="\$HOME/.hermes-home"
247
- EOF
248
- ok "Added 'export HERMES_HOME=$HOME_DIR' to $SHELL_RC"
249
-
250
  # ----------------------------------------------------------------------------
251
  # 11. Summary + launch
252
  # ----------------------------------------------------------------------------
@@ -263,7 +278,8 @@ ${G}✓ Ready.${N}
263
  ${C}hermes gateway run${N} — start Telegram bot in the foreground (Ctrl-C to stop)
264
  ${C}hermes gateway install${N} && ${C}hermes gateway start${N} — run gateway as a background service
265
 
266
- Open a new shell (or run ${C}source $SHELL_RC${N}) so HERMES_HOME is picked up automatically.
 
267
 
268
  EOF
269
 
 
215
  ok "Secrets saved to $SECRETS (mode 600)"
216
 
217
  # ----------------------------------------------------------------------------
218
+ # 10. Patch the hermes entrypoint so HERMES_HOME defaults to the shadow dir
219
  # ----------------------------------------------------------------------------
220
+ # Shell-rc exports require users to source/relaunch. Patching the launcher at
221
+ # ~/.local/bin/hermes makes plain `hermes` and `hermes gateway` Just Work in
222
+ # *any* shell, immediately, no sourcing. If a user explicitly sets HERMES_HOME
223
+ # (e.g. for a profile), that wins via :=.
224
+ HERMES_BIN="$HOME/.local/bin/hermes"
225
+ if [ -f "$HERMES_BIN" ] && ! grep -q "HERMES_HOME:=" "$HERMES_BIN"; then
226
+ python3 - "$HERMES_BIN" "$HOME_DIR" <<'PY'
227
+ import sys, pathlib
228
+ bin_path, home_dir = sys.argv[1], sys.argv[2]
229
+ p = pathlib.Path(bin_path)
230
+ lines = p.read_text().splitlines(keepends=True)
231
+ # Find the exec line and inject defaults right before it
232
+ out = []
233
+ injected = False
234
+ for line in lines:
235
+ if not injected and line.lstrip().startswith("exec "):
236
+ out.append(f': "${{HERMES_HOME:={home_dir}}}"\n')
237
+ out.append("export HERMES_HOME\n")
238
+ injected = True
239
+ out.append(line)
240
+ p.write_text("".join(out))
241
+ PY
242
+ ok "Patched $HERMES_BIN so 'hermes' defaults to HERMES_HOME=$HOME_DIR"
243
+ else
244
+ ok "$HERMES_BIN already patched (or not found)"
245
+ fi
246
+
247
+ # Clean up any prior shell-rc block from older bootstrap versions
248
  SHELL_NAME="${SHELL##*/}"
249
  case "$SHELL_NAME" in
250
  zsh) SHELL_RC="$HOME/.zshrc" ;;
251
  bash) SHELL_RC="$HOME/.bashrc" ;;
252
  *) SHELL_RC="$HOME/.profile" ;;
253
  esac
 
 
254
  if [ -f "$SHELL_RC" ] && grep -q "# hermes-bucket" "$SHELL_RC"; then
255
  python3 - "$SHELL_RC" <<'PY'
256
  import sys, pathlib, re
257
  p = pathlib.Path(sys.argv[1])
258
  text = p.read_text()
 
259
  new = re.sub(r"\n*# hermes-bucket[^\n]*\n(?:[^\n]*\n)*?(?=\n|\Z)", "\n", text)
260
  p.write_text(new)
261
  PY
262
+ ok "Removed legacy hermes-bucket block from $SHELL_RC"
263
  fi
264
 
 
 
 
 
 
 
 
 
265
  # ----------------------------------------------------------------------------
266
  # 11. Summary + launch
267
  # ----------------------------------------------------------------------------
 
278
  ${C}hermes gateway run${N} — start Telegram bot in the foreground (Ctrl-C to stop)
279
  ${C}hermes gateway install${N} && ${C}hermes gateway start${N} — run gateway as a background service
280
 
281
+ These work in any shell no sourcing, no aliases. The hermes launcher
282
+ itself now defaults HERMES_HOME to $HOME_DIR.
283
 
284
  EOF
285