{ #!/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.. getImports() { i="https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh" import="$(mktemp)" if command_exists curl; then curl -fsSL $i -o $import else echo "curl is required, but missing.." exit 1 fi source "$import" sleep 0.3 rm "$import" echo_warning "cleaned $import" } checkDeps() { echo_info "Checking dependencies.." 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() { echo_info "Installing missing dependencies.." case "$distro" in arch | opensuse | fedora) run _install go ;; debian | ubuntu) run _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" echo_info "Getting the pkgui binary from $url" 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() { echo_info "Installing the binary" if [ -d "$HOME/.local/bin" ]; then run 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.." run $_sudo ln -sfr ./pkgui /bin/pkgui && echo_note "Linked to /bin/pkgui" fi } main() { if $silent; then echo_warning "Executing script silently!" fi if ! getDependencies; then echo_error "Error when installing dependencies.." fi checkDeps instDeps getPkgUI instPkgUI } if getImports; then main fi }