#!/usr/bin/env bash
set -euo pipefail
# -------------------------------
# Force clean start for Bash session
# -------------------------------
# Clear any previously cached commands or functions
hash -r
unset -f install_pkg install_section || true
unset CORE_PACKAGES DEV_PACKAGES SCRIPT_PACKAGES VCS_PACKAGES OPTIONAL_TOOLS \
CONTAINERS_PACKAGES DEVOPS_PACKAGES CICD_PACKAGES NET_MON_PACKAGES DB_PACKAGES \
SYSDBG_PACKAGES WEB_PACKAGES DOC_PACKAGES GUI_PACKAGES MATH_PACKAGES SEC_PACKAGES \
FS_PACKAGES PROD_PACKAGES META_PACKAGES || true
# -------------------------------
# Output folder for failed packages
# -------------------------------
FAIL_LOG=~/Documents/fails/setup-failures-$(date +%Y%m%d-%H%M%S).txt
mkdir -p ~/Documents/fails
touch "$FAIL_LOG"
# -------------------------------
# Ensure backports repo is added
# -------------------------------
if ! grep -q "bookworm-backports" /etc/apt/sources.list /etc/apt/sources.list.d/*; then
echo "Adding Bookworm backports repo..."
echo "deb http://deb.debian.org/debian bookworm-backports main" | sudo tee /etc/apt/sources.list.d/backports.list
sudo apt update
fi
# -------------------------------
# Update apt cache
# -------------------------------
sudo apt clean
sudo apt update
# -------------------------------
# Helper function: install a package
# -------------------------------
install_pkg() {
local pkg="$1"
echo -e "\n--- Installing $pkg ---"
if sudo apt install -y "$pkg"; then
echo "$pkg installed successfully."
return 0
fi
# Check if package exists
if apt-cache show "$pkg" > /dev/null 2>&1; then
echo "Package '$pkg' exists but failed to install from main repo."
else
echo "Package '$pkg' does not exist in main repo."
echo "$pkg (non-existent)" >> "$FAIL_LOG"
return 1
fi
# Check backports
if apt-cache -t bookworm-backports show "$pkg" > /dev/null 2>&1; then
echo "Package '$pkg' is available in bookworm-backports."
read -rp "Install $pkg from backports? (Y/n): " ans
ans=${ans:-Y}
if [[ "$ans" =~ ^[Yy]$ ]]; then
if sudo apt -t bookworm-backports install -y "$pkg"; then
echo "$pkg installed from backports successfully."
return 0
else
echo "$pkg (backport install failed)" >> "$FAIL_LOG"
echo "Failed to install $pkg from backports, logged to $FAIL_LOG"
return 1
fi
else
echo "$pkg (backport skipped by user)" >> "$FAIL_LOG"
return 1
fi
else
echo "Package '$pkg' not found in backports."
echo "$pkg (non-existent)" >> "$FAIL_LOG"
return 1
fi
}
# -------------------------------
# Install all packages in a section
# -------------------------------
install_section() {
local -n pkgs=$1
for pkg in "${pkgs[@]}"; do
install_pkg "$pkg" || continue
done
}
# -------------------------------
# Package Sections
# -------------------------------
CORE_PACKAGES=(build-essential dkms linux-headers-$(uname -r) curl wget git vim nano htop neofetch tree lsof zip unzip p7zip-full rsync cron anacron jq yq bc file socat netcat-openbsd nmap tmux screen less ripgrep fd-find fzf bat bash-completion silversearcher-ag aptitude locales-all python3 python3-pip python3-venv)
DEV_PACKAGES=(clang clangd llvm gdb valgrind lldb cmake ninja-build pkg-config autoconf automake libtool make cmake-curses-gui strace ltrace ccache gperf flex bison gettext)
SCRIPT_PACKAGES=(ruby ruby-dev golang rustc cargo nodejs npm openjdk-jdk maven gradle)
VCS_PACKAGES=(git git-lfs gitg gitk mercurial subversion gh tig)
OPTIONAL_TOOLS=(meld diffutils diffstat colordiff)
CONTAINERS_PACKAGES=(docker.io docker-compose podman buildah skopeo qemu-kvm libvirt-daemon-system libvirt-clients virt-manager vagrant vde2 bridge-utils kubectl helm minikube terraform packer ansible)
DEVOPS_PACKAGES=(ansible ansible-lint salt-minion puppet bolt chef-workstation rsnapshot borgbackup restic duplicity rclone rclone-browser tmuxinator)
CICD_PACKAGES=(gitlab-runner jenkins groovy makepasswd)
NET_MON_PACKAGES=(iproute2 iputils-ping net-tools nmap traceroute tcpdump mtr-tiny iftop iptraf-ng curl wget httpie inetutils-tools openssh-server openssh-client autossh whois dnsutils bind9-utils wireguard-tools ethtool iw wpasupplicant telnet socat bmon iotop sysstat dstat vnstat glances lm-sensors htop atop)
DB_PACKAGES=(sqlite3 postgresql postgresql-client mariadb-server redis-server redis-tools mongodb-clients mysql-client pgcli mycli litecli)
SYSDBG_PACKAGES=(sysdig bpftrace bcc-tools perf linux-tools-common linux-perf gdb-multiarch binutils strace ltrace hexedit bless ghex linux-source dwarves pahole libcap-dev libseccomp-dev)
WEB_PACKAGES=(nginx apache2 lighttpd php php-cli php-mbstring php-xml php-json php-sqlite3 python3-flask python3-fastapi uvicorn gunicorn nodejs npm yarnpkg postman gnome-terminal)
DOC_PACKAGES=(pandoc texlive texlive-latex-extra markdown grip asciidoctor doxygen graphviz plantuml)
GUI_PACKAGES=(code geany kate gedit ghex gnome-terminal terminator tilix dconf-editor gparted baobab)
MATH_PACKAGES=(python3-numpy python3-scipy python3-pandas python3-matplotlib python3-jupyter-notebook python3-scikit-learn python3-venv octave gnuplot r-base)
SEC_PACKAGES=(ufw fail2ban lynis clamav clamav-daemon apparmor apparmor-utils openssl gpg pinentry-gtk2 seahorse chkrootkit rkhunter nmap nikto john hashcat)
FS_PACKAGES=(ncdu btrfs-progs xfsprogs e2fsprogs f2fs-tools exfatprogs ntfs-3g partclone partimage rsnapshot timeshift borgbackup rclone)
PROD_PACKAGES=(zsh zsh-autosuggestions zsh-syntax-highlighting fonts-powerline powerline kitty alacritty syncthing flameshot peek)
META_PACKAGES=(build-essential devscripts debhelper fakeroot python3-dev python3-all python3-all-dev default-jdk-headless git-all docker-compose podman kubectl ansible terraform)
# -------------------------------
# Install each section
# -------------------------------
install_section CORE_PACKAGES
install_section DEV_PACKAGES
install_section SCRIPT_PACKAGES
install_section VCS_PACKAGES
install_section OPTIONAL_TOOLS
install_section CONTAINERS_PACKAGES
install_section DEVOPS_PACKAGES
install_section CICD_PACKAGES
install_section NET_MON_PACKAGES
install_section DB_PACKAGES
install_section SYSDBG_PACKAGES
install_section WEB_PACKAGES
install_section DOC_PACKAGES
install_section GUI_PACKAGES
install_section MATH_PACKAGES
install_section SEC_PACKAGES
install_section FS_PACKAGES
install_section PROD_PACKAGES
install_section META_PACKAGES
# -------------------------------
# VSCode Latest
# -------------------------------
if ! [ -f /etc/apt/keyrings/packages.microsoft.gpg ]; then
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/keyrings/packages.microsoft.gpg > /dev/null
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
sudo apt update
fi
install_pkg code || true
# -------------------------------
# Cleanup
# -------------------------------
sudo apt autoremove -y
echo "Installation finished. Check $FAIL_LOG for failed packages."| Associated Context | |
|---|---|
| Type | Code Snippet ( .sh ) |
| Associated Tags | Bash session Clean start Clear previously cached commands or functions Installing a package Updating backports repo Checking for failed packages Check if the package exists and not install from main repo Update apt cache Output folder |
| 💡 Smart Description | This code snippet sets up a bash environment for bash session, clears any previously cached commands or functions. It also checks if the backports repo is added and installs it from another repository using Docker's package-cache command to check if there are no |
| 🔎 Suggested Searches | Updating Bookworm backports from main repo with bash cmd Checking if apt-cache is added on the root directory Bash script to install a package and update backports repo How to force clean start for Bash session in bash command Installing or updating bookworm backports repository using bash commands |
| Related Links | http://deb.debian.org/debian https://packages.microsoft.com/keys/microsoft.asc https://packages.microsoft.com/repos/code https://docs.docker.com/engine/reference/commandline/container_run/ https://docs.docker.com/engine/reference/commandline/restart/ https://docs.docker.com/engine/reference/commandline/exec/ |
| Related People | Morgen |
| Sensitive Information | No Sensitive Information Detected |
| Shareable Link | https://peers8862.pieces.cloud/?p=39fa4c85fc |