63 lines
1.9 KiB
Bash
Executable File
63 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# Quick and dirty way to build the site
|
|
|
|
# Script configuration
|
|
BUILD_DIR="/tmp/site_builder"
|
|
TARGET_DIR="/srv/http"
|
|
SITE_DIR="blog.sgorava.xyz"
|
|
REPOSITORY_URL="https://git.sgorava.xyz/Websites/blog.sgorava.xyz.git"
|
|
|
|
|
|
# Helper functions
|
|
function fail {
|
|
printf '%s\n' "$1" >&2 ## Send message to stderr.
|
|
exit "${2-1}" ## Return a code specified by $2, or 1 by default.
|
|
}
|
|
|
|
|
|
# Prepare - Clean and Create temporary directory
|
|
printf "=== Phase: Prepare ===\n"
|
|
# Check if variables are set.
|
|
if [ ${BUILD_DIR:+1} ] && [ ${TARGET_DIR:+1} ] && [ ${SITE_DIR:+1} ] && [ ${REPOSITORY_URL:+1} ]
|
|
then
|
|
# Prepare build directory
|
|
rm -rfv "${BUILD_DIR}/${SITE_DIR}" || fail "Unable to delete build directory."
|
|
mkdir -pv "${BUILD_DIR}" || fail "Unable to create build directory."
|
|
# Prepare target directory
|
|
mkdir -pv "${TARGET_DIR}/${SITE_DIR}" || fail "Unable to create target directory."
|
|
else
|
|
printf "One of the configuration variables is not set.\n\n"
|
|
printf "BUILD_DIR=\"%s\"\n" "${BUILD_DIR}"
|
|
printf "TARGET_DIR=\"%s\"\n" "${TARGET_DIR}"
|
|
printf "SITE_DIR=\"%s\"\n" "${SITE_DIR}"
|
|
printf "REPOSITORY_URL=\"%s\"\n" "${REPOSITORY_URL}"
|
|
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# Clone the repository
|
|
printf "=== Phase: Clone ===\n"
|
|
cd "${BUILD_DIR}" || fail "Unable to change to the build directory."
|
|
git clone "${REPOSITORY_URL}" "${SITE_DIR}" || fail "Unable to clone the repository."
|
|
|
|
|
|
# Build
|
|
printf "=== Phase: Build ===\n"
|
|
cd "${SITE_DIR}" || fail "Unable to change to the repository directory."
|
|
|
|
printf "=== Run Openring ===\n"
|
|
openring -S openring/openring.txt < openring/openring.html > layouts/partials/openring.html || fail "Unable to generate Openring data."
|
|
|
|
printf "=== Run hugo ===\n"
|
|
hugo --cleanDestinationDir --noChmod --buildFuture
|
|
|
|
|
|
# Sync
|
|
printf "=== Phase: Sync ===\n"
|
|
rsync -avz --delete "public/" "${TARGET_DIR}/${SITE_DIR}/" || fail "Unable to sync with target directory."
|
|
|
|
|
|
# Clean the vuild directory
|
|
rm -rf "${BUILD_DIR}/${SITE_DIR}" && printf "=== Done ===\n"
|