scripts/installs/neovide.sh
2025-04-14 09:22:15 +02:00

131 lines
4.2 KiB
Bash
Executable file

#!/bin/sh
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
RED='\033[0;31m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
LIGHT_GREEN='\033[0;92m'
BOLD='\033[1m'
NC='\033[0m' # No Color
echo_error() {
printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2
}
echo_info() {
printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1"
}
echo_warning() {
printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1"
}
echo_note() {
printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1"
}
# ─< check if command exists silently >───────────────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# ─< Silent execution >─────────────────────────────────────────────────────────────────
silentexec() {
"$@" >/dev/null 2>&1
}
# ─< Check if the user is root and set _sudo variable if necessary >───────────────────────
checkRoot() {
if [ "$(id -u)" -ne 0 ]; then
if command_exists sudo; then
echo_info "User is not root. Using sudo for privileged operations."
_sudo="sudo"
else
echo_error "No sudo found and you're not root! Can't install packages."
return 1
fi
else
echo_info "Root access confirmed."
_sudo=""
fi
}
installNeovide() {
if ! command_exists cargo; then
curl --proto '=https' --tlsv1.2 -sSf "https://sh.rustup.rs" | sh
"$HOME/.cargo/bin/cargo" install --git https://github.com/neovide/neovide
else
cargo install --git https://github.com/neovide/neovide
fi
if [ -e "$HOME/.cargo/bin/neovide" ]; then
$_sudo ln -rs "$HOME/.cargo/bin/neovide" /bin/neovide
fi
}
i_arch() {
deps="base-devel fontconfig freetype2 libglvnd sndio cmake git gtk3 python sdl2 vulkan-intel libxkbcommon-x11"
$_sudo pacman -Sy
for dep in $deps; do
if ! command_exists $dep; then
silentexec $_sudo pacman --noconfirm -S "$dep" || echo_error "Couldn't install $dep"
fi
done
}
i_debian() {
$_sudo apt-get update
deps="curl gnupg ca-certificates git gcc-multilib g++-multilib cmake libssl-dev pkg-config libfreetype6-dev libasound2-dev libexpat1-dev libxcb-composite0-dev libbz2-dev libsndio-dev freeglut3-dev libxmu-dev libxi-dev libfontconfig1-dev libxcursor-dev"
for dep in $deps; do
if ! command_exists $dep; then
silentexec $_sudo apt-get install --assume-yes "$dep" || echo_error "Couldn't install $dep"
fi
done
}
i_fedora() {
deps="fontconfig-devel freetype-devel libX11-xcb libX11-devel libstdc++-static libstdc++-devel"
$_sudo dnf update
for dep in $deps; do
if ! command_exists $dep; then
silentexec $_sudo dnf install "$dep" || echo_error "Couldn't install $dep"
fi
done
$_sudo dnf groupinstall "Development Tools" "Development Libraries"
$_sudo dnf install dnf-plugins-core
}
checkDistrosAndDependencies() {
if [ -f /etc/os-release ]; then
echo_info "Sourcing /etc/os-release to determine the distribution..."
. /etc/os-release
case "$ID" in
debian | ubuntu | kali | linuxmint | pop | elementary | zorin | kubuntu | neon | kdeneon | deepin | linuxlite | linuxmintdebian | linuxmintubuntu | linuxmintkali | linuxmintpop | linuxmintelementary | linuxmintzorin | linuxmintkubuntu | linuxmintneon | linuxmintkdeneon | linuxmintdeepin | linuxmintlinuxlite) i_debian ;;
arch | manjaro | endeavouros) i_arch ;;
fedora | centos | rhel | rocky | almalinux) i_fedora ;;
*)
case "$ID_LIKE" in
*debian*) i_debian ;;
*arch*) i_arch ;;
*fedora*) i_fedora ;;
*)
echo_error "Unsupported distribution: $ID"
exit 1
;;
esac
;;
esac
else
echo_error "No os-release file found under /etc/. Exiting now!"
exit 1
fi
}
main() {
if checkRoot; then
checkDistrosAndDependencies && installNeovide
fi
}
main