You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

  1. #!/bin/bash
  2. # deploy.sh - Script to handle local deployment
  3. # Usage: ./deploy.sh [--no-commit] [source_dir] [dest_dir] [base_path]
  4. set -e # Exit on error
  5. # Default settings
  6. COMMIT_CHANGES=true
  7. SOURCE_DIR="dist" # Default source directory
  8. DEST_DIR="$HOME/Git/sparanoid.com-prod" # Default destination
  9. BASE_PATH="/lab/7z" # Default base path
  10. LOG_FILE="deploy-sparanoid.log"
  11. # Parse arguments
  12. while [[ "$#" -gt 0 ]]; do
  13. case $1 in
  14. --no-commit) COMMIT_CHANGES=false ;;
  15. *)
  16. if [ -z "$SOURCE_OVERRIDE" ]; then
  17. SOURCE_OVERRIDE="$1"
  18. elif [ -z "$DEST_OVERRIDE" ]; then
  19. DEST_OVERRIDE="$1"
  20. elif [ -z "$BASE_OVERRIDE" ]; then
  21. BASE_OVERRIDE="$1"
  22. else
  23. echo "Error: Unexpected argument $1"
  24. exit 1
  25. fi
  26. ;;
  27. esac
  28. shift
  29. done
  30. # Override defaults if provided
  31. [ -n "$SOURCE_OVERRIDE" ] && SOURCE_DIR="$SOURCE_OVERRIDE"
  32. [ -n "$DEST_OVERRIDE" ] && DEST_DIR="$DEST_OVERRIDE"
  33. [ -n "$BASE_OVERRIDE" ] && BASE_PATH="$BASE_OVERRIDE"
  34. # Create destination directory if it doesn't exist
  35. mkdir -p "$DEST_DIR/site/$BASE_PATH"
  36. # Log start with parameters used
  37. echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting deployment" | tee -a "$LOG_FILE"
  38. echo "Source: $SOURCE_DIR" | tee -a "$LOG_FILE"
  39. echo "Destination: $DEST_DIR/site/$BASE_PATH" | tee -a "$LOG_FILE"
  40. echo "Auto-commit: $([ "$COMMIT_CHANGES" = true ] && echo "enabled" || echo "disabled")" | tee -a "$LOG_FILE"
  41. # Copy files to local directory
  42. rsync -avz --delete --progress \
  43. "$SOURCE_DIR/" \
  44. "$DEST_DIR/site/$BASE_PATH" >>"$LOG_FILE" 2>&1
  45. if [ $? -eq 0 ]; then
  46. echo "[$(date '+%Y-%m-%d %H:%M:%S')] File sync completed successfully" | tee -a "$LOG_FILE"
  47. # Run auto-commit if enabled
  48. if [ "$COMMIT_CHANGES" = true ] && [ -f "$DEST_DIR/auto-commit" ]; then
  49. echo "[$(date '+%Y-%m-%d %H:%M:%S')] Running auto-commit script..." | tee -a "$LOG_FILE"
  50. cd "$DEST_DIR" && bash "auto-commit" >>"$LOG_FILE" 2>&1
  51. fi
  52. else
  53. echo "[$(date '+%Y-%m-%d %H:%M:%S')] Error: File sync failed" | tee -a "$LOG_FILE"
  54. exit 1
  55. fi
  56. echo "[$(date '+%Y-%m-%d %H:%M:%S')] Deployment completed" | tee -a "$LOG_FILE"
  57. exit 0