addet more tests..

This commit is contained in:
pika 2025-05-23 21:26:15 +02:00
parent b1c9ecf661
commit 9872177bd3

258
test.sh Executable file → Normal file
View file

@ -1,12 +1,24 @@
#!/usr/bin/env bash
deplist=()
{
#!/usr/bin/env bash
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
}
source-script() {
# WHY:
# This import will give you the following variables:
# _sudo="sudo -E" <- only if non root user
# distro = <distro name, like 'arch', 'debian', 'fedora'..>
# 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() {
local url="$1"
local import="$(mktemp)"
if command_exists curl; then
@ -20,208 +32,70 @@ source-script() {
. "$import"
sleep 0.1
rm -f "$import"
}
}
spin-get-dependencies() {
line
ask-stuff() {
choose multiplexer "Select a multiplexer" tmux zellij </dev/tty
choose menu "Select a menu package" rofi wofi tofi </dev/tty
choose shell "Select a shell" zsh bash fish nushell </dev/tty
spin grey "Getting dependencies.."
stuff=(
$multiplexer
$menu
$shell
$package
)
}
# 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 base-devel)
depsAlpine=(git neofetch waybar wlogout)
install-stuff() {
ask-stuff
local err
# declare -A deplist
declare -A deps=(
[debian]="depsDebian"
[ubuntu]="depsDebian"
[fedora]="depsFedora"
[arch]="depsArch"
[alpine]="depsAlpine"
[opensuse]="depsOpensuse"
arr=(
nautilus
firefox-esr
)
# INFO:
# ╭────────────────────────────────────────────────────────────────╮
# │ This variable stores the packages you provided for each distro │
# ╰────────────────────────────────────────────────────────────────╯
declare -n pkgArray="${deps[$distro]}"
check-and-install ${arr[@]} ${stuff[@]}
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[*]}"
if confirm "Do you want to remove the previous installed (doesn't inclued the stuff you put in yourself) packages?"; then
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?" </dev/tty; then
for pkg in "${deplist[@]}"; do
spin bold red "Removing $pkg"
if run --err err --out out pkg-remove "$pkg"; then
pen grey bold "Packages to remove: $(pen bold red ${#arr[@]})"
for pkg in "${arr[@]}"; do
spin "Removing $pkg"
if run --err err pkg-remove $pkg; then
upclear
check "Removed $pkg"
line
else
check "$pkg could not get removed.."
echo_error "${err:-}"
echo_note "${out:-}"
line
continue
upclear
throw "Error removing $pkg"
echo-error "${err:-}"
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"
main() {
seek package "What packages should also get installed? space separated list.." </dev/tty
if confirm "Do you want to 'install-stuff'?" </dev/tty; then
line
install-stuff
fi
# for i in {3..6}; do
# spin grey "Testing $i seconds.."
# if sleep $i; then
# upclear
# check green bold "Successfully waited $i seconds!"
# # line
# fi
# done
check "Complete!"
}
}
setup-env() {
local beddu=https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh
local pika=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh
if ! command_exists pen && ! command_exists spin; then
source-script $pika
source-script $beddu
dream="https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh"
if getImports "$dream"; then
main
fi
}
if setup-env; then
# ─< package variable >───────────────────────────────────────────────────────────────────
unset PACKAGE
if command_exists pen; then
pen green bold "Pen exists"
else
pen red bold "Pen does not exist"
fi
if command_exists spin; then
pen green bold "spin does exist"
else
pen red bold "spin doesn't exist"
fi
# ─< 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