120 lines
3.1 KiB
Bash
120 lines
3.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Must be root
|
|
if [[ "${EUID}" -ne 0 ]]; then
|
|
echo "Kjør som root: sudo bash $0"
|
|
exit 1
|
|
fi
|
|
|
|
### 1) Ensure required packages installed
|
|
need_pkgs=(landscape-common figlet lolcat)
|
|
missing=()
|
|
for p in "${need_pkgs[@]}"; do
|
|
if ! dpkg -s "$p" >/dev/null 2>&1; then
|
|
missing+=("$p")
|
|
fi
|
|
done
|
|
|
|
if ((${#missing[@]} > 0)); then
|
|
echo "Installerer manglende pakker: ${missing[*]}"
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update -y
|
|
apt-get install -y "${missing[@]}"
|
|
fi
|
|
|
|
### 2) Ask punchline (clear wording, always from TTY)
|
|
echo
|
|
read -r -p "Skriv ønsket punchline (vises under hostname i banneret): " PUNCHLINE </dev/tty
|
|
if [[ -z "${PUNCHLINE// }" ]]; then
|
|
echo "Punchline kan ikke være tom."
|
|
exit 1
|
|
fi
|
|
|
|
GLOBAL_BASHRC="/etc/bash.bashrc"
|
|
MARKER_START="# >>> global custom bashrc (managed) >>>"
|
|
MARKER_END="# <<< global custom bashrc (managed) <<<"
|
|
|
|
# Backup
|
|
cp -a "$GLOBAL_BASHRC" "${GLOBAL_BASHRC}.backup.$(date +%Y%m%d_%H%M%S)" 2>/dev/null || true
|
|
|
|
# Remove old managed block (if any)
|
|
tmp="$(mktemp)"
|
|
awk -v s="$MARKER_START" -v e="$MARKER_END" '
|
|
$0==s {inside=1; next}
|
|
$0==e {inside=0; next}
|
|
!inside {print}
|
|
' "$GLOBAL_BASHRC" > "$tmp"
|
|
cat "$tmp" > "$GLOBAL_BASHRC"
|
|
rm -f "$tmp"
|
|
|
|
# Append fresh managed block (NO expansion while writing)
|
|
cat >> "$GLOBAL_BASHRC" <<'EOF'
|
|
|
|
# >>> global custom bashrc (managed) >>>
|
|
# Only run in interactive shells
|
|
case "$-" in
|
|
*i*) ;;
|
|
*) return ;;
|
|
esac
|
|
|
|
##### HISTORY / BASICS #####
|
|
HISTCONTROL=ignoreboth
|
|
shopt -s histappend
|
|
HISTSIZE=999999
|
|
HISTFILESIZE=999999
|
|
shopt -s checkwinsize
|
|
|
|
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
|
|
|
##### PROMPT (GLOBAL) #####
|
|
export PS1="\[\e[0m\]\[\e[38;5;35m\]╭─(\[\e[38;5;38m\]\t\[\e[38;5;35m\])-(\[\e[38;5;38m\]\j\[\e[38;5;35m\])-(\[\e[38;5;38m\]\H\[\e[38;5;35m\])-(\[\e[38;5;38m\]\w\[\e[38;5;35m\])\n\[\e[38;5;35m\]╰──🚀 \[\e[0m\]"
|
|
|
|
##### COLORS / ALIASES #####
|
|
if [ -x /usr/bin/dircolors ]; then
|
|
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
|
alias ls='ls --color=auto'
|
|
alias grep='grep --color=auto'
|
|
alias fgrep='fgrep --color=auto'
|
|
alias egrep='egrep --color=auto'
|
|
fi
|
|
|
|
alias ll='ls -alF'
|
|
alias la='ls -A'
|
|
alias l='ls -CF'
|
|
|
|
if [ -f ~/.bash_aliases ]; then
|
|
. ~/.bash_aliases
|
|
fi
|
|
|
|
if ! shopt -oq posix; then
|
|
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
|
. /usr/share/bash-completion/bash_completion
|
|
elif [ -f /etc/bash_completion ]; then
|
|
. /etc/bash_completion
|
|
fi
|
|
fi
|
|
|
|
##### BANNER #####
|
|
LOLCAT="/usr/games/lolcat"
|
|
if [ ! -x "$LOLCAT" ]; then
|
|
LOLCAT="$(command -v lolcat 2>/dev/null || true)"
|
|
fi
|
|
[ -z "$LOLCAT" ] && LOLCAT="cat"
|
|
|
|
figlet "$(hostname)" -c | "$LOLCAT"
|
|
figlet -f digital "__PUNCHLINE__" -c | "$LOLCAT"
|
|
landscape-sysinfo | "$LOLCAT"
|
|
# <<< global custom bashrc (managed) <<<
|
|
|
|
EOF
|
|
|
|
# Replace placeholder with user punchline (safe)
|
|
safe_punchline="$(printf '%s' "$PUNCHLINE" | sed 's/[\/&]/\\&/g')"
|
|
sed -i "s/__PUNCHLINE__/${safe_punchline}/g" "$GLOBAL_BASHRC"
|
|
|
|
echo
|
|
echo "Ferdig ✅"
|
|
echo "Global PS1 + banner er nå aktivt for alle brukere."
|
|
echo "Kjør scriptet på nytt for å endre punchline."
|