{ #!/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 pkg-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/dream.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" pen bold yellow "cleaned $import" } checkDeps() { pen bold blue "Checking dependencies.." if ! command_exists pkgui; then return 0 else pen bold yellow "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 pen bold yellow "$pkg is already installed.." return 69 fi ;; *) if command_exists $pkg; then return 0 else pen bold yellow "$pkg is required, but missing.." return 69 fi ;; esac done } instDeps() { pen bold blue "Installing missing dependencies.." case "$distro" in arch | opensuse | fedora) pkg-install go ;; debian | ubuntu) pkg-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" pen bold blue "Getting the pkgui binary from $url" cd $tempDir || mkdir $tempDir && cd $tempDir pen bold blue "Curling the binary directly via $url.." curl -fsSL $url -o pkgui || pen bold yellow "Could not curl $url" chmod +x ./pkgui } instPkgUI() { pen bold blue "Installing the binary" if [ -d "$HOME/.local/bin" ]; then ln -srf ./pkgui "$HOME/.local/bin/pkgui" && pen bold blue "Linked to $HOME/.local/bin/pkgui" else pen bold blue "Couldn't find $HOME/.local/bin directory, linking systemwide.." $_sudo ln -sfr ./pkgui /bin/pkgui && pen bold blue "Linked to /bin/pkgui" fi } main() { if $silent; then pen bold yellow "Executing script silently!" fi if ! getDependencies; then echo-error "Error when installing dependencies.." fi checkDeps instDeps getPkgUI instPkgUI } if getImports; then main fi }