No description
Find a file
2025-05-23 20:34:07 +02:00
distros.sh dream.sh 2025-05-23 20:13:15 +02:00
dream.sh wip 2025-05-23 20:34:07 +02:00
LICENSE Initial commit 2025-05-07 10:07:03 +02:00
README.ai.md wip 2025-05-20 21:22:14 +02:00
README.md wip 2025-05-21 10:07:04 +02:00
script-import.sh wip 2025-05-21 17:40:45 +02:00
test.sh wip 2025-05-23 20:17:15 +02:00

imports

distros.sh

Import the script inside your own script like this:

url="https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh"
import="$(mktemp)"
if command_exists curl; then
  curl -fsSL $url -o $import
else
  echo "curl is required, but missing.."
  exit 1
fi

source "$import"
sleep 0.3
rm "$import"

So now that you have imported the distros.sh script, you can run some fancy things in your script..

distro-variables

There are most of the big linux distros as a variable which contains boolean values.
Also there is a 'distros' variable, containing the fancy distro name. More

variable values
$distros One value of arch, debian, ubuntu, fedora, opensuse, alpine
$arch boolean - true/false
$debian boolean - true/false
$ubuntu boolean - true/false
$fedora boolean - true/false
$opensuse boolean - true/false
$alpine boolean - true/false

Some really simple examples

if $arch; then
    echo "This system is using arch!"
elif $debian; then
    echo "This system is using debian!"
fi

or..

case "$distros" in
    ubuntu)
        echo "Using ubuntu!"
    ;;
    arch)
        echo "Using archlinux!"
    ;;
    opensuse)
        echo "Using opensuse!"
    ;;
esac

Package managing functions

There are two big functions here to mention:

  • _install()
  • _checkAndInstall()

_install()

You can simply install a package with the respected packagemanager.

On arch, it will install with either paru, yay or pacman (in this order)
On debian/ubuntu, it will install with either nala or apt-get (in this order)

Fedora, opensuse and alpine will always use their respected packagemanager

Usage:

_install curl

Will install curl

deps=(curl bash git zoxide)

_install "${deps[@]}"

Will install everything in the deps array, but it will install it in one go!

_checkAndInstall()

If you have many packages being installed, you may want to check if they are installed first, and then install them one by one via an array. You can do this easily with the checkAndInstall function. Just pass in an array like ${array[@]} and it will auto check and install the packages in the array list one by one.

deps=(git wget curl vim zsh)
checkAndInstall "${deps[@]}"

This will install the packages one by one, it will basically do..

for pkg in "${deps[@]}"; do
  if ! command_exists $pkg; then
      _install $pkg
  else
      echo "$pkg is already installed"
  fi
done

BONUS:

Since bash v5, you can define declared arrays. Which will make dependency installation for various systems extremely easy:

This is a snippet which i often use with this script sourced..:

  # INFO:
  # ╭─────────────────────────────────────────────────────────────────────────╮
  # │ You can define dependencies for various linux distros here. It will     │
  # │ automagically be pulled via the $pkgArray[$distro] variable             │
  # ╰─────────────────────────────────────────────────────────────────────────╯

  genericDeps=(virt-manager)

  depsDebian=(qemu-system libvirt-dev libvirt-glib-1.0-dev)
  depsFedora=(qemu libvirt)
  depsOpensuse=(qemu libvirt)
  depsArch=(qemu-full libvirt)
  depsAlpine=()

  declare -A deps=(
    [debian]="depsDebian"
    [ubuntu]="depsUbuntu"
    [fedora]="depsFedora"
    [opensuse]="depsOpensuse"
    [arch]="depsArch"
    [alpine]="depsAlpine"
  )

  # INFO:
  # ╭────────────────────────────────────────────────────────────────╮
  # │ This variable stores the packages you provided for each distro │
  # ╰────────────────────────────────────────────────────────────────╯
  declare -n pkgArray="${deps[$distro]}"

  case "$distro" in
  debian | ubuntu | arch | fedora | opensuse)
    echo_info "Installing generic dependencies.."
    checkAndInstall "${genericDeps[@]}"

    echo_info "Installing special dependencies.."
    checkAndInstall "${pkgArray[@]}"
    ;;
  *)
    echo_error "There are no dependencies to install for $distro"
    return 69
    ;;
  esac