{ #!/usr/bin/env bash # ─< Check if the given command exists silently >───────────────────────────────────────── command_exists() { command -v "$@" >/dev/null 2>&1 } # WHY: # This import will give you the following variables: # _sudo="sudo -E" <- only if non root user # distro = # 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.. if command_exists curl; then eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh)" else echo "curl is required, but missing.." exit 1 fi checkDeps() { if ! command_exists pkgui; then return 0 else echo_warning "pkgui is already installed.." return 69 fi for pkg in go curl pkgui; do case "$pkg" in pkgui) if command_exists $pkg; then return 0 else echo_warning "$pkg is already installed.." return 69 fi ;; *) if command_exists $pkg; then return 0 else echo_warning "$pkg is required, but missing.." return 69 fi ;; esac done } instDeps() { case "$distro" in arch | opensuse | fedora) _install go ;; debian | ubuntu) _install golang ;; *) echo_error "$distro is not supported by this script" ;; esac } getPkgUI() { local tempDir="$(mktemp -d)" local url="https://git.k4li.de/scripts/installs/raw/branch/main/.src/pkgui" cd $tempDir || mkdir $tempDir && cd $tempDir echo_info "Curling the binary directly via $url.." # echo_warning "DEBUG: # $PWD # $(ls -la) # " curl -fsSL $url -o pkgui || echo_warning "Could not curl $url" chmod +x ./pkgui } instPkgUI() { if [ -d "$HOME/.local/bin" ]; then ln -srf ./pkgui "$HOME/.local/bin/pkgui" && echo_note "Linked to $HOME/.local/bin/pkgui" else echo_note "Couldn't find $HOME/.local/bin directory, linking systemwide.." $_sudo ln -sfr ./pkgui /bin/pkgui && echo_note "Linked to /bin/pkgui" fi } main() { if checkDeps; then if instDeps; then if getPkgUI; then instPkgUI fi fi fi } main }