addet more tests..

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

296
test.sh Executable file → Normal file
View file

@ -1,227 +1,101 @@
#!/usr/bin/env bash {
deplist=() #!/usr/bin/env bash
# ─< Check if the given command exists silently >───────────────────────────────────────── # ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() { command_exists() {
command -v "$@" >/dev/null 2>&1 command -v "$@" >/dev/null 2>&1
} }
source-script() { # WHY:
local url="$1" # This import will give you the following variables:
local import="$(mktemp)" # _sudo="sudo -E" <- only if non root user
if command_exists curl; then # distro = <distro name, like 'arch', 'debian', 'fedora'..>
curl -fsSL $url -o $import # arch = bool
elif command_exists wget; then # fedora = bool
wget -o $import $url # opensuse = bool....
else # You can then use it for, `if $arch; then`
echo "curl/wget is required, but missing.." # Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
exit 69 # CAUTION:
fi # 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
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" . "$import"
sleep 0.1 sleep 0.1
rm -f "$import"
}
spin-get-dependencies() { rm -f "$import"
line }
spin grey "Getting dependencies.." 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
# INFO: stuff=(
# ╭─────────────────────────────────────────────────────────────────────────╮ $multiplexer
# │ You can define dependencies for various linux distros here. It will │ $menu
# │ automagically be pulled via the $pkgArray[$distro] variable │ $shell
# ╰─────────────────────────────────────────────────────────────────────────╯ $package
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)
# declare -A deplist install-stuff() {
ask-stuff
local err
declare -A deps=( arr=(
[debian]="depsDebian" nautilus
[ubuntu]="depsDebian" firefox-esr
[fedora]="depsFedora" )
[arch]="depsArch"
[alpine]="depsAlpine"
[opensuse]="depsOpensuse"
)
# INFO: check-and-install ${arr[@]} ${stuff[@]}
# ╭────────────────────────────────────────────────────────────────╮
# │ This variable stores the packages you provided for each distro │
# ╰────────────────────────────────────────────────────────────────╯
declare -n pkgArray="${deps[$distro]}"
case "$distro" in if confirm "Do you want to remove the previous installed (doesn't inclued the stuff you put in yourself) packages?"; then
debian | ubuntu | arch | fedora | alpine | opensuse) line
for pkg in "${pkgArray[@]}"; do pen grey bold "Packages to remove: $(pen bold red ${#arr[@]})"
if ! command_exists $pkg; then for pkg in "${arr[@]}"; do
deplist+=("$pkg") spin "Removing $pkg"
fi if run --err err pkg-remove $pkg; then
done upclear
check "Removed $pkg"
else
upclear
throw "Error removing $pkg"
echo-error "${err:-}"
fi
done
fi
}
check "pkglist: ${deplist[*]}" main() {
line seek package "What packages should also get installed? space separated list.." </dev/tty
if confirm "Do you want to 'install-stuff'?" </dev/tty; then
# pen red "$deplist" line
# pkglist=${deplist[@]} install-stuff
fi
# for dep in "${deplist[@]}"; do # for i in {3..6}; do
# pen bold grey "Dep: $dep" # spin grey "Testing $i seconds.."
# if sleep $i; then
# upclear
# check green bold "Successfully waited $i seconds!"
# # line
# fi
# done # done
# spin-installation "${deplist[@]}" }
# for pk in "${pkglist[@]}"; do dream="https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh"
# pen bold red "Pkg: $pk" if getImports "$dream"; then
# done main
# 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
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!"
}
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
fi 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