This commit is contained in:
pika 2025-04-10 21:50:30 +02:00
parent 51dd337f8c
commit 14afc57f44

View file

@ -1,41 +1,35 @@
{
#!/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
#!/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() {
echo_error() {
printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2
}
}
echo_info() {
echo_info() {
printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1"
}
}
echo_warning() {
echo_warning() {
printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1"
}
}
echo_note() {
echo_note() {
printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1"
}
}
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&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() {
# ─< 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."
@ -48,11 +42,11 @@
echo_info "Root access confirmed."
_sudo=""
fi
}
}
check_root
check_root
gitUserSetup() {
gitUserSetup() {
local g_username="server-agent"
local g_mail="info@team-pieck.de"
local g_branch="main"
@ -76,9 +70,9 @@
chmod 600 "$HOME/.git-credentials"
fi
}
}
gitDirSetup() {
gitDirSetup() {
cd /opt/docker || echo_error "could not cd /opt/docker"
if $_sudo ping -w2 10.255.255.1; then
@ -101,9 +95,9 @@
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() {
set_cronjob() {
# Configuration
CRON_COMMAND="/opt/scripts/hlpush.sh"
@ -136,24 +130,23 @@
echo_warning "Notice: Cronjob already exists"
exit 0
fi
}
}
if ! command_exists git; then
if ! command_exists git; then
return 1
echo_error "You don't have git installed!"
fi
fi
gitUserSetup
gitUserSetup
if [[ -d /opt/docker/ ]]; then
if [[ -d /opt/docker/ ]]; then
gitDirSetup
fi
fi
if [[ -d /opt/scripts/bash ]]; then
if [[ -d /opt/scripts/bash ]]; then
set_cronjob
else
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
}
fi