Mail-in-a-Box and Publii

Free open-source email self-hosting solution Mail-in-a-Box provides hosting for static HTML websites.

Publii is a desktop-based CMS for Windows, Mac and Linux that makes creating static websites fast and hassle-free, even for beginners.

Publii has a way to upload the data to the server using SFTP but Publii as well stores the configuration in clear text files, so if you use key-based authentication with a password I do not recommend saving it in Publii.

Instead, I suggest to use Publii's Manual upload feature where it generates the websites' code onto your hard disk and upload it with a script to the Mail-in-a-Box server.

Preparation

Set /var/mailinabox/www/your_website_folder as the folder for your website in Mail-in-a-Box administrative interface.

Change the owner of the website folder on your Mail-in-a-Box machine:
sudo chown -R your_user_name /var/mailinabox/www/your_website_folder

Integration

Preparing the content

When you've finished editing your content in Publii, click Sync your website button. It will generate the HTML files.

One of the files will be files.publii.json, which Publii recommends to protect. We will address it later during the upload.

Script to upload the content

The following script removes the file files.publii.json from the output folder and uploads the rest of the files to the server:

#!/bin/bash

# === Settings ===
SRC_DIR="/source/path"       # Local folder that contains Publii output
DEST_USER="user"             # SSH-user on the server
DEST_HOST="box.example.com"   # Mail-in-a-Box host
DEST_DIR="/destination/path" # Destination path on the server

# === Remove files.publii.json ===
echo "Removing files.publii.json..."
find "$SRC_DIR" -type f -name 'files.publii.json' -delete

# === Change permissions locally ===
# So the server can access the files after the upload
echo "Updating permissions locally"
find "$SRC_DIR" -type f -exec chmod 644 {} +
find "$SRC_DIR" -type d -exec chmod 755 {} +

# === Open the SSH port ===
echo "Opening SSH port on the target server"
fwknop -n box.example.com --wget-cmd /opt/homebrew/bin/wget

# === Rsync to the server ===
# Caution!
#   * With --delete parameter all files and folders in the specified
# directory
on the server that do not exist in the local SRC_DIR
# will be DELETED!
#     If you specify the root directory of the server,
#     you might accidentally delete important data.
#     Be extremely careful with your paths!
#   * Remove the --dry-run option after you are
# completely sure that everything works fine!
echo "Uploading website..."
rsync -avz --delete --dry-run --itemize-changes -e ssh "$SRC_DIR"/ "$DEST_USER@$DEST_HOST:$DEST_DIR/"

Don't forget to make the file executable: chmod +x publii.sh

This is it! Now your publishing is semi-automated!