From 2c3e2e404c87d01166471ec9f27912d654dec9bb Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 8 Aug 2023 22:06:21 -0400 Subject: acid: Update check_source Script is renamed to 'cyche-source' and updated to account for a couple of potential edge-cases during a git update. Signed-off-by: Malfurious --- acid/check_source | 47 ------------------------------------------- acid/cyche-source | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 47 deletions(-) delete mode 100755 acid/check_source create mode 100755 acid/cyche-source (limited to 'acid') diff --git a/acid/check_source b/acid/check_source deleted file mode 100755 index b86e32d..0000000 --- a/acid/check_source +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# check_source -# -# Check a git source for new updates. A local cache repository is cloned if -# doesn't exist. If updates are found, we attempt to checkout the -# newest version according to (see git-for-each-ref(1)). -# -# The new (or current) git commit hash is printed to stdout. If the file tree -# is updated, this file exits non-zero. - -gethash() { - git for-each-ref \ - --count=1 \ - --format='%(objectname)' \ - --sort='-creatordate' \ - "$1" #ref -} - -cd '/git' - -if ! [ -d "$1" ]; then - git clone "$2" "$1" >&2 - touch "$1/.git/previous_hash" - touch "$1/.git/previous_slug" -fi - -cd "$1" - -git fetch --all --prune >&2 -prev=$(cat '.git/previous_hash') -next=$(gethash "$3") -echo "$next" - -if [ "$prev" != "$next" ]; then - git submodule deinit --all -f >/dev/null 2>&1 - git reset . >/dev/null 2>&1 - git checkout . >/dev/null 2>&1 - git clean -xffd >/dev/null 2>&1 - - git checkout "$next" >/dev/null 2>&1 - git submodule update --init --recursive >/dev/null 2>&1 - - exit 1 -fi - -exit 0 diff --git a/acid/cyche-source b/acid/cyche-source new file mode 100755 index 0000000..dd290ac --- /dev/null +++ b/acid/cyche-source @@ -0,0 +1,60 @@ +#!/bin/bash + +# cyche-source +# +# Check a git source for new updates. A local cache repository is cloned if +# doesn't exist. If updates are found, we attempt to checkout the newest +# version according to (see from git-for-each-ref(1)). +# +# The new (or current, if no update occurred) object hash is printed to stdout. +# This may be a commit hash. However, if matches an annotated tag, +# then the hash names the tag object. The caller should cache this hash value +# upon successful deployment. +# +# If the file tree is updated, this file exits non-zero. + +gethash() { + git for-each-ref \ + --count=1 \ + --format='%(objectname)' \ + --sort='-creatordate' \ + "$1" # pattern +} + +cd '/services' + +if ! [ -d "$1" ]; then + git clone "$2" "$1" >&2 + touch "$1/.git/previous_hash" + touch "$1/.git/previous_slug" +fi + +cd "$1" + +git remote set-url origin "$2" >&2 # pick up url changes +git fetch --all --prune >&2 + +prev=$(cat '.git/previous_hash') +next=$(gethash "$3") + +if [ -z "$next" ]; then + # no matching refs + next="$prev" +fi + +echo "$next" + +if [ "$prev" != "$next" ]; then + # update file tree + git submodule deinit --all --force >/dev/null 2>&1 + git reset . >/dev/null 2>&1 + git checkout . >/dev/null 2>&1 + git clean -xffd >/dev/null 2>&1 + + git checkout "$next" >/dev/null 2>&1 + git submodule update --init --recursive >/dev/null 2>&1 + + exit 1 +fi + +exit 0 -- cgit v1.2.3