imports/test.sh
2025-05-23 20:13:15 +02:00

144 lines
3.3 KiB
Bash

{
#!/usr/bin/env bash
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# run() {
# if $silent; then
# # silentexec "$@" &
# spin "Installing packages" &
# silentexec "$@"
# else
# "$@"
# fi
# }
# 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
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"
}
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
}
install-stuff() {
arr=(
firefox-bin
blender-bin
$package
)
# case "$distro" in
# arch)
# $_sudo pacman -Syu
# ;;
# esac
check-and-install ${arr[@]}
if confirm "Do you want to remove the previous installed packages?"; then
for pkg in "${arr[@]}"; do
pkg-remove $pkg
done
fi
}
func1() {
spin yellow "installing stuff"
# if run install-stuff; then
if run --err err --out out git clone --depth=1 https://github.com/neovim/neovim.git; then
check "Installation complete"
line
pen "${out:-}"
else
throw "Installation failed!"
pen "${err:-}"
fi
}
func2() {
# run --err install-stuff
if [ -d ./neovim ]; then
if confirm "$(pen bold blue 'Do you want to remove the cloned ./neovim directory?')" </dev/tty; then
rm -rf ./neovim/
else
pen red bold "Did not remove the neovim directory!"
fi
fi
}
func3() {
local err
arr=(
firefox-esr
)
if $arch; then
spin blue "Installing.."
if run --err err checkAndInstall "${arr[@]}"; then
check "Installed $(pen red ${arr[*]})"
else
throw "Something went wrong installing ${arr[*]}.."
throw "${err:-}"
fi
fi
}
main() {
# if $silent; then
# echo_warning "Executing script silently!"
# fi
# func1
# func2
# func3
# if ask-stuff; then
choose package "What packages should also get installed? space separated list.."
if confirm "Do you want to 'install-stuff'?"; then
install-stuff
fi
# fi
# while install-stuff && break; do
# spin "Installing packages.."
# done
}
dream="https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh"
if getImports "$dream"; then
main
fi
# fi
}