111 lines
3.1 KiB
Bash
111 lines
3.1 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"
|
|
}
|
|
|
|
checkAndInstall() {
|
|
for deps in "$@"; do
|
|
if ! command_exists $deps; then
|
|
_install "$deps"
|
|
else
|
|
echo_note "skipping $deps - as it's 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 --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 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)
|
|
echo_info "Updating sources and installing base dependencies.."
|
|
silentexec installBuildDependencies
|
|
|
|
echo_info "Cloning neovim sources.."
|
|
silentexec cloneSources
|
|
|
|
echo_info "Building neovim.."
|
|
silentexec makeInstall
|
|
;;
|
|
*)
|
|
installBuildDependencies
|
|
cloneSources
|
|
makeInstall
|
|
;;
|
|
esac
|
|
fi
|
|
}
|