-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
60 lines (50 loc) · 1.54 KB
/
Copy pathinstall.sh
File metadata and controls
60 lines (50 loc) · 1.54 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
#!/usr/bin/env bash
# Bash history installer. Runs as root.
# - Drops history configuration into /etc/profile.d/ so every interactive shell
# (login and non-login) picks it up.
# - Strips the skeleton ~/.bashrc history block so it cannot override system values.
# - Registers .bash_history with home-persist so it survives workspace rebuilds.
set -eo pipefail
cat > /etc/profile.d/bash-history.sh <<'PROF'
if [ -z "${__BASH_HIST_CONFIGURED:-}" ]; then
__BASH_HIST_CONFIGURED=1
HISTCONTROL=ignoreboth
HISTSIZE=10000
HISTFILESIZE=20000
shopt -s histappend
PROMPT_COMMAND="${PROMPT_COMMAND:+${PROMPT_COMMAND};}history -a; history -n"
fi
PROF
patch_bashrc() {
local file="$1"
[ -f "$file" ] || return 0
sed -i '/^# .*history/d' "$file"
if grep -q '^HISTCONTROL=' "$file"; then
sed -i 's/^HISTCONTROL=.*/HISTCONTROL=ignoreboth/' "$file"
else
echo 'HISTCONTROL=ignoreboth' >> "$file"
fi
if grep -q '^HISTSIZE=' "$file"; then
sed -i 's/^HISTSIZE=.*/HISTSIZE=10000/' "$file"
else
echo 'HISTSIZE=10000' >> "$file"
fi
if grep -q '^HISTFILESIZE=' "$file"; then
sed -i 's/^HISTFILESIZE=.*/HISTFILESIZE=20000/' "$file"
else
echo 'HISTFILESIZE=20000' >> "$file"
fi
if grep -q '^shopt -s histappend' "$file"; then
sed -i '/^shopt -s histappend/d' "$file"
fi
}
patch_bashrc /etc/skel/.bashrc
home="${_REMOTE_USER:+/home/${_REMOTE_USER}}"
[ -n "$home" ] && patch_bashrc "$home/.bashrc"
mkdir -p /etc/home-persist.d
cat > /etc/home-persist.d/bash.json <<'EOF'
{
"source": "bash",
"paths": [".bash_history"]
}
EOF