diff --git a/neovide.sh b/neovide.sh index 029853a..42bc72e 100644 --- a/neovide.sh +++ b/neovide.sh @@ -1,54 +1,4 @@ -#!/usr/bin/env 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 -} +#!/usr/bin/env bash installNeovide() { if ! command_exists cargo; then @@ -65,16 +15,14 @@ installNeovide() { 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" + _install "$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 @@ -84,48 +32,27 @@ i_debian() { } i_fedora() { - deps="fontconfig-devel freetype-devel libX11-xcb libX11-devel libstdc++-static libstdc++-devel" - $_sudo dnf update + deps="fontconfig-devel freetype-devel libX11-xcb libX11-devel libstdc++-static libstdc++-devel dnf-plugins-core" for dep in $deps; do if ! command_exists $dep; then - silentexec $_sudo dnf install "$dep" || echo_error "Couldn't install $dep" + _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 +setup() { + case "$distro" in + arch) i_arch ;; + fedora) i_fedora ;; + debian | ubuntu) i_debian ;; + *) + echo_error "$distro is not supported by this script" + return 69 + ;; + esac } -main() { - if checkRoot; then - checkDistrosAndDependencies && installNeovide - fi -} - -main +if setup; then + installNeovide +fi