207 lines
5 KiB
Bash
Executable file
207 lines
5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# ─< ANSI color codes >───────────────────────────────────────────────────────────────────
|
|
RED='\033[0;31m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
GREEN='\033[0;32m'
|
|
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"
|
|
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
|
|
}
|
|
|
|
# Function to print colored text
|
|
print_color() {
|
|
printf "%b%s%b\n" "$1" "$2" "$NC"
|
|
}
|
|
|
|
# Function to return to the main menu
|
|
return_to_menu() {
|
|
echo_info "Returning to the main menu in 3 seconds..."
|
|
sleep 3
|
|
}
|
|
|
|
gitDir="$HOME/git/dotfiles"
|
|
dotRemote="https://git.k4li.de/dotfiles"
|
|
instRemote="https://git.k4li.de/scripts/sh/raw/branch/main/installs"
|
|
|
|
if [ ! -d "$gitDir" ]; then
|
|
print_color "$RED" "=== git dir created - $gitDir ==="
|
|
mkdir -p "$gitDir"
|
|
fi
|
|
|
|
d_="git curl"
|
|
for dependency in $d_; do
|
|
if ! command_exists "$dependency"; then
|
|
print_color "$RED" "You're missing some dependencies!"
|
|
print_color "$RED" "Install $dependency and start the script again"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Function to display the menu
|
|
display_menu() {
|
|
clear
|
|
print_color "$BLUE" "=== Environment Setup Menu ==="
|
|
for i in "${!options[@]}"; do
|
|
if [[ $i -eq $selected ]]; then
|
|
print_color "$GREEN" "> ${options[$i]}"
|
|
else
|
|
echo " ${options[$i]}"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Function to handle dotfiles setup
|
|
nvimSetup() {
|
|
print_color "$YELLOW" "Setting up neovim..."
|
|
if [ ! -d "$HOME/.config/nvim" ]; then
|
|
echo_note "Installing into .config directly"
|
|
git clone --branch minimal --recurse-submodule --depth=1 "${dotRemote}/nvim.git" "$HOME/.config/nvim"
|
|
else
|
|
if [ -d "$gitDir/nvim" ]; then
|
|
cd "$gitDir/nvim" || {
|
|
echo_error "The given path - $gitDir/nvim - was not found!"
|
|
return 1
|
|
}
|
|
git pull --recurse-submodule
|
|
else
|
|
echo_note "Installing into $gitDir/nvim"
|
|
git clone --branch minimal --recurse-submodule --depth=1 "${dotRemote}/nvim.git" "$gitDir/nvim"
|
|
fi
|
|
fi
|
|
|
|
return_to_menu
|
|
}
|
|
|
|
# Function to handle CLI tool installation
|
|
nvimMinimalSetup() {
|
|
print_color "$YELLOW" "Setting up neovim minimal branch..."
|
|
if [ ! -d "$HOME/.config/nvim" ]; then
|
|
echo_note "Installing into .config directly"
|
|
git clone --branch minimal --recurse-submodule --depth=1 "${dotRemote}/nvim.git" "$HOME/.config/nvim"
|
|
else
|
|
if [ -d "$gitDir/nvim-minimal" ]; then
|
|
cd "$gitDir/nvim-minimal" || {
|
|
echo_error "The given path - $gitDir/nvim-minimal - was not found!"
|
|
return 1
|
|
}
|
|
git pull --recurse-submodule
|
|
else
|
|
echo_note "Installing into $gitDir/nvim-minimal"
|
|
git clone --branch minimal --recurse-submodule --depth=1 "${dotRemote}/nvim.git" "$gitDir/nvim-minimal"
|
|
fi
|
|
fi
|
|
|
|
return_to_menu
|
|
}
|
|
|
|
installStuff() {
|
|
echo_info "I want to install.."
|
|
read -r gitPackage </dev/tty
|
|
|
|
echo_note "Installing from $instRemote/$gitPackage"
|
|
curl -fsSL "${instRemote}/${gitPackage}.sh" | sh
|
|
|
|
return_to_menu
|
|
}
|
|
|
|
sudoOptions() {
|
|
if [[ -e /etc/sudoers ]]; then
|
|
echo "Defaults pwfeedback" | $_sudo tee -a /etc/sudoers
|
|
echo "Defaults insults" | $_sudo tee -a /etc/sudoers
|
|
else
|
|
echo_error "There is no /etc/sudoers file."
|
|
fi
|
|
return_to_menu
|
|
}
|
|
|
|
# Menu options
|
|
declare -a options=(
|
|
"Sudo-Options"
|
|
"neovim"
|
|
"neovim-minimal"
|
|
"Install.."
|
|
"Exit"
|
|
)
|
|
|
|
# Main menu loop
|
|
main_menu() {
|
|
local selected=0
|
|
local key=""
|
|
|
|
while true; do
|
|
display_menu
|
|
|
|
# Read a single character
|
|
read -rsn1 key
|
|
|
|
case $key in
|
|
q | Q)
|
|
exit 0
|
|
;;
|
|
A | k) # Up arrow or k
|
|
((selected--))
|
|
if [[ $selected -lt 0 ]]; then
|
|
selected=$((${#options[@]} - 1))
|
|
fi
|
|
;;
|
|
B | j) # Down arrow or j
|
|
((selected++))
|
|
if [[ $selected -ge ${#options[@]} ]]; then
|
|
selected=0
|
|
fi
|
|
;;
|
|
"" | l) # Enter key
|
|
case $selected in
|
|
0) sudoOptions ;;
|
|
1) nvimSetup ;;
|
|
2) nvimMinimalSetup ;;
|
|
3) installStuff ;;
|
|
4) exit 0 ;;
|
|
esac
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
# Start the main menu
|
|
check_root
|
|
main_menu </dev/tty
|