diff --git a/scripts/BOOTSTRAP.md b/scripts/BOOTSTRAP.md new file mode 100644 index 0000000..7d525dd --- /dev/null +++ b/scripts/BOOTSTRAP.md @@ -0,0 +1,154 @@ +# ORLY Relay Bootstrap Script + +This directory contains a bootstrap script that automates the deployment of the ORLY relay. + +## Quick Start + +### One-Line Installation + +Clone the repository and deploy the relay with a single command: + +```bash +curl -sSL https://git.nostrdev.com/mleku/next.orly.dev/raw/branch/main/scripts/bootstrap.sh | bash +``` + +**Note:** This assumes the script is accessible at the raw URL path. Adjust the URL based on your git server's raw file URL format. + +### Alternative: Download and Execute + +If you prefer to review the script before running it: + +```bash +# Download the script +curl -o bootstrap.sh https://git.nostrdev.com/mleku/next.orly.dev/raw/branch/main/scripts/bootstrap.sh + +# Review the script +cat bootstrap.sh + +# Make it executable and run +chmod +x bootstrap.sh +./bootstrap.sh +``` + +## What the Bootstrap Script Does + +1. **Checks Prerequisites** + - Verifies that `git` is installed on your system + +2. **Clones or Updates Repository** + - Clones the repository to `~/src/next.orly.dev` if it doesn't exist + - If the repository already exists, pulls the latest changes from the main branch + - Stashes any local changes before updating + +3. **Runs Deployment** + - Executes `scripts/deploy.sh` to: + - Install Go if needed + - Build the ORLY relay with embedded web UI + - Install the binary to `~/.local/bin/orly` + - Set up systemd service + - Configure necessary capabilities + +4. **Provides Next Steps** + - Shows commands to start, check status, and view logs + +## Post-Installation + +After the bootstrap script completes, you can: + +### Start the relay +```bash +sudo systemctl start orly +``` + +### Enable on boot +```bash +sudo systemctl enable orly +``` + +### Check status +```bash +sudo systemctl status orly +``` + +### View logs +```bash +sudo journalctl -u orly -f +``` + +### View relay identity +```bash +~/.local/bin/orly identity +``` + +## Configuration + +The relay configuration is managed through environment variables. Edit the systemd service file to configure: + +```bash +sudo systemctl edit orly +``` + +See the main README.md for available configuration options. + +## Troubleshooting + +### Git Not Found +```bash +# Ubuntu/Debian +sudo apt-get update && sudo apt-get install -y git + +# Fedora/RHEL +sudo dnf install -y git + +# Arch +sudo pacman -S git +``` + +### Permission Denied Errors + +Make sure your user has sudo privileges for systemd service management. + +### Port 443 Already in Use + +If you're running TLS on port 443, make sure no other service is using that port: + +```bash +sudo netstat -tlnp | grep :443 +``` + +### Script Fails to Clone + +If the repository URL is not accessible, you may need to: +- Check your network connection +- Verify the git server is accessible +- Use SSH URL instead (modify the script's `REPO_URL` variable) + +## Manual Deployment + +If you prefer to deploy manually without the bootstrap script: + +```bash +# Clone repository +git clone https://git.nostrdev.com/mleku/next.orly.dev.git ~/src/next.orly.dev + +# Enter directory +cd ~/src/next.orly.dev + +# Run deployment +./scripts/deploy.sh +``` + +## Security Considerations + +When running scripts from the internet: +1. Always review the script contents before execution +2. Use HTTPS URLs to prevent man-in-the-middle attacks +3. Verify the source is trustworthy +4. Consider using the "download and review" method instead of piping directly to bash + +## Support + +For issues or questions: +- Open an issue on the git repository +- Check the main README.md for detailed documentation +- Review logs with `sudo journalctl -u orly -f` diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100755 index 0000000..3c37a2e --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash +# +# Bootstrap script for ORLY relay +# +# This script clones the ORLY repository and runs the deployment script. +# It can be executed directly via curl: +# +# curl -sSL https://git.nostrdev.com/mleku/next.orly.dev/raw/branch/main/scripts/bootstrap.sh | bash +# +# Or downloaded and executed: +# +# curl -o bootstrap.sh https://git.nostrdev.com/mleku/next.orly.dev/raw/branch/main/scripts/bootstrap.sh +# chmod +x bootstrap.sh +# ./bootstrap.sh + +set -e # Exit on error +set -u # Exit on undefined variable +set -o pipefail # Exit on pipe failure + +# Configuration +REPO_URL="https://git.nostrdev.com/mleku/next.orly.dev.git" +REPO_NAME="next.orly.dev" +CLONE_DIR="${HOME}/src/${REPO_NAME}" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Print functions +print_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Error handler +error_exit() { + print_error "$1" + exit 1 +} + +# Check if git is installed +check_git() { + if ! command -v git &> /dev/null; then + error_exit "git is not installed. Please install git and try again." + fi + print_success "git is installed" +} + +# Clone or update repository +clone_or_update_repo() { + if [ -d "${CLONE_DIR}/.git" ]; then + print_info "Repository already exists at ${CLONE_DIR}" + print_info "Updating repository..." + + cd "${CLONE_DIR}" || error_exit "Failed to change to directory ${CLONE_DIR}" + + # Stash any local changes + if ! git diff-index --quiet HEAD --; then + print_warning "Local changes detected. Stashing them..." + git stash || error_exit "Failed to stash changes" + fi + + # Pull latest changes + git pull origin main || error_exit "Failed to update repository" + print_success "Repository updated successfully" + else + print_info "Cloning repository from ${REPO_URL}..." + + # Create parent directory if it doesn't exist + mkdir -p "$(dirname "${CLONE_DIR}")" || error_exit "Failed to create directory $(dirname "${CLONE_DIR}")" + + # Clone the repository + git clone "${REPO_URL}" "${CLONE_DIR}" || error_exit "Failed to clone repository" + print_success "Repository cloned successfully to ${CLONE_DIR}" + + cd "${CLONE_DIR}" || error_exit "Failed to change to directory ${CLONE_DIR}" + fi +} + +# Run deployment script +run_deployment() { + print_info "Running deployment script..." + + if [ ! -f "${CLONE_DIR}/scripts/deploy.sh" ]; then + error_exit "Deployment script not found at ${CLONE_DIR}/scripts/deploy.sh" + fi + + chmod +x "${CLONE_DIR}/scripts/deploy.sh" || error_exit "Failed to make deployment script executable" + + "${CLONE_DIR}/scripts/deploy.sh" || error_exit "Deployment failed" + + print_success "Deployment completed successfully!" +} + +# Main execution +main() { + echo "" + print_info "ORLY Relay Bootstrap Script" + print_info "==============================" + echo "" + + check_git + clone_or_update_repo + run_deployment + + echo "" + print_success "Bootstrap process completed successfully!" + echo "" + print_info "The ORLY relay has been deployed." + print_info "Repository location: ${CLONE_DIR}" + echo "" + print_info "To start the relay service:" + echo " sudo systemctl start orly" + echo "" + print_info "To check the relay status:" + echo " sudo systemctl status orly" + echo "" + print_info "To view relay logs:" + echo " sudo journalctl -u orly -f" + echo "" +} + +# Run main function +main