installs/neovim.sh
2025-05-10 10:28:38 +02:00

86 lines
2.6 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', 'ubuntu', 'fedora', 'opensuse' or 'alpine'>
# 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..
if command_exists curl; then
eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh)"
else
echo "curl is required, but missing.."
exit 1
fi
checkAndInstall() {
for deps in "$@"; do
if ! command_exists $deps; then
_install "$deps"
else
echo_note "skipping $deps - as is already installed.."
fi
done
}
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) checkAndInstall "${depsDebian[@]}" ;;
fedora) checkAndInstall "${depsFedora[@]}" ;;
opensuse) checkAndInstall "${depsOpensuse[@]}" ;;
arch) checkAndInstall "${depsArch[@]}" ;;
alpine) 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 git clone 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 make CMAKE_BUILD_TYPE=RelWithDebInfo; then
$_sudo make install
else
echo_error "Failure while building!"
exit 1
fi
}
installBuildDependencies
cloneSources
makeInstall
}