This commit is contained in:
pika 2025-04-10 21:30:06 +02:00
parent 67059eb38f
commit 0223e81763

View file

@ -28,6 +28,29 @@ 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() {
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"
@ -57,9 +80,9 @@ gitUserSetup() {
gitDirSetup() {
cd /opt/docker || echo_error "could not cd /opt/docker"
if ping -w2 10.255.255.1; then
if $_sudo ping -w2 10.255.255.1; then
local location="hl"
elif ping -w2 10.69.69.2; then
elif $_sudo ping -w2 10.69.69.2; then
location="vps"
fi