This commit is contained in:
Gerhard Hoffmann 2023-05-26 08:16:24 +02:00
parent 6e7501e54c
commit 0e8aa33feb
2 changed files with 51 additions and 53 deletions

View File

@ -8,43 +8,46 @@ readonly CHECKOUT_HISTORY_FILE="/opt/app/tools/atbupdate/checkout_history"
readonly GIT_UPDATE_LOG="/opt/app/tools/atbupdate/update_log.csv" readonly GIT_UPDATE_LOG="/opt/app/tools/atbupdate/update_log.csv"
readonly OPKG_COMMANDS_FILE="/etc/psa_update/opkg_commands" readonly OPKG_COMMANDS_FILE="/etc/psa_update/opkg_commands"
if [ -f $CHECKOUT_HISTORY_FILE ]; then write_log_file () {
# repo: customer_281 if [ -f $CHECKOUT_HISTORY_FILE ]; then
readonly repo=$(basename $(git rev-parse --show-toplevel)) # repo: customer_281
# branch: customer_281:HEAD->zg1/zone1,origin/zg1/zone1 readonly repo=$(basename $(git rev-parse --show-toplevel))
readonly branch=$(git log --graph --all --decorate $2 | head -n 1 | sed -E -e 's/(.*?)\((.*)\)/\2/g' | sed -E -e s/[[:space:]]//g) # branch: customer_281:HEAD->zg1/zone1,origin/zg1/zone1
readonly line="$repo:$branch" readonly branch=$(git log --graph --all --decorate $2 | head -n 1 | sed -E -e 's/(.*?)\((.*)\)/\2/g' | sed -E -e s/[[:space:]]//g)
readonly now="$(date +%Y-%m-%dT%T)" readonly line="$repo:$branch"
if ! grep -Eq "$line" $CHECKOUT_HISTORY_FILE; then readonly now="$(date +%Y-%m-%dT%T)"
# line not found. first checkout of this branch (on this PSA). if ! grep -Eq "$line" $CHECKOUT_HISTORY_FILE; then
# mark dc and print-templates to be downloaded by update-tool. # line not found. first checkout of this branch (on this PSA).
echo $line >> $CHECKOUT_HISTORY_FILE # mark dc and print-templates to be downloaded by update-tool.
echo "DOWNLOAD, /etc/dc/dc2c.4.21.bin, $now, N/A" >> $GIT_UPDATE_LOG echo $line >> $CHECKOUT_HISTORY_FILE
echo "DOWNLOAD, /etc/psa_config/DC2C_print01.json, $now, N/A" >> $GIT_UPDATE_LOG echo "DOWNLOAD, /etc/dc/dc2c.4.21.bin, $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_print01.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_print02.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_print03.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_print04.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print32.json, $now, N/A" >> $GIT_UPDATE_LOG echo "DOWNLOAD, /etc/psa_config/DC2C_print29.json, $now, N/A" >> $GIT_UPDATE_LOG
if grep -q . "${OPKG_COMMANDS_FILE}"; then echo "DOWNLOAD, /etc/psa_config/DC2C_print32.json, $now, N/A" >> $GIT_UPDATE_LOG
readarray opkg_commands < <(cat $OPKG_COMMANDS_FILE) if grep -qE . "${OPKG_COMMANDS_FILE}"; then
for opkg_c in "${opkg_commands[@]}"; do readarray opkg_commands < <(cat $OPKG_COMMANDS_FILE)
# check for lines longer than 'opkg ' for opkg_c in "${opkg_commands[@]}"; do
if [ "${#opkg_c}" -gt 4 ]; then # check for lines longer than 'opkg '
# comment: spaces, at least one '#' if [ "${#opkg_c}" -gt 4 ]; then
grep -qE '^[[:space:]]*#+.*$' <<< "$opkg_c" && continue # comment: spaces, at least one '#'
grep -qE '^[[:space:]]*#+.*$' <<< "$opkg_c" && continue
echo "DDD=${#opkg_c}DDD" echo -n "EXECUTE, $opkg_c, $now, N/A" | tr -d '\n\r' >> $GIT_UPDATE_LOG 2>&1
echo -n "EXECUTE, $opkg_c, $now, N/A" | tr -d '\n\r' >> $GIT_UPDATE_LOG 2>&1 echo "" >> $GIT_UPDATE_LOG 2>&1
echo "" >> $GIT_UPDATE_LOG 2>&1 fi
fi done
done fi
else
echo "Found existing line: $line. Do nothing"
fi fi
else else
echo "Found existing line: $line. Do nothing" echo "*******************************************************"
echo " $CHECKOUT_HISTORY_FILE DOES NOT EXIST !!! "
echo "*******************************************************"
fi fi
else }
echo "*******************************************************"
echo " $CHECKOUT_HISTORY_FILE DOES NOT EXIST !!! " write_log_file
echo "*******************************************************"
fi

View File

@ -28,29 +28,24 @@ get_commit_for_blob () {
} }
write_log_file () { write_log_file () {
local __date=$(date +"%Y-%m-%dT%T") local now=$(date +"%Y-%m-%dT%T")
for fn in $(git diff-tree -r HEAD@{1} HEAD --name-only); do for fn in $(git diff-tree -r HEAD@{1} HEAD --name-only); do
if grep -E -q "(DC.*json|dc.*hex|dc.*bin|tariff.*json)" <<< $fn; then if grep -qE "(DC.*json|dc.*hex|dc.*bin|tariff.*json)" <<< $fn; then
# called in repository: $fn is e.g. etc/psa_tariff/tariff01.json # called in repository: $fn is e.g. etc/psa_tariff/tariff01.json
# add '/' prefix # add '/' prefix
fn=$(echo $fn | awk '{ printf "/"$0 }') echo "DOWNLOAD, $(echo $fn | awk '{ printf "/"$0 }'), $now, N/A" >> "$GIT_UPDATE_LOG"
# if [[ -f "$fn" ]]; then
# blob=$(get_blob "$fn")
# commit=$(get_commit_for_blob $blob "$fn")
# fsize=$(ls -l "$fn" | awk '{ print $5 }')
# echo "$fn $fsize $blob $commit" >> $GIT_PULL_TMP
# fi
echo "DOWNLOAD, $fn, $__date, N/A" >> "$GIT_UPDATE_LOG"
fi fi
if grep -E -q ".*opkg_commands" <<< $fn; then if grep -qE ".*opkg_commands" <<< $fn; then
readarray opkg_commands < <(cat $fn) readarray opkg_commands < <(cat $fn)
for opkg_c in "${opkg_commands[@]}"; do for opkg_c in "${opkg_commands[@]}"; do
test -z $opkg_c && continue; # check for lines longer than 'opkg '
test ! -z $(grep -E "^\s*[#]+.*$" <<< $opkg_c) && continue if [ "${#opkg_c}" -gt 4 ]; then
echo -n "EXECUTE, $opkg_c, $__date, N/A" | tr -d '\n\r' >> $GIT_UPDATE_LOG 2>&1 # comment: spaces, at least one '#'
echo "" >> $GIT_UPDATE_LOG 2>&1 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 done
# source "$fn"
fi fi
done done
} }