#!/usr/bin/env bash # Run on the server as root after rsyncing the app files. set -euo pipefail APP_DIR=/opt/albumen MEDIA_DIR=/var/albumen echo "==> Creating directories" mkdir -p "$APP_DIR"/{cache/thumbs,tmp,log,public/img} mkdir -p "$MEDIA_DIR" echo "==> Creating service user" id albumen &>/dev/null || useradd -r -s /usr/sbin/nologin -d "$APP_DIR" albumen echo "==> Installing gems" cd "$APP_DIR" bundle install --without development test echo "==> Generating audio placeholder SVG" cat > "$APP_DIR/public/img/audio.svg" <<'SVG' SVG echo "==> Setting permissions" chown -R albumen:albumen "$APP_DIR" "$MEDIA_DIR" chmod +x "$APP_DIR/scripts/"*.rb echo "==> Setting up nginx" cp "$APP_DIR/config/nginx-albumen.conf" /etc/nginx/sites-available/albumen ln -sf /etc/nginx/sites-available/albumen /etc/nginx/sites-enabled/albumen rm -f /etc/nginx/sites-enabled/default nginx -t systemctl enable nginx systemctl restart nginx echo "==> Setting up systemd service" cp "$APP_DIR/config/albumen.service" /etc/systemd/system/ systemctl daemon-reload systemctl enable albumen echo "" echo "==> Setup complete!" echo "" echo "Next steps:" echo " 1. Set admin password: ruby $APP_DIR/scripts/set_password.rb" echo " 2. Start the service: systemctl start albumen" echo " 3. Check logs: journalctl -u albumen -f" echo " 4. Drop photos into: $MEDIA_DIR" echo " 5. Run update script: ruby $APP_DIR/scripts/update.rb"