{ #!/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" } installBuildDependencies() { echo_info "Checking build dependencies, and installs missing.." declare -A DistroDeps=( [debian]="ninja-build gettext cmake curl build-essential" [fedora]="ninja-build cmake gcc make gettext curl glibc-gconv-extra" [opensuse]="ninja cmake gcc-c++ gettext-tools curl" [arch]="base-devel cmake ninja curl" [alpine]="build-base cmake coreutils curl gettext-tiny-dev" ) # local depsDebian=(ninja-build gettext cmake curl build-essential) # local depsFedora=(ninja-build cmake gcc make gettext curl glibc-gconv-extra) # local depsOpensuse=(ninja cmake gcc-c++ gettext-tools curl) # local depsArch=(base-devel cmake ninja curl) # local depsAlpine=(build-base cmake coreutils curl gettext-tiny-dev) case "$distro" in # ─< old >──────────────────────────────────────────────────────────────────────────────── # debian) checkAndInstall "${depsDebian[@]}" ;; # fedora) checkAndInstall "${depsFedora[@]}" ;; # opensuse) checkAndInstall "${depsOpensuse[@]}" ;; # arch) checkAndInstall "${depsArch[@]}" ;; # alpine) checkAndInstall "${alpine[@]}" ;; # *) # echo_error "Cannot install for $distro" # exit 1 # ;; debian) checkAndInstall "${DistroDeps[debian]}" ;; fedora) checkAndInstall "${DistroDeps[fedora]}" ;; opensuse) checkAndInstall "${DistroDeps[opensuse]}" ;; arch) checkAndInstall "${DistroDeps[arch]}" ;; alpine) checkAndInstall "${DistroDeps[alpine]}" ;; *) echo_error "Cannot install for $distro" exit 1 ;; esac } cloneSources() { local cloneDir="$(mktemp -d)" echo_info "Cloning neovim sources into tempdir at $cloneDir" cd $cloneDir || mkdir $cloneDir && cd $cloneDir if command_exists git; then if run git clone --depth=1 https://github.com/neovim/neovim.git; then cd neovim || echo_error "Cannot navigate into neovim" else echo_error "Cannot clone the repo.." fi else echo_error "Git was required, but is missing.. exiting now" exit 1 fi } makeInstall() { echo_info "Compiling neovim from source" if run make CMAKE_BUILD_TYPE=RelWithDebInfo; then echo_info "Installing neovim.." run $_sudo make install else echo_error "Failure while building!" exit 1 fi } checkAndInitConfig() { if [ -d "$HOME/.config/nvim/" ]; then echo_info "Prefetching neovim setup configuration.." run nvim --headless +q fi } if getImports; then case "$1" in --silent | -s) silent=true echo_warning "Running the script silently.." ;; *) silent=false ;; esac fi installBuildDependencies cloneSources makeInstall checkAndInitConfig }