installs/neovim.sh
2025-05-11 14:41:31 +02:00

96 lines
2.7 KiB
Bash

{
#!/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 = <distro name, like 'arch', 'debian', 'fedora'..>
# 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() {
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
debian) run checkAndInstall "${depsDebian[@]}" ;;
fedora) run checkAndInstall "${depsFedora[@]}" ;;
opensuse) run checkAndInstall "${depsOpensuse[@]}" ;;
arch) run checkAndInstall "${depsArch[@]}" ;;
alpine) run checkAndInstall "${alpine[@]}" ;;
*)
echo_error "Cannot install for $distro"
exit 1
;;
esac
}
cloneSources() {
local cloneDir="$(mktemp -d)"
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() {
if run make CMAKE_BUILD_TYPE=RelWithDebInfo; then
$_sudo make install
else
echo_error "Failure while building!"
exit 1
fi
}
if getImports; then
case "$1" in
--silent | -s)
silent=true
;;
*)
silent=false
;;
esac
fi
installBuildDependencies
cloneSources
makeInstall
}