#!/usr/bin/env bash set -euo pipefail if [[ "${EUID}" -ne 0 ]]; then echo "Kjør som root: sudo bash $0" exit 1 fi 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="# >>> dotfiles (managed) >>>" MARKER_END="# <<< dotfiles (managed) <<<" # Ensure required packages are installed (no prompt) missing_pkgs=() if ! command -v figlet >/dev/null 2>&1; then missing_pkgs+=("figlet") fi if ! command -v lolcat >/dev/null 2>&1 && [[ ! -x /usr/games/lolcat ]]; then missing_pkgs+=("lolcat") fi if ! command -v landscape-sysinfo >/dev/null 2>&1; then missing_pkgs+=("landscape-common") fi if ((${#missing_pkgs[@]} > 0)); then if command -v apt-get >/dev/null 2>&1; then apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y "${missing_pkgs[@]}" elif command -v dnf >/dev/null 2>&1; then dnf install -y "${missing_pkgs[@]}" elif command -v yum >/dev/null 2>&1; then yum install -y "${missing_pkgs[@]}" elif command -v pacman >/dev/null 2>&1; then pacman -Sy --noconfirm "${missing_pkgs[@]}" elif command -v zypper >/dev/null 2>&1; then zypper -n in "${missing_pkgs[@]}" else echo "Fant ingen støttet pakkehåndterer for å installere: ${missing_pkgs[*]}" exit 1 fi fi # Prompt for punchline (stored globally) current_punchline="Hello" if [[ -r /etc/ps1-punchline ]]; then current_punchline="$(head -n 1 /etc/ps1-punchline 2>/dev/null || echo "Hello")" current_punchline="${current_punchline%%$'\r'}" fi if [[ -t 0 ]]; then echo "Punchline (enter for å beholde eksisterende):" read -r -p "> " new_punchline else new_punchline="" fi if [[ -n "${new_punchline}" ]]; then printf '%s\n' "${new_punchline}" > /etc/ps1-punchline else printf '%s\n' "${current_punchline}" > /etc/ps1-punchline fi chmod 0644 /etc/ps1-punchline # Copy modules cp -f "$SRC_PS1" "$DST_PS1" chmod 0644 "$DST_PS1" cp -f "$SRC_BANNER" "$DST_BANNER" chmod 0644 "$DST_BANNER" # Ensure /etc/bash.bashrc sources both (idempotent) tmp="$(mktemp)" orig_mode="$(stat -c '%a' "$BASH_BASHRC")" orig_owner="$(stat -c '%u' "$BASH_BASHRC")" orig_group="$(stat -c '%g' "$BASH_BASHRC")" awk -v s="$MARKER_START" -v e="$MARKER_END" ' $0==s {inside=1; next} $0==e {inside=0; next} !inside {print} ' "$BASH_BASHRC" > "$tmp" cat >> "$tmp" </dev/null 2>&1; then restorecon "$BASH_BASHRC" >/dev/null 2>&1 || true fi rm -f "$tmp" echo "✅ Installert globalt (Linux/WSL):" echo " - $DST_PS1" echo " - $DST_BANNER" echo " - sourcet fra $BASH_BASHRC" echo echo "Åpne et nytt shell for å se endringene." echo echo "Disable per bruker:" echo " export DISABLE_GLOBAL_PS1=1" 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"