bootstrap.sh raw

   1  #!/usr/bin/env bash
   2  #
   3  # Bootstrap script for ORLY relay
   4  #
   5  # This script clones the ORLY repository and runs the deployment script.
   6  # It can be executed directly via curl:
   7  #
   8  #   curl -sSL https://git.nostrdev.com/mleku/next.orly.dev/raw/branch/main/scripts/bootstrap.sh | bash
   9  #
  10  # Or downloaded and executed:
  11  #
  12  #   curl -o bootstrap.sh https://git.nostrdev.com/mleku/next.orly.dev/raw/branch/main/scripts/bootstrap.sh
  13  #   chmod +x bootstrap.sh
  14  #   ./bootstrap.sh
  15  
  16  set -e  # Exit on error
  17  set -u  # Exit on undefined variable
  18  set -o pipefail  # Exit on pipe failure
  19  
  20  # Configuration
  21  REPO_URL="https://git.nostrdev.com/mleku/next.orly.dev.git"
  22  REPO_NAME="next.orly.dev"
  23  CLONE_DIR="${HOME}/src/${REPO_NAME}"
  24  
  25  # Colors for output
  26  RED='\033[0;31m'
  27  GREEN='\033[0;32m'
  28  YELLOW='\033[1;33m'
  29  BLUE='\033[0;34m'
  30  NC='\033[0m' # No Color
  31  
  32  # Print functions
  33  print_info() {
  34      echo -e "${BLUE}[INFO]${NC} $1"
  35  }
  36  
  37  print_success() {
  38      echo -e "${GREEN}[SUCCESS]${NC} $1"
  39  }
  40  
  41  print_warning() {
  42      echo -e "${YELLOW}[WARNING]${NC} $1"
  43  }
  44  
  45  print_error() {
  46      echo -e "${RED}[ERROR]${NC} $1"
  47  }
  48  
  49  # Error handler
  50  error_exit() {
  51      print_error "$1"
  52      exit 1
  53  }
  54  
  55  # Check if git is installed
  56  check_git() {
  57      if ! command -v git &> /dev/null; then
  58          error_exit "git is not installed. Please install git and try again."
  59      fi
  60      print_success "git is installed"
  61  }
  62  
  63  # Clone or update repository
  64  clone_or_update_repo() {
  65      if [ -d "${CLONE_DIR}/.git" ]; then
  66          print_info "Repository already exists at ${CLONE_DIR}"
  67          print_info "Updating repository..."
  68  
  69          cd "${CLONE_DIR}" || error_exit "Failed to change to directory ${CLONE_DIR}"
  70  
  71          # Stash any local changes
  72          if ! git diff-index --quiet HEAD --; then
  73              print_warning "Local changes detected. Stashing them..."
  74              git stash || error_exit "Failed to stash changes"
  75          fi
  76  
  77          # Pull latest changes
  78          git pull origin main || error_exit "Failed to update repository"
  79          print_success "Repository updated successfully"
  80      else
  81          print_info "Cloning repository from ${REPO_URL}..."
  82  
  83          # Create parent directory if it doesn't exist
  84          mkdir -p "$(dirname "${CLONE_DIR}")" || error_exit "Failed to create directory $(dirname "${CLONE_DIR}")"
  85  
  86          # Clone the repository
  87          git clone "${REPO_URL}" "${CLONE_DIR}" || error_exit "Failed to clone repository"
  88          print_success "Repository cloned successfully to ${CLONE_DIR}"
  89  
  90          cd "${CLONE_DIR}" || error_exit "Failed to change to directory ${CLONE_DIR}"
  91      fi
  92  }
  93  
  94  # Run deployment script
  95  run_deployment() {
  96      print_info "Running deployment script..."
  97  
  98      if [ ! -f "${CLONE_DIR}/scripts/deploy.sh" ]; then
  99          error_exit "Deployment script not found at ${CLONE_DIR}/scripts/deploy.sh"
 100      fi
 101  
 102      chmod +x "${CLONE_DIR}/scripts/deploy.sh" || error_exit "Failed to make deployment script executable"
 103  
 104      "${CLONE_DIR}/scripts/deploy.sh" || error_exit "Deployment failed"
 105  
 106      print_success "Deployment completed successfully!"
 107  }
 108  
 109  # Main execution
 110  main() {
 111      echo ""
 112      print_info "ORLY Relay Bootstrap Script"
 113      print_info "=============================="
 114      echo ""
 115  
 116      check_git
 117      clone_or_update_repo
 118      run_deployment
 119  
 120      echo ""
 121      print_success "Bootstrap process completed successfully!"
 122      echo ""
 123      print_info "The ORLY relay has been deployed."
 124      print_info "Repository location: ${CLONE_DIR}"
 125      echo ""
 126      print_info "To start the relay service:"
 127      echo "  sudo systemctl start orly"
 128      echo ""
 129      print_info "To check the relay status:"
 130      echo "  sudo systemctl status orly"
 131      echo ""
 132      print_info "To view relay logs:"
 133      echo "  sudo journalctl -u orly -f"
 134      echo ""
 135  }
 136  
 137  # Run main function
 138  main
 139