Zion Boggan
repos/Darwin/ingest/setup-bash-history-flush.sh
zionboggan.com ↗
49 lines · bash
History for this file →
1
 
2
set -Eeuo pipefail
3
 
4
FLUSH_SNIPPET='# Darwin: flush bash history after every command
5
export HISTFILE="${HISTFILE:-$HOME/.bash_history}"
6
export HISTFILESIZE=100000
7
export HISTSIZE=10000
8
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }history -a"'
9
 
10
install_on_ct() {
11
  local host="$1"
12
  local label="$2"
13
  echo "=== Installing history flush on $label ($host) ==="
14
 
15
  if [ "$host" = "localhost" ]; then
16
    local dest="/etc/profile.d/darwin-history-flush.sh"
17
    if [ -f "$dest" ]; then
18
      echo "  Already installed at $dest - skipping"
19
    else
20
      printf '%s\n' "$FLUSH_SNIPPET" > "$dest"
21
      chmod 644 "$dest"
22
      echo "  Installed at $dest"
23
    fi
24
  else
25
    ssh -o BatchMode=yes -o ConnectTimeout=8 -o StrictHostKeyChecking=accept-new \
26
      root@"$host" bash -s <<'REMOTE'
27
FLUSH_SNIPPET='# Darwin: flush bash history after every command
28
export HISTFILE="${HISTFILE:-$HOME/.bash_history}"
29
export HISTFILESIZE=100000
30
export HISTSIZE=10000
31
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }history -a"'
32
dest="/etc/profile.d/darwin-history-flush.sh"
33
if [ -f "$dest" ]; then
34
  echo "  Already installed at $dest - skipping"
35
else
36
  printf '%s\n' "$FLUSH_SNIPPET" > "$dest"
37
  chmod 644 "$dest"
38
  echo "  Installed at $dest"
39
fi
40
REMOTE
41
  fi
42
}
43
 
44
install_on_ct "localhost" "CT215"
45
install_on_ct "REDACTED-IP" "CT241"
46
 
47
echo ""
48
echo "Done. New login shells on each CT will now flush bash_history live."
49
echo "Existing sessions: run 'source /etc/profile.d/darwin-history-flush.sh' to activate."