{ #!/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.." 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) declare -A deps=( [debian]="depsDebian" [ubuntu]="depsDebian" [opensuse]="depsOpensuse" [fedora]="depsFedora" [arch]="depsArch" [alpine]="depsAlpine" ) declare -n pkgArray="${deps[$distro]}" case "$distro" in debian | ubuntu | arch | fedora | alpine | opensuse) checkAndInstall "${pkgArray[@]}" ;; *) echo_error "Cannot install for $distro" exit 1 ;; esac } cloneSources() { cloneDir="$(mktemp -d)" echo_info "Cloning neovim sources into tempdir at $cloneDir/neovim" 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.." nvim --headless +q else echo_warning "You don't have a neovim config installed. Do you want to clone one now? [Y]es (standard), [m]inimal, [n]o" read -r askNvim case "$askNvim" in [Yy]) git clone --recursive --depth=1 https://git.k4li.de/dotfiles/nvim.git "$HOME/.config/nvim" sleep 0.2 nvim --headless +q ;; [Mm]) git clone --recursive --depth=1 https://git.k4li.de/dotfiles/nvim-mini.git "$HOME/.config/nvim" sleep 0.2 nvim --headless +q ;; [Nn]) return 0 ;; *) return 69 ;; esac 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 echo_note "Cleaning up old $cloneDir directory.." rm -rf "$cloneDir" }