1
This commit is contained in:
@@ -20,63 +20,86 @@ BASH_BASHRC="/etc/bash.bashrc"
|
|||||||
MARKER_START="# >>> dotfiles (managed) >>>"
|
MARKER_START="# >>> dotfiles (managed) >>>"
|
||||||
MARKER_END="# <<< dotfiles (managed) <<<"
|
MARKER_END="# <<< dotfiles (managed) <<<"
|
||||||
|
|
||||||
# Ensure required packages are installed (no prompt)
|
# Select install mode (PS1, banner, or both)
|
||||||
missing_pkgs=()
|
install_ps1=1
|
||||||
if ! command -v figlet >/dev/null 2>&1; then
|
install_banner=1
|
||||||
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
|
if [[ -t 0 ]]; then
|
||||||
echo "Punchline (enter for å beholde eksisterende):"
|
echo "Installer valg:"
|
||||||
read -r -p "> " new_punchline
|
echo " 1) Kun PS1"
|
||||||
else
|
echo " 2) Kun banner"
|
||||||
new_punchline=""
|
echo " 3) Begge (PS1 + banner)"
|
||||||
|
read -r -p "Velg [3]: " install_choice
|
||||||
|
case "${install_choice}" in
|
||||||
|
1) install_ps1=1; install_banner=0 ;;
|
||||||
|
2) install_ps1=0; install_banner=1 ;;
|
||||||
|
""|3) install_ps1=1; install_banner=1 ;;
|
||||||
|
*) echo "Ugyldig valg, bruker begge."; install_ps1=1; install_banner=1 ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${new_punchline}" ]]; then
|
if [[ "$install_banner" -eq 1 ]]; then
|
||||||
printf '%s\n' "${new_punchline}" > /etc/ps1-punchline
|
# Ensure required packages are installed (no prompt)
|
||||||
else
|
missing_pkgs=()
|
||||||
printf '%s\n' "${current_punchline}" > /etc/ps1-punchline
|
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
|
||||||
fi
|
fi
|
||||||
chmod 0644 /etc/ps1-punchline
|
|
||||||
|
|
||||||
# Copy modules
|
# Copy modules
|
||||||
cp -f "$SRC_PS1" "$DST_PS1"
|
if [[ "$install_ps1" -eq 1 ]]; then
|
||||||
chmod 0644 "$DST_PS1"
|
cp -f "$SRC_PS1" "$DST_PS1"
|
||||||
|
chmod 0644 "$DST_PS1"
|
||||||
|
fi
|
||||||
|
|
||||||
cp -f "$SRC_BANNER" "$DST_BANNER"
|
if [[ "$install_banner" -eq 1 ]]; then
|
||||||
chmod 0644 "$DST_BANNER"
|
cp -f "$SRC_BANNER" "$DST_BANNER"
|
||||||
|
chmod 0644 "$DST_BANNER"
|
||||||
|
fi
|
||||||
|
|
||||||
# Ensure /etc/bash.bashrc sources both (idempotent)
|
# Ensure /etc/bash.bashrc sources both (idempotent)
|
||||||
tmp="$(mktemp)"
|
tmp="$(mktemp)"
|
||||||
@@ -93,12 +116,18 @@ cat >> "$tmp" <<EOF
|
|||||||
|
|
||||||
$MARKER_START
|
$MARKER_START
|
||||||
# Load PS1 + Banner (managed)
|
# Load PS1 + Banner (managed)
|
||||||
if [ -r "$DST_PS1" ]; then
|
$(if [[ "$install_ps1" -eq 1 ]]; then cat <<'INNER'
|
||||||
. "$DST_PS1"
|
if [ -r "/etc/profile.d/ps1.sh" ]; then
|
||||||
|
. "/etc/profile.d/ps1.sh"
|
||||||
fi
|
fi
|
||||||
if [ -r "$DST_BANNER" ]; then
|
INNER
|
||||||
. "$DST_BANNER"
|
fi)
|
||||||
|
$(if [[ "$install_banner" -eq 1 ]]; then cat <<'INNER'
|
||||||
|
if [ -r "/etc/profile.d/banner.sh" ]; then
|
||||||
|
. "/etc/profile.d/banner.sh"
|
||||||
fi
|
fi
|
||||||
|
INNER
|
||||||
|
fi)
|
||||||
$MARKER_END
|
$MARKER_END
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -109,8 +138,12 @@ fi
|
|||||||
rm -f "$tmp"
|
rm -f "$tmp"
|
||||||
|
|
||||||
echo "✅ Installert globalt (Linux/WSL):"
|
echo "✅ Installert globalt (Linux/WSL):"
|
||||||
echo " - $DST_PS1"
|
if [[ "$install_ps1" -eq 1 ]]; then
|
||||||
echo " - $DST_BANNER"
|
echo " - $DST_PS1"
|
||||||
|
fi
|
||||||
|
if [[ "$install_banner" -eq 1 ]]; then
|
||||||
|
echo " - $DST_BANNER"
|
||||||
|
fi
|
||||||
echo " - sourcet fra $BASH_BASHRC"
|
echo " - sourcet fra $BASH_BASHRC"
|
||||||
echo
|
echo
|
||||||
echo "Åpne et nytt shell for å se endringene."
|
echo "Åpne et nytt shell for å se endringene."
|
||||||
|
|||||||
Reference in New Issue
Block a user