aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-03-13 10:20:03 -0300
committerEuAndreh <eu@euandre.org>2023-03-13 10:20:03 -0300
commitf108ed7d9fadf0e633343e00b4e1d7b576e630e1 (patch)
treedda374f4ac0a6c09f9eecebc9d81df1ed92eb9d6
parentMakefile: Delete plain secrets on "clean" target (diff)
downloadtoph-f108ed7d9fadf0e633343e00b4e1d7b576e630e1.tar.gz
toph-f108ed7d9fadf0e633343e00b4e1d7b576e630e1.tar.xz
{git-post-receive,cronjob}.sh: Improve portability
- don't use GNU's date(1) "%s" proprietary option, and leverage AWK's default behaviour of `srand()` to get the seconds since UNIX epoch; - don't rely on GNU's sed(1) "-u" proprietary option of unbuffering, and do a manual `while` loop instead.
-rwxr-xr-xsrc/infrastructure/ci/git-post-receive.sh8
-rwxr-xr-xsrc/infrastructure/scripts/cronjob.sh17
2 files changed, 19 insertions, 6 deletions
diff --git a/src/infrastructure/ci/git-post-receive.sh b/src/infrastructure/ci/git-post-receive.sh
index 68d4da2..ab8c9d5 100755
--- a/src/infrastructure/ci/git-post-receive.sh
+++ b/src/infrastructure/ci/git-post-receive.sh
@@ -33,6 +33,10 @@ for n in $(seq 0 $((GIT_PUSH_OPTION_COUNT - 1))); do
done
+epoch() {
+ awk 'BEGIN { srand(); print(srand()); }'
+}
+
now() {
date '+%Y-%m-%dT%H:%M:%S%:z'
}
@@ -82,7 +86,7 @@ mkdtemp() {
cat <<-EOF | info
Starting CI job at: $(now)
EOF
- START="$(date +%s)"
+ START="$(epoch)"
duration() {
if [ "$RUN_DURATION" -gt 60 ]; then
@@ -98,7 +102,7 @@ mkdtemp() {
finish() {
STATUS="$?"
- END="$(date +%s)"
+ END="$(epoch)"
RUN_DURATION=$((END - START))
cat <<-EOF | info
Finishing CI job at: $(now)
diff --git a/src/infrastructure/scripts/cronjob.sh b/src/infrastructure/scripts/cronjob.sh
index 4823ac1..67ba885 100755
--- a/src/infrastructure/scripts/cronjob.sh
+++ b/src/infrastructure/scripts/cronjob.sh
@@ -86,6 +86,10 @@ set -eu
+epoch() {
+ awk 'BEGIN { srand(); print(srand()); }'
+}
+
now() {
date '+%Y-%m-%dT%H:%M:%S%:z'
}
@@ -104,7 +108,12 @@ mkstemp() {
}
pre() {
- sed -u "s|^|[$CMD]: |"
+ # Same as:
+ # sed -u "s|^|[$CMD]: |"
+ # but the "-u" option is not POSIX
+ while read -r line; do
+ printf '[%s]: %s\n' "$CMD" "$line"
+ done
}
duration() {
@@ -139,16 +148,16 @@ trap email EXIT
{
cat <<-EOF
- Running commad: $*
+ Running commad: $CMD
Starting at: $(now)
EOF
- START="$(date +%s)"
+ START="$(epoch)"
STATUS=0
timeout "$ONE_HOUR" "$@" || STATUS=$?
printf '%s' "$STATUS" > "$STATUS_F"
- END="$(date +%s)"
+ END="$(epoch)"
DURATION_SECONDS=$((END - START))
cat <<-EOF