This commit is contained in:
2026-01-24 05:25:45 +00:00
parent 73c54192f7
commit ee39628557
3 changed files with 81 additions and 132 deletions

View File

@@ -1,119 +0,0 @@
#!/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."

58
dotfiles/banner/banner.sh Normal file
View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Banner module (global/user). Runs once per login session.
case "$-" in
*i*) ;;
*) return 0 ;;
esac
# Disable switch (per-user/per-shell)
# 1) env: DISABLE_GLOBAL_BANNER=1
# 2) file: ~/.config/ps1/disable-banner
if [[ "${DISABLE_GLOBAL_BANNER:-0}" == "1" ]]; then
return 0
fi
if [[ -f "$HOME/.config/ps1/disable-banner" ]]; then
return 0
fi
# Run banner only once per session
if [[ -n "${__BANNER_ALREADY_SHOWN:-}" ]]; then
return 0
fi
__BANNER_ALREADY_SHOWN=1
# Find tools (be defensive)
FIGLET="$(command -v figlet 2>/dev/null || true)"
LANDSCAPE="$(command -v landscape-sysinfo 2>/dev/null || true)"
# lolcat is often /usr/games/lolcat on Ubuntu
if [[ -x /usr/games/lolcat ]]; then
LOLCAT="/usr/games/lolcat"
else
LOLCAT="$(command -v lolcat 2>/dev/null || true)"
fi
# If lolcat missing, fallback to cat (no color)
if [[ -z "${LOLCAT:-}" ]]; then
LOLCAT="cat"
fi
# Punchline source:
# - global file: /etc/ps1-punchline
# - fallback: "Hello"
PUNCHLINE="Hello"
if [[ -r /etc/ps1-punchline ]]; then
PUNCHLINE="$(cat /etc/ps1-punchline 2>/dev/null || echo "Hello")"
fi
# Print banner (only if figlet exists)
if [[ -n "${FIGLET:-}" ]]; then
"$FIGLET" "$(hostname)" -c | "$LOLCAT"
"$FIGLET" -f digital "$PUNCHLINE" -c | "$LOLCAT"
fi
# Print sysinfo if available (Linux)
if [[ -n "${LANDSCAPE:-}" ]]; then
"$LANDSCAPE" | "$LOLCAT"
fi

View File

@@ -10,21 +10,24 @@ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SRC_PS1="$REPO_ROOT/ps1/ps1.sh"
SRC_BANNER="$REPO_ROOT/banner/banner.sh"
DST_PS1="/etc/profile.d/ps1.sh"
DST_BANNER="/etc/profile.d/banner.sh"
BASH_BASHRC="/etc/bash.bashrc"
MARKER_START="# >>> global ps1 (managed) >>>"
MARKER_END="# <<< global ps1 (managed) <<<"
if [[ ! -r "$SRC_PS1" ]]; then
echo "Fant ikke $SRC_PS1"
exit 1
fi
MARKER_START="# >>> dotfiles (managed) >>>"
MARKER_END="# <<< dotfiles (managed) <<<"
# Copy modules
cp -f "$SRC_PS1" "$DST_PS1"
chmod 0644 "$DST_PS1"
# Ensure /etc/bash.bashrc sources it (idempotent)
cp -f "$SRC_BANNER" "$DST_BANNER"
chmod 0644 "$DST_BANNER"
# Ensure /etc/bash.bashrc sources both (idempotent)
tmp="$(mktemp)"
awk -v s="$MARKER_START" -v e="$MARKER_END" '
$0==s {inside=1; next}
@@ -37,17 +40,24 @@ rm -f "$tmp"
cat >> "$BASH_BASHRC" <<EOF
$MARKER_START
# Load global PS1 (managed)
# Load PS1 + Banner (managed)
if [ -r "$DST_PS1" ]; then
. "$DST_PS1"
fi
if [ -r "$DST_BANNER" ]; then
. "$DST_BANNER"
fi
$MARKER_END
EOF
echo "✅ Linux/WSL global PS1 installert:"
echo " $DST_PS1"
echo " og sourcet fra $BASH_BASHRC"
echo "✅ Installert globalt (Linux/WSL):"
echo " - $DST_PS1"
echo " - $DST_BANNER"
echo " - sourcet fra $BASH_BASHRC"
echo
echo "Disable per bruker:"
echo " export DISABLE_GLOBAL_PS1=1"
echo " eller touch ~/.config/ps1/disable"
echo " export DISABLE_GLOBAL_BANNER=1"
echo " eller:"
echo " mkdir -p ~/.config/ps1 && touch ~/.config/ps1/disable # disable PS1"
echo " mkdir -p ~/.config/ps1 && touch ~/.config/ps1/disable-banner # disable banner"