From a08d654c26e2142f95cc46e35813e1ae8f664c8f Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 5 Jun 2023 15:46:58 +0200 Subject: [PATCH] adding post-checkout hook ad for zone1 --- .githooks/post-checkout | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 .githooks/post-checkout diff --git a/.githooks/post-checkout b/.githooks/post-checkout new file mode 100755 index 0000000..a381e6c --- /dev/null +++ b/.githooks/post-checkout @@ -0,0 +1,54 @@ +#!/bin/bash - +# echo "POST-CHECKOUT" +# echo "PREV-HEAD=$1" +# echo "CURR-HEAD=$2" +# echo "BRANCH-CHECKOUT=$3" + +readonly CHECKOUT_HISTORY_FILE="/opt/app/tools/atbupdate/checkout_history" +readonly GIT_UPDATE_LOG="/opt/app/tools/atbupdate/update_log.csv" +readonly OPKG_COMMANDS_FILE="/etc/psa_update/opkg_commands" + +write_log_file () { + if [ -f $CHECKOUT_HISTORY_FILE ]; then + # repo: customer_281 + readonly repo=$(basename $(git rev-parse --show-toplevel)) + # branch: customer_281:HEAD->zg1/zone1,origin/zg1/zone1 + readonly branch=$(git log --graph --all --decorate $2 | head -n 1 | sed -E -e 's/(.*?)\((.*)\)/\2/g' | sed -E -e s/[[:space:]]//g) + readonly line="$repo:$branch" + readonly now="$(date +%Y-%m-%dT%T)" + if ! grep -Eq "$line" $CHECKOUT_HISTORY_FILE; then + # line not found. first checkout of this branch (on this PSA). + # mark dc and print-templates to be downloaded by update-tool. + echo "DOWNLOAD, /etc/dc/dc2c.bin, $now, N/A" >> $GIT_UPDATE_LOG + echo "DOWNLOAD, /etc/psa_config/DC2C_print01.json, $now, N/A" >> $GIT_UPDATE_LOG + echo "DOWNLOAD, /etc/psa_config/DC2C_print02.json, $now, N/A" >> $GIT_UPDATE_LOG + echo "DOWNLOAD, /etc/psa_config/DC2C_print03.json, $now, N/A" >> $GIT_UPDATE_LOG + echo "DOWNLOAD, /etc/psa_config/DC2C_print04.json, $now, N/A" >> $GIT_UPDATE_LOG + echo "DOWNLOAD, /etc/psa_config/DC2C_print29.json, $now, N/A" >> $GIT_UPDATE_LOG + echo "DOWNLOAD, /etc/psa_config/DC2C_print32.json, $now, N/A" >> $GIT_UPDATE_LOG + if grep -qE . "${OPKG_COMMANDS_FILE}"; then + readarray opkg_commands < <(cat $OPKG_COMMANDS_FILE) + for opkg_c in "${opkg_commands[@]}"; do + # check for lines longer than 'opkg ' + if [ "${#opkg_c}" -gt 4 ]; then + # comment: spaces, at least one '#' + grep -qE '^[[:space:]]*#+.*$' <<< "$opkg_c" && continue + echo -n "EXECUTE, $opkg_c, $now, N/A" | tr -d '\n\r' >> $GIT_UPDATE_LOG 2>&1 + echo "" >> $GIT_UPDATE_LOG 2>&1 + fi + done + fi + else + echo "Found existing line: $line. Do nothing" + fi + echo "$line" >> $CHECKOUT_HISTORY_FILE + # echo "$line @$now" >> $CHECKOUT_HISTORY_FILE + else + echo "*******************************************************" + echo " $CHECKOUT_HISTORY_FILE DOES NOT EXIST !!! " + echo "*******************************************************" + fi +} + +write_log_file +