diff options
author | Aaron Ball <nullspoon@oper.io> | 2024-10-26 20:33:19 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2024-10-26 20:47:44 -0600 |
commit | f77bb51602cf92813b2cdf946de4fdc2e1980920 (patch) | |
tree | 6971e180c24952314a3d34d8b06d43cd5a55d9d6 | |
download | motd.sh-f77bb51602cf92813b2cdf946de4fdc2e1980920.tar.gz motd.sh-f77bb51602cf92813b2cdf946de4fdc2e1980920.tar.xz |
Initial commit of post-receive hook
Supports deploying and cleaning up deleted items, as well as calling
make on any changed source code (to be added later).
-rwxr-xr-x | hooks/post-receive | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/hooks/post-receive b/hooks/post-receive new file mode 100755 index 0000000..adefe8d --- /dev/null +++ b/hooks/post-receive @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +deploy() { + local path="${1}" + + # Deploy any pages that were changed + for i in ${FILES_E[*]} ${FILES_A[*]} ${FILES_M[*]}; do + _log "Processing and installing ${i}" + + if [ "${i##*.}" = 'md' ]; then + dest="${path}/html/$(basename ${i%.*}).html" + cmark --to html "${SRC}" > "${DEST}" + printf '<div class="paragraph datelastedit"><p>Last edited: %s</p></div>\n' \ + "$(date '+%F %T %Z')" >> "${DEST}" + + elif [ "${i%%/*}" = 'src' ]; then + (cd src && make && make install DEPLOYDIR="${path}") + + else + # Don't want to use dest for this, as we don't want to change file + # extentions + install -v -D "${i}" "${path}/${i}" + fi + done + +} + +cleanup() { + local path="${1}" + + # Clean up any deleted files + for i in ${FILES_D[*]}; do + # Pre-determine path for processed files + out="${path}/html/$(basename ${i%.*}).html" + + if [ -e "${path}/${i}" ]; then + _log "Deleting file ${i}" + rm -f "${path}/${i}" + + elif [ -e "${out}" ]; then + _log "Deleting post ${out}" + rm -f "${out}" + fi + done +} + +deploy "${WEB}/motd.sh" +cleanup "${WEB}/motd.sh" |