From 3067b212767d8e8de9f828e79c73d02339e97a8be6f16d28531af8c78f24b4f9 Mon Sep 17 00:00:00 2001 From: Heath Petersen Date: Sun, 12 Jul 2026 13:53:17 -0500 Subject: [PATCH] clean up --- files/home_hpf_ans_bin_ansible_pull_sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/files/home_hpf_ans_bin_ansible_pull_sh b/files/home_hpf_ans_bin_ansible_pull_sh index c7787bb..2c2d3a1 100644 --- a/files/home_hpf_ans_bin_ansible_pull_sh +++ b/files/home_hpf_ans_bin_ansible_pull_sh @@ -1,14 +1,24 @@ #!/bin/bash -source ~/.ansible-venv/bin/activate +# - Fix branch to check out + +. "${HOME}/.ansible-venv/bin/activate" GIT_REPO_BASE="https://gitea.admin-a.hpetersenfamily.com/heath/ansible" GIT_REPO="${GIT_REPO_BASE}.git" +LOG_FILE="/var/log/ansible-pull.sh.log" +LOCK_FILE="/tmp/ansible-pull.sh.lock" -ANSIBLE_PULL_LOG="/var/log/ansible-pull.log" +# - Redirect all further output to the log file and create a lock file +exec >>"${LOG_FILE}" 2>&1 9>"${LOCK_FILE}" -echo | sudo tee -a "${ANSIBLE_PULL_LOG}" -echo -n "$(basename "${0}"): " | sudo tee -a "${ANSIBLE_PULL_LOG}" -date "+%Y-%m-%d %H:%M:%S" | sudo tee -a "${ANSIBLE_PULL_LOG}" -ansible-pull --only-if-changed --url "${GIT_REPO}" "${@}" 2>&1 | sudo tee -a "${ANSIBLE_PULL_LOG}" +# - Log that we've gotten this far +echo +echo "$(basename "${0}"): $(date "+%Y-%m-%d %H:%M:%S")" +echo "----------" +# - If we can't lock the lock file, don't proceed +if ! flock -n 9; then echo "ERROR - Another copy of ansible-pull.sh is already running! Exiting..." ; exit 1 ; fi + +# - Do our work +ansible-pull --only-if-changed --url "${GIT_REPO}" --checkout main "${@}"