diff --git a/install-blesh.sh b/blesh.sh similarity index 100% rename from install-blesh.sh rename to blesh.sh diff --git a/neovim.sh b/neovim.sh index ba7188a..174f18f 100644 --- a/neovim.sh +++ b/neovim.sh @@ -1,223 +1,86 @@ { - #!/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" - } + #!/usr/bin/env bash # ─< Check if the given command exists silently >───────────────────────────────────────── command_exists() { command -v "$@" >/dev/null 2>&1 } - # Check if the user is root and set sudo variable if necessary - check_root() { - if [ "$(id -u)" -ne 0 ]; then - echo_note "checked $(id -u)" - if command_exists sudo; then - echo_note "Checking sudo" - echo_warning "User is not root. Using sudo for privileged operations." - _sudo="sudo" + # WHY: + # This import will give you the following variables: + # _sudo="sudo -E" <- only if non root user + # distro = + # 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 "${1[@]}"; do + if ! command_exists $deps; then + _install "$1" 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 - if [ -n "$_sudo" ]; then - echo_info "--- check_root done --- echo '$_sudo' |" - else - echo_warning "sudo variable is empty: $_sudo" - fi - } - - # ─< Dependencies >───────────────────────────────────────────────────────────────────── - deps="git cargo meson luarocks pipx curl ripgrep make composer npm gcc g++ unzip zip" - - # ─< Distribution-specific installation functions >───────────────────────────────────── - inst_ubuntu() { - $_sudo apt-get update - for _deps in $deps; do - $_sudo apt-get install -y "$_deps" ──────────────────────────────────────── - get_packager() { - if [ -e /etc/os-release ]; then - echo_info "Detecting distribution..." - . /etc/os-release + cloneSources(){ + local cloneDir="$(mktemp -d)" + cd $cloneDir || mkdir $cloneDir && cd $cloneDir - # Convert $ID and $ID_LIKE to lowercase - ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]') - ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]') - - case "$ID" in - ubuntu | pop) inst_ubuntu ;; - debian) inst_debian ;; - fedora) inst_fedora ;; - alpine) inst_alpine ;; - arch | manjaro | garuda | endeavour) inst_arch ;; - opensuse*) inst_opensuse ;; - *) - if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then - inst_debian - elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then - inst_ubuntu - elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then - inst_arch - elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then - inst_fedora - elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then - inst_opensuse - else - echo_error "Unsupported distribution: $ID" - exit 1 - fi - ;; - esac + 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 "Unable to detect distribution. /etc/os-release not found." + echo_error "Git was required, but is missing.. exiting now" exit 1 fi } - # ─< Main function >───────────────────────────────────────────────────────────────── - main() { - if command_exists nvim; then - checkVersion - if [ "$(printf '%s\n' "$latest_version" "$currentVersion" | sort -V | head -n1)" = "$latest_version" ]; then - echo_warning "Neovim is already installed in version: $currentVersion" - echo_error "Exiting now!" - exit 0 - fi - fi - - echo_info "Starting Neovim installation script..." - get_packager - if command -v nvim >/dev/null 2>&1; then - echo_note "Neovim has been successfully installed!" - echo_info "Neovim version: $(nvim --version | head -n1)" + makeInstall(){ + if make CMAKE_BUILD_TYPE=RelWithDebInfo; then + $_sudo make install else - echo_error "Neovim installation failed." + echo_error "Failure while building!" exit 1 fi } - # ─< Script execution >───────────────────────────────────────────────────────────── - check_root && main + installBuildDependencies + cloneSources + makeInstall } diff --git a/neovim.sh.bak b/neovim.sh.bak new file mode 100644 index 0000000..ba7188a --- /dev/null +++ b/neovim.sh.bak @@ -0,0 +1,223 @@ +{ + #!/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 the given command exists silently >───────────────────────────────────────── + command_exists() { + command -v "$@" >/dev/null 2>&1 + } + + # Check if the user is root and set sudo variable if necessary + check_root() { + if [ "$(id -u)" -ne 0 ]; then + echo_note "checked $(id -u)" + if command_exists sudo; then + echo_note "Checking sudo" + echo_warning "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 + if [ -n "$_sudo" ]; then + echo_info "--- check_root done --- echo '$_sudo' |" + else + echo_warning "sudo variable is empty: $_sudo" + fi + } + + # ─< Dependencies >───────────────────────────────────────────────────────────────────── + deps="git cargo meson luarocks pipx curl ripgrep make composer npm gcc g++ unzip zip" + + # ─< Distribution-specific installation functions >───────────────────────────────────── + inst_ubuntu() { + $_sudo apt-get update + for _deps in $deps; do + $_sudo apt-get install -y "$_deps" ──────────────────────────────────────── + get_packager() { + if [ -e /etc/os-release ]; then + echo_info "Detecting distribution..." + . /etc/os-release + + # Convert $ID and $ID_LIKE to lowercase + ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]') + ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]') + + case "$ID" in + ubuntu | pop) inst_ubuntu ;; + debian) inst_debian ;; + fedora) inst_fedora ;; + alpine) inst_alpine ;; + arch | manjaro | garuda | endeavour) inst_arch ;; + opensuse*) inst_opensuse ;; + *) + if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then + inst_debian + elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then + inst_ubuntu + elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then + inst_arch + elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then + inst_fedora + elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then + inst_opensuse + else + echo_error "Unsupported distribution: $ID" + exit 1 + fi + ;; + esac + else + echo_error "Unable to detect distribution. /etc/os-release not found." + exit 1 + fi + } + + # ─< Main function >───────────────────────────────────────────────────────────────── + main() { + if command_exists nvim; then + checkVersion + if [ "$(printf '%s\n' "$latest_version" "$currentVersion" | sort -V | head -n1)" = "$latest_version" ]; then + echo_warning "Neovim is already installed in version: $currentVersion" + echo_error "Exiting now!" + exit 0 + fi + fi + + echo_info "Starting Neovim installation script..." + get_packager + if command -v nvim >/dev/null 2>&1; then + echo_note "Neovim has been successfully installed!" + echo_info "Neovim version: $(nvim --version | head -n1)" + else + echo_error "Neovim installation failed." + exit 1 + fi + } + + # ─< Script execution >───────────────────────────────────────────────────────────── + check_root && main +}