#!/bin/bash
#
# © 2026 Christopher Roy Bratušek <nano@jpberlin.de>
#
# License: GNU GPL v3+
#
# See /usr/share/nanolx/hugo-push.conf for example configuration. Save that file as
#   ${HOME}/.hugo-push.conf
#

version="0.0.1"
reldate="2026/07/29"

scriptname=$(basename ${0})

if [[ -f ${HOME}/.${scriptname}.conf ]]; then
        source "${HOME}/.${scriptname}.conf"
else    echo "no ${HOME}/.${scriptname}.conf exists"
    exit 1
fi

case "${@}" in
   "" )
        if [ -d "${HUGO_PATH}" ]; then
            cd "${HUGO_PATH}"
            hugo || exit 1
            if [ -f ${HOME}/.${scriptname}.pw ]; then
                HUGO_FTP_PW=$(gpg --decrypt ${HOME}/.${scriptname}.pw) || HUGO_FTP_PW=""
            else    error "No GPG encrypted password file (${HOME}/.${scriptname}.pw) found"
            fi

            lftp -c "set ssl:check-hostname no; \
                    open ftp://${HUGO_FTP_USR}:${HUGO_FTP_PW}@${HUGO_FTP_SRV}; \
                    mirror -R -L ${HUGO_PATH}/public/ /${HUGO_FTP_DIR}"
        else
            echo "no hugo repository at ${HUGO_PATH}"
        fi
    ;;

    version)
        echo "$(basename ${0}) ${version} (${reldate})"
    ;;

    -h | --help | * )
        echo "${scriptname} ${version} (${reldate})

© 2026 Christopher Roy Bratušek <nano@jpberlin.de>

licensed under the GNU General Public License v3 (or newer)

builds hugo website and uploads it to webspace using ftp, requires lftp and

    ${HOME}/.${scriptname}.conf

see

    /usr/share/nanolx/${scriptname}.conf

for example configuration"
    ;;

esac
