#!/usr/bin/env bash # ─< Check if the given command exists silently >───────────────────────────────────────── command-exists() { command -v "$@" >/dev/null 2>&1 } # ─< Check if the user is root and set sudo variable if necessary >─────────────────────── check_root() { if [ "$(id -u)" -ne 0 ]; then if command-exists sudo; then echo "User is not root. Using sudo for privileged operations." _sudo="sudo -E" else echo "No sudo found and you're not root! Can't install packages." return 1 fi else echo "Root access confirmed." _sudo="" fi } get-packager() { local packagers packagers=( apt dnf pacman zypper apk ) for packager in "${packagers[@]}"; do if command-exists $packager; then case $packager in apt) pkg-install() { if command-exists nala; then $_sudo nala install --assume-yes "$@" else $_sudo apt install --assume-yes "$@" fi } ;; dnf) pkg-install() { $_sudo dnf -y install "$@" } ;; pacman) pkg-install() { if command-exists paru; then paru --noconfirm -S "$@" elif command-exists yay; then yay --noconfirm -S "$@" else $_sudo pacman --noconfirm -S "$@" fi } ;; zypper) pkg-install() { $_sudo zypper install "$@" } ;; apk) pkg-install() { $_sudo apk add "$@" } ;; esac fi done } source-script() { i="$1" import="$(mktemp)" if command-exists curl; then curl -fsSL $i -o $import else echo "curl is required, but missing.." exit 1 fi source "$import" sleep 0.3 rm "$import" } script-exists() { local install_url=https://git.k4li.de/scripts/installs/raw/branch/main local script_url for pkg in "$@"; do script_url="${install_url}/${pkg}.sh" if curl -fsSL $script_url 2>/dev/null; then return 0 else return 69 fi done } install-func() { local pkg for pkg in "$@"; do if script-exists $pkg; then eval "$(curl -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/${pkg}.sh)" else pkg-install "$pkg" fi done exit 0 } help-func() { echo "How to use?" echo echo "pika [argument] [options]" echo "argument=[i|install]" echo "options:" echo "i|install: