addet dotfiles and sudo setup via bash tui
This commit is contained in:
parent
5e9b9c9755
commit
739628676f
1 changed files with 183 additions and 0 deletions
183
setup/tuiDots.sh
Executable file
183
setup/tuiDots.sh
Executable file
|
@ -0,0 +1,183 @@
|
|||
#!/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
|
||||
}
|
||||
|
||||
# Menu options
|
||||
declare -a options=(
|
||||
"Sudo-Options"
|
||||
"neovim"
|
||||
"neovim-minimal"
|
||||
"Exit"
|
||||
)
|
||||
|
||||
# Function to print colored text
|
||||
print_color() {
|
||||
printf "%b%s%b\n" "$1" "$2" "$NC"
|
||||
}
|
||||
|
||||
gitDir="$HOME/git/dotfiles"
|
||||
dotRemote="https://git.k4li.de/dotfiles"
|
||||
|
||||
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
|
||||
sleep 2
|
||||
}
|
||||
|
||||
# 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
|
||||
sleep 2
|
||||
}
|
||||
|
||||
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
|
||||
sleep 3
|
||||
}
|
||||
|
||||
# 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
|
||||
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) exit 0 ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Start the main menu
|
||||
check_root
|
||||
main_menu </dev/tty
|
Loading…
Add table
Add a link
Reference in a new issue