Compare commits
55 Commits
103952bdb9
...
szeged_pre
Author | SHA1 | Date | |
---|---|---|---|
5bca1f498b | |||
2d1f11fd74 | |||
2d76b37e5d | |||
b5b3aa7e34 | |||
e3403b2ddd | |||
82d6dc643a | |||
ef4d27eb91 | |||
215b155f2d | |||
901fa4c319 | |||
e356456fb5 | |||
bcc96a388f | |||
8f50f62a52 | |||
847c58afc8 | |||
2abdf963ac | |||
96d76b856a | |||
9eff70b780 | |||
2a8be547a8 | |||
17521771e3 | |||
515c77bed4 | |||
f2617d8151 | |||
4f9c6155e1 | |||
33511a5bcb | |||
bd0d07f56f | |||
b8bc61daea | |||
27cd99f96a | |||
729778043a | |||
31e1aad762 | |||
f8c091ad0c | |||
e5e6c4c1cd | |||
95a9307631 | |||
fc1c2221b1 | |||
9b1549306d | |||
a8f691741b | |||
c229f7072c | |||
7a35039dad | |||
42fb74a041 | |||
d69f767002 | |||
7c2d78e6db | |||
9dd7eb7a3c | |||
87be571e43 | |||
2045dcedf5 | |||
9d6bb99963 | |||
8b5cda7f73 | |||
52271bef21 | |||
f080f34bb3 | |||
6f8ba186dd | |||
0541206033 | |||
b3eed36db8 | |||
966a779065 | |||
da3c9abbf5 | |||
3574453066 | |||
27445f354a | |||
83aa2dbd5c | |||
cfce4ae53c | |||
7a77d03c7e |
@@ -82,33 +82,37 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert_s () {
|
assert_s () {
|
||||||
if [ -z ${!1} ]; then
|
# if [ -z ${!1} ]; then
|
||||||
log_fatal "$1 not set"
|
# log_fatal "$1 not set"
|
||||||
fi
|
# fi
|
||||||
log_debug "$1=${!1}"
|
# log_debug "$1=${!1}"
|
||||||
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_d () {
|
assert_d () {
|
||||||
if [ ! -d ${!1} ]; then
|
# if [ ! -d ${!1} ]; then
|
||||||
log_fatal "$1 does not exist"
|
# log_fatal "$1 does not exist"
|
||||||
fi
|
# fi
|
||||||
log_debug "$1=${!1}"
|
# log_debug "$1=${!1}"
|
||||||
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_f () {
|
assert_f () {
|
||||||
if [ ! -f ${!1} ]; then
|
# if [ ! -f ${!1} ]; then
|
||||||
log_fatal "$1 does not exist"
|
# log_fatal "$1 does not exist"
|
||||||
fi
|
# fi
|
||||||
log_debug "$1=${!1}"
|
#log_debug "$1=${!1}"
|
||||||
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_a () {
|
assert_a () {
|
||||||
local readonly __m="${1}[@]"
|
local readonly __m="${1}[@]"
|
||||||
local readonly __n=(${!__m})
|
local readonly __n=(${!__m})
|
||||||
local __len=${#__n[@]}
|
local __len=${#__n[@]}
|
||||||
if [ $__len -eq 0 ]; then
|
# if [ $__len -eq 0 ]; then
|
||||||
log_fatal "$1 not set"
|
# log_fatal "$1 not set"
|
||||||
fi
|
# fi
|
||||||
log_debug "$1=$__n"
|
# log_debug "$1=$__n"
|
||||||
|
:
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
279
git_helpers
279
git_helpers
@@ -57,6 +57,18 @@ revert_to_commit_before_pull () {
|
|||||||
}
|
}
|
||||||
# revert_to_commit_before_pull
|
# revert_to_commit_before_pull
|
||||||
|
|
||||||
|
git_branch () {
|
||||||
|
# always relative to a git repository
|
||||||
|
echo $(git branch -a | grep '*' | awk '{ print $2 }')
|
||||||
|
}
|
||||||
|
|
||||||
|
git_customer_branch () {
|
||||||
|
if cd_customer_repository; then
|
||||||
|
customer_branch=$(git_branch)
|
||||||
|
cd_home;
|
||||||
|
echo $customer_branch
|
||||||
|
fi
|
||||||
|
}
|
||||||
# clone the customer repository in ./workspace.
|
# clone the customer repository in ./workspace.
|
||||||
# this is done only once.
|
# this is done only once.
|
||||||
#
|
#
|
||||||
@@ -70,72 +82,104 @@ revert_to_commit_before_pull () {
|
|||||||
#
|
#
|
||||||
clone_customer_repository () {
|
clone_customer_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
if [ "$PWD" = "$WORKING_DIRECTORY" ]; then
|
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
|
||||||
if ! [[ -d "./$WORKSPACE_DIR" ]]; then
|
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||||
{ mkdir -p ./$WORKSPACE_DIR; }
|
fi
|
||||||
|
|
||||||
|
mkdir -p "./$WORKSPACE_DIR"
|
||||||
|
# check if the directory is empty. If so, clone the
|
||||||
|
# customer repository
|
||||||
|
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
|
||||||
|
log_info "$func:${LINENO} cloning ${1} into ${PWD}/${WORKSPACE_DIR}..."
|
||||||
|
if ! cd "./$WORKSPACE_DIR"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not change to $WORKSPACE_DIR"
|
||||||
fi
|
fi
|
||||||
# check if the directory is empty. If so, clone the
|
if ! exec_git_command git clone "$1"; then
|
||||||
# customer repository
|
update_psa_clone_error # message to ISMAS
|
||||||
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
|
log_fatal "$func:${LINENO} can not clone $1"
|
||||||
log_debug "$func:${LINENO} cloning ${1} ..."
|
|
||||||
if cd "./$WORKSPACE_DIR"
|
|
||||||
then
|
|
||||||
$(exec_git_command git clone "$1")
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
log_debug "$func:${LINENO} cloning ${1} done"
|
|
||||||
local res=$(exec_git_command git --git-dir="${CUSTOMER_ID_BASE_DIR}/.git" --work-tree="/" init)
|
|
||||||
if ! [[ -z $res ]]; then
|
|
||||||
CLONE_CUSTOMER_REPOSITORY=true
|
|
||||||
log_debug "$func:${LINENO} re-init of ${1} done"
|
|
||||||
cd -; return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
cd -
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# the directory is not empty, so we assume the
|
|
||||||
# customer-repository has been cloned already
|
|
||||||
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
|
|
||||||
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
|
|
||||||
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
|
|
||||||
else
|
|
||||||
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
|
||||||
log_debug "$func:${LINENO} $__m"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
########################## CLONING DONE ############################
|
||||||
|
log_debug "$func:${LINENO} cloning ${1} done"
|
||||||
|
# after cloning, cd into repository, and re-initialize,
|
||||||
|
# setting the work-tree as "/". This has the effect that
|
||||||
|
# a "git pull" will automatically fetched files in the
|
||||||
|
# corresponding sytem-folders.
|
||||||
|
####################### CD INTO REPOSITORY ##########################
|
||||||
|
if ! cd ${CUSTOMER_ID_BASE_DIR}; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not change to $CUSTOMER_ID_BASE_DIR"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} cd into $CUSTOMER_ID_BASE_DIR"
|
||||||
|
##################### CONFIGURE HOOKS DIRECTORY ######################
|
||||||
|
if ! exec_git_command git config core.hooksPath .githooks; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not configure hooks directory"
|
||||||
|
fi
|
||||||
|
###################### CHECKOUT LOCAL BRANCH #########################
|
||||||
|
if ! exec_git_command git checkout "$LOCAL_BRANCH"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not checkout $LOCAL_BRANCH"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
|
||||||
|
######################## CONFIGURE WORKTREE ##########################
|
||||||
|
if ! exec_git_command git config core.worktree "/"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not configure worktree '/'"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} configured worktree '/'"
|
||||||
|
########################### FETCH ALL #################################
|
||||||
|
if ! exec_git_command git fetch --all; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} can not fetch --all for $LOCAL_BRANCH"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} fetch repository"
|
||||||
|
########################## RE-INIT REPOSITORY ########################
|
||||||
|
if ! exec_git_command git reset --hard "$LOCAL_BRANCH"; then
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
log_fatal "$func:${LINENO} re-init of $LOCAL_BRANCH failed"
|
||||||
|
fi
|
||||||
|
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
|
||||||
|
INITIAL_CLONE=true
|
||||||
|
log_debug "$func:${LINENO} re-init of ${1} done"
|
||||||
|
update_psa_clone_customer_repository
|
||||||
|
else
|
||||||
|
# the directory is not empty, so we assume the
|
||||||
|
# customer-repository has been cloned already
|
||||||
|
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
|
||||||
|
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
|
||||||
|
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
|
||||||
|
fi
|
||||||
|
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
||||||
|
log_info "$func:${LINENO} $__m, no clone necessary"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
update_psa_clone_error # message to ISMAS
|
cd_home
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
# clone_customer_repository ->
|
# clone_customer_repository ->
|
||||||
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
|
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
|
||||||
|
|
||||||
cd_customer_repository () {
|
cd_customer_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
# has to be called in WORKING_DIRECTORY
|
|
||||||
cd "$WORKING_DIRECTORY"
|
|
||||||
if [ "$PWD" = "${WORKING_DIRECTORY}" ]; then
|
|
||||||
repository_dir="./$WORKSPACE_DIR/$CUSTOMER_ID"
|
|
||||||
if ! [[ -d "$repository_dir" ]]; then
|
|
||||||
log_crit "$func:${LINENO}: $repository_dir does not exist!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! { cd $repository_dir; } ; then
|
|
||||||
log_crit "$func:${LINENO}: cannot cd to $repository_dir!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: cd to $repository_dir!"
|
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
|
||||||
return 0
|
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||||
fi
|
fi
|
||||||
return 1
|
|
||||||
|
if ! [[ -d "$CUSTOMER_ID_BASE_DIR" ]]; then
|
||||||
|
log_fatal "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR does not exist!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! cd "$CUSTOMER_ID_BASE_DIR"; then
|
||||||
|
log_fatal "$func:${LINENO}: cannot cd to $CUSTOMER_ID_BASE_DIR !!!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_debug "$func:${LINENO}: cd to $CUSTOMER_ID_BASE_DIR"
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
cd_home () {
|
cd_home () {
|
||||||
if cd - &>/dev/null ; then
|
if cd "$WORKING_DIRECTORY" &>/dev/null ; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
@@ -148,109 +192,20 @@ pull_customer_repository () {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local commit_before_pull=$(latest_commit)
|
log_crit "$func:${LINENO}: executing 'git pull'..."
|
||||||
if [ -z $commit_before_pull ]; then
|
exec_git_command 'git pull'
|
||||||
log_warn "$func:${LINENO}: commit_before_pull empty"
|
|
||||||
cd_home ; return 1
|
# GIT_UPDATE_LOG updated by hook post-merge. it contains the names of the
|
||||||
|
# changed files or opkg-commands to execute.
|
||||||
|
# If 'git pull' has fetched new data, then there are lines starting with
|
||||||
|
# DOWNLOAD or EXECUTE.
|
||||||
|
if grep -qE "^[[:space:]]*(DOWNLOAD|EXECUTE)" "$GIT_UPDATE_LOG"; then
|
||||||
|
log_info "$func:${LINENO}: new data fetched from repository"
|
||||||
|
cd_home; return 0
|
||||||
fi
|
fi
|
||||||
log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
|
|
||||||
log_debug "$func:${LINENO}: executing 'git pull'..."
|
log_warn "$func:${LINENO}: no data fetched from repository"
|
||||||
|
cd_home; return 1
|
||||||
local git_result=$(exec_git_command 'git pull')
|
|
||||||
|
|
||||||
if [ -z "$git_result" ]; then
|
|
||||||
log_warn "$func:${LINENO}: git result empty" ; cd_home;
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# see https://www.gnu.org/
|
|
||||||
# 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
|
||||||
|
|
||||||
@@ -279,4 +234,20 @@ changed_file_names () {
|
|||||||
"while in $PWD"
|
"while in $PWD"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
# fi
|
|
||||||
|
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{} sh -c "git ls-tree {} -- $1 |
|
||||||
|
grep -q $blob && echo {}")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
20
log_helpers
20
log_helpers
@@ -17,7 +17,8 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
|||||||
readonly FATAL=5
|
readonly FATAL=5
|
||||||
readonly MAX_DEBUG_LEVEL=6
|
readonly MAX_DEBUG_LEVEL=6
|
||||||
|
|
||||||
log_level=0
|
log_level=$INFO
|
||||||
|
FATAL_FAILURE=false
|
||||||
|
|
||||||
set_dbg_level () {
|
set_dbg_level () {
|
||||||
if [ $1 < $MAX_DEBUG_LEVEL ]; then
|
if [ $1 < $MAX_DEBUG_LEVEL ]; then
|
||||||
@@ -29,50 +30,61 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
|||||||
return $log_level
|
return $log_level
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log_to_file() {
|
||||||
if [[ $(("$(wc -l < $log_file)")) -ge $((100000)) ]]; then
|
if [[ $(("$(wc -l < $log_file)")) -ge $((100000)) ]]; then
|
||||||
# remove first line
|
# remove first line
|
||||||
sed -e 1d -i $log_file
|
sed -e 1d -i $log_file
|
||||||
fi
|
fi
|
||||||
local msg="$(date +'%Y-%m-%d_%T'): $*"
|
local msg="$(date +'%Y-%m-%d_%T'): $*"
|
||||||
echo "log:$msg" >&2
|
|
||||||
echo "$msg" >> $log_file
|
echo "$msg" >> $log_file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
local msg="$(date +'%Y-%m-%d_%T'): $*"
|
||||||
|
echo "log:$msg" >&2
|
||||||
|
}
|
||||||
|
|
||||||
log_debug() {
|
log_debug() {
|
||||||
if [ $log_level = $DEBUG ]; then
|
log_to_file "DEBUG $*"
|
||||||
|
if [ $log_level -le $DEBUG ]; then
|
||||||
log "DEBUG $*"
|
log "DEBUG $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info() {
|
log_info() {
|
||||||
|
log_to_file "INFO $*"
|
||||||
if [ $log_level -le $INFO ]; then
|
if [ $log_level -le $INFO ]; then
|
||||||
log "INFO $*"
|
log "INFO $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_warn() {
|
log_warn() {
|
||||||
|
log_to_file "WARN $*"
|
||||||
if [ $log_level -le $WARN ]; then
|
if [ $log_level -le $WARN ]; then
|
||||||
log "WARN $*"
|
log "WARN $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_crit() {
|
log_crit() {
|
||||||
|
log_to_file "CRIT $*"
|
||||||
if [ $log_level -le $CRIT ]; then
|
if [ $log_level -le $CRIT ]; then
|
||||||
log "CRIT $*"
|
log "CRIT $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_error() {
|
log_error() {
|
||||||
|
log_to_file "ERROR $*"
|
||||||
if [ $log_level -le $ERROR ]; then
|
if [ $log_level -le $ERROR ]; then
|
||||||
log "ERROR $*"
|
log "ERROR $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_fatal() {
|
log_fatal() {
|
||||||
|
log_to_file "FATAL $*"
|
||||||
if [ $log_level -le $FATAL ]; then
|
if [ $log_level -le $FATAL ]; then
|
||||||
log "FATAL $*"
|
log "FATAL $*"
|
||||||
log "exiting ..."
|
log "exiting ..."
|
||||||
|
FATAL_FAILURE=true
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
source ./log_helpers
|
source ./log_helpers
|
||||||
|
|
||||||
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
if [ "${news_from_ismas_sourced:-1}" = "1" ]; then # include only once
|
||||||
|
readonly news_from_ismas_sourced=${BASH_SOURCE[0]}
|
||||||
readonly APISM_DIRECT_PORT=7778
|
readonly APISM_DIRECT_PORT=7778
|
||||||
|
|
||||||
updates_available () {
|
updates_available () {
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
source ./log_helpers
|
source ./log_helpers
|
||||||
|
|
||||||
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
|
||||||
|
readonly news_to_ismas_sourced=${BASH_SOURCE[0]}
|
||||||
|
|
||||||
readonly APISM_DB_PORT=7777
|
readonly APISM_DB_PORT=7777
|
||||||
readonly UPDATE_ISMAS_PROGRESS="U0010"
|
readonly UPDATE_ISMAS_PROGRESS="U0010"
|
||||||
@@ -69,6 +70,18 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
|||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_clone_customer_repository () {
|
||||||
|
PERCENT=10
|
||||||
|
local params=("U0010" # event
|
||||||
|
$PERCENT # percent
|
||||||
|
$RC_SUCCESS # resultcode
|
||||||
|
"clone_customer_repository" # step
|
||||||
|
"git cloned $CUSTOMER_REPOSITORY_PATH" # step_result
|
||||||
|
"") # version
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
update_psa_pull_customer_repository () {
|
update_psa_pull_customer_repository () {
|
||||||
PERCENT=10
|
PERCENT=10
|
||||||
@@ -382,8 +395,8 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
|||||||
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
|
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
|
||||||
\"HASH\":\"$(compute_hash)\"
|
\"HASH\":\"$(compute_hash)\"
|
||||||
},
|
},
|
||||||
\"TARIFF\": {
|
\"TARIFF\" : {
|
||||||
$(<$TC_PSA_TC_FILE)
|
$(<$TC_PSA_TC_FILE)
|
||||||
},
|
},
|
||||||
\"HARDWARE\" : {
|
\"HARDWARE\" : {
|
||||||
\"DEVICES\" : [
|
\"DEVICES\" : [
|
||||||
|
76
read_config
76
read_config
@@ -22,39 +22,32 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
readonly UPDATEPSABEGIN=./.updatepsa/begin
|
readonly UPDATEPSABEGIN=./.updatepsa/begin
|
||||||
readonly UPDATEPSAEND=./.updatepsa/end
|
readonly UPDATEPSAEND=./.updatepsa/end
|
||||||
|
|
||||||
|
# name of file containing the logs following a 'git pull':
|
||||||
|
# basically, there are two kinds of entries:
|
||||||
|
readonly GIT_UPDATE_LOG=/opt/app/tools/atbupdate/update_log.csv
|
||||||
|
|
||||||
readonly PROGRAM=`basename $0`
|
readonly PROGRAM=`basename $0`
|
||||||
readonly WORKSPACE_DIR=workspace
|
readonly WORKSPACE_DIR=workspace
|
||||||
|
|
||||||
EXITCODE=$RC_SUCCESS
|
EXITCODE=$RC_SUCCESS
|
||||||
CLONE_CUSTOMER_REPOSITORY=false
|
INITIAL_CLONE=false
|
||||||
|
APISM_RUNNING=0
|
||||||
|
|
||||||
# read config file (JSON syntax)
|
# read config file (JSON syntax)
|
||||||
read_config() {
|
read_config() {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME}
|
|
||||||
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
|
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
|
||||||
|
|
||||||
if ! [ -f "$CONFIGFILENAME" ]; then
|
if ! [ -f "$CONFIGFILENAME" ]; then
|
||||||
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
|
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -d "$WORKING_DIRECTORY" ]; then
|
|
||||||
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME"
|
log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME"
|
||||||
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
|
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
|
||||||
|
|
||||||
local readonly cf="$CONFIGFILENAME"
|
local readonly cf="$CONFIGFILENAME"
|
||||||
|
|
||||||
### TODO: wieso wird hier in das verzeichnis gewechselt
|
|
||||||
if cd $WORKING_DIRECTORY ; then
|
|
||||||
log_debug "$func:${LINENO}: cd to $WORKING_DIRECTORY"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: cannot cd to $WORKING_DIRECTORY"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
|
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
|
||||||
assert_s GIT_SSL_NO_VERIFY
|
assert_s GIT_SSL_NO_VERIFY
|
||||||
|
|
||||||
@@ -88,7 +81,30 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
|
|
||||||
readonly ZONE_GROUPS=(${__zone_groups[@]})
|
readonly ZONE_GROUPS=(${__zone_groups[@]})
|
||||||
assert_a ZONE_GROUPS
|
assert_a ZONE_GROUPS
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
|
||||||
|
# TODO
|
||||||
|
# Zone aus /etc/zone_nr auslesen
|
||||||
|
#
|
||||||
|
readonly ZONE_GROUP=1
|
||||||
|
local __zone=1
|
||||||
|
readonly ZONE_FILE="$(cat "$cf" | jq -r .zone)"
|
||||||
|
if [ -f "$ZONE_FILE" ]; then
|
||||||
|
__zone=$(cat "$ZONE_FILE")
|
||||||
|
__zone=$((__zone))
|
||||||
|
fi
|
||||||
|
|
||||||
|
readonly ZONE=$__zone
|
||||||
|
readonly LOCAL_BRANCH="$(cat "$cf" | jq -r .local_branches[$ZONE])"
|
||||||
|
|
||||||
|
if [ -z "$WORKING_DIRECTORY" ]; then
|
||||||
|
log_fatal "${func}:${LINENO}: empty WORKING_DIRECTORY"
|
||||||
|
fi
|
||||||
|
if ! cd "$WORKING_DIRECTORY"; then
|
||||||
|
log_fatal "${func}:${LINENO}: cannot cd to $WORKING_DIRECTORY"
|
||||||
|
fi
|
||||||
|
log_debug "${func}:${LINENO}: cd to $WORKING_DIRECTORY"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -97,13 +113,15 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
compute_hash () {
|
compute_hash () {
|
||||||
if cd_customer_repository; then
|
if cd_customer_repository; then
|
||||||
local hash=""
|
local hash=""
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
hash=$(git log -n 1 --pretty=format:%H)
|
hash=$(git log -n 1 --pretty=format:%H)
|
||||||
else
|
else
|
||||||
hash=$(git log -n 1 --pretty=format:%H -- $1)
|
hash=$(git hash-object "$1")
|
||||||
fi
|
fi
|
||||||
echo ${hash:0:10} # return the first 10 hex characters
|
cd_home ; echo ${hash:0:10} # return the first 10 hex characters
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
compute_version () {
|
compute_version () {
|
||||||
@@ -114,6 +132,10 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
|
|
||||||
check_sanity_of_repository () {
|
check_sanity_of_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
|
||||||
|
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||||
|
fi
|
||||||
|
|
||||||
assert_d CUSTOMER_ID_BASE_DIR
|
assert_d CUSTOMER_ID_BASE_DIR
|
||||||
|
|
||||||
@@ -146,13 +168,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
# readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
|
# readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
|
||||||
# assert_a CUST_BASE_DIRS
|
# assert_a CUST_BASE_DIRS
|
||||||
|
|
||||||
# TODO
|
|
||||||
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
|
|
||||||
# TODO
|
|
||||||
# Zone aus /etc/zone_nr auslesen
|
|
||||||
#
|
|
||||||
readonly ZONE_GROUP=1
|
|
||||||
readonly ZONE=1
|
|
||||||
readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
|
readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
|
||||||
#readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
|
#readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
|
||||||
#assert_d CUST_BASE_DIR
|
#assert_d CUST_BASE_DIR
|
||||||
@@ -187,7 +203,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
readonly SYSCONF_INI="sysconfig.ini"
|
readonly SYSCONF_INI="sysconfig.ini"
|
||||||
readonly SYSCTRL_INI="SystemControl.ini"
|
readonly SYSCTRL_INI="SystemControl.ini"
|
||||||
readonly TARIFF_CURRENT="tariff.current"
|
readonly TARIFF_CURRENT="tariff.current"
|
||||||
readonly DC="dc2c.hex"
|
readonly DC="dc2c.bin"
|
||||||
readonly TARIFF_SUMMER="summer_tariff.json"
|
readonly TARIFF_SUMMER="summer_tariff.json"
|
||||||
readonly TARIFF_WINTER="winter_tariff.json"
|
readonly TARIFF_WINTER="winter_tariff.json"
|
||||||
|
|
||||||
@@ -206,7 +222,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
readonly SYSCTRL_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCTRL_INI"
|
readonly SYSCTRL_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCTRL_INI"
|
||||||
readonly SYSCTRL_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCTRL_INI"
|
readonly SYSCTRL_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCTRL_INI"
|
||||||
readonly SYSCTRL_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI"
|
readonly SYSCTRL_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI"
|
||||||
readonly ZONE_FILE="$ETC_SYS_DIR/zone_nr"
|
# readonly ZONE_FILE="$ETC_SYS_DIR/zone_nr"
|
||||||
readonly CUST_ID_FILE="$ETC_SYS_DIR/cust_nr"
|
readonly CUST_ID_FILE="$ETC_SYS_DIR/cust_nr"
|
||||||
readonly TC_SYS_TC_FILE="${ATBAPP_SYS_DIR}/$TARIFF_CURRENT"
|
readonly TC_SYS_TC_FILE="${ATBAPP_SYS_DIR}/$TARIFF_CURRENT"
|
||||||
readonly OPKG_CMDS_SYS_FILE="${OPKG_SYS_DIR}/opkg_commands"
|
readonly OPKG_CMDS_SYS_FILE="${OPKG_SYS_DIR}/opkg_commands"
|
||||||
@@ -372,11 +388,11 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
${DC_PSA_DC_FILE##*${CUSTOMER_ID}/} \
|
${DC_PSA_DC_FILE##*${CUSTOMER_ID}/} \
|
||||||
${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/})
|
${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/})
|
||||||
|
|
||||||
log_debug "known json/ini/hex_files ->"
|
# log_debug "known json/ini/hex_files ->"
|
||||||
for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
|
# for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
|
||||||
tab=$'\t'
|
# tab=$'\t'
|
||||||
log_debug "$tab$tab ${KNOWN_FILES[$i]}"
|
# log_debug "$tab$tab ${KNOWN_FILES[$i]}"
|
||||||
done
|
# done
|
||||||
log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
|
log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
|
||||||
|
|
||||||
# compute version string for current (i.e. previous) version
|
# compute version string for current (i.e. previous) version
|
||||||
|
43
update_psa
43
update_psa
@@ -5,6 +5,7 @@
|
|||||||
# UPDATE PSA
|
# UPDATE PSA
|
||||||
# Usage:
|
# Usage:
|
||||||
# update_psa [ --? ]
|
# update_psa [ --? ]
|
||||||
|
# [ -m ]
|
||||||
# [ --help ]
|
# [ --help ]
|
||||||
# [ --wdir "working_directory" ]
|
# [ --wdir "working_directory" ]
|
||||||
# [ --file "config_file" ]
|
# [ --file "config_file" ]
|
||||||
@@ -14,18 +15,24 @@
|
|||||||
# ./update_psa --file $PWD/update_psa.conf --wdir $PWD
|
# ./update_psa --file $PWD/update_psa.conf --wdir $PWD
|
||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
if [ $# -eq 0 ]; then
|
# if [ $# -eq 0 ]; then
|
||||||
# no parameters given -> nothing to do
|
# no parameters given -> nothing to do
|
||||||
exit 0
|
# exit 0
|
||||||
fi
|
#fi
|
||||||
|
|
||||||
if [ -z $IFS ]; then
|
if [ -z $IFS ]; then
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
MAINTENANCE="NO"
|
||||||
|
WORKING_DIRECTORY=${PWD}
|
||||||
|
|
||||||
# parse commandline parameters
|
# parse commandline parameters
|
||||||
while test $# -gt 0; do
|
while test $# -gt 0; do
|
||||||
case $1 in
|
case $1 in
|
||||||
|
--maintenance | -m )
|
||||||
|
MAINTENANCE="YES"
|
||||||
|
;;
|
||||||
--file | --fil | --fi | --f | -file | -fil | -fi | -f )
|
--file | --fil | --fi | --f | -file | -fil | -fi | -f )
|
||||||
shift
|
shift
|
||||||
CONFIGFILENAME="$1"
|
CONFIGFILENAME="$1"
|
||||||
@@ -36,7 +43,11 @@ while test $# -gt 0; do
|
|||||||
;;
|
;;
|
||||||
--wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w )
|
--wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w )
|
||||||
shift
|
shift
|
||||||
WORKING_DIRECTORY="$1"
|
if [ "$1" = "." ]; then
|
||||||
|
WORKING_DIRECTORY="$PWD"
|
||||||
|
else
|
||||||
|
WORKING_DIRECTORY="$1"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
|
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
|
||||||
usage_and_exit 0
|
usage_and_exit 0
|
||||||
@@ -47,6 +58,7 @@ while test $# -gt 0; do
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--dbg | --db | --d | -dbg | -db | -d )
|
--dbg | --db | --d | -dbg | -db | -d )
|
||||||
|
shift
|
||||||
set_dbg_level $DEBUG
|
set_dbg_level $DEBUG
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
@@ -58,25 +70,12 @@ while test $# -gt 0; do
|
|||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
source ./update_psa_impl
|
source ./update_psa_impl
|
||||||
|
|
||||||
if read_config
|
if read_config; then
|
||||||
then
|
update_psa
|
||||||
if clone_customer_repository $CUSTOMER_REPOSITORY_PATH
|
exit 0
|
||||||
then
|
|
||||||
check_sanity_of_repository
|
|
||||||
|
|
||||||
#set_updates_available
|
|
||||||
#while :
|
|
||||||
#do
|
|
||||||
# sleep 5
|
|
||||||
# updates_available && break
|
|
||||||
#done
|
|
||||||
|
|
||||||
update_psa
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
exit 1
|
||||||
exit $EXIT_CODE
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@@ -6,11 +6,15 @@
|
|||||||
"customer_location" : "szeged",
|
"customer_location" : "szeged",
|
||||||
|
|
||||||
"" : "unique customer identifier",
|
"" : "unique customer identifier",
|
||||||
"customer_id" : "customer_szeged_281",
|
"customer_id" : "customer_281",
|
||||||
|
|
||||||
"" : "zone file for PSA",
|
"" : "zone file for PSA",
|
||||||
"zone" : "/etc/zone_nr",
|
"zone" : "/etc/zone_nr",
|
||||||
|
|
||||||
|
"" : "local branches",
|
||||||
|
"local_branches" : ["master",
|
||||||
|
"zg1/zone1", "zg1/zone2", "zg1/zone3", "zg1/zone4"],
|
||||||
|
|
||||||
"" : "customer number of PSA",
|
"" : "customer number of PSA",
|
||||||
"customer_id_" : "/etc/cust_nr",
|
"customer_id_" : "/etc/cust_nr",
|
||||||
|
|
||||||
@@ -22,8 +26,8 @@
|
|||||||
"" : "0-index used as size of following array",
|
"" : "0-index used as size of following array",
|
||||||
"" : ".zg[0]: #n of zones_groups",
|
"" : ".zg[0]: #n of zones_groups",
|
||||||
"" : ".zg[1].z[0]: #n of zones in zg[1]",
|
"" : ".zg[1].z[0]: #n of zones in zg[1]",
|
||||||
"zg" : [ 1, { "z" : [ 3, 1, 2, 3] } ],
|
"zg" : [ 1, { "z" : [ 4, 1, 2, 4] } ],
|
||||||
|
|
||||||
"" : "url of customer repository",
|
"" : "url of customer repository",
|
||||||
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_szeged_281"
|
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_281.git"
|
||||||
}
|
}
|
||||||
|
@@ -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 $1; then
|
if ! pull_customer_repository; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
@@ -373,8 +373,37 @@ cleanup_previous_version() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
check_for_apism () {
|
check_for_running_apism () {
|
||||||
nc localhost 7778
|
local func="${FUNCNAME[0]}"
|
||||||
|
if nc localhost 7778
|
||||||
|
then
|
||||||
|
APISM_RUNNING=1
|
||||||
|
log_info "$func:${LINENO}: APISM is running..."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
log_fatal "$func:${LINENO}: !!! APISM NOT RUNNING !!!"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_default_route () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
if ip route | head -n 1 | grep -q '^default'
|
||||||
|
then
|
||||||
|
log_info "$func:${LINENO}: default route set"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
log_fatal "$func:${LINENO}: !!! NO DEFAULT ROUTE SET !!!"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_route_to_repository () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
# ip_address=$1, e.g. git.mimbach.de (185.191.219.134)
|
||||||
|
# 185.191.219.134 via 192.168.5.254 ...
|
||||||
|
if test "$#" -eq 1 && ip route get "$1" | head -n 1 | grep -q "^$1"
|
||||||
|
then
|
||||||
|
log_info "$func:${LINENO}: route to repository available"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
log_fatal "$func:${LINENO}: !!! NO ROUTE TO REPO SET !!!"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_customer_id () {
|
get_customer_id () {
|
||||||
|
146
update_psa_impl
146
update_psa_impl
@@ -13,6 +13,8 @@ trap collect_current_configuration EXIT
|
|||||||
collect_current_configuration () {
|
collect_current_configuration () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
$FATAL_FAILURE && return 1
|
||||||
|
|
||||||
# TODO: eventuell muss die version neu berechnet werden
|
# TODO: eventuell muss die version neu berechnet werden
|
||||||
current_settings_to_ismas
|
current_settings_to_ismas
|
||||||
|
|
||||||
@@ -29,118 +31,50 @@ collect_current_configuration () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_psa() {
|
update_psa() {
|
||||||
|
|
||||||
if ! updates_available; then # check for false alarm
|
|
||||||
update_psa_false_alarm "update requested, but no WAIT state detected"
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
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]}"
|
||||||
|
|
||||||
|
check_default_route
|
||||||
|
check_route_to_repository "185.191.219.134" # git.mimbach.de
|
||||||
|
# even for a git clone a running APISM is needed
|
||||||
|
check_for_running_apism
|
||||||
|
|
||||||
|
# an initial clone of the customer-repository (e.g. customer_281) is
|
||||||
|
# always possible, even without a ISMAS-WAIT-button
|
||||||
|
clone_customer_repository ${CUSTOMER_REPOSITORY_PATH}
|
||||||
|
check_sanity_of_repository
|
||||||
|
$INITIAL_CLONE && return 0
|
||||||
|
|
||||||
|
if [ "$MAINTENANCE" = "NO" ]; then
|
||||||
|
log_info "update_psa:${LINENO}: MAINTENANCE OFF. Checking for updates..."
|
||||||
|
# someone must have activated the WAIT-button in ISMAS.
|
||||||
|
# Request the status of this button in updates_available().
|
||||||
|
if ! updates_available; then
|
||||||
|
update_psa_false_alarm "update requested, but no WAIT state detected !!!"
|
||||||
|
log_fatal "update_psa:${LINENO}: update requested, but no WAIT state detected !!!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# simulate an activated WAIT-button
|
||||||
|
set_updates_available
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
sleep 5
|
||||||
|
updates_available && break
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: fetch/merge updates..."
|
log_debug "$func:${LINENO}: fetch/merge updates..."
|
||||||
|
|
||||||
# Fetch new updates (using git)
|
# Fetch new updates (using git). but only when repository has already been
|
||||||
while :
|
# cloned.
|
||||||
do
|
if ! fetch_customer_updates; then
|
||||||
local repository_is_already_up_to_date=""
|
log_error "$func:${LINENO}: fetch no data for $customer_id"\
|
||||||
if ! fetch_customer_updates repository_is_already_up_to_date; then
|
"-> no files to update -> no psa update"
|
||||||
if [ "$repository_is_already_up_to_date" = "yes" ]; then
|
update_psa_false_alarm \
|
||||||
log_error "$func:${LINENO}: $customer_id is up-to-date"\
|
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
|
||||||
"-> no files to update -> no psa update"
|
# TODO
|
||||||
update_psa_false_alarm \
|
fi
|
||||||
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
|
|
||||||
exit $?
|
|
||||||
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
|
||||||
|
|
||||||
# no backup necessary as saved in git-repo
|
|
||||||
|
|
||||||
local changed_files=$(changed_file_names)
|
|
||||||
|
|
||||||
if ! check_hardware_compatibility "$files_to_copy" ; then
|
|
||||||
local __r=$?
|
|
||||||
log_error "$func:${LINENO}: json/ini-files not fit for PSA"
|
|
||||||
revert_customer_repository
|
|
||||||
exit $__r
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check if the opkg-command-file has been changed during 'git pull'
|
|
||||||
if grep -qE ".*opkg_commands.*?" <<< $changed_files; then
|
|
||||||
# read opkg_cmds: each line respresents an opkg-command
|
|
||||||
readarray opkg_commands < <(cat $OPKG_CMDS_PSA_FILE)
|
|
||||||
for opkg_c in "${opkg_commands[@]}"; do
|
|
||||||
if grep -qE "^\s*[#]+.*$" <<< $opkg_c; then
|
|
||||||
continue # found comment line
|
|
||||||
fi
|
|
||||||
|
|
||||||
# package manipulation commands without package:
|
|
||||||
local cwp="update|upgrade|clean"
|
|
||||||
# informational commands without package:
|
|
||||||
cwp="${cwp}|list|list-installed|list-upgradable"
|
|
||||||
|
|
||||||
if grep -qE "^.*\s+($cwp)\s+.*$" <<< $opkg_c; then
|
|
||||||
local p=$(printf '%s' "$opkg_c" | awk '{ print $NF }')
|
|
||||||
local opkg_output=()
|
|
||||||
if ! exec_opkg_info "$p" opkg_output; then
|
|
||||||
log_error "$func:${LINENO}: opkg info $opkg_c failed"
|
|
||||||
revert_customer_repository ; exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! check_md5_for_opkg_packages opkg_output; then
|
|
||||||
log_error "$func:${LINENO}: "\
|
|
||||||
"wrong md5sum for opkg packages"
|
|
||||||
revert_customer_repository ; exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# perform a dry-run and check if everything might work as expected.
|
|
||||||
if ! exec_opkg_noaction $opkg_c; then
|
|
||||||
log_error "$func:${LINENO}: "\
|
|
||||||
"opkg --noaction $opkg_c failed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Actually execute the opkg command
|
|
||||||
if ! exec_opkg $opkg_c; then
|
|
||||||
log_error "$func:${LINENO}: exec_opkg $opkg_c failed"
|
|
||||||
fallback_to_previous_version
|
|
||||||
revert_customer_repository ; exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
log_info "$func:${LINENO}: no opkg commands to execute"
|
|
||||||
update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
|
|
||||||
$RC_SUCCESS "no opkg commands to execute"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cleanup.
|
|
||||||
#if ! cleanup_previous_version; then
|
|
||||||
# log_error "$func:${LINENO}: cleanup_previous_version failed"
|
|
||||||
#fi
|
|
||||||
|
|
||||||
# compute version string for current (i.e. new) version
|
|
||||||
compute_version
|
|
||||||
|
|
||||||
update_psa_cleanup $UPDATE_ISMAS_PROGRESS \
|
|
||||||
$RC_SUCCESS "cleanup after psa update"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user