diff --git a/CHANGELOG.md b/CHANGELOG.md index 74372fb..98ab860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ All notable changes to OpenHamClock will be documented in this file. - `.env` is auto-created from `.env.example` on first run - Settings won't be overwritten by git updates - Supports: CALLSIGN, LOCATOR, PORT, HOST, UNITS, TIME_FORMAT, THEME, LAYOUT +- **Update script** - Easy updates for local/Pi installations (`./scripts/update.sh`) + - Backs up config, pulls latest, rebuilds, preserves settings - **Network access configuration** - Set `HOST=0.0.0.0` to access from other devices - **Grid locator auto-conversion** - Automatically calculates lat/lon from LOCATOR - **Setup wizard** - Settings panel auto-opens if CALLSIGN or LOCATOR is missing diff --git a/README.md b/README.md index 75475a4..2013040 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,25 @@ The backend server provides: ## 🚀 Deployment +### Raspberry Pi + +One-line install for Raspberry Pi: +```bash +curl -sSL https://raw.githubusercontent.com/k0cjh/openhamclock/main/scripts/setup-pi.sh | bash +``` + +Or with kiosk mode (auto-starts fullscreen on boot): +```bash +curl -sSL https://raw.githubusercontent.com/k0cjh/openhamclock/main/scripts/setup-pi.sh | bash -s -- --kiosk +``` + +After installation: +```bash +cd ~/openhamclock +nano .env # Edit your callsign and locator +./restart.sh +``` + ### Railway ```bash # railway.toml and railway.json are included @@ -241,6 +260,34 @@ npm run build NODE_ENV=production node server.js ``` +## 🔄 Updating + +For local/Pi installations, use the update script: + +```bash +cd ~/openhamclock +./scripts/update.sh +``` + +The update script will: +1. ✅ Back up your `.env` configuration +2. ✅ Pull the latest code from GitHub +3. ✅ Install any new dependencies +4. ✅ Rebuild the frontend +5. ✅ Preserve your settings + +Then restart the server: +```bash +sudo systemctl restart openhamclock +# or +./restart.sh +``` + +**Note:** If you installed from a zip file (not git clone), you'll need to: +1. Back up your `.env` file +2. Download the new zip +3. Extract and restore your `.env` + ## 🤝 Contributing 1. Fork the repository diff --git a/scripts/setup-pi.sh b/scripts/setup-pi.sh index 5979570..776cf31 100644 --- a/scripts/setup-pi.sh +++ b/scripts/setup-pi.sh @@ -140,12 +140,18 @@ setup_repository() { git pull else echo "Cloning repository..." - git clone https://github.com/accius/openhamclock.git "$INSTALL_DIR" + git clone https://github.com/k0cjh/openhamclock.git "$INSTALL_DIR" cd "$INSTALL_DIR" fi # Install npm dependencies - npm install --production + npm install + + # Build frontend for production + npm run build + + # Make update script executable + chmod +x scripts/update.sh 2>/dev/null || true echo -e "${GREEN}✓ OpenHamClock installed to $INSTALL_DIR${NC}" } @@ -317,10 +323,11 @@ print_summary() { echo -e " ${BLUE}Web Interface:${NC} http://localhost:3000" echo "" echo -e " ${YELLOW}Helper Commands:${NC}" - echo " $INSTALL_DIR/start.sh - Start server manually" - echo " $INSTALL_DIR/stop.sh - Stop everything" - echo " $INSTALL_DIR/restart.sh - Restart server" - echo " $INSTALL_DIR/status.sh - Check status" + echo " $INSTALL_DIR/scripts/update.sh - Update to latest version" + echo " $INSTALL_DIR/start.sh - Start server manually" + echo " $INSTALL_DIR/stop.sh - Stop everything" + echo " $INSTALL_DIR/restart.sh - Restart server" + echo " $INSTALL_DIR/status.sh - Check status" echo "" echo -e " ${YELLOW}Service Commands:${NC}" echo " sudo systemctl start ${SERVICE_NAME}" diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100644 index 0000000..bd7cf11 --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,138 @@ +#!/bin/bash +# OpenHamClock Update Script +# Updates to the latest version while preserving your configuration + +set -e + +echo "╔═══════════════════════════════════════════════════════╗" +echo "║ OpenHamClock Update Script ║" +echo "╚═══════════════════════════════════════════════════════╝" +echo "" + +# Check if we're in the right directory +if [ ! -f "server.js" ] || [ ! -f "package.json" ]; then + echo "❌ Error: Please run this script from the openhamclock directory" + echo " cd /path/to/openhamclock" + echo " ./scripts/update.sh" + exit 1 +fi + +# Check if git is available +if ! command -v git &> /dev/null; then + echo "❌ Error: git is not installed" + echo " sudo apt install git" + exit 1 +fi + +# Check if this is a git repository +if [ ! -d ".git" ]; then + echo "❌ Error: This doesn't appear to be a git repository" + echo " If you installed from a zip file, you'll need to:" + echo " 1. Back up your .env file" + echo " 2. Download the new version" + echo " 3. Extract and copy your .env back" + exit 1 +fi + +echo "📋 Current version:" +grep '"version"' package.json | head -1 + +echo "" +echo "🔍 Checking for updates..." + +# Fetch latest changes +git fetch origin + +# Check if there are updates +LOCAL=$(git rev-parse HEAD) +REMOTE=$(git rev-parse origin/main 2>/dev/null || git rev-parse origin/master) + +if [ "$LOCAL" = "$REMOTE" ]; then + echo "✅ Already up to date!" + exit 0 +fi + +echo "📦 Updates available!" +echo "" + +# Show what's new +echo "📝 Changes since your version:" +git log --oneline HEAD..origin/main 2>/dev/null || git log --oneline HEAD..origin/master +echo "" + +# Confirm update +read -p "🔄 Do you want to update? (y/N) " -n 1 -r +echo "" +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "❌ Update cancelled" + exit 0 +fi + +echo "" +echo "🛡️ Backing up configuration..." + +# Backup .env if it exists +if [ -f ".env" ]; then + cp .env .env.backup + echo " ✓ .env → .env.backup" +fi + +# Backup any other local config +if [ -f "config.json" ]; then + cp config.json config.json.backup + echo " ✓ config.json → config.json.backup" +fi + +echo "" +echo "⬇️ Pulling latest changes..." +git pull origin main 2>/dev/null || git pull origin master + +echo "" +echo "📦 Installing dependencies..." +npm install + +echo "" +echo "🔨 Building frontend..." +npm run build + +echo "" +echo "🔄 Restoring configuration..." + +# Restore .env (should still be there since it's gitignored, but just in case) +if [ -f ".env.backup" ] && [ ! -f ".env" ]; then + cp .env.backup .env + echo " ✓ .env restored from backup" +fi + +# Restore config.json if needed +if [ -f "config.json.backup" ] && [ ! -f "config.json" ]; then + cp config.json.backup config.json + echo " ✓ config.json restored from backup" +fi + +echo "" +echo "📋 New version:" +grep '"version"' package.json | head -1 + +echo "" +echo "╔═══════════════════════════════════════════════════════╗" +echo "║ ✅ Update Complete! ║" +echo "╚═══════════════════════════════════════════════════════╝" +echo "" +echo "🔄 Restart the server to apply changes:" +echo "" + +# Check if running as systemd service +if systemctl is-active --quiet openhamclock 2>/dev/null; then + echo " sudo systemctl restart openhamclock" +else + echo " # If running in terminal, press Ctrl+C and run:" + echo " npm start" + echo "" + echo " # If running as a service:" + echo " sudo systemctl restart openhamclock" +fi + +echo "" +echo "📖 See CHANGELOG.md for what's new" +echo ""