Change mirror command to work better with existing target directories: - Use cd/lcd to change to directories first - Simplify mirror command to work from current directories - Add mkdir fallback if target directory doesn't exist - Fix SSL setting from ssl-allow to ssl-force for proper FTPS This resolves issues when httpsdocs directory already exists on server. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
166 lines
3.7 KiB
Bash
Executable File
166 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#
|
|
# FTPS Deployment Script for markusgraf.ch
|
|
#
|
|
# This script deploys the Hugo-built static site to the production server
|
|
# via FTPS (FTP over SSL/TLS).
|
|
#
|
|
# Prerequisites:
|
|
# - Hugo site must be built (public/ directory exists)
|
|
# - lftp must be installed
|
|
# - FTPS_PASSWORD environment variable must be set
|
|
#
|
|
# Usage:
|
|
# export FTPS_PASSWORD='your-password'
|
|
# ./scripts/deploy.sh
|
|
#
|
|
# Server Details:
|
|
# - Server: www.markusgraf.ch
|
|
# - Username: gurix
|
|
# - Target Directory: httpsdocs/
|
|
# - Source Directory: public/
|
|
#
|
|
|
|
set -e # Exit on error
|
|
set -u # Exit on undefined variable
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
FTPS_SERVER="www.markusgraf.ch"
|
|
TARGET_DIR="httpsdocs"
|
|
SOURCE_DIR="public"
|
|
|
|
#
|
|
# Print error message in red and exit
|
|
#
|
|
error() {
|
|
echo -e "${RED}ERROR: $1${NC}" >&2
|
|
exit 1
|
|
}
|
|
|
|
#
|
|
# Print warning message in yellow
|
|
#
|
|
warn() {
|
|
echo -e "${YELLOW}WARNING: $1${NC}" >&2
|
|
}
|
|
|
|
#
|
|
# Print success message in green
|
|
#
|
|
success() {
|
|
echo -e "${GREEN}$1${NC}"
|
|
}
|
|
|
|
#
|
|
# Print info message
|
|
#
|
|
info() {
|
|
echo "$1"
|
|
}
|
|
|
|
#
|
|
# Check all prerequisites before deployment
|
|
#
|
|
check_prerequisites() {
|
|
info "Checking prerequisites..."
|
|
|
|
# Check if public/ directory exists and is not empty
|
|
if [ ! -d "$SOURCE_DIR" ]; then
|
|
error "Directory '$SOURCE_DIR' does not exist. Please run 'hugo build' first."
|
|
fi
|
|
|
|
if [ ! "$(ls -A $SOURCE_DIR)" ]; then
|
|
error "Directory '$SOURCE_DIR' is empty. Please run 'hugo build' first."
|
|
fi
|
|
|
|
# Check if lftp is installed
|
|
if ! command -v lftp &> /dev/null; then
|
|
error "lftp is not installed. Please install it first:
|
|
Ubuntu/Debian: sudo apt-get install lftp
|
|
macOS: brew install lftp
|
|
Fedora: sudo dnf install lftp"
|
|
fi
|
|
|
|
# Check if FTPS_PASSWORD is set
|
|
if [ -z "${FTPS_PASSWORD:-}" ]; then
|
|
error "FTPS_PASSWORD environment variable is not set.
|
|
Please set it before running this script:
|
|
export FTPS_PASSWORD='your-password'"
|
|
fi
|
|
|
|
# Check if FTPS_USER is set
|
|
if [ -z "${FTPS_USER:-}" ]; then
|
|
error "FTPS_USER environment variable is not set.
|
|
Please set it before running this script:
|
|
export FTPS_USER='user'"
|
|
fi
|
|
|
|
success "All prerequisites met."
|
|
}
|
|
|
|
#
|
|
# Deploy site to server via FTPS
|
|
#
|
|
deploy() {
|
|
info "Starting deployment to $FTPS_SERVER..."
|
|
info "Connecting as user: $FTPS_USER"
|
|
info "Uploading from: $SOURCE_DIR/"
|
|
info "Target directory: $TARGET_DIR/"
|
|
|
|
# Use lftp to upload files via FTPS
|
|
# Note: Password is passed via environment variable to avoid exposure in process list
|
|
lftp -e "
|
|
set ftps:initial-prot '';
|
|
set ftp:ssl-force true;
|
|
set ftp:ssl-protect-data true;
|
|
set ssl:verify-certificate no;
|
|
set net:timeout 30;
|
|
set net:max-retries 3;
|
|
set net:reconnect-interval-base 5;
|
|
open ftps://$FTPS_USER:$FTPS_PASSWORD@$FTPS_SERVER;
|
|
cd $TARGET_DIR || mkdir -p $TARGET_DIR;
|
|
lcd $SOURCE_DIR;
|
|
mirror --reverse --delete --verbose --parallel=3;
|
|
bye
|
|
"
|
|
|
|
local exit_code=$?
|
|
|
|
if [ $exit_code -eq 0 ]; then
|
|
success "Deployment completed successfully!"
|
|
info "Your site is now live at https://markusgraf.ch"
|
|
return 0
|
|
else
|
|
error "Deployment failed with exit code $exit_code.
|
|
|
|
Troubleshooting:
|
|
- Verify your password is correct
|
|
- Check network connectivity to $FTPS_SERVER
|
|
- Ensure the target directory '$TARGET_DIR' exists on the server
|
|
- Check server logs for additional details"
|
|
fi
|
|
}
|
|
|
|
#
|
|
# Main execution
|
|
#
|
|
main() {
|
|
info "=== FTPS Deployment Script ==="
|
|
info ""
|
|
|
|
check_prerequisites
|
|
info ""
|
|
|
|
deploy
|
|
}
|
|
|
|
# Run main function
|
|
main
|