#!/usr/bin/env bash # ─< Check if the given command exists silently >───────────────────────────────────────── command_exists() { command -v "$@" >/dev/null 2>&1 } # WHY: # This import will give you the following variables: # _sudo="sudo -E" <- only if non root user # distro = # arch = bool # fedora = bool # opensuse = bool.... # You can then use it for, `if $arch; then` # Also this gives you the _install command, which installs a package pased on the packagemanager/distro used. # CAUTION: # This only wokrs for generic package names, like neovim, or vim, or tmux etc.. # not every package packagemanager has the same packagenames for their packages.. getImports() { i="https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh" import="$(mktemp)" echo "importing $i into $import" if command_exists curl; then curl -fsSL $i -o $import elif command_exists wget; then wget $i -o $import else echo "curl/wget is required, but missing.." exit 1 fi source "$import" sleep 0.3 rm "$import" && echo_warning "cleaned $import" } init_docker() { if command -v docker >/dev/null 2>&1; then echo_info "Docker was installed correctly. Do you want to add $(whoami) to the docker group? (y/n)" read -r dgroup /dev/null echo_info "Addet repository. Updating and installing now.." sleep 1 $_sudo apt-get update checkAndInstall "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin" else echo_info "executing trixie.." _install docker.io docker-compose fi } _ubuntu() { echo_info "executing ubuntu" sleep 2 $_sudo apt-get update && $_sudo apt-get install -y ca-certificates curl && $_sudo install -m 0755 -d /etc/apt/keyrings && $_sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && $_sudo chmod a+r /etc/apt/keyrings/docker.asc echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | $_sudo tee /etc/apt/sources.list.d/docker.list >/dev/null echo_info "Addet repository. Updating and installing now.." sleep 0.5 $_sudo apt-get update checkAndInstall "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin" } _fedora() { echo_info "executing fedora" sleep 2 _install dnf-plugins-core $_sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo checkAndInstall "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin" } main() { case "$distro" in arch) _arch ;; debian) _debian ;; ubuntu) _ubuntu ;; fedora) _fedora ;; *) echo "$distro is not supported by this script" ;; esac } if getImports; then case "$1" in --silent | -s) echo_warning "Executing silently!" echo_info "Executing $distro" case "$distro" in arch) silentexec _arch ;; debian) silentexec _debian ;; ubuntu) silentexec _ubuntu ;; fedora) silentexec _fedora ;; *) echo "$distro is not supported by this script" exit 1 ;; esac init_docker ;; *) if main; then init_docker fi ;; esac fi