Compare commits

..

No commits in common. "3574453066c772fa17288dbb6417718fe61df981" and "cfce4ae53c7bb70de595d4e7d5f17d09e45e4837" have entirely different histories.

3 changed files with 137 additions and 46 deletions

View File

@ -83,26 +83,14 @@ clone_customer_repository () {
$(exec_git_command git clone "$1") $(exec_git_command git clone "$1")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
log_debug "$func:${LINENO} cloning ${1} done" log_debug "$func:${LINENO} cloning ${1} done"
# after cloning, cd into repository, and re-initialize, local res=$(exec_git_command git --git-dir="${CUSTOMER_ID_BASE_DIR}/.git" --work-tree="/" init)
# setting the work-tree as "/". This has the effect that
# a "git pull" will automatically fetched files in the
# corresponding sytem-folders.
if cd ${CUSTOMER_ID_BASE_DIR}; then
local res=$(exec_git_command git --git-dir=.git --work-tree=/ init)
if ! [[ -z $res ]]; then if ! [[ -z $res ]]; then
# re-initialized. copy post-merge (a hook called
# when 'git pull' is executed and changed data
# are received).
if cp ".githooks/post-merge" ".git/hooks"; then
log_debug "$func:${LINENO} copied post-merge to .git/hooks"
CLONE_CUSTOMER_REPOSITORY=true CLONE_CUSTOMER_REPOSITORY=true
log_debug "$func:${LINENO} re-init of ${1} done" log_debug "$func:${LINENO} re-init of ${1} done"
cd_home; return 0 cd -; return 0
fi fi
fi fi
fi cd -
fi
cd_home; return 1
fi fi
else else
# the directory is not empty, so we assume the # the directory is not empty, so we assume the
@ -160,27 +148,109 @@ pull_customer_repository () {
return 1 return 1
fi fi
#local commit_before_pull=$(latest_commit) local commit_before_pull=$(latest_commit)
#if [ -z $commit_before_pull ]; then if [ -z $commit_before_pull ]; then
# log_warn "$func:${LINENO}: commit_before_pull empty" log_warn "$func:${LINENO}: commit_before_pull empty"
# cd_home ; return 1 cd_home ; return 1
#fi fi
#log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull" log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
rm -f "$OPKG_CMDS_TMP"
rm -f "$GIT_PULL_TMP"
log_debug "$func:${LINENO}: executing 'git pull'..." log_debug "$func:${LINENO}: executing 'git pull'..."
exec_git_command 'git pull'
# GIT_PULL_TMP created by hook post-merge. it contains the names of the local git_result=$(exec_git_command 'git pull')
# changed files.
if [[ -f $GIT_PULL_TMP ]]; then if [ -z "$git_result" ]; then
cd_home; return 0 log_warn "$func:${LINENO}: git result empty" ; cd_home;
return 1
fi fi
log_warn "$func:${LINENO}: no data fetched form repository" # see https://www.gnu.org/
cd_home; return 1 # software/bash/manual/html_node/Shell-Parameter-Expansion.html
# [...]
#
# ${parameter//pattern/string}
#
# If there are two slashes separating parameter and pattern (...),
# all matches of pattern are replaced with string.
#
# If the expansion of string is null, matches of pattern are deleted.
# [...]
git_result=${git_result//[$'\r\n\t']/ }
log_debug "$func:${LINENO} git-pull-result=${git_result}"
if grep -qE "^.*?Already\s+\up\s+\to\s+date.*$" <<< "$git_result"; then
log_warn "$func:${LINENO}: repository $PWD already up to date."
read $1 <<< 'yes'
cd_home ; return 1
fi
local commit_after_pull=$(latest_commit)
if [ -z $commit_after_pull ]; then
cd_home ; return 1
fi
log_debug "$func:${LINENO}: commit_after_pull=$commit_after_pull"
# Note: # 'git pull' is a 'git fetch' followed by a 'git merge'.
# Here's the fetch portion:
#
# remote: Counting objects: 11, done.
# remote: Compressing objects: 100% (5/5), done.
# remote: Total 7 (delta 2), reused 0 (delta 0)
#
# At this point, you've told the remote what you want.
# It finds all the objects it needs to give you,
# compresses them for faster transfer over the network,
# and then reports what it's sending you.
#
# Unpacking objects: 100% (7/7), done.
#
# You receive the pack (set of compressed objects) and unpack it.
#
# From ssh://my.remote.host.com/~/git/myproject
# * branch master -> FETCH_HEAD
# You've fetched the branch 'master' from the given remote;
# the ref FETCH_HEAD now points to it.
# Now we move on to the merge - precisely, git will merge
# FETCH_HEAD (the remote's master branch) into your current branch
# (presumably master).
#
#######################################################################
# here starts "message"
#
# Updating 9d447d2..f74fb21
# Fast forward
#
# It turns out that you haven't diverged from the remote's master branch,
# so the merge is a fast-forward (a trivial merge where it simply moves
# you forward in the history).
#
# Git notes the original position of your master branch (9d447d2)
# and the new position (f74fb21) it's been fast-forwarded to.
# If you had diverged from the remote's master branch,
# you'd see the output of a recursive merge here - Merge made
# by recursive, possibly along with some Auto-merged <file>
# and (oh no!) merge conflicts!
#
# szeged/1/1/etc/psa_config/device.conf | 13 +++++++------
# szeged/update.conf | 2 +-
# 2 files changed, 8 insertions(+), 7 deletions(-)
#
# Finally, it shows you the diffstat between the original and post-merge
# position of your master branch;
# this is basically what you'd get from
#
# git diff --stat master@{1} master.
#
update_commit="${commit_before_pull}..${commit_after_pull}"
if ! grep -qE ".*Updating\s+${update_commit}.*?" <<< $git_result; then
log_crit "$func:${LINENO}: no $update_commit in [ $git_result ]"
cd_home ; return 1
fi
cd_home ; return 0
} }
# pull_customer_repository customer_281 # pull_customer_repository customer_281

View File

@ -24,7 +24,7 @@ exec_opkg_command () {
# Fetch/merge updates from predefined repository using git. # Fetch/merge updates from predefined repository using git.
# #
fetch_customer_updates() { fetch_customer_updates() {
if ! pull_customer_repository; then if ! pull_customer_repository $1; then
return 1 return 1
fi fi
return 0 return 0

View File

@ -35,20 +35,42 @@ update_psa() {
exit $? exit $?
fi fi
rm -f "$OPKG_CMDS_TMP"
rm -f "$GIT_PULL_TMP"
update_psa_activated # message to ISMAS update_psa_activated # message to ISMAS
local try_update_count=0
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO}: fetch/merge updates..." log_debug "$func:${LINENO}: fetch/merge updates..."
# Fetch new updates (using git) # Fetch new updates (using git)
if ! fetch_customer_updates; then while :
log_error "$func:${LINENO}: fetch no data for $customer_id"\ do
local repository_is_already_up_to_date=""
if ! fetch_customer_updates repository_is_already_up_to_date; then
if [ "$repository_is_already_up_to_date" = "yes" ]; then
log_error "$func:${LINENO}: $customer_id is up-to-date"\
"-> no files to update -> no psa update" "-> no files to update -> no psa update"
update_psa_false_alarm \ update_psa_false_alarm \
"update request, but no change in $CUSTOMER_REPOSITORY_PATH" "update request, but no change in $CUSTOMER_REPOSITORY_PATH"
# TODO exit $?
fi fi
try_updates_count=$((try_updates_count+1))
if [[ "$try_updates_count" -eq 5 ]]; then
log_error "$func:${LINENO}: fetch/merging failed"
update_psa_pull_error # message to ISMAS
exit $?
fi
update_psa_pull_error # message to ISMAS
sleep 10s
else
# Fetched updates successfully
try_updates_count=0
break
fi
done
update_psa_pull_customer_repository # message to ISMAS update_psa_pull_customer_repository # message to ISMAS
@ -56,7 +78,7 @@ update_psa() {
# local changed_files=$(changed_file_names) # local changed_files=$(changed_file_names)
if [[ -f "$GIT_PULL_TMP" ]]; then if [[ ! -z $GIT_PULL_TMP ]]; then
# TODO # TODO
if ! check_hardware_compatibility "$files_to_copy" ; then if ! check_hardware_compatibility "$files_to_copy" ; then
local __r=$? local __r=$?
@ -66,7 +88,7 @@ update_psa() {
fi fi
fi fi
if [[ -f "$OPKG_CMDS_TMP" ]]; then if [[ ! -z "$OPKG_CMDS_TMP" ]]; then
local commands="$(cat ${OPKG_CMDS_TMP} | tr '\n' '; ')" local commands="$(cat ${OPKG_CMDS_TMP} | tr '\n' '; ')"
log_info "$func:${LINENO}: executed opkg commands" log_info "$func:${LINENO}: executed opkg commands"
update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \ update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
@ -136,7 +158,6 @@ update_psa() {
update_psa_cleanup $UPDATE_ISMAS_PROGRESS \ update_psa_cleanup $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "cleanup after psa update" $RC_SUCCESS "cleanup after psa update"
# TODO
exit 0 exit 0
} }