2023-03-27 16:10:41 +02:00
|
|
|
#!/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
|
|
|
|
|
2023-06-27 14:46:50 +02:00
|
|
|
GIT_UPDATE_LOG=/opt/app/tools/atbupdate/update_log.csv
|
2023-03-27 16:10:41 +02:00
|
|
|
|
2023-06-27 14:46:50 +02:00
|
|
|
#TODO: use in UpdateController
|
2023-03-27 16:10:41 +02:00
|
|
|
|
2023-04-25 11:53:13 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2023-06-27 14:46:50 +02:00
|
|
|
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
|
2023-04-25 11:53:13 +02:00
|
|
|
fi
|
2023-06-27 14:46:50 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
write_log_file
|
|
|
|
|