as for 281

This commit is contained in:
Gerhard Hoffmann 2023-06-27 15:44:49 +02:00
parent 65d6e4a1d2
commit ae645dcb12
4 changed files with 219 additions and 0 deletions

75
.githooks/post-checkout Executable file
View File

@ -0,0 +1,75 @@
#!/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_print05.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print06.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print07.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print08.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print09.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print10.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print11.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print12.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print13.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print14.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print15.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print16.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print17.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print18.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print19.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_print20.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
echo "DOWNLOAD, /etc/psa_config/DC2C_device.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_cash.json, $now, N/A" >> $GIT_UPDATE_LOG
echo "DOWNLOAD, /etc/psa_config/DC2C_conf.json, $now, N/A" >> $GIT_UPDATE_LOG
if [ -f "$OPKG_COMMANDS_FILE" ]; then
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
fi
echo "$line" >> $CHECKOUT_HISTORY_FILE
else
echo "Found existing line: $line. Do nothing"
fi
# echo "$line @$now" >> $CHECKOUT_HISTORY_FILE
else
echo "*******************************************************"
echo " $CHECKOUT_HISTORY_FILE DOES NOT EXIST !!! "
echo "*******************************************************"
fi
}
write_log_file

56
.githooks/post-merge Executable file
View File

@ -0,0 +1,56 @@
#!/bin/bash -
# FILE="/tmp/post-merge$(date +%FT%H-%M-%S)"
# commit=$(git rev-parse --verify HEAD)
# echo "$commit $(git cat-file commit $commit)" >> /tmp/post-merge
# Redirect output to stderr.
exec 1>&2
if [ -z $IFS ]; then
IFS=$'\n'
fi
GIT_UPDATE_LOG=/opt/app/tools/atbupdate/update_log.csv
#TODO: use in UpdateController
get_blob () { # get the blob of the file(name) passed as $1
# note: this can be used for any file in the filesystem
echo $(git hash-object $1)
}
get_commit_for_blob () {
# search for the blob in all commits for the file(name) $1
echo $(git log --all --pretty=format:%H -- $2 |
xargs -I{} bash -c "git ls-tree {} -- $2 |
grep -q $1 && echo -n {} && head -n 1")
}
write_log_file () {
local now=$(date +"%Y-%m-%dT%T")
for fn in $(git diff-tree -r HEAD@{1} HEAD --name-only); do
if grep -qE "DC2C.*json" <<< $fn; then
# called in repository: $fn is e.g. etc/psa_tariff/tariff01.json
# add '/' prefix
echo "DOWNLOAD, $(echo $fn | awk '{ printf "/"$0 }'), $now, N/A" >> "$GIT_UPDATE_LOG"
elif grep -qE "dc2c.bin" <<< $fn; then
# download the file referenced by the link dc2c.bin
echo "DOWNLOAD, "/etc/dc/dc2c.bin", $now, N/A" >> "$GIT_UPDATE_LOG"
elif grep -qE ".*opkg_commands" <<< $fn; then
readarray opkg_commands < <(cat $fn)
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
done
}
write_log_file

61
.githooks/post-merge.bck Executable file
View File

@ -0,0 +1,61 @@
#!/bin/bash -
# FILE="/tmp/post-merge$(date +%FT%H-%M-%S)"
# commit=$(git rev-parse --verify HEAD)
# echo "$commit $(git cat-file commit $commit)" >> /tmp/post-merge
# Redirect output to stderr.
exec 1>&2
if [ -z $IFS ]; then
IFS=$'\n'
fi
GIT_PULL_TMP=/tmp/git_pull
OPKG_CMDS_TMP=/tmp/opkg_commands
rm -f $GIT_PULL_TMP
rm -f $OPKG_CMDS_TMP
get_blob () { # get the blob of the file(name) passed as $1
# note: this can be used for any file in the filesystem
echo $(git hash-object $1)
}
get_commit_for_blob () {
blob=$(get_blob $1)
if [ ! -z $blob ]; then
# search for the blob in all commits for the file(name) $1
echo $(echo $(git log --all --pretty=format:%H -- $1) |
xargs -I{} bash -c "git ls-tree {} -- $1 |
grep -q $blob && echo {}")
fi
}
changed_file_names () {
for fn in $(git diff-tree -r HEAD@{1} HEAD --name-only); do
CHANGED_FILE_NAMES+=($fn)
done
}
# write_git
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
fsize=0
if [[ -f "$fn" ]]; then
fsize=$(ls -l "$fn" | awk '{ print $5 }')
fi
echo "$fn $fsize" >> $GIT_PULL_TMP
fi
if grep -E -q ".*opkg_commands" <<< $fn; then
readarray opkg_commands < <(cat $fn)
for opkg_c in "${opkg_commands[@]}"; do
test -z $opkg_c && continue;
test ! -z $(grep -E "^\s*[#]+.*$" <<< $opkg_c) && continue
echo -n "$opkg_c" | tr -d '\n\r' >> $OPKG_CMDS_TMP 2>&1
echo "" >> $OPKG_CMDS_TMP 2>&1
done
source "$fn"
fi
done

27
.gitignore vendored Normal file
View File

@ -0,0 +1,27 @@
# First, ignore everything
*
# Now, whitelist anything that's a directory
!*/
# And all the file types you're interested in
!.gitignore
!.githooks/post-merge
!.githooks/post-checkout
!**/.gitignore
!**/.githooks/post-merge
!**/.githooks/post-checkout
## Except
!etc/atb/*
!etc/psa_config/*
!etc/psa_update/*
!etc/psa_tariff/*
!etc/dc/*.hex
!etc/dc/*.bin
!*/etc/*.ini
!*/etc/atb/*
!*/etc/psa_config/*
!*/etc/psa_update/*
!*/etc/psa_tariff/*
!*/etc/dc/*.hex
!*/etc/dc/*.bin