feat: warn if role missing

This commit is contained in:
deadcxap
2025-08-24 04:05:17 +03:00
parent ce4c60ed02
commit c1e6a22fdc
2 changed files with 47 additions and 25 deletions
+40 -18
View File
@@ -53,8 +53,7 @@ Usage: $0 --user NAME --sshkey KEY [options]
-s, --ssh-ip IP (optional) IP allowed to access SSH
-m, --monitor-ip IP (optional) IP allowed to access Beszel port 45876/tcp
-v, --vector URL (optional) URL of Vector sink
-c, --compose-url URL (optional) URL of docker-compose.yaml
-d, --compose-dir DIR (optional) Directory to place compose file
-r, --role NAME (optional) Role name to bootstrap
-n, --netbird-key KEY (optional) Netbird setup key
-i, --netbird-ip IP (optional) Netbird central server IP
-p, --netbird-port PORT (optional) Netbird central server port
@@ -66,8 +65,7 @@ SSH_KEY=""
SSH_ALLOWED_IP=""
MONITOR_IP=""
VECTOR_ENDPOINT=""
COMPOSE_URL=""
COMPOSE_DIR=""
ROLE=""
NETBIRD_KEY=""
NETBIRD_IP=""
NETBIRD_PORT=""
@@ -79,8 +77,7 @@ while [[ $# -gt 0 ]]; do
-s|--ssh-ip) SSH_ALLOWED_IP="$2"; shift 2;;
-m|--monitor-ip) MONITOR_IP="$2"; shift 2;;
-v|--vector) VECTOR_ENDPOINT="$2"; shift 2;;
-c|--compose-url) COMPOSE_URL="$2"; shift 2;;
-d|--compose-dir) COMPOSE_DIR="$2"; shift 2;;
-r|--role) ROLE="$2"; shift 2;;
-n|--netbird-key) NETBIRD_KEY="$2"; shift 2;;
-i|--netbird-ip) NETBIRD_IP="$2"; shift 2;;
-p|--netbird-port) NETBIRD_PORT="$2"; shift 2;;
@@ -94,11 +91,6 @@ if [[ -z "$USERNAME" || -z "$SSH_KEY" ]]; then
exit 1
fi
if [[ -n "$COMPOSE_URL" && -z "$COMPOSE_DIR" ]] || [[ -z "$COMPOSE_URL" && -n "$COMPOSE_DIR" ]]; then
log "Both --compose-url and --compose-dir must be provided together"
exit 1
fi
if [[ $(id -u) -ne 0 ]]; then
echo "This script must be run as root" >&2
exit 1
@@ -230,12 +222,42 @@ EOF"
run "Checking Vector service" systemctl is-active --quiet vector
}
setup_compose() {
[[ -z "$COMPOSE_URL" ]] && return
run "Creating directory $COMPOSE_DIR" mkdir -p "$COMPOSE_DIR"
run "Downloading compose file" curl -fsSL "$COMPOSE_URL" -o "$COMPOSE_DIR/docker-compose.yml"
run "Setting ownership for compose dir" chown -R "$USERNAME:$USERNAME" "$COMPOSE_DIR"
run "Starting docker compose" bash -c "cd '$COMPOSE_DIR' && docker compose up -d"
setup_role() {
[[ -z "$ROLE" ]] && return
local TEMP_DIR ROLE_SRC ROLE_TARGET INIT_SCRIPT REPO_URL ROLE_URL
REPO_URL="https://github.com/deadcxap/init_scripts.git"
ROLE_URL="https://api.github.com/repos/deadcxap/init_scripts/contents/$ROLE"
log "Checking role $ROLE exists in repository"
if curl -fsSL -o /dev/null "$ROLE_URL"; then
log "OK: role $ROLE exists in repository"
SUMMARY+=("Role check: OK")
else
log "WARN: role $ROLE not found in repository, skipping"
SUMMARY+=("Role check: WARN")
return
fi
TEMP_DIR=$(mktemp -d)
run "Cloning role repository" git clone --depth=1 "$REPO_URL" "$TEMP_DIR"
ROLE_SRC="$TEMP_DIR/$ROLE"
if [[ ! -d "$ROLE_SRC" ]]; then
log "WARN: role directory $ROLE_SRC not found after clone, skipping"
SUMMARY+=("Role copy: WARN")
run "Cleaning up role repository" rm -rf "$TEMP_DIR"
return
fi
run "Copying role files" cp -r "$ROLE_SRC" /opt/
ROLE_TARGET="/opt/$ROLE"
run "Setting ownership for $ROLE_TARGET" chown -R "$USERNAME:$USERNAME" "$ROLE_TARGET"
INIT_SCRIPT="$ROLE_TARGET/init.sh"
if [[ -f "$INIT_SCRIPT" ]]; then
run "Running init.sh for $ROLE" bash "$INIT_SCRIPT"
run "Checking $ROLE stack" bash -c "cd '$ROLE_TARGET' && docker compose ps | grep -q 'Up'"
run "Removing init.sh for $ROLE" rm -f "$INIT_SCRIPT"
else
log "WARN: init.sh not found in $ROLE_TARGET, skipping"
SUMMARY+=("init.sh for $ROLE: MISSING")
fi
run "Cleaning up role repository" rm -rf "$TEMP_DIR"
}
main() {
@@ -250,7 +272,7 @@ main() {
configure_logrotate
install_netbird
setup_vector
setup_compose
setup_role
}
main