batman
This commit is contained in:
commit
cc8ffcfcc2
38 changed files with 6046 additions and 0 deletions
38
bash/setup/hlpush.sh
Executable file
38
bash/setup/hlpush.sh
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/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"
|
||||
}
|
||||
|
||||
main() {
|
||||
local dir="/opt/docker"
|
||||
|
||||
cd $dir || echo_error "Can't navigate to $dir"
|
||||
|
||||
git add .
|
||||
|
||||
git commit -m "Automatic push on $(date)"
|
||||
|
||||
git push
|
||||
}
|
||||
|
||||
main
|
152
bash/setup/homelapGitSetup.sh
Executable file
152
bash/setup/homelapGitSetup.sh
Executable file
|
@ -0,0 +1,152 @@
|
|||
#!/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"
|
||||
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
|
||||
}
|
||||
|
||||
check_root
|
||||
|
||||
gitUserSetup() {
|
||||
local g_username="server-agent"
|
||||
local g_mail="info@team-pieck.de"
|
||||
local g_branch="main"
|
||||
local g_domain="git.k4li.de"
|
||||
|
||||
local CREDENTIALS_FILE="$HOME/.git-credentials"
|
||||
|
||||
git config --global user.name "$g_username"
|
||||
git config --global user.email "$g_mail"
|
||||
git config --global init.defaultBranch "$g_branch"
|
||||
|
||||
if [[ ! -e "$CREDENTIALS_FILE" ]]; then
|
||||
echo_note "Enter your authentication token:"
|
||||
read -r -s g_token </dev/tty # The '-s' flag hides input for privacy
|
||||
# Append the new credentials to the file
|
||||
echo "https://$g_username:$g_token@$g_domain" >>"$CREDENTIALS_FILE"
|
||||
|
||||
echo "Credentials added for $g_domain in $CREDENTIALS_FILE"
|
||||
|
||||
git config --global credential.helper store
|
||||
|
||||
chmod 600 "$HOME/.git-credentials"
|
||||
fi
|
||||
}
|
||||
|
||||
gitDirSetup() {
|
||||
cd /opt/docker || echo_error "could not cd /opt/docker"
|
||||
|
||||
if $_sudo ping -w2 10.255.255.1; then
|
||||
local location="hl"
|
||||
elif $_sudo ping -w2 10.69.69.2; then
|
||||
location="vps"
|
||||
fi
|
||||
|
||||
git init .
|
||||
|
||||
git branch -m main
|
||||
|
||||
if git remote add origin "https://git.k4li.de/homelab/${location}-$(hostname)"; then
|
||||
|
||||
git add .
|
||||
|
||||
git commit -m "Initial script commit"
|
||||
|
||||
git push -u origin main
|
||||
else
|
||||
echo_error 'Failed setting the git repo up with git remote add "$(hostname)" "https://git.k4li.de/homelab/${location}-$(hostname).git"'
|
||||
fi
|
||||
}
|
||||
|
||||
set_cronjob() {
|
||||
|
||||
# Configuration
|
||||
CRON_COMMAND="/opt/scripts/hlpush.sh"
|
||||
CRON_SCHEDULE="0 3,15 * * *"
|
||||
CRON_LOG="./cronjobs.log"
|
||||
CRON_ENTRY="$CRON_SCHEDULE $CRON_COMMAND >> $CRON_LOG 2>&1"
|
||||
|
||||
# Check for existing entry
|
||||
EXISTING_ENTRIES=$(crontab -l 2>/dev/null)
|
||||
|
||||
# Add entry if not exists
|
||||
if ! echo "$EXISTING_ENTRIES" | grep -qF "$CRON_ENTRY"; then
|
||||
# Create temporary cron file
|
||||
TMPFILE=$(mktemp)
|
||||
|
||||
# Preserve existing entries
|
||||
[ -n "$EXISTING_ENTRIES" ] && echo "$EXISTING_ENTRIES" >"$TMPFILE"
|
||||
|
||||
# Add header and new entry
|
||||
echo -e "\n# Daily 3AM/3PM job added $(date)" >>"$TMPFILE"
|
||||
echo "$CRON_ENTRY" >>"$TMPFILE"
|
||||
|
||||
# Install new cron file
|
||||
crontab "$TMPFILE"
|
||||
rm -f "$TMPFILE"
|
||||
|
||||
echo_info "Success: Cronjob installed"
|
||||
echo_note "Verify with: crontab -l"
|
||||
else
|
||||
echo_warning "Notice: Cronjob already exists"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
if ! command_exists git; then
|
||||
return 1
|
||||
echo_error "You don't have git installed!"
|
||||
fi
|
||||
|
||||
gitUserSetup
|
||||
|
||||
if [[ -d /opt/docker/ ]]; then
|
||||
gitDirSetup
|
||||
fi
|
||||
|
||||
if [[ -d /opt/scripts/bash ]]; then
|
||||
set_cronjob
|
||||
else
|
||||
if command_exists curl; then
|
||||
curl -o /opt/scripts/hlpush.sh https://git.k4li.de/scripts/bash/raw/branch/main/setup/hlpush.sh
|
||||
fi
|
||||
fi
|
207
bash/setup/tuiDots.sh
Executable file
207
bash/setup/tuiDots.sh
Executable file
|
@ -0,0 +1,207 @@
|
|||
#!/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
|
Loading…
Add table
Add a link
Reference in a new issue