#!/usr/bin/env bash set -euo pipefail APP_NAME="${1:-}" GIT_REF="${2:-}" if [[ -z "$APP_NAME" || -z "$GIT_REF" ]]; then echo "usage: deploy-app " >&2 exit 2 fi if ! [[ "$APP_NAME" =~ ^[A-Za-z0-9._-]+$ ]]; then echo "invalid app name: $APP_NAME" >&2 exit 2 fi if ! [[ "$GIT_REF" =~ ^[0-9a-fA-F]{7,40}$ ]]; then echo "invalid git ref: $GIT_REF" >&2 exit 2 fi APP_DIR="/srv/apps/$APP_NAME" if [[ ! -d "$APP_DIR/.git" ]]; then echo "app repo not present at $APP_DIR; clone it first (or extend deploy-app to clone)" >&2 exit 1 fi cd "$APP_DIR" git fetch --all --prune git checkout -f "$GIT_REF" git submodule update --init --recursive if [[ -x "./deploy.sh" ]]; then ./deploy.sh else echo "ERROR: deploy.sh missing or not executable" >&2 exit 1 fi