diff --git a/arch/.src/colorscript.sh b/arch/.src/colorscript.sh new file mode 100644 index 0000000..6bf13ab --- /dev/null +++ b/arch/.src/colorscript.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# ─< 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 + if command_exists sudo; then + echo_info "User is not root. Using sudo for privileged operations." + _sudo="sudo -E" + 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 ! command_exists git; then + echo_error "Some dependencies are missing!" + exit 1 +fi + +clone() { + local cloneDir="/opt/shell-color-scripts" + if [ ! -d "$cloneDir" ]; then + $_sudo git clone --depth=1 https://github.com/charitarthchugh/shell-color-scripts "$cloneDir" && + $_sudo chmod +x "$cloneDir/colorscript.sh" + fi +} + +link() { + if [ -d "$HOME/.local/bin" ]; then + $_sudo ln -sfr /opt/shell-color-scripts/colorscript.sh "$HOME/.local/bin/colorscript" || echo_error "Could not link the script" + $_sudo ln -sfr /opt/shell-color-scripts/colorscript.sh /usr/bin/colorscript || echo_error "Could not link the script" + else + $_sudo ln -sfr /opt/shell-color-scripts/colorscript.sh /usr/bin/colorscript || echo_error "Could not link the script" + fi +} + +checkInstall() { + if command_exists colorscript; then + echo_note "Installation complete" + else + echo_warning "Something went wrong?" + fi +} + +check_root && + if clone; then + link + fi + +checkInstall diff --git a/arch/.src/neovim.sh b/arch/.src/neovim.sh new file mode 100644 index 0000000..104a524 --- /dev/null +++ b/arch/.src/neovim.sh @@ -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" + done + inst_generic + } + + inst_debian() { + $_sudo apt-get update + for _deps in $deps; do + $_sudo apt-get install -y "$_deps" + done + inst_generic + } + + inst_fedora() { + $_sudo dnf update + for _deps in $deps; do + $_sudo dnf install -y "$_deps" + done + $_sudo dnf install -y neovim + } + + inst_arch() { + $_sudo pacman -Syu --noconfirm + for _deps in $deps; do + $_sudo pacman -S --noconfirm "$_deps" + done + $_sudo pacman -S --noconfirm --needed neovim + } + + inst_opensuse() { + $_sudo zypper refresh + for _deps in $deps; do + $_sudo zypper in "$_deps" + done + $_sudo zypper in neovim + } + + inst_alpine() { + $_sudo apk update + for _deps in $deps; do + $_sudo apk add "$_deps" + done + $_sudo apk add neovim + } + + echo_info "Fetching latest stable Neovim version..." + latest_version=$(curl -s https://api.github.com/repos/neovim/neovim/releases/latest | grep 'tag_name' | cut -d\" -f4) + + inst_generic() { + tempdir="$(mktemp -d)" + if [ ! -d "$HOME/.bin" ]; then + mkdir -p "$HOME/.bin" + fi + + echo_info "Downloading Neovim version $latest_version..." + + # Determine architecture + arch=$(uname -m) + if [ "$arch" = "aarch64" ] || [ "$arch" = "armv7l" ]; then + nvim_tarball="nvim-linux-arm64.tar.gz" + else + nvim_tarball="nvim-linux-x86_64.tar.gz" + fi + + # Download the tarball + curl -fsSL -o "$tempdir/nvim.tar.gz" "https://github.com/neovim/neovim/releases/download/${latest_version}/${nvim_tarball}" + + # Change to the temporary directory and extract + cd "$tempdir" + tar -xzf nvim.tar.gz + + # Remove old installation if it exists + rm -rf "$HOME/.bin/nvim-linux-x86_64" "$HOME/.bin/nvim-linux-arm64" + + # Copy to destination + cp -r ./nvim-linux-* "$HOME/.bin/" + + # Create symlinks with absolute paths + inst_paths="/usr/bin /usr/share/bin $HOME/.local/bin" + for in_path in $inst_paths; do + if [ -d "$in_path" ]; then + echo_info "Installing into $in_path" + $_sudo ln -sf "$HOME/.bin/nvim-linux-*/bin/nvim" "$in_path/nvim" + fi + done + + # Clean up + rm -rf "$tempdir" + + echo_info "Neovim $latest_version installed successfully" + } + + checkVersion() { + currentVersion="$(nvim --version | head -n1 | awk '{print $2}')" + } + + # ─< Distribution detection and installation >──────────────────────────────────────── + 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 +} diff --git a/arch/.src/omp.sh b/arch/.src/omp.sh new file mode 100644 index 0000000..4b3ee97 --- /dev/null +++ b/arch/.src/omp.sh @@ -0,0 +1,252 @@ +#!/usr/bin/env bash + +install_dir="" +themes_dir="" +executable="" +version="" + +error() { + printf "\e[31m$1\e[0m\n" + exit 1 +} + +info() { + printf "$1\n" +} + +warn() { + printf "⚠️ \e[33m$1\e[0m\n" +} + +help() { + # Display Help + echo "Install script for Oh My Posh" + echo + echo "Syntax: install.sh [-h] [-d ] [-t ] [-v ]" + echo "options:" + echo "-h Print this help." + echo "-d Specify the installation directory. Defaults to $HOME/bin, $HOME/.local/bin or the directory where oh-my-posh is installed." + echo "-t Specify the themes installation directory. Defaults to the oh-my-posh cache directory." + echo "-v Version to download, defaults to latest" + echo +} + +while getopts ":hd:t:v:" option; do + case $option in + h) # display Help + help + exit;; + d) # Enter a name + install_dir=${OPTARG};; + t) # themes directory + themes_dir=${OPTARG};; + v) # version + version=${OPTARG};; + \?) # Invalid option + echo "Invalid option command line option. Use -h for help." + exit 1 + esac +done + +SUPPORTED_TARGETS="linux-386 linux-amd64 linux-arm linux-arm64 darwin-amd64 darwin-arm64 freebsd-386 freebsd-amd64 freebsd-arm freebsd-arm64" + +validate_dependency() { + if ! command -v $1 >/dev/null; then + error "$1 is required to install Oh My Posh. Please install $1 and try again.\n" + fi +} + +validate_dependencies() { + validate_dependency curl + validate_dependency unzip + validate_dependency realpath + validate_dependency dirname +} + +set_install_directory() { + if [ -n "$install_dir" ]; then + # expand directory + install_dir="${install_dir/#\~/$HOME}" + return 0 + fi + + # check if we have oh-my-posh installed, if so, use the executable directory + # to install into and follow symlinks + if command -v oh-my-posh >/dev/null; then + posh_dir=$(command -v oh-my-posh) + real_dir=$(realpath $posh_dir) + install_dir=$(dirname $real_dir) + info "Oh My Posh is already installed, updating existing installation in:" + info " ${install_dir}" + return 0 + fi + + # check if $HOME/bin exists and is writable + if [ -d "$HOME/bin" ] && [ -w "$HOME/bin" ]; then + install_dir="$HOME/bin" + return 0 + fi + + # check if $HOME/.local/bin exists and is writable + if ([ -d "$HOME/.local/bin" ] && [ -w "$HOME/.local/bin" ]) || mkdir -p "$HOME/.local/bin"; then + install_dir="$HOME/.local/bin" + return 0 + fi + + error "Cannot determine installation directory. Please specify a directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}" +} + +validate_install_directory() { + #check if installation dir exists + if [ ! -d "$install_dir" ]; then + error "Directory ${install_dir} does not exist, set a different directory and try again." + fi + + # Check if regular user has write permission + if [ ! -w "$install_dir" ]; then + error "Cannot write to ${install_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}" + fi + + # check if the directory is in the PATH + good=$( + IFS=: + for path in $PATH; do + if [ "${path%/}" = "${install_dir}" ]; then + printf 1 + break + fi + done + ) + + if [ "${good}" != "1" ]; then + warn "Installation directory ${install_dir} is not in your \$PATH, add it using \nexport PATH=\$PATH:${install_dir}" + fi +} + +validate_themes_directory() { + + # Validate if the themes directory exists + if ! mkdir -p "$themes_dir" > /dev/null 2>&1; then + error "Cannot write to ${themes_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -t {directory}" + fi + + #check user write permission + if [ ! -w "$themes_dir" ]; then + error "Cannot write to ${themes_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -t {directory}" + fi +} + +install_themes() { + if [ -n "$themes_dir" ]; then + # expand directory + themes_dir="${themes_dir/#\~/$HOME}" + fi + + cache_dir=$($executable cache path) + + # validate if the user set the path to the themes directory + if [ -z "$themes_dir" ]; then + themes_dir="${cache_dir}/themes" + fi + + validate_themes_directory + + info "🎨 Installing oh-my-posh themes in ${themes_dir}\n" + + zip_file="${cache_dir}/themes.zip" + + url="https://cdn.ohmyposh.dev/releases/latest/themes.zip" + + http_response=$(curl -s -f -L $url -o $zip_file -w "%{http_code}") + + if [ $http_response = "200" ] && [ -f $zip_file ]; then + unzip -o -q $zip_file -d $themes_dir + # make sure the files are readable and writable for all users + chmod a+rwX ${themes_dir}/*.omp.* + rm $zip_file + else + warn "Unable to download themes at ${url}\nPlease validate your curl, connection and/or proxy settings" + fi +} + +install() { + arch=$(detect_arch) + platform=$(detect_platform) + target="${platform}-${arch}" + + good=$( + IFS=" " + for t in $SUPPORTED_TARGETS; do + if [ "${t}" = "${target}" ]; then + printf 1 + break + fi + done + ) + + if [ "${good}" != "1" ]; then + error "${arch} builds for ${platform} are not available for Oh My Posh" + fi + + info "\nℹ️ Installing oh-my-posh for ${target} in ${install_dir}" + + executable=${install_dir}/oh-my-posh + url=https://cdn.ohmyposh.dev/releases/latest/posh-${target} + if [ "$version" ]; then + url=https://cdn.ohmyposh.dev/releases/${version}/posh-${target} + fi + + info "⬇️ Downloading oh-my-posh from ${url}" + + http_response=$(curl -s -f -L $url -o $executable -w "%{http_code}") + + if [ $http_response != "200" ] || [ ! -f $executable ]; then + error "Unable to download executable at ${url}\nPlease validate your curl, connection and/or proxy settings" + fi + + chmod +x $executable + + install_themes + + info "🚀 Installation complete.\n\nYou can follow the instructions at https://ohmyposh.dev/docs/installation/prompt" + info "to setup your shell to use oh-my-posh." + if [ $http_response = "200" ]; then + info "\nIf you want to use a built-in theme, you can find them in the ${themes_dir} directory:" + info " oh-my-posh init {shell} --config ${themes_dir}/{theme}.omp.json\n" + fi +} + +detect_arch() { + arch="$(uname -m | tr '[:upper:]' '[:lower:]')" + + case "${arch}" in + x86_64) arch="amd64" ;; + armv*) arch="arm" ;; + arm64) arch="arm64" ;; + aarch64) arch="arm64" ;; + i686) arch="386" ;; + esac + + if [ "${arch}" = "arm64" ] && [ "$(getconf LONG_BIT)" -eq 32 ]; then + arch=arm + fi + + printf '%s' "${arch}" +} + + +detect_platform() { + platform="$(uname -s | awk '{print tolower($0)}')" + + case "${platform}" in + linux) platform="linux" ;; + darwin) platform="darwin" ;; + esac + + printf '%s' "${platform}" +} + +validate_dependencies +set_install_directory +validate_install_directory +install diff --git a/debian/.src/setupDebian.sh b/arch/.src/setup.sh similarity index 100% rename from debian/.src/setupDebian.sh rename to arch/.src/setup.sh diff --git a/arch/Dockerfile b/arch/Dockerfile new file mode 100644 index 0000000..971d42e --- /dev/null +++ b/arch/Dockerfile @@ -0,0 +1,29 @@ +FROM archlinux:latest + +RUN pacman -Sy && pacman -S --noconfirm --needed curl zsh fzf zoxide unzip sudo git make stow fastfetch cowsay + +COPY ./.src/colorscript.sh . +COPY ./.src/neovim.sh . +COPY ./.src/omp.sh . +# COPY ./.src/zellij.sh . + +RUN bash ./omp.sh -d /bin && rm ./omp.sh +# RUN bash neovim.sh -s && rm neovim.sh +# RUN bash zellij.sh -s && rm zellij.sh +# RUN bash colorscript.sh -s && rm colorscript.sh +RUN curl -o neovim.sh -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/neovim.sh +RUN curl -o colorscript.sh -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/colorscript.sh +RUN bash ./neovim.sh -s +RUN bash ./colorscript.sh + +RUN useradd -m -G wheel -r -s /usr/bin/zsh archlinux + +RUN echo "archlinux ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers +USER archlinux +WORKDIR /home/archlinux + +COPY ./.src/setup.sh . + +RUN git clone --recursive --depth=1 https://git.k4li.de/dotfiles/minimal.git /home/archlinux/dotfiles + +ENTRYPOINT /usr/bin/zsh diff --git a/debian/.src/neovim.sh b/debian/.src/neovim.sh index 104a524..eb90262 100644 --- a/debian/.src/neovim.sh +++ b/debian/.src/neovim.sh @@ -1,223 +1,190 @@ { - #!/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.. + 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" + + source-script "https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh" + } + + getDependencies() { + echo_pkg deps "Checking build dependencies, and installs missing.." + + local depsDebian=(git ninja-build gettext cmake curl build-essential) + local depsFedora=(git ninja-build cmake gcc make gettext curl glibc-gconv-extra) + local depsOpensuse=(git ninja cmake gcc-c++ gettext-tools curl) + local depsArch=(git base-devel cmake ninja curl) + local depsAlpine=(git build-base cmake coreutils curl gettext-tiny-dev) + + declare -A deps=( + [debian]="depsDebian" + [ubuntu]="depsDebian" + [opensuse]="depsOpensuse" + [fedora]="depsFedora" + [arch]="depsArch" + [alpine]="depsAlpine" + ) + + declare -n pkgArray="${deps[$distro]}" + + case "$distro" in + debian | ubuntu | arch | fedora | alpine | opensuse) + checkAndInstall "${pkgArray[@]}" + ;; + *) + echo_error "Cannot install for $distro" + exit 1 + ;; + esac + } + + cloneSources() { + local err + cloneDir="$(mktemp -d)" + # echo_pkg git "Cloning $PACKAGE sources at $cloneDir/neovim.." + + cd $cloneDir || mkdir $cloneDir && cd $cloneDir + + if command_exists git; then + spin yellow "Cloning $PACKAGE sources at $cloneDir/neovim.." + sleep 1 + if run --err err git clone --depth=1 https://github.com/neovim/neovim.git; then + check "Cloned sources" + line + + cd neovim || throw "Cannot navigate into neovim" + # pen ${output:-} else - echo_error "No sudo found and you're not root! Can't install packages." - return 1 + throw "Cannot clone the repo.." + pen bold red "The error: $err" fi else - echo_info "Root access confirmed." - _sudo="" + echo_error "Git was required, but is missing.. exiting now" + exit 1 fi - if [ -n "$_sudo" ]; then - echo_info "--- check_root done --- echo '$_sudo' |" + + } + + makeInstall() { + # echo_pkg build "Compiling neovim from source" + spin "Compiling neovim from source" + if run make CMAKE_BUILD_TYPE=RelWithDebInfo; then + check "Compiled $PACKAGE from source" + line + echo_pkg install + $_sudo make install 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" - done - inst_generic - } - - inst_debian() { - $_sudo apt-get update - for _deps in $deps; do - $_sudo apt-get install -y "$_deps" - done - inst_generic - } - - inst_fedora() { - $_sudo dnf update - for _deps in $deps; do - $_sudo dnf install -y "$_deps" - done - $_sudo dnf install -y neovim - } - - inst_arch() { - $_sudo pacman -Syu --noconfirm - for _deps in $deps; do - $_sudo pacman -S --noconfirm "$_deps" - done - $_sudo pacman -S --noconfirm --needed neovim - } - - inst_opensuse() { - $_sudo zypper refresh - for _deps in $deps; do - $_sudo zypper in "$_deps" - done - $_sudo zypper in neovim - } - - inst_alpine() { - $_sudo apk update - for _deps in $deps; do - $_sudo apk add "$_deps" - done - $_sudo apk add neovim - } - - echo_info "Fetching latest stable Neovim version..." - latest_version=$(curl -s https://api.github.com/repos/neovim/neovim/releases/latest | grep 'tag_name' | cut -d\" -f4) - - inst_generic() { - tempdir="$(mktemp -d)" - if [ ! -d "$HOME/.bin" ]; then - mkdir -p "$HOME/.bin" - fi - - echo_info "Downloading Neovim version $latest_version..." - - # Determine architecture - arch=$(uname -m) - if [ "$arch" = "aarch64" ] || [ "$arch" = "armv7l" ]; then - nvim_tarball="nvim-linux-arm64.tar.gz" - else - nvim_tarball="nvim-linux-x86_64.tar.gz" - fi - - # Download the tarball - curl -fsSL -o "$tempdir/nvim.tar.gz" "https://github.com/neovim/neovim/releases/download/${latest_version}/${nvim_tarball}" - - # Change to the temporary directory and extract - cd "$tempdir" - tar -xzf nvim.tar.gz - - # Remove old installation if it exists - rm -rf "$HOME/.bin/nvim-linux-x86_64" "$HOME/.bin/nvim-linux-arm64" - - # Copy to destination - cp -r ./nvim-linux-* "$HOME/.bin/" - - # Create symlinks with absolute paths - inst_paths="/usr/bin /usr/share/bin $HOME/.local/bin" - for in_path in $inst_paths; do - if [ -d "$in_path" ]; then - echo_info "Installing into $in_path" - $_sudo ln -sf "$HOME/.bin/nvim-linux-*/bin/nvim" "$in_path/nvim" - fi - done - - # Clean up - rm -rf "$tempdir" - - echo_info "Neovim $latest_version installed successfully" - } - - checkVersion() { - currentVersion="$(nvim --version | head -n1 | awk '{print $2}')" - } - - # ─< Distribution detection and installation >──────────────────────────────────────── - 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." + echo_error "Failure while building!" 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 + checkAndInitConfig() { + if [ -d "$HOME/.config/nvim/" ]; then + # echo_pkg qol "Prefetching neovim setup configuration.." + spin "Prefetching neovim setup configuration.." + if run nvim --headless +q; then + check "Prefetched config" + else + throw "Prefetching config went terribly wrong!" 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 + # echo_warning "You don't have a neovim config installed. Do you want to clone one now? [Y]es (standard), [m]inimal, [n]o" + # read -r askNvim + choose askNvim "You don't have a neovim config installed. Do you want to clone one now?" "pika's standard config" "pika's minimal config" none + + case "$askNvim" in + "pika's standard config") + git clone --recursive --depth=1 https://git.k4li.de/dotfiles/nvim.git "$HOME/.config/nvim" + sleep 0.2 + nvim --headless +q + ;; + "pika's minimal config") + git clone --recursive --depth=1 https://git.k4li.de/dotfiles/nvim-mini.git "$HOME/.config/nvim" + sleep 0.2 + nvim --headless +q + ;; + none) return 0 ;; + *) + echo_error "Something failed HARD!" + return 69 + ;; + esac fi } - # ─< Script execution >───────────────────────────────────────────────────────────── - check_root && main + main() { + if $silent; then + echo_warning "Executing script silently!" + fi + + if ! getDependencies; then + echo_error "Error when installing dependencies.." + fi + + cloneSources + makeInstall + + checkAndInitConfig ─────────────────────────────────────────────────────────────────── + unset PACKAGE + + # ─< argument list variables >──────────────────────────────────────────────────────────── + silent=false + + sleep 0.1 + + PACKAGE=neovim + if command_exists "$PACKAGE"; then + echo_warning "$PACKAGE is already installed!" + echo_warning "Exiting now!" + exit 69 + fi + + # ─< parse arguments and get variable contents >────────────────────────────────────────── + for arg in "$@"; do + case "$arg" in + --silent | -s) + export silent=true + ;; + esac + done + + main > /etc/sudoers USER debian WORKDIR /home/debian -COPY ./.src/setupDebian.sh . +COPY .src/setup.sh . +COPY .src/neovim.sh . RUN git clone --recursive --depth=1 https://git.k4li.de/dotfiles/minimal.git /home/debian/dotfiles diff --git a/fedora/Dockerfile b/fedora/Dockerfile new file mode 100644 index 0000000..4b32da2 --- /dev/null +++ b/fedora/Dockerfile @@ -0,0 +1,26 @@ +FROM fedora:latest + +# RUN dnf update && dnf install --assumeyes curl zsh fzf zoxide unzip sudo git make stow fastfetch exa +RUN dnf install --assumeyes curl zsh fzf zoxide unzip git make stow + +# COPY ./.src/colorscript.sh . +# COPY ./.src/neovim.sh . +# COPY ./.src/omp.sh . +# COPY ./.src/zellij.sh . + +# RUN bash ./omp.sh -d /bin && rm ./omp.sh +# RUN bash neovim.sh && rm neovim.sh +# RUN bash zellij.sh && rm zellij.sh +# RUN bash colorscript.sh && rm colorscript.sh + +RUN useradd -m -G wheel -r -s /usr/bin/zsh fedora + +RUN echo "fedora ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers +USER fedora +WORKDIR /home/fedora + +COPY ./setup.sh . + +RUN git clone --recursive --depth=1 https://git.k4li.de/dotfiles/minimal.git /home/fedora/dotfiles + +ENTRYPOINT /usr/bin/zsh diff --git a/fedora/setup.sh b/fedora/setup.sh new file mode 100755 index 0000000..e2f92ef --- /dev/null +++ b/fedora/setup.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +cd $HOME/dotfiles/ +{ + echo "${CYAN}Updating submodules..${NC}" && + git submodule update --init --recursive && + echo "${CYAN}Pulling down submodules..${NC}" && + git pull --recurse-submodule +} + +stow dotfiles/ +stow zsh/ + +exec zsh diff --git a/ubuntu/.src/colorscript.sh b/ubuntu/.src/colorscript.sh new file mode 100644 index 0000000..6bf13ab --- /dev/null +++ b/ubuntu/.src/colorscript.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# ─< 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 + if command_exists sudo; then + echo_info "User is not root. Using sudo for privileged operations." + _sudo="sudo -E" + 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 ! command_exists git; then + echo_error "Some dependencies are missing!" + exit 1 +fi + +clone() { + local cloneDir="/opt/shell-color-scripts" + if [ ! -d "$cloneDir" ]; then + $_sudo git clone --depth=1 https://github.com/charitarthchugh/shell-color-scripts "$cloneDir" && + $_sudo chmod +x "$cloneDir/colorscript.sh" + fi +} + +link() { + if [ -d "$HOME/.local/bin" ]; then + $_sudo ln -sfr /opt/shell-color-scripts/colorscript.sh "$HOME/.local/bin/colorscript" || echo_error "Could not link the script" + $_sudo ln -sfr /opt/shell-color-scripts/colorscript.sh /usr/bin/colorscript || echo_error "Could not link the script" + else + $_sudo ln -sfr /opt/shell-color-scripts/colorscript.sh /usr/bin/colorscript || echo_error "Could not link the script" + fi +} + +checkInstall() { + if command_exists colorscript; then + echo_note "Installation complete" + else + echo_warning "Something went wrong?" + fi +} + +check_root && + if clone; then + link + fi + +checkInstall diff --git a/ubuntu/.src/neovim.sh b/ubuntu/.src/neovim.sh new file mode 100644 index 0000000..eb90262 --- /dev/null +++ b/ubuntu/.src/neovim.sh @@ -0,0 +1,190 @@ +{ + #!/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 = + # 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" + + source-script "https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh" + } + + getDependencies() { + echo_pkg deps "Checking build dependencies, and installs missing.." + + local depsDebian=(git ninja-build gettext cmake curl build-essential) + local depsFedora=(git ninja-build cmake gcc make gettext curl glibc-gconv-extra) + local depsOpensuse=(git ninja cmake gcc-c++ gettext-tools curl) + local depsArch=(git base-devel cmake ninja curl) + local depsAlpine=(git build-base cmake coreutils curl gettext-tiny-dev) + + declare -A deps=( + [debian]="depsDebian" + [ubuntu]="depsDebian" + [opensuse]="depsOpensuse" + [fedora]="depsFedora" + [arch]="depsArch" + [alpine]="depsAlpine" + ) + + declare -n pkgArray="${deps[$distro]}" + + case "$distro" in + debian | ubuntu | arch | fedora | alpine | opensuse) + checkAndInstall "${pkgArray[@]}" + ;; + *) + echo_error "Cannot install for $distro" + exit 1 + ;; + esac + } + + cloneSources() { + local err + cloneDir="$(mktemp -d)" + # echo_pkg git "Cloning $PACKAGE sources at $cloneDir/neovim.." + + cd $cloneDir || mkdir $cloneDir && cd $cloneDir + + if command_exists git; then + spin yellow "Cloning $PACKAGE sources at $cloneDir/neovim.." + sleep 1 + if run --err err git clone --depth=1 https://github.com/neovim/neovim.git; then + check "Cloned sources" + line + + cd neovim || throw "Cannot navigate into neovim" + # pen ${output:-} + else + throw "Cannot clone the repo.." + pen bold red "The error: $err" + fi + else + echo_error "Git was required, but is missing.. exiting now" + exit 1 + fi + + } + + makeInstall() { + # echo_pkg build "Compiling neovim from source" + spin "Compiling neovim from source" + if run make CMAKE_BUILD_TYPE=RelWithDebInfo; then + check "Compiled $PACKAGE from source" + line + echo_pkg install + $_sudo make install + else + echo_error "Failure while building!" + exit 1 + fi + } + + checkAndInitConfig() { + if [ -d "$HOME/.config/nvim/" ]; then + # echo_pkg qol "Prefetching neovim setup configuration.." + spin "Prefetching neovim setup configuration.." + if run nvim --headless +q; then + check "Prefetched config" + else + throw "Prefetching config went terribly wrong!" + fi + else + # echo_warning "You don't have a neovim config installed. Do you want to clone one now? [Y]es (standard), [m]inimal, [n]o" + # read -r askNvim + choose askNvim "You don't have a neovim config installed. Do you want to clone one now?" "pika's standard config" "pika's minimal config" none + + case "$askNvim" in + "pika's standard config") + git clone --recursive --depth=1 https://git.k4li.de/dotfiles/nvim.git "$HOME/.config/nvim" + sleep 0.2 + nvim --headless +q + ;; + "pika's minimal config") + git clone --recursive --depth=1 https://git.k4li.de/dotfiles/nvim-mini.git "$HOME/.config/nvim" + sleep 0.2 + nvim --headless +q + ;; + none) return 0 ;; + *) + echo_error "Something failed HARD!" + return 69 + ;; + esac + fi + } + + main() { + if $silent; then + echo_warning "Executing script silently!" + fi + + if ! getDependencies; then + echo_error "Error when installing dependencies.." + fi + + cloneSources + makeInstall + + checkAndInitConfig ─────────────────────────────────────────────────────────────────── + unset PACKAGE + + # ─< argument list variables >──────────────────────────────────────────────────────────── + silent=false + + sleep 0.1 + + PACKAGE=neovim + if command_exists "$PACKAGE"; then + echo_warning "$PACKAGE is already installed!" + echo_warning "Exiting now!" + exit 69 + fi + + # ─< parse arguments and get variable contents >────────────────────────────────────────── + for arg in "$@"; do + case "$arg" in + --silent | -s) + export silent=true + ;; + esac + done + + main ] [-t ] [-v ]" + echo "options:" + echo "-h Print this help." + echo "-d Specify the installation directory. Defaults to $HOME/bin, $HOME/.local/bin or the directory where oh-my-posh is installed." + echo "-t Specify the themes installation directory. Defaults to the oh-my-posh cache directory." + echo "-v Version to download, defaults to latest" + echo +} + +while getopts ":hd:t:v:" option; do + case $option in + h) # display Help + help + exit;; + d) # Enter a name + install_dir=${OPTARG};; + t) # themes directory + themes_dir=${OPTARG};; + v) # version + version=${OPTARG};; + \?) # Invalid option + echo "Invalid option command line option. Use -h for help." + exit 1 + esac +done + +SUPPORTED_TARGETS="linux-386 linux-amd64 linux-arm linux-arm64 darwin-amd64 darwin-arm64 freebsd-386 freebsd-amd64 freebsd-arm freebsd-arm64" + +validate_dependency() { + if ! command -v $1 >/dev/null; then + error "$1 is required to install Oh My Posh. Please install $1 and try again.\n" + fi +} + +validate_dependencies() { + validate_dependency curl + validate_dependency unzip + validate_dependency realpath + validate_dependency dirname +} + +set_install_directory() { + if [ -n "$install_dir" ]; then + # expand directory + install_dir="${install_dir/#\~/$HOME}" + return 0 + fi + + # check if we have oh-my-posh installed, if so, use the executable directory + # to install into and follow symlinks + if command -v oh-my-posh >/dev/null; then + posh_dir=$(command -v oh-my-posh) + real_dir=$(realpath $posh_dir) + install_dir=$(dirname $real_dir) + info "Oh My Posh is already installed, updating existing installation in:" + info " ${install_dir}" + return 0 + fi + + # check if $HOME/bin exists and is writable + if [ -d "$HOME/bin" ] && [ -w "$HOME/bin" ]; then + install_dir="$HOME/bin" + return 0 + fi + + # check if $HOME/.local/bin exists and is writable + if ([ -d "$HOME/.local/bin" ] && [ -w "$HOME/.local/bin" ]) || mkdir -p "$HOME/.local/bin"; then + install_dir="$HOME/.local/bin" + return 0 + fi + + error "Cannot determine installation directory. Please specify a directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}" +} + +validate_install_directory() { + #check if installation dir exists + if [ ! -d "$install_dir" ]; then + error "Directory ${install_dir} does not exist, set a different directory and try again." + fi + + # Check if regular user has write permission + if [ ! -w "$install_dir" ]; then + error "Cannot write to ${install_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}" + fi + + # check if the directory is in the PATH + good=$( + IFS=: + for path in $PATH; do + if [ "${path%/}" = "${install_dir}" ]; then + printf 1 + break + fi + done + ) + + if [ "${good}" != "1" ]; then + warn "Installation directory ${install_dir} is not in your \$PATH, add it using \nexport PATH=\$PATH:${install_dir}" + fi +} + +validate_themes_directory() { + + # Validate if the themes directory exists + if ! mkdir -p "$themes_dir" > /dev/null 2>&1; then + error "Cannot write to ${themes_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -t {directory}" + fi + + #check user write permission + if [ ! -w "$themes_dir" ]; then + error "Cannot write to ${themes_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -t {directory}" + fi +} + +install_themes() { + if [ -n "$themes_dir" ]; then + # expand directory + themes_dir="${themes_dir/#\~/$HOME}" + fi + + cache_dir=$($executable cache path) + + # validate if the user set the path to the themes directory + if [ -z "$themes_dir" ]; then + themes_dir="${cache_dir}/themes" + fi + + validate_themes_directory + + info "🎨 Installing oh-my-posh themes in ${themes_dir}\n" + + zip_file="${cache_dir}/themes.zip" + + url="https://cdn.ohmyposh.dev/releases/latest/themes.zip" + + http_response=$(curl -s -f -L $url -o $zip_file -w "%{http_code}") + + if [ $http_response = "200" ] && [ -f $zip_file ]; then + unzip -o -q $zip_file -d $themes_dir + # make sure the files are readable and writable for all users + chmod a+rwX ${themes_dir}/*.omp.* + rm $zip_file + else + warn "Unable to download themes at ${url}\nPlease validate your curl, connection and/or proxy settings" + fi +} + +install() { + arch=$(detect_arch) + platform=$(detect_platform) + target="${platform}-${arch}" + + good=$( + IFS=" " + for t in $SUPPORTED_TARGETS; do + if [ "${t}" = "${target}" ]; then + printf 1 + break + fi + done + ) + + if [ "${good}" != "1" ]; then + error "${arch} builds for ${platform} are not available for Oh My Posh" + fi + + info "\nℹ️ Installing oh-my-posh for ${target} in ${install_dir}" + + executable=${install_dir}/oh-my-posh + url=https://cdn.ohmyposh.dev/releases/latest/posh-${target} + if [ "$version" ]; then + url=https://cdn.ohmyposh.dev/releases/${version}/posh-${target} + fi + + info "⬇️ Downloading oh-my-posh from ${url}" + + http_response=$(curl -s -f -L $url -o $executable -w "%{http_code}") + + if [ $http_response != "200" ] || [ ! -f $executable ]; then + error "Unable to download executable at ${url}\nPlease validate your curl, connection and/or proxy settings" + fi + + chmod +x $executable + + install_themes + + info "🚀 Installation complete.\n\nYou can follow the instructions at https://ohmyposh.dev/docs/installation/prompt" + info "to setup your shell to use oh-my-posh." + if [ $http_response = "200" ]; then + info "\nIf you want to use a built-in theme, you can find them in the ${themes_dir} directory:" + info " oh-my-posh init {shell} --config ${themes_dir}/{theme}.omp.json\n" + fi +} + +detect_arch() { + arch="$(uname -m | tr '[:upper:]' '[:lower:]')" + + case "${arch}" in + x86_64) arch="amd64" ;; + armv*) arch="arm" ;; + arm64) arch="arm64" ;; + aarch64) arch="arm64" ;; + i686) arch="386" ;; + esac + + if [ "${arch}" = "arm64" ] && [ "$(getconf LONG_BIT)" -eq 32 ]; then + arch=arm + fi + + printf '%s' "${arch}" +} + + +detect_platform() { + platform="$(uname -s | awk '{print tolower($0)}')" + + case "${platform}" in + linux) platform="linux" ;; + darwin) platform="darwin" ;; + esac + + printf '%s' "${platform}" +} + +validate_dependencies +set_install_directory +validate_install_directory +install diff --git a/ubuntu/.src/setup.sh b/ubuntu/.src/setup.sh new file mode 100755 index 0000000..e2f92ef --- /dev/null +++ b/ubuntu/.src/setup.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +cd $HOME/dotfiles/ +{ + echo "${CYAN}Updating submodules..${NC}" && + git submodule update --init --recursive && + echo "${CYAN}Pulling down submodules..${NC}" && + git pull --recurse-submodule +} + +stow dotfiles/ +stow zsh/ + +exec zsh diff --git a/ubuntu/Dockerfile b/ubuntu/Dockerfile new file mode 100644 index 0000000..af187b8 --- /dev/null +++ b/ubuntu/Dockerfile @@ -0,0 +1,24 @@ +FROM ubuntu:noble + +RUN apt update && apt install --assume-yes curl zsh fzf zoxide unzip sudo git make stow + +COPY ./.src/colorscript.sh . +COPY ./.src/neovim.sh . +COPY ./.src/omp.sh . + +RUN bash ./omp.sh -d /bin && rm ./omp.sh +RUN bash colorscript.sh && rm colorscript.sh +RUN bash neovim.sh && rm neovim.sh + +# RUN useradd -m -G sudo -r -s /usr/bin/zsh ubuntu +RUN usermod -aG sudo ubuntu + +RUN echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers +USER ubuntu +WORKDIR /home/ubuntu + +COPY .src/setup.sh . + +RUN git clone --recursive --depth=1 https://git.k4li.de/dotfiles/minimal.git /home/ubuntu/dotfiles + +ENTRYPOINT /usr/bin/zsh