#!/usr/bin/env bashset -euhelp() { cat <<EOFUsage: $0 [OPTIONS]Options: -a Update API -w Update Web -A Update API & Web -m Apply migration in API -h Show this help and exitEOF}# False by defaultapply_migration=0update_api=0update_web=0# Check if any flag was passedif [[ $# -eq 0 ]]; then help; exit 1fiwhile getopts ":awAmh" opt; do case $opt in a) update_api=1 ;; w) update_web=1 ;; A) update_api=1; update_web=1 ;; m) apply_migration=1;; h) help; exit 0 ;; \?) help; exit 1 ;; esacdoneif (( update_api || update_web )); then git pullfiif (( update_api )); then echo "Updating api" cd packages/api bun i --frozen-lockfile if (( apply_migration )); then echo "Applying migration" bun run db:migrate fi cd ../.. echo "Restarting api service" systemctl --user restart nexus-apielif (( apply_migration )); then echo "Applying migration" cd packages/api bun run db:migrate cd ../.. echo "Restarting api service" systemctl --user restart nexus-apifiif (( update_web )); then echo "Updating web" cd packages/web bun i --frozen-lockfile bun run build cd ../.. echo "Restarting web service" systemctl --user restart nexus-webfiecho "Update complete"