customer_281/.githooks/post-checkout

56 lines
2.6 KiB
Plaintext
Raw Normal View History

2023-05-25 16:32:08 +02:00
#!/bin/bash -
# echo "POST-CHECKOUT"
# echo "PREV-HEAD=$1"
# echo "CURR-HEAD=$2"
# echo "BRANCH-CHECKOUT=$3"
2023-05-25 16:20:18 +02:00
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"
2023-05-25 14:51:42 +02:00
2023-05-25 16:20:18 +02:00
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)"
2023-05-25 16:20:18 +02:00
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.
2023-05-25 16:20:18 +02:00
echo $line >> $CHECKOUT_HISTORY_FILE
echo "DOWNLOAD, /etc/dc/dc2c.4.21.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
2023-05-25 16:32:08 +02:00
if grep -q . "${OPKG_COMMANDS_FILE}"; then
2023-05-25 16:20:18 +02:00
readarray opkg_commands < <(cat $OPKG_COMMANDS_FILE)
for opkg_c in "${opkg_commands[@]}"; do
2023-05-25 17:16:10 +02:00
# check for empty lines
2023-05-25 17:25:12 +02:00
echo "CCC=${opkg_c}CCC"
2023-05-25 17:28:09 +02:00
if grep -qE '^[[:space:]]+$' <<< "${opkg_c}"; then
2023-05-25 17:21:15 +02:00
continue
fi
2023-05-25 17:31:07 +02:00
if [ ${#opkg_c} -eq 0 ]; then
continue
fi
2023-05-25 17:25:12 +02:00
echo "DDD=${opkg_c}DDD"
2023-05-25 17:21:15 +02:00
# check if line is not starting with '#'
if ! grep -qE "^\s*[#]+.*$" <<< "$opkg_c"; then
echo -n "EXECUTE, $opkg_c, $now, N/A" | tr -d '\n\r' >> $GIT_UPDATE_LOG 2>&1
echo "" >> $GIT_UPDATE_LOG 2>&1
2023-05-25 16:47:29 +02:00
fi
2023-05-25 16:20:18 +02:00
done
fi
2023-05-25 15:04:51 +02:00
else
echo "Found existing line: $line. Do nothing"
2023-05-25 14:51:42 +02:00
fi
else
echo "*******************************************************"
2023-05-25 16:20:18 +02:00
echo " $CHECKOUT_HISTORY_FILE DOES NOT EXIST !!! "
echo "*******************************************************"
2023-05-25 14:33:48 +02:00
fi