Project

General

Profile

Task #167

Updated by Nawan 15 days ago

```bash 
 #!/bin/bash 

 # --- CONFIGURATION --- 

 # Path to the Fossil repository file on the server 
 FOSSIL_REPO="/path/to/mywebsite.fossil" 

 # The temporary directory to create the working copy for Hugo build 
 # This must be outside the web root. 
 WORK_DIR="/tmp/hugo_build_temp" 

 # The final destination for the static site files on the web server (via rsync) 
 # This is usually the document root (e.g., public_html) 
 # Replace user@host:path_to_webroot with your actual details 
 RSYNC_DEST="user@host:/var/www/myhugo-site-public" 

 # --- DEPLOYMENT LOGIC --- 

 # Ensure we operate in a clean environment 
 mkdir -p "$WORK_DIR" 
 cd "$WORK_DIR" || exit 1 

 # 1. Clean up any previous checkout (important for a fresh build) 
 rm -rf "$WORK_DIR"/* 

 # 2. Check out the latest committed version from the repository 
 # We use 'fossil open' to establish a checkout connection 
 # The '--once' flag tells it to only run the checkout and exit (not start a UI) 
 fossil open "$FOSSIL_REPO" 

 # 3. Build the Hugo site 
 # The 'hugo' command builds the site into the 'public/' subdirectory of the 
 # current working directory (which is $WORK_DIR) 
 # Use '--cleanDestinationDir' if you want a complete wipe before building 
 echo "Building Hugo site..." 
 hugo 

 # Check if the Hugo build was successful 
 if [ $? -ne 0 ]; then 
     echo "Hugo build failed! Aborting deployment." 
     exit 1 
 fi 

 # 4. Deploy the static files using rsync over SSH 
 # -a: archive mode (preserves permissions, ownership, etc.) 
 # -v: verbose 
 # -z: compress file data during transfer 
 # --delete: delete extra files from the destination that are not present in the source 
 echo "Deploying with rsync..." 
 rsync -avz --delete public/ "$RSYNC_DEST" 

 # 5. Clean up the temporary checkout directory after successful deployment 
 cd / 
 fossil close --force || true # Close the checkout connection 
 rm -rf "$WORK_DIR" 
 echo "Deployment complete." 
 ```

Back