From ee39628557b081a6a552a4e7e68bc5b5c2a92e44 Mon Sep 17 00:00:00 2001 From: steffen Date: Sat, 24 Jan 2026 05:25:45 +0000 Subject: [PATCH] . --- bannerscript.sh | 119 ----------------------- dotfiles/banner/banner.sh | 58 +++++++++++ dotfiles/install/install-linux-global.sh | 36 ++++--- 3 files changed, 81 insertions(+), 132 deletions(-) delete mode 100644 bannerscript.sh create mode 100644 dotfiles/banner/banner.sh diff --git a/bannerscript.sh b/bannerscript.sh deleted file mode 100644 index 8a5a8db..0000000 --- a/bannerscript.sh +++ /dev/null @@ -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/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." diff --git a/dotfiles/banner/banner.sh b/dotfiles/banner/banner.sh new file mode 100644 index 0000000..a700e00 --- /dev/null +++ b/dotfiles/banner/banner.sh @@ -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 diff --git a/dotfiles/install/install-linux-global.sh b/dotfiles/install/install-linux-global.sh index 698f0bb..e3bc7a5 100644 --- a/dotfiles/install/install-linux-global.sh +++ b/dotfiles/install/install-linux-global.sh @@ -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" <