installs/test.sh
2025-05-22 13:06:51 +02:00

143 lines
4.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# ─< 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() {
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=(bash zsh curl git neofetch waybar wlogout)
depsFedora=(bash zsh curl git neofetch waybar wlogout)
depsOpensuse=(bash zsh curl git neofetch waybar wlogout)
depsArch=(bash zsh curl git neofetch waybar wlogout)
depsAlpine=(bash zsh curl git neofetch waybar wlogout)
declare -A deplist
local 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
pkglist="${deplist[@]}"
;;
*)
echo_error "There are no dependencies to install for $distro"
return 69
;;
esac
}
# echo default
main() {
local err
if ! spin-get-dependencies; then
throw "Dependencies could not get generated!"
else
check "Dependency list generated!"
spin bold yellow "Installing packagelist.. ${pkglist[@]}"
if run --err err pkg-install "${pkglist[*]}"; then
check "Installed packages!"
else
throw "$(pen bold blue ${pkglist[*]}) could not get installed!"
echo_error "${err:-}"
fi
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"
}
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