#!/usr/bin/env bash deplist=() # ─< Check if the given command exists silently >───────────────────────────────────────── command_exists() { command -v "$@" >/dev/null 2>&1 } source-script() { local url="$1" local import="$(mktemp)" if command_exists curl; then curl -fsSL $url -o $import elif command_exists wget; then wget -o $import $url else echo "curl/wget is required, but missing.." exit 69 fi . "$import" sleep 0.1 rm -f "$import" } spin-get-dependencies() { line spin grey "Getting dependencies.." # INFO: # ╭─────────────────────────────────────────────────────────────────────────╮ # │ You can define dependencies for various linux distros here. It will │ # │ automagically be pulled via the $pkgArray[$distro] variable │ # ╰─────────────────────────────────────────────────────────────────────────╯ depsDebian=(git neofetch waybar wlogout g++ build-essentials) depsFedora=(git neofetch waybar wlogout) depsOpensuse=(git neofetch waybar wlogout) depsArch=(git neofetch waybar wlogout firefox-esr base-devel) depsAlpine=(git neofetch waybar wlogout) # declare -A deplist declare -A deps=( [debian]="depsDebian" [ubuntu]="depsDebian" [fedora]="depsFedora" [arch]="depsArch" [alpine]="depsAlpine" [opensuse]="depsOpensuse" ) # INFO: # ╭────────────────────────────────────────────────────────────────╮ # │ This variable stores the packages you provided for each distro │ # ╰────────────────────────────────────────────────────────────────╯ declare -n pkgArray="${deps[$distro]}" case "$distro" in debian | ubuntu | arch | fedora | alpine | opensuse) for pkg in "${pkgArray[@]}"; do if ! command_exists $pkg; then deplist+=("$pkg") fi done check "pkglist: ${deplist[*]}" line # pen red "$deplist" # pkglist=${deplist[@]} # for dep in "${deplist[@]}"; do # pen bold grey "Dep: $dep" # done # spin-installation "${deplist[@]}" # for pk in "${pkglist[@]}"; do # pen bold red "Pkg: $pk" # done # line # exit 1 ;; *) echo_error "There are no dependencies to install for $distro" return 69 ;; esac } # spin-installation() { # local err out # local pkgs="$@" # # for pkg in "${pkgs[@]}"; do # spin bold yellow "Installing $pkg" # if run --err err --out out pkg-install "$pkg"; then # check "Installed $pkg" # line # else # throw "$pkg could not get installed.." # echo_error "${err:-}" # echo_note "${out:-}" # line # fi # done # } main() { local err out if spin-get-dependencies; then check "Dependency list generated!" pen red bold "There are ${#deplist[@]} items to install.." # local pkgs="$@" for ((i = 0; i < "${#deplist[@]}"; i++)); do for pkg in "${deplist[@]}"; do spin bold yellow "Installing $pkg" if run --err err --out out pkg-install "$pkg"; then check "Installed $pkg" line else check "$pkg could not get installed.." echo_error "${err:-}" echo_note "${out:-}" line continue fi done done check "debug" else throw "Dependencies could not get generated!" exit 69 fi if confirm "Do you want to remove all installed packages?"; then for pkg in "${deplist[@]}"; do spin bold red "Removing $pkg" if run --err err --out out pkg-remove "$pkg"; then check "Removed $pkg" line else check "$pkg could not get removed.." echo_error "${err:-}" echo_note "${out:-}" line continue fi done check "debug" fi # case "$distro" in # arch) # pen bold blue "This is Arch!" # ;; # debian) # pen bold red "This is Debian!" # ;; # ubuntu) # pen bold orange "This is Ubuntu!" # ;; # fedora) # pen blue "This is Fedora!" # ;; # alpine) # pen italic blue "This is Alpine!" # ;; # opensuse) # pen green bold "This is OpenSuse!" # ;; # *) # echo "$distro is not supported by this script!" # exit 1 # ;; # esac # source_script "https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh" check "Complete!" } beddu=https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh pika=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh if source-script $pika && source-script $beddu; then # ─< package variable >─────────────────────────────────────────────────────────────────── unset PACKAGE # ─< argument list variables >──────────────────────────────────────────────────────────── silent=false sleep 0.1 # ─< parse arguments and get variable contents >────────────────────────────────────────── for arg in "$@"; do case "$arg" in --silent | -s) export silent=true ;; esac done main fi