#!/usr/bin/env sh # # Custom functions for debian-like systems. # # Machine architecture trashman_debian_arch() { local arch="`uname -m`" # Fix arch if [ "$arch" = "x86_64" ]; then arch="amd64" fi echo $arch } # Check if package is installed trashman_apt_check() { if [ -z "$1" ]; then return fi #dpkg -s $1 > /dev/null 2>&1 # See https://stackoverflow.com/questions/1298066/check-if-a-package-is-installed-and-then-install-it-if-its-not#1298103 dpkg-query -W -f='${Status}' $1 > /dev/null 2>&1 | grep -q '^install ok' return $? } trashman_apt_update() { $SUDO apt-get update } trashman_apt_install() { if [ -z "$1" ]; then return fi trashman_apt_update local install="" for package in $*; do if ! trashman_apt_check $package; then install="$install $package" fi done LC_ALL=C DEBIAN_FRONTEND=noninteractive $SUDO apt-get install -y $install || exit 1 } # Install an apt repository key trashman_install_apt_key() { local orig="$1" local dest="$2" local base_dest="$3" if [ ! -e "$orig" ]; then exit 1 fi if [ -z "$base_dest" ]; then base_dest="/etc/apt/trusted.gpg.d" fi $SUDO cp $orig $base_dest/$dest || exit 1 $SUDO chown root.root $base_dest/$dest && $SUDO chmod 644 $base_dest/$dest || exit 1 } # Determine Debian major version name trashman_debian_major_version_name() { if [ ! -e "/etc/debian_version" ]; then return 1 fi local number="`cut -d . -f 1 /etc/debian_version`" if [ "$number" = "12" ]; then echo "bookworm" elif [ "$number" = "11" ]; then echo "bullseye" elif [ "$number" = "10" ]; then echo "buster" elif [ "$number" = "9" ]; then echo "stretch" fi }