Compare commits
100 Commits
34ffefd45f
...
szeged_pre
Author | SHA1 | Date | |
---|---|---|---|
c229f7072c | |||
7a35039dad | |||
42fb74a041 | |||
d69f767002 | |||
7c2d78e6db | |||
9dd7eb7a3c | |||
87be571e43 | |||
2045dcedf5 | |||
9d6bb99963 | |||
8b5cda7f73 | |||
52271bef21 | |||
f080f34bb3 | |||
6f8ba186dd | |||
0541206033 | |||
b3eed36db8 | |||
966a779065 | |||
da3c9abbf5 | |||
3574453066 | |||
27445f354a | |||
83aa2dbd5c | |||
cfce4ae53c | |||
7a77d03c7e | |||
103952bdb9 | |||
0516843837 | |||
d538f21a57 | |||
f860c901f5 | |||
8f07fbcf53 | |||
326c6ea001 | |||
66511262e1 | |||
21591d8e3d | |||
a3e311e375 | |||
73a18d5615 | |||
a769fe0e12 | |||
0285fed0a1 | |||
ba556f02bd | |||
e46f596270 | |||
c3def117a5 | |||
fcef0f6ed6 | |||
729c0f8c18 | |||
ba1f70fec4 | |||
dc6226bbb7 | |||
6bf95ba131 | |||
7a06811aa5 | |||
259b61cda5 | |||
fe52f263a8 | |||
7e0eccc8d0 | |||
e941af6420 | |||
4b6723b8e6 | |||
ec660a9fad | |||
a884019431 | |||
da32f34b4e | |||
e419b74e46 | |||
a0602c820c | |||
fa5bbc76a5 | |||
4a0b0896bb | |||
39dea2f43f | |||
32fab5c34b | |||
33a6dcb181 | |||
262a851045 | |||
1ad3b7e68f | |||
312f87487d | |||
5d53c448bc | |||
f3b933fc1d | |||
c99cbce45a | |||
3bbbe57c54 | |||
da9f0a73a4 | |||
23150e1e3e | |||
e41bdf540d | |||
bcb961fc95 | |||
f70e4946d7 | |||
0571498503 | |||
d8f36deca0 | |||
2158f65c65 | |||
1ee72f26af | |||
e2fc368371 | |||
d6131e04e9 | |||
98a2e09bd5 | |||
1939779f67 | |||
b9caeb2e3c | |||
0ee446dcc0 | |||
99fe056626 | |||
6bc2854e78 | |||
d351f4485c | |||
283e4666c7 | |||
11e8ef90c0 | |||
6741ed8b34 | |||
0770d664b6 | |||
100f50f537 | |||
703cc9e3bd | |||
f9276b3fdb | |||
2f169e966e | |||
03eba24bbe | |||
43110e0cd7 | |||
eb122ed51f | |||
9ceabd922d | |||
e355cbe4ab | |||
3be55e2702 | |||
57df68fabf | |||
6cca174d66 | |||
d890ff9f07 |
9
clone_customer_repository
Executable file
9
clone_customer_repository
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#! /bin/bash -
|
||||||
|
# set -x
|
||||||
|
|
||||||
|
if [ $# -eq 2 ]; then
|
||||||
|
test mkdir -p $1 && cd $1 && git clone $2
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Usage: ./${0##*/} <workspace-directory> <path-to-customer-repository>
|
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#! /bin/bash -
|
||||||
# set -x
|
# set -x
|
||||||
|
|
||||||
source ./log_helpers
|
source ./log_helpers
|
||||||
@@ -6,6 +6,24 @@ source ./log_helpers
|
|||||||
if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
|
if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
|
||||||
readonly general_utils_sourced=${BASH_SOURCE[0]}
|
readonly general_utils_sourced=${BASH_SOURCE[0]}
|
||||||
|
|
||||||
|
# compare two strings
|
||||||
|
equal () {
|
||||||
|
case "$1" in
|
||||||
|
"$2")
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
return 1 # they don't match
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if second string is contained in first string
|
||||||
|
contains () {
|
||||||
|
if grep -qE "$2" <<< $1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1 # not contained
|
||||||
|
}
|
||||||
|
|
||||||
exec_process_substitution () {
|
exec_process_substitution () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
log_debug "$func:${LINENO} exec-ing [$*]"
|
log_debug "$func:${LINENO} exec-ing [$*]"
|
||||||
@@ -16,12 +34,13 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
|
|||||||
local ps_pid=$! # remember pid of process substitution
|
local ps_pid=$! # remember pid of process substitution
|
||||||
|
|
||||||
local __result=""
|
local __result=""
|
||||||
|
|
||||||
while read __tmp <&$fd; do
|
while read __tmp <&$fd; do
|
||||||
if ! [ -z "$__tmp" ]; then
|
if ! [ -z "$__tmp" ]; then
|
||||||
__result="${__result}$__tmp"
|
__result+=" $__tmp"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
exec {fd}>&- # close fd (i.e. process substitution)
|
exec {fd}>&- # close fd (i.e. process substitution)
|
||||||
wait $ps_pid # wait for the subshell to finish
|
wait $ps_pid # wait for the subshell to finish
|
||||||
|
|
||||||
@@ -31,6 +50,7 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
|
|||||||
printf '%s' "$__result"
|
printf '%s' "$__result"
|
||||||
return $__result_code
|
return $__result_code
|
||||||
}
|
}
|
||||||
|
# exec_process_substitution 'opkg --noaction list'
|
||||||
|
|
||||||
usage () {
|
usage () {
|
||||||
echo "Usage: $PROGRAM [--file config] [--?] [--help] [--version] [--dbg]"
|
echo "Usage: $PROGRAM [--file config] [--?] [--help] [--version] [--dbg]"
|
||||||
@@ -60,4 +80,39 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
|
|||||||
echo "INFO: $2 completed successfully" >&2
|
echo "INFO: $2 completed successfully" >&2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_s () {
|
||||||
|
# if [ -z ${!1} ]; then
|
||||||
|
# log_fatal "$1 not set"
|
||||||
|
# fi
|
||||||
|
# log_debug "$1=${!1}"
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_d () {
|
||||||
|
# if [ ! -d ${!1} ]; then
|
||||||
|
# log_fatal "$1 does not exist"
|
||||||
|
# fi
|
||||||
|
# log_debug "$1=${!1}"
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_f () {
|
||||||
|
# if [ ! -f ${!1} ]; then
|
||||||
|
# log_fatal "$1 does not exist"
|
||||||
|
# fi
|
||||||
|
#log_debug "$1=${!1}"
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_a () {
|
||||||
|
local readonly __m="${1}[@]"
|
||||||
|
local readonly __n=(${!__m})
|
||||||
|
local __len=${#__n[@]}
|
||||||
|
# if [ $__len -eq 0 ]; then
|
||||||
|
# log_fatal "$1 not set"
|
||||||
|
# fi
|
||||||
|
# log_debug "$1=$__n"
|
||||||
|
:
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
|
208
git_helpers
208
git_helpers
@@ -57,51 +57,94 @@ revert_to_commit_before_pull () {
|
|||||||
}
|
}
|
||||||
# revert_to_commit_before_pull
|
# revert_to_commit_before_pull
|
||||||
|
|
||||||
# clone the customer repository in ./UpdateController/workspace.
|
# clone the customer repository in ./workspace.
|
||||||
# this is done only once.
|
# this is done only once.
|
||||||
|
#
|
||||||
|
# Cloning into 'customer_281'...
|
||||||
|
# remote: Enumerating objects: 1087, done.
|
||||||
|
# remote: Counting objects: 100% (1087/1087), done.
|
||||||
|
# remote: Compressing objects: 100% (946/946), done.
|
||||||
|
# remote: Total 1087 (delta 404), reused 0 (delta 0), pack-reused 0
|
||||||
|
# Receiving objects: 100% (1087/1087), 103.27 KiB | 873.00 KiB/s, done.
|
||||||
|
# Resoving deltas: 100% (410/410), done.
|
||||||
|
#
|
||||||
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
|
mkdir -p "./$WORKSPACE_DIR"
|
||||||
{ mkdir -p ./$workspace_dir; }
|
|
||||||
fi
|
|
||||||
# check if the directory is empty. If so, clone the
|
# check if the directory is empty. If so, clone the
|
||||||
# customer repository
|
# customer repository
|
||||||
if ! find ./$workspace_dir -mindepth 1 -maxdepth 1 | read; then
|
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
|
||||||
log_debug "$func:${LINENO} cloning ${1} ..."
|
log_debug "$func:${LINENO} cloning ${1} ..."
|
||||||
if { cd "./$workspace_dir" ; }; then
|
if cd "./$WORKSPACE_DIR"
|
||||||
|
then
|
||||||
$(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"
|
||||||
cd - ; return 0
|
GIT_CLONE_EXECUTED=1
|
||||||
|
rm -f $GIT_PULL_TMP
|
||||||
|
rm -f $OPKG_CMDS_TMP
|
||||||
|
# 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.
|
||||||
|
if cd ${CUSTOMER_ID_BASE_DIR}; then
|
||||||
|
# local res=$(exec_git_command git --git-dir=.git --work-tree=/ init)
|
||||||
|
exec_git_command git checkout "$LOCAL_BRANCH"
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
|
||||||
|
exec_git_command git config core.worktree "/"
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
log_debug "$func:${LINENO} configured worktree"
|
||||||
|
exec_git_command git fetch --all
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
log_debug "$func:${LINENO} fetch repository"
|
||||||
|
exec_git_command git reset --hard "$LOCAL_BRANCH"
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
|
||||||
|
# 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
|
||||||
|
log_debug "$func:${LINENO} re-init of ${1} done"
|
||||||
|
cd_home; return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
cd -
|
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
|
||||||
# customer-repository has been cloned already
|
# customer-repository has been cloned already
|
||||||
if ! [[ -d "./${workspace_dir}/$customer_id" ]]; then
|
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
|
||||||
log_fatal "$func:${LINENO} "\
|
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
|
||||||
"wrong repository: $(ls -d './${workspace_dir}/*')"
|
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
|
||||||
else
|
else
|
||||||
local __m="./${workspace_dir}/$customer_id exists"
|
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
||||||
log_debug "$func:${LINENO} $__m"
|
log_debug "$func:${LINENO} $__m"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
return 1
|
|
||||||
|
update_psa_clone_error # message to ISMAS
|
||||||
|
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 () {
|
||||||
# has to be called in ./UpdateController
|
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
current_dir=${PWD##*/}
|
# has to be called in WORKING_DIRECTORY
|
||||||
current_dir="./${current_dir:-/}"
|
cd "$WORKING_DIRECTORY"
|
||||||
if [ "$current_dir" = "./UpdateController" ]; then
|
if [ "$PWD" = "${WORKING_DIRECTORY}" ]; then
|
||||||
repository_dir="./workspace/${customer_id}"
|
repository_dir="./$WORKSPACE_DIR/$CUSTOMER_ID"
|
||||||
if ! [[ -d "$repository_dir" ]]; then
|
if ! [[ -d "$repository_dir" ]]; then
|
||||||
log_crit "$func:${LINENO}: $repository_dir does not exist!"
|
log_crit "$func:${LINENO}: $repository_dir does not exist!"
|
||||||
return 1
|
return 1
|
||||||
@@ -126,115 +169,33 @@ cd_home () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pull_customer_repository () {
|
pull_customer_repository () {
|
||||||
# has to be called in ./UpdateController
|
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
if ! cd_customer_repository ; then
|
if ! cd_customer_repository; then
|
||||||
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
|
||||||
cd_home ; return 1
|
# log_warn "$func:${LINENO}: commit_before_pull empty"
|
||||||
|
# cd_home ; return 1
|
||||||
|
#fi
|
||||||
|
#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'..."
|
||||||
|
exec_git_command 'git pull'
|
||||||
|
|
||||||
|
# GIT_PULL_TMP created by hook post-merge. it contains the names of the
|
||||||
|
# changed files.
|
||||||
|
if [[ -f $GIT_PULL_TMP ]]; then
|
||||||
|
cd_home; return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
|
log_warn "$func:${LINENO}: no data fetched form 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
|
||||||
|
|
||||||
@@ -245,13 +206,14 @@ changed_file_names () {
|
|||||||
git_res=${git_res//[$'\r\n\t']/ }
|
git_res=${git_res//[$'\r\n\t']/ }
|
||||||
log_debug "$func:${LINENO}: git_res=$git_res"
|
log_debug "$func:${LINENO}: git_res=$git_res"
|
||||||
local file_names=""
|
local file_names=""
|
||||||
for f in ${known_files[@]} ; do
|
for f in ${KNOWN_FILES[@]} ; do
|
||||||
if grep -qE ".*\s+${f}\s+.*" <<< $git_res; then
|
if grep -qE "${f}" <<< "$git_res"; then
|
||||||
if ! [ -z $file_names ]; then
|
if ! [ -z $file_names ]; then
|
||||||
file_names="$f $file_names"
|
file_names="$f $file_names"
|
||||||
else
|
else
|
||||||
file_names="$f"
|
file_names="$f"
|
||||||
fi
|
fi
|
||||||
|
log_debug "$func:${LINENO}: $f found in $git_res"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
33
load_tariff
Executable file
33
load_tariff
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#! /bin/bash -
|
||||||
|
# set -x
|
||||||
|
|
||||||
|
#
|
||||||
|
# echo "Usage: ./${0##*/} <tariff.config> <tariff.current>"
|
||||||
|
#
|
||||||
|
# tariff.config: a JSON-file representing the tariff which should be used
|
||||||
|
# (this tariff-file is generated by a web-based tool of
|
||||||
|
# Mobilisis)
|
||||||
|
# tariff.current: a file containing infos about the currently used tariff:
|
||||||
|
# VERSION: version of the tariff
|
||||||
|
# PROJECT: e.g. szeged
|
||||||
|
# ZONE: usually 1
|
||||||
|
# INFO: additional info for the tariff (optional)
|
||||||
|
# LOADED: date when tariff has been loaded
|
||||||
|
#
|
||||||
|
# This file will be used by the update_psa-script to send
|
||||||
|
# a message to ISMAS containing the current settings of the PSA.
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ $# -eq 2 ]; then
|
||||||
|
if [ -f $1 ]; then
|
||||||
|
out="\"VERSION\":\"$(cat $1 | jq -r .version)\"",
|
||||||
|
out+="\"PROJECT\":\"$(cat $1 | jq -r .project)\"",
|
||||||
|
out+="\"ZONE\":$(cat $1 | jq -r .zone)",
|
||||||
|
out+="\"INFO\":\"$(cat $1 | jq -r .info)\"",
|
||||||
|
out+="\"LOADED\":\"$(date +%Y-%m-%dT%T)\""
|
||||||
|
echo $out > $2
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Usage: ./${0##*/} <tariff.config> <tariff.current>"
|
20
log_helpers
20
log_helpers
@@ -1,6 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# set -x
|
# set -x
|
||||||
|
|
||||||
|
RED='\e[0;31m'
|
||||||
|
GREEN='\e[0;32m'
|
||||||
|
NC='\e[0m' # No Color
|
||||||
|
|
||||||
if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
||||||
readonly log_helpers_sourced=${BASH_SOURCE[0]}
|
readonly log_helpers_sourced=${BASH_SOURCE[0]}
|
||||||
|
|
||||||
@@ -35,8 +39,8 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
|||||||
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'): $*"
|
||||||
printf "log:$msg\n" >&2
|
echo "log:$msg" >&2
|
||||||
printf "$msg\n" >> $log_file
|
echo "$msg" >> $log_file
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug() {
|
log_debug() {
|
||||||
@@ -47,32 +51,32 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
|||||||
|
|
||||||
log_info() {
|
log_info() {
|
||||||
if [ $log_level -le $INFO ]; then
|
if [ $log_level -le $INFO ]; then
|
||||||
log "INFO $*"
|
log "${GREEN}INFO $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_warn() {
|
log_warn() {
|
||||||
if [ $log_level -le $WARN ]; then
|
if [ $log_level -le $WARN ]; then
|
||||||
log "WARN $*"
|
log "${RED}WARN $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_crit() {
|
log_crit() {
|
||||||
if [ $log_level -le $CRIT ]; then
|
if [ $log_level -le $CRIT ]; then
|
||||||
log "CRIT $*"
|
log "${RED}CRIT $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_error() {
|
log_error() {
|
||||||
if [ $log_level -le $ERROR ]; then
|
if [ $log_level -le $ERROR ]; then
|
||||||
log "ERROR $*"
|
log "${RED}ERROR $*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_fatal() {
|
log_fatal() {
|
||||||
if [ $log_level -le $FATAL ]; then
|
if [ $log_level -le $FATAL ]; then
|
||||||
log "FATAL $*"
|
log "${RED}FATAL $*"
|
||||||
log "exiting ..."
|
log "${RED}exiting ..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
35
news_from_ismas
Executable file
35
news_from_ismas
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
# !/bin/bash -
|
||||||
|
|
||||||
|
source ./log_helpers
|
||||||
|
|
||||||
|
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
||||||
|
readonly APISM_DIRECT_PORT=7778
|
||||||
|
|
||||||
|
updates_available () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
|
||||||
|
sleep 1) | nc localhost $APISM_DIRECT_PORT)"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
local trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
|
||||||
|
log_debug "$func:${LINENO}: apism_trigger=\"$trigger\""
|
||||||
|
grep -qE "WAIT" <<< "$trigger" && return 0
|
||||||
|
else
|
||||||
|
log_error "$func:${LINENO}: apism request failed"
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
update_status () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
|
||||||
|
sleep 1) | nc localhost $APISM_DIRECT_PORT)"
|
||||||
|
local trigger=""
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
|
||||||
|
log_debug "$func:${LINENO}: apism_trigger=\"$trigger\""
|
||||||
|
else
|
||||||
|
log_error "$func:${LINENO}: apism request failed"
|
||||||
|
fi
|
||||||
|
echo "$trigger"
|
||||||
|
}
|
||||||
|
fi
|
442
news_to_ismas
Executable file
442
news_to_ismas
Executable file
@@ -0,0 +1,442 @@
|
|||||||
|
# !/bin/bash -
|
||||||
|
|
||||||
|
source ./log_helpers
|
||||||
|
|
||||||
|
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
||||||
|
|
||||||
|
readonly APISM_DB_PORT=7777
|
||||||
|
readonly UPDATE_ISMAS_PROGRESS="U0010"
|
||||||
|
readonly UPDATE_SUCCEEDED="U0001" # update finished: 100%
|
||||||
|
readonly UPDATE_ACTIVATED="U0002" # reset TRG
|
||||||
|
readonly UPDATE_ISMAS_ERROR="U0003" # update error
|
||||||
|
|
||||||
|
# error codes
|
||||||
|
readonly RC_SUCCESS=0
|
||||||
|
readonly RC_NO_UPDATE_NECESSARY=1
|
||||||
|
readonly RC_GIT_CLONE_ERROR=2
|
||||||
|
readonly RC_GIT_PULL_ERROR=3
|
||||||
|
readonly RC_BACKUP_ERROR=4
|
||||||
|
readonly RC_HASH_VALUE_ERROR=5
|
||||||
|
readonly RC_HW_COMPATIBILITY_ERROR=6
|
||||||
|
readonly RC_COPY_ERROR=7
|
||||||
|
readonly RC_OPKG_COMMANDS_ERROR=8
|
||||||
|
readonly RC_CLEANUP_ERROR=9
|
||||||
|
|
||||||
|
PERCENT=1
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_activated () {
|
||||||
|
PERCENT=$((PERCENT+1))
|
||||||
|
local params=("U0010" # event
|
||||||
|
$PERCENT
|
||||||
|
$RC_SUCCESS # resultcode
|
||||||
|
"activated" # step
|
||||||
|
"detected WAIT state" # step_result
|
||||||
|
"") # version
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
update_psa_false_alarm () {
|
||||||
|
PERCENT=$((PERCENT+1))
|
||||||
|
local params=("U0003"
|
||||||
|
$PERCENT
|
||||||
|
$RC_NO_UPDATE_NECESSARY
|
||||||
|
"false_alarm"
|
||||||
|
"$1"
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
update_psa_activated_new_software () {
|
||||||
|
PERCENT=100
|
||||||
|
local params=("U0010"
|
||||||
|
$PERCENT
|
||||||
|
$RC_SUCCESS
|
||||||
|
"activated_new_software"
|
||||||
|
"<hier nochmal eine liste was alles installiert wurde>"
|
||||||
|
"<zugehoerige versionen>")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_pull_customer_repository () {
|
||||||
|
PERCENT=10
|
||||||
|
local params=("U0010" # event
|
||||||
|
$PERCENT # percent
|
||||||
|
0 # resultcode
|
||||||
|
"pull_customer_repository" # step
|
||||||
|
"git pulled $CUSTOMER_REPOSITORY_PATH" # step_result
|
||||||
|
"") # version
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
update_psa_pull_error () {
|
||||||
|
PERCENT=10
|
||||||
|
local params=("U0003"
|
||||||
|
$PERCENT
|
||||||
|
$RC_GIT_PULL_ERROR
|
||||||
|
"pull_error"
|
||||||
|
"git failed to pull $CUSTOMER_REPOSITORY_PATH"
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
update_psa_clone_error () {
|
||||||
|
PERCENT=10
|
||||||
|
local params=("U0003"
|
||||||
|
$PERCENT
|
||||||
|
$RC_GIT_CLONE_ERROR
|
||||||
|
"clone_error"
|
||||||
|
"git failed to clone $CUSTOMER_REPOSITORY_PATH"
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_backup () {
|
||||||
|
PERCENT=20
|
||||||
|
local params=("U0010"
|
||||||
|
$PERCENT
|
||||||
|
$RC_SUCCESS
|
||||||
|
"backup"
|
||||||
|
"backup of (hier noch alle dateien angeben)"
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
update_psa_backup_error () {
|
||||||
|
PERCENT=20
|
||||||
|
local params=("U0010"
|
||||||
|
$PERCENT
|
||||||
|
$RC_BACKUP_ERROR
|
||||||
|
"backup_error"
|
||||||
|
"backup of (hier noch alle dateien angeben) failed"
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_report_changed_file_names () {
|
||||||
|
PERCENT=30
|
||||||
|
local params=("U0010"
|
||||||
|
$PERCENT
|
||||||
|
$RC_SUCCESS
|
||||||
|
"report_changed_file_names"
|
||||||
|
"changed filenames: [$@]"
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_check_hash () {
|
||||||
|
PERCENT=40
|
||||||
|
local params=($1 # event
|
||||||
|
$PERCENT
|
||||||
|
$2 # resultcode
|
||||||
|
"check_hash" # step
|
||||||
|
"$3" # step_result
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
test $2 -eq $RC_SUCCESS && return $?
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_check_hardware_compatibility () {
|
||||||
|
PERCENT=50
|
||||||
|
local params=($1 # event
|
||||||
|
$PERCENT
|
||||||
|
$2 # resultcode
|
||||||
|
"check_hardware_compatibility" # step
|
||||||
|
"$3" # step_result
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
test $2 -eq $RC_SUCCESS && return $?
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
# conf/ini files
|
||||||
|
update_psa_copy_conf_and_ini_files () {
|
||||||
|
PERCENT=60
|
||||||
|
local params=($1 # event
|
||||||
|
$PERCENT
|
||||||
|
$2 # resultcode
|
||||||
|
"copy_conf_and_ini_files" # step
|
||||||
|
"$3" # step_result
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
test $2 -eq $RC_SUCCESS && return $?
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
# exec opkg-commands (dry-run)
|
||||||
|
update_psa_install_opkg_packages_dry_run () {
|
||||||
|
PERCENT=70
|
||||||
|
# TODO
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
# exec opkg-commands
|
||||||
|
update_psa_install_opkg_packages () {
|
||||||
|
PERCENT=80
|
||||||
|
local params=($1 # event
|
||||||
|
$PERCENT
|
||||||
|
$2 # resultcode
|
||||||
|
"install_opkg_packages" # step
|
||||||
|
"$3" # step_result
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
test $2 -eq $RC_SUCCESS && return $?
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
# remove backup in case of success
|
||||||
|
update_psa_cleanup () {
|
||||||
|
PERCENT=90
|
||||||
|
local params=($1 # event
|
||||||
|
$PERCENT
|
||||||
|
$2 # resultcode
|
||||||
|
"cleanup" # step
|
||||||
|
"$3" # step_result
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
test $2 -eq $RC_SUCCESS && return $?
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_update_succeeded () {
|
||||||
|
PERCENT=100
|
||||||
|
local params=($1 # event
|
||||||
|
$PERCENT
|
||||||
|
$2 # resultcode
|
||||||
|
"update_succeeded" # step
|
||||||
|
"$3" # step_result
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
test $2 -eq $RC_SUCCESS && return $?
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
update_psa_activate_update () {
|
||||||
|
PERCENT=100
|
||||||
|
local params=($1 # event
|
||||||
|
$PERCENT
|
||||||
|
$2 # resultcode
|
||||||
|
"activate_update" # step
|
||||||
|
"$3" # step_result
|
||||||
|
"")
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
test $2 -eq $RC_SUCCESS && return $?
|
||||||
|
|
||||||
|
EXITCODE=$((EXITCODE+1))
|
||||||
|
test $EXITCODE -gt 125 && EXITCODE=125
|
||||||
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
||||||
|
return $EXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
# only for testing
|
||||||
|
set_updates_available () {
|
||||||
|
local params=("U0099" # event
|
||||||
|
$PERCENT # percent
|
||||||
|
0 # resultcode
|
||||||
|
"set_updates_available" # step
|
||||||
|
"" # step_result
|
||||||
|
"") # version
|
||||||
|
news_to_ismas ${params[*]}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
set_update_active () {
|
||||||
|
reset_update_trigger
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
news_to_ismas () {
|
||||||
|
# $1: EVENT: U0001 update finished: 100%
|
||||||
|
# U0002 reset TRG
|
||||||
|
# U0003 error
|
||||||
|
# U0010 for update process
|
||||||
|
# $2: PERCENT : "only for ISMAS: 0-100%",
|
||||||
|
# $3: RESULTCODE : "only for ISMAS",
|
||||||
|
# 0: Success
|
||||||
|
# 1: no Update nessesary
|
||||||
|
# 2: Backup failed
|
||||||
|
# 3: Package error/ Wrong package
|
||||||
|
# 4: Install Error
|
||||||
|
# $4: STEP : "running step (only for us): update_psa...",
|
||||||
|
# $5: STEP_RESULT : "error and result text",
|
||||||
|
# $6: VERSION : "opkg and conf info; what will be updated"
|
||||||
|
#
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
local p=("$@")
|
||||||
|
local data="#M=APISM#C=CMD_EVENT#J=
|
||||||
|
{
|
||||||
|
\"REASON\":\"SW_UP\",
|
||||||
|
\"TIMESTAMP\":\"$(date +%Y-%m-%dT%T.000%z)\",
|
||||||
|
\"EVENT_ID\":\"0\",
|
||||||
|
\"EVENT\":\"${p[0]}\",
|
||||||
|
\"EVENTSTATE\":1,
|
||||||
|
\"PARAMETER\": {
|
||||||
|
\"PERCENT\" : ${p[1]},
|
||||||
|
\"RESULTCODE\" : ${p[2]},
|
||||||
|
\"STEP\" : \"update_psa_${p[3]}\",
|
||||||
|
\"STEP_RESULT\" : \"${p[4]}\",
|
||||||
|
\"VERSION\" : \"$VERSION\"
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
log_debug "$func:${LINENO}: data=$data"
|
||||||
|
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# send current psa setting to ismas at end of update procedure
|
||||||
|
#
|
||||||
|
current_settings_to_ismas () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
local p=("$@")
|
||||||
|
|
||||||
|
local data="#M=APISM#C=CMD_SENDVERSION#J=
|
||||||
|
{
|
||||||
|
\"VERSION_INFO\" : {
|
||||||
|
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
|
||||||
|
\"HASH\":\"$(compute_hash)\"
|
||||||
|
},
|
||||||
|
\"TARIFF\": {
|
||||||
|
$(<$TC_PSA_TC_FILE)
|
||||||
|
},
|
||||||
|
\"HARDWARE\" : {
|
||||||
|
\"DEVICES\" : [
|
||||||
|
\"PTU5\", \"DC\", \"PRINTER\", \"BNA\"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
\"OS\" : {
|
||||||
|
\"$(uname)\": \"$(uname -a)\"
|
||||||
|
},
|
||||||
|
\"CONFIG\" : {
|
||||||
|
\"PTU5\" : {
|
||||||
|
\"CPU_SERIAL\" : \"$(cat /proc/cpuinfo |
|
||||||
|
grep Serial |
|
||||||
|
sed -E -e 's/.*:\s*(.*)/\1/g')\"
|
||||||
|
},
|
||||||
|
\"DC\" : {
|
||||||
|
\"VERSION\" : \"$(compute_hash ${DC_PSA_DC_FILE})\",
|
||||||
|
\"MD5SUM\" : \"\"
|
||||||
|
},
|
||||||
|
\"PRINTER\" : {
|
||||||
|
},
|
||||||
|
\"BNA\" : {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
\"SOFTWARE\": {
|
||||||
|
\"RAUC\" : \"$(rauc --version)\",
|
||||||
|
\"OPKG\" : \"$(opkg --version)\",
|
||||||
|
\"ATBQT\" : {
|
||||||
|
\"VERSION\" : \"$($ATBQT_ATB_SYS_BIN_FILE -v |
|
||||||
|
grep Version |
|
||||||
|
sed -E -e 's/.*:\s*(.*)/\1/g')\",
|
||||||
|
\"GIT_DESCRIBE\" : \"$($ATBQT_ATB_SYS_BIN_FILE -v |
|
||||||
|
grep git |
|
||||||
|
sed -E -e 's/.*:\s*(.*)/\1/g')\"
|
||||||
|
},
|
||||||
|
\"PLUGINS\" : {
|
||||||
|
$(get_plugins)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
|
||||||
|
log_debug "$func:${LINENO}: data=$data EXITCODE=$EXITCODE"
|
||||||
|
|
||||||
|
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
|
||||||
|
|
||||||
|
# if [ $EXITCODE -eq $RC_SUCCESS ]; then
|
||||||
|
update_psa_update_succeeded $UPDATE_SUCCEEDED \
|
||||||
|
$RC_SUCCESS "psa update succeeded" $VERSION
|
||||||
|
|
||||||
|
update_psa_update_succeeded $UPDATE_ACTIVATED \
|
||||||
|
$RC_SUCCESS "psa update activated" $VERSION
|
||||||
|
|
||||||
|
log_info "$func:${LINENO}: success"
|
||||||
|
# fi
|
||||||
|
}
|
||||||
|
fi
|
561
read_config
561
read_config
@@ -1,247 +1,396 @@
|
|||||||
#!/bin/bash
|
#! /bin/bash -
|
||||||
# set -x
|
# set -x
|
||||||
|
|
||||||
source ./log_helpers
|
source ./log_helpers
|
||||||
|
source ./general_utils
|
||||||
|
|
||||||
if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
||||||
readonly read_config_sourced=${BASH_SOURCE[0]}
|
readonly read_config_sourced=${BASH_SOURCE[0]}
|
||||||
|
|
||||||
|
readonly MAJOR="0"
|
||||||
|
readonly MINOR="1"
|
||||||
|
readonly PATCH="0"
|
||||||
|
|
||||||
|
readonly DATEFLAGS="+%Y.%m.%dT%H.%M.%S"
|
||||||
|
readonly STRIPCOMMENTS='sed -e s/#.*$//g'
|
||||||
|
readonly STRIPWHITESPACE='sed -E -e s/^[[:space:]]*$//g'
|
||||||
|
readonly INDENT="awk '{ print \"\t\t\t\" \$0 }'"
|
||||||
|
readonly JOINLINES="tr '\n' '\040'"
|
||||||
|
|
||||||
|
readonly UPDATEPSAHOME=$HOME/.updatepsa
|
||||||
|
|
||||||
|
readonly UPDATEPSABEGIN=./.updatepsa/begin
|
||||||
|
readonly UPDATEPSAEND=./.updatepsa/end
|
||||||
|
|
||||||
|
readonly OPKG_CMDS_TMP=/tmp/opkg_commands
|
||||||
|
readonly GIT_PULL_TMP=/tmp/git_pull
|
||||||
|
|
||||||
|
readonly PROGRAM=`basename $0`
|
||||||
|
readonly WORKSPACE_DIR=workspace
|
||||||
|
|
||||||
|
GIT_CLONE_EXECUTED=0
|
||||||
|
|
||||||
|
EXITCODE=$RC_SUCCESS
|
||||||
|
CLONE_CUSTOMER_REPOSITORY=false
|
||||||
|
|
||||||
# read config file (JSON syntax)
|
# read config file (JSON syntax)
|
||||||
#
|
|
||||||
read_config() {
|
read_config() {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
readonly GIT_SSL_NO_VERIFY="$(cat "$1" | jq -r .GIT_SSL_NO_VERIFY)"
|
WORKING_DIRECTORY=${PWD}
|
||||||
if [ -z "$GIT_SSL_NO_VERIFY" ]; then
|
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
|
||||||
log_fatal "$func:${LINENO} GIT_SSL_NO_VERIFY not set in $1"
|
|
||||||
fi
|
|
||||||
log_debug "$func:${LINENO}: GIT_SSL_NO_VERIFY=$GIT_SSL_NO_VERIFY"
|
|
||||||
|
|
||||||
readonly working_directory="$(cat "$1" | jq -r .working_directory)"
|
|
||||||
if [ -z "$working_directory" ]; then
|
|
||||||
log_fatal "$func:${LINENO}: working_directory not set in $1"
|
|
||||||
fi
|
|
||||||
log_debug "$func:${LINENO}: working_directory=$working_directory"
|
|
||||||
|
|
||||||
readonly workspace_dir="$(cat "$1" | jq -r .workspace_dir)"
|
|
||||||
if [ -z "$workspace_dir" ]; then
|
|
||||||
log_fatal "$func:${LINENO}: workspace_dir not set in $1"
|
|
||||||
fi
|
|
||||||
log_debug "$func:${LINENO}: workspace_dir=$workspace_dir"
|
|
||||||
|
|
||||||
readonly customer_location=$(cat "$1" | jq -r .customer_location)
|
|
||||||
if [ -z "$customer_location" ]; then
|
|
||||||
log_fatal "$func:${LINENO}: customer_location not set in $1"
|
|
||||||
fi
|
|
||||||
log_debug "$func:${LINENO}: customer-location=$customer_location"
|
|
||||||
|
|
||||||
readonly customer_id="customer_$(cat "$1" | jq -r .customer_id)"
|
if ! [ -f "$CONFIGFILENAME" ]; then
|
||||||
if [ -z "$customer_id" ]; then
|
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
|
||||||
log_fatal "$func:${LINENO} customer_id not set in $1"
|
|
||||||
fi
|
fi
|
||||||
log_debug "$func:${LINENO}: customer-id=$customer_id"
|
|
||||||
|
log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME"
|
||||||
|
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
|
||||||
|
|
||||||
local __r_path="$(cat "$1" | jq -r .cust_repository_path)"
|
local readonly cf="$CONFIGFILENAME"
|
||||||
if [ -z "$__r_path" ]; then
|
|
||||||
log_fatal "$func:${LINENO}: customer repository path not set in $1"
|
### 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
|
fi
|
||||||
readonly customer_repository_path="${__r_path}/${customer_id}.git"
|
|
||||||
log_debug "$func:${LINENO}: customer r-path=$customer_repository_path"
|
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
|
||||||
|
assert_s GIT_SSL_NO_VERIFY
|
||||||
|
|
||||||
readonly number_of_zone_groups="$(cat "$1" | jq -r .zone_group[0])"
|
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
|
||||||
log_debug "$func:${LINENO}: $number_of_zone_groups zone_group(s)"
|
assert_s CUSTOMER_LOCATION
|
||||||
|
|
||||||
local __zone_groups=(0)
|
readonly CUSTOMER_ID="$(cat "$cf" | jq -r .customer_id)"
|
||||||
for zg in `seq 1 $number_of_zone_groups`; do
|
assert_s CUSTOMER_ID
|
||||||
local __n_zones="$(cat "$1" | jq -r .zone_group[$zg].zone[0])"
|
|
||||||
|
readonly CUSTOMER_REPOSITORY_PATH="$(cat "$cf" |
|
||||||
|
jq -r .cust_repository_path)"
|
||||||
|
assert_s CUSTOMER_REPOSITORY_PATH
|
||||||
|
|
||||||
|
local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
|
||||||
|
readonly CUSTOMER_ID_BASE_DIR="${__customer_id_base_dir}/${CUSTOMER_ID}"
|
||||||
|
|
||||||
|
local __number_of_zone_groups=$(cat "$cf" |
|
||||||
|
jq -r .zg[0] |
|
||||||
|
sed -E -e 's/[[:space:]]*//g')
|
||||||
|
# TODO: was ist hier falsch
|
||||||
|
# __n_of_zgroups=$(echo "$__n_of_zgrps" | ${STRIPWHITESPACE} )
|
||||||
|
# log_debug "$func:${LINENO}: #n of zone_groups: $__number_of_zone_groups"
|
||||||
|
|
||||||
|
local __zone_groups=($__number_of_zone_groups)
|
||||||
|
for zg in `seq 1 $__number_of_zone_groups`; do
|
||||||
|
local __n_zones=$(cat "$cf" |
|
||||||
|
jq -r .zg[$zg].z |
|
||||||
|
sed -E -e 's/[][,[:space:]]*//g') # rm ][ as well
|
||||||
__zone_groups[$zg]=$__n_zones
|
__zone_groups[$zg]=$__n_zones
|
||||||
done
|
done
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: reading ${1} done"
|
readonly ZONE_GROUPS=(${__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
|
||||||
|
readonly ZONE=1
|
||||||
|
|
||||||
|
readonly LOCAL_BRANCH="$(cat "$cf" | jq -r .local_branches[$ZONE])"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
###############################################################################
|
###############################################################################
|
||||||
########################## parsing with jq finished ###########################
|
########################## parsing with jq finished ###########################
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
compute_hash () {
|
||||||
|
if cd_customer_repository; then
|
||||||
|
local hash=""
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
hash=$(git log -n 1 --pretty=format:%H)
|
||||||
|
else
|
||||||
|
hash=$(git hash-object "$1")
|
||||||
|
fi
|
||||||
|
cd_home ; echo ${hash:0:10} # return the first 10 hex characters
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
compute_version () {
|
||||||
|
VERSION="$MAJOR.$MINOR.$PATCH+$CUSTOMER_LOCATION-$(compute_hash)"
|
||||||
|
cd_home; return 0
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
check_sanity_of_repository () {
|
check_sanity_of_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
local __customer_base_dir="$working_directory/${workspace_dir}"
|
|
||||||
__customer_base_dir="${__customer_base_dir}/${customer_id}"
|
|
||||||
|
|
||||||
readonly customer_id_base_dir=${__customer_base_dir}
|
|
||||||
log_debug "$func:${LINENO}: customer_id_base_dir="
|
|
||||||
log_debug "$func:${LINENO}: $customer_id_base_dir"
|
|
||||||
|
|
||||||
__customer_base_dir="${__customer_base_dir}/${customer_location}"
|
|
||||||
|
|
||||||
readonly customer_location_dir="$__customer_base_dir"
|
|
||||||
log_debug "$func:${LINENO}: customer_location_dir="
|
|
||||||
log_debug "$func:${LINENO}: $customer_location_dir"
|
|
||||||
|
|
||||||
readonly update_conf="${customer_location_dir}/update.conf"
|
|
||||||
log_debug "$func:${LINENO}: update.conf="
|
|
||||||
log_debug "$func:${LINENO}: $update_conf"
|
|
||||||
|
|
||||||
readonly current_conf="${customer_location_dir}/current.conf"
|
assert_d CUSTOMER_ID_BASE_DIR
|
||||||
log_debug "$func:${LINENO}: current.conf="
|
|
||||||
log_debug "$func:${LINENO}: $current_conf"
|
CUSTOMER_LOCATION_DIR="$CUSTOMER_ID_BASE_DIR"
|
||||||
|
#CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}"
|
||||||
|
#CUST_LOC_DIR=$CUSTOMER_LOCATION_DIR
|
||||||
|
assert_d CUSTOMER_LOCATION_DIR
|
||||||
|
|
||||||
# readonly zone_groups=(${__zone_groups[@]})
|
# readonly zone_groups=(${__zone_groups[@]})
|
||||||
# for (( j=0; j<${#zone_groups[@]}; ++j)); do
|
# by now (03.03.2023) there is only one zone group.
|
||||||
# log_debug "$func:${LINENO}: zgroup[$j]: ${zone_groups[$j]} zones"
|
#readonly local __zgroup=1
|
||||||
# done
|
#local __number_of_zone_groups=${ZONE_GROUPS[0]}
|
||||||
|
#local __zindex=1
|
||||||
|
#local __customer_base_dirs=("placeholder")
|
||||||
|
#for __zg in `seq 1 $__number_of_zone_groups`; do
|
||||||
|
# local __n_of_zones=${ZONE_GROUPS[$__zindex]}
|
||||||
|
# log_debug "$func:${LINENO}: zgroup $__zg has $__n_of_zones zones"
|
||||||
|
# for (( j=1; j<=$__n_of_zones; ++j)); do
|
||||||
|
# __customer_base_dirs+=("${CUSTOMER_LOCATION_DIR}/$__zgroup/$j")
|
||||||
|
# log_debug "$func:${LINENO}: zone $j"
|
||||||
|
# ((++__zindex))
|
||||||
|
# done
|
||||||
|
#done
|
||||||
|
|
||||||
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
|
# for szeged:
|
||||||
readonly zgroup=1
|
# placeholder
|
||||||
readonly zone=1
|
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/1
|
||||||
readonly customer_base_dir="${__customer_base_dir}/${zgroup}/${zone}"
|
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/2
|
||||||
if [ -d "$customer_base_dir" ]; then
|
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/3
|
||||||
log_debug "$func:${LINENO}: customer-base-dir="
|
# readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
|
||||||
log_debug "$func:${LINENO}: $customer_base_dir"
|
# assert_a CUST_BASE_DIRS
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $customer_base_dir does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly psa_config_dir="${customer_base_dir}/etc/psa_config"
|
|
||||||
if [ -d "$psa_config_dir" ]; then
|
|
||||||
log_debug "$func:${LINENO}: psa_config_dir="
|
|
||||||
log_debug "$func:${LINENO}: $psa_config_dir"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $psa_config_dir does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly psa_update_dir="${customer_base_dir}/etc/psa_update"
|
|
||||||
if [ -d "$psa_update_dir" ]; then
|
|
||||||
log_debug "$func:${LINENO}: psa_update_dir="
|
|
||||||
log_debug "$func:${LINENO}: $psa_update_dir"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $psa_update_dir does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly psa_base_ini_dir="${customer_base_dir}/opt/app"
|
|
||||||
if [ -d "$psa_base_ini_dir" ]; then
|
|
||||||
log_debug "$func:${LINENO}: psa_base_ini_dir="
|
|
||||||
log_debug "$func:${LINENO}: $psa_base_ini_dir"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $psa_base_ini_dir does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly psa_sysconfig_dir="${psa_base_ini_dir}/sysconfig"
|
|
||||||
# if [ -d "$psa_syconfig_dir" ]; DOES NOT WORK !!!
|
|
||||||
if ls -al $psa_sysconfig_dir > /dev/null; then
|
|
||||||
log_debug "$func:${LINENO}: psa_sysconfig_dir="
|
|
||||||
log_debug "$func:${LINENO}: $psa_sysconfig_dir"
|
|
||||||
else
|
|
||||||
log_error "$func:${LINENO}: $psa_sysconfig_dir does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly psa_ismasmgr_dir="${psa_base_ini_dir}/ISMASMgr"
|
readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
|
||||||
if [ -d "$psa_ismasmgr_dir" ]; then
|
#readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
|
||||||
log_debug "$func:${LINENO}: psa_ismasmgr_dir="
|
#assert_d CUST_BASE_DIR
|
||||||
log_debug "$func:${LINENO}: $psa_ismasmgr_dir"
|
|
||||||
else
|
readonly ETC_SYS_DIR="/etc"
|
||||||
log_fatal "$func:${LINENO}: $psa_ismasmgr_dir does not exist"
|
readonly ATB_SYS_DIR="/etc/atb"
|
||||||
fi
|
readonly DC_SYS_DIR="/etc/dc"
|
||||||
|
readonly TARIFF_SYS_DIR="/etc/psa_tariff"
|
||||||
|
readonly OPKG_SYS_DIR="/etc/psa_update"
|
||||||
|
readonly CONF_SYS_DIR="/etc/psa_config"
|
||||||
|
readonly OPT_SYS_DIR="/opt"
|
||||||
|
readonly APP_SYS_DIR="/opt/app"
|
||||||
|
readonly SYSCONFIG_SYS_DIR="/opt/app/sysconfig"
|
||||||
|
readonly ATBAPP_SYS_DIR="/opt/app/ATBAPP"
|
||||||
|
readonly ISMASMGR_SYS_DIR="/opt/app/ISMASMgr"
|
||||||
|
|
||||||
readonly psa_atbqt_dir="${psa_base_ini_dir}/ATBAPP"
|
readonly ETC_PSA_DIR=${CUST_BASE_DIR}${ETC_SYS_DIR}
|
||||||
if [ -d "$psa_atbqt_dir" ]; then
|
readonly ATB_PSA_DIR=${CUST_BASE_DIR}${ATB_SYS_DIR}
|
||||||
log_debug "$func:${LINENO}: psa_atbqt_dir="
|
readonly DC_PSA_DIR=${CUST_BASE_DIR}${DC_SYS_DIR}
|
||||||
log_debug "$func:${LINENO}: $psa_atbqt_dir"
|
readonly TARIFF_PSA_DIR=${CUST_BASE_DIR}${TARIFF_SYS_DIR}
|
||||||
else
|
readonly OPKG_PSA_DIR=${CUST_BASE_DIR}${OPKG_SYS_DIR}
|
||||||
log_fatal "$func:${LINENO}: $psa_atbqt_dir does not exist"
|
readonly CONF_PSA_DIR=${CUST_BASE_DIR}${CONF_SYS_DIR}
|
||||||
fi
|
readonly OPT_PSA_DIR=${CUST_BASE_DIR}${OPT_SYS_DIR}
|
||||||
|
readonly APP_PSA_DIR=${CUST_BASE_DIR}${APP_SYS_DIR}
|
||||||
readonly atbqt_ini="${psa_atbqt_dir}/ATBQT.ini"
|
readonly ATBAPP_PSA_DIR=${CUST_BASE_DIR}${ATBAPP_SYS_DIR}
|
||||||
if [ -f "$atbqt_ini" ]; then
|
readonly SYSCONFIG_PSA_DIR=${CUST_BASE_DIR}${SYSCONFIG_SYS_DIR}
|
||||||
log_debug "$func:${LINENO}: ATBTQT.ini="
|
readonly ISMASMGR_PSA_DIR=${CUST_BASE_DIR}${ISMASMGR_SYS_DIR}
|
||||||
log_debug "$func:${LINENO}: $atbqt_ini"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $atbqt_ini does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly ismasmgr_ismasmgr_ini="${psa_ismasmgr_dir}/ISMASMgr.ini"
|
|
||||||
if [ -f "$ismasmgr_ismasmgr_ini" ]; then
|
|
||||||
log_debug "$func:${LINENO}: ismasmgr_ismasmgr.ini="
|
|
||||||
log_debug "$func:${LINENO}: $ismasmgr_ismasmgr_ini"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $ismasmgr_ismasmgr_ini does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly sysconfig_ismasmgr_ini="${psa_sysconfig_dir}/ISMASMgr.ini"
|
|
||||||
if [ -f "$sysconfig_ismasmgr_ini" ]; then
|
|
||||||
log_debug "$func:${LINENO}: sysconfig_ismasmgr.ini="
|
|
||||||
log_debug "$func:${LINENO}: $sysconfig_ismasmgr_ini"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $sysconfig_ismasmgr_ini does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly sysconfig_sysconfig_ini="${psa_sysconfig_dir}/sysconfig.ini"
|
|
||||||
if [ -f "$sysconfig_sysconfig_ini" ]; then
|
|
||||||
log_debug "$func:${LINENO}: sysconfig_sysconfig.ini="
|
|
||||||
log_debug "$func:${LINENO}: $sysconfig_sysconfig_ini"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $sysconfig_sysconfig_ini does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly sysconfig_sysctrl_ini="${psa_sysconfig_dir}/SystemControl.ini"
|
|
||||||
if [ -f "$sysconfig_sysctrl_ini" ]; then
|
|
||||||
log_debug "$func:${LINENO}: sysconfig_systemcontrol.ini="
|
|
||||||
log_debug "$func:${LINENO}: $sysconfig_sysctrl_ini"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $sysconfig_sysctrl_ini does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly emp_conf="${psa_config_dir}/emp.conf"
|
|
||||||
if [ -f "$emp_conf" ]; then
|
|
||||||
log_debug "$func:${LINENO}: emp.conf="
|
|
||||||
log_debug "$func:${LINENO}: $emp_conf"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $emp_conf does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly device_conf="${psa_config_dir}/device.conf"
|
|
||||||
if [ -f "$device_conf" ]; then
|
|
||||||
log_debug "$func:${LINENO}: device.conf="
|
|
||||||
log_debug "$func:${LINENO}: $device_conf"
|
|
||||||
else
|
|
||||||
log_debug "$func:${LINENO}: $device_conf does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly printer_conf="${psa_config_dir}/printer.conf"
|
readonly ATBQT_BIN="ATBQT"
|
||||||
if [ -f "$printer_conf" ]; then
|
readonly ATBQT_INI="ATBQT.ini"
|
||||||
log_debug "$func:${LINENO}: printer.conf="
|
readonly ISMASMGR_INI="ISMASMgr.ini"
|
||||||
log_debug "$func:${LINENO}: $printer_conf"
|
readonly SYSCONF_INI="sysconfig.ini"
|
||||||
else
|
readonly SYSCTRL_INI="SystemControl.ini"
|
||||||
log_fatal "$func:${LINENO}: $printer_conf does not exist"
|
readonly TARIFF_CURRENT="tariff.current"
|
||||||
fi
|
readonly DC="dc2c.hex"
|
||||||
|
readonly TARIFF_SUMMER="summer_tariff.json"
|
||||||
readonly opkg_cmds_file="${psa_update_dir}/opkg_commands"
|
readonly TARIFF_WINTER="winter_tariff.json"
|
||||||
if [ -f "$opkg_cmds_file" ]; then
|
|
||||||
log_debug "$func:${LINENO}: opkg_commands="
|
|
||||||
log_debug "$func:${LINENO}: $opkg_cmds_file"
|
|
||||||
else
|
|
||||||
log_fatal "$func:${LINENO}: $opkg_cmds_file does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly known_files=(${customer_location}/update.conf \
|
readonly DC_SYS_DC_FILE="${DC_SYS_DIR}/$DC"
|
||||||
${customer_location}/current.conf \
|
readonly ATBQT_ATB_SYS_BIN_FILE="${ATBAPP_SYS_DIR}/$ATBQT_BIN"
|
||||||
${device_conf##*${customer_id}/} \
|
readonly ATBQT_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ATBQT_INI"
|
||||||
${emp_conf##*${customer_id}/} \
|
readonly ATBQT_APP_SYS_INI_FILE="${ATBAPP_SYS_DIR}/$ATBQT_INI"
|
||||||
${printer_conf##*${customer_id}/} \
|
readonly ATBQT_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ATBQT_INI"
|
||||||
${opkg_cmds_file##*${customer_id}/} \
|
readonly ISMASMGRATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ISMASMGR_INI"
|
||||||
${atbqt_ini##*${customer_id}/} \
|
readonly ISMASMGRAPP_SYS_INI_FILE="${ISMASMGR_SYS_DIR}/$ISMASMGR_INI"
|
||||||
${ismasmgr_ismasmgr_ini##*${customer_id}/} \
|
readonly ISMASMGRETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ISMASMGR_INI"
|
||||||
${sysconfig_ismasmgr_ini##*${customer_id}/} \
|
readonly ISMASMGRSCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$ISMASMGR_INI"
|
||||||
${sysconfig_sysconfig_ini##*${customer_id}/} \
|
readonly SYSCONF_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCONF_INI"
|
||||||
${sysconfig_sysctrl_ini##*${customer_id}/})
|
readonly SYSCONF_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCONF_INI"
|
||||||
|
readonly SYSCONF_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCONF_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_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI"
|
||||||
|
readonly ZONE_FILE="$ETC_SYS_DIR/zone_nr"
|
||||||
|
readonly CUST_ID_FILE="$ETC_SYS_DIR/cust_nr"
|
||||||
|
readonly TC_SYS_TC_FILE="${ATBAPP_SYS_DIR}/$TARIFF_CURRENT"
|
||||||
|
readonly OPKG_CMDS_SYS_FILE="${OPKG_SYS_DIR}/opkg_commands"
|
||||||
|
readonly DC2C_SYS_SERIAL_JSON="${CONF_SYS_DIR}/DC2C_serial.json"
|
||||||
|
readonly DC2C_SYS_CASH_JSON="${CONF_SYS_DIR}/DC2C_cash.json"
|
||||||
|
readonly DC2C_SYS_CONF_JSON="${CONF_SYS_DIR}/DC2C_conf.json"
|
||||||
|
readonly DC_PSA_DC_FILE="${DC_PSA_DIR}/$DC"
|
||||||
|
readonly TARIFF_SYS_SUMMER="${TARIFF_SYS_DIR}${TARIFF_SUMMER}"
|
||||||
|
readonly TARIFF_SYS_WINTER="${TARIFF_SYS_DIR}${TARIFF_WINTER}"
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: conf/ini_files=$(echo ${known_files[@]})"
|
readonly ATBQT_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$ATBQT_INI"
|
||||||
log_debug "$func:${LINENO}: sanity of ${customer_repository_path} OK"
|
readonly ATBQT_APP_PSA_INI_FILE="${ATBAPP_PSA_DIR}/$ATBQT_INI"
|
||||||
|
readonly ATBQT_ETC_PSA_INI_FILE="${ETC_PSA_DIR}/$ATBQT_INI"
|
||||||
|
readonly ISMASMGRATB_PSA_INI_FILE="${ATB_PSA_DIR}/$ISMASMGR_INI"
|
||||||
|
readonly ISMASMGRAPP_PSA_INI_FILE="${ISMASMGR_PSA_DIR}/$ISMASMGR_INI"
|
||||||
|
readonly ISMASMGRETC_PSA_INI_FILE="${ETC_PSA_DIR}/$ISMASMGR_INI"
|
||||||
|
readonly ISMASMGRSCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$ISMASMGR_INI"
|
||||||
|
readonly SYSCONF_ETC_PSA_INI_FILE="${ETC_PSA_DIR}/$SYSCONF_INI"
|
||||||
|
readonly SYSCONF_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$SYSCONF_INI"
|
||||||
|
readonly SYSCONF_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCONF_INI"
|
||||||
|
readonly SYSCTRL_ETC_PSA_INI_FILE="${ETC_PSA_DIR}/$SYSCTRL_INI"
|
||||||
|
readonly SYSCTRL_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$SYSCTRL_INI"
|
||||||
|
readonly SYSCTRL_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCTRL_INI"
|
||||||
|
readonly OPKG_CMDS_PSA_FILE="${OPKG_PSA_DIR}/opkg_commands"
|
||||||
|
readonly TC_PSA_TC_FILE="${ATBAPP_PSA_DIR}/$TARIFF_CURRENT"
|
||||||
|
# readonly PSA_UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
|
||||||
|
readonly DC2C_PSA_SERIAL_JSON="${CONF_PSA_DIR}/DC2C_serial.json"
|
||||||
|
readonly DC2C_PSA_CASH_JSON="${CONF_PSA_DIR}/DC2C_cash.json"
|
||||||
|
readonly DC2C_PSA_CONF_JSON="${CONF_PSA_DIR}/DC2C_conf.json"
|
||||||
|
|
||||||
|
assert_d ETC_SYS_DIR
|
||||||
|
assert_d ATB_SYS_DIR
|
||||||
|
assert_d DC_SYS_DIR
|
||||||
|
assert_d TARIFF_SYS_DIR
|
||||||
|
assert_d OPKG_SYS_DIR
|
||||||
|
assert_d CONF_SYS_DIR
|
||||||
|
assert_d OPT_SYS_DIR
|
||||||
|
assert_d APP_SYS_DIR
|
||||||
|
assert_d ATBAPP_SYS_DIR
|
||||||
|
assert_d SYSCONFIG_SYS_DIR
|
||||||
|
assert_d ISMASMGR_SYS_DIR
|
||||||
|
|
||||||
|
assert_d ETC_PSA_DIR
|
||||||
|
assert_d ATB_PSA_DIR
|
||||||
|
assert_d DC_PSA_DIR
|
||||||
|
assert_d TARIFF_PSA_DIR
|
||||||
|
assert_d OPKG_PSA_DIR
|
||||||
|
assert_d CONF_PSA_DIR
|
||||||
|
assert_d OPT_PSA_DIR
|
||||||
|
assert_d APP_PSA_DIR
|
||||||
|
assert_d ATBAPP_PSA_DIR
|
||||||
|
assert_d SYSCONFIG_PSA_DIR
|
||||||
|
assert_d ISMASMGR_PSA_DIR
|
||||||
|
|
||||||
|
assert_f DC_SYS_DC_FILE
|
||||||
|
assert_f ZONE_FILE
|
||||||
|
assert_f CUST_ID_FILE
|
||||||
|
assert_f ATBQT_ATB_SYS_BIN_FILE
|
||||||
|
assert_f ATBQT_ATB_SYS_INI_FILE
|
||||||
|
assert_f ATBQT_APP_SYS_INI_FILE
|
||||||
|
assert_f ATBQT_ETC_SYS_INI_FILE
|
||||||
|
assert_f ISMASMGRATB_SYS_INI_FILE
|
||||||
|
assert_f ISMASMGRAPP_SYS_INI_FILE
|
||||||
|
assert_f ISMASMGRETC_SYS_INI_FILE
|
||||||
|
assert_f ISMASMGRSCF_SYS_INI_FILE
|
||||||
|
assert_f SYSCONF_ETC_SYS_INI_FILE
|
||||||
|
assert_f SYSCONF_ATB_SYS_INI_FILE
|
||||||
|
assert_f SYSCONF_SCF_SYS_INI_FILE
|
||||||
|
assert_f SYSCTRL_ETC_SYS_INI_FILE
|
||||||
|
assert_f SYSCTRL_ATB_SYS_INI_FILE
|
||||||
|
assert_f SYSCTRL_SCF_SYS_INI_FILE
|
||||||
|
assert_f TC_SYS_TC_FILE
|
||||||
|
assert_f OPKG_CMDS_SYS_FILE
|
||||||
|
assert_f DC2C_SYS_CONF_JSON
|
||||||
|
assert_f DC2C_SYS_SERIAL_JSON
|
||||||
|
assert_f DC2C_SYS_CASH_JSON
|
||||||
|
|
||||||
|
assert_f DC_PSA_DC_FILE
|
||||||
|
assert_f ATBQT_ATB_PSA_INI_FILE
|
||||||
|
assert_f ATBQT_APP_PSA_INI_FILE
|
||||||
|
assert_f ATBQT_ETC_PSA_INI_FILE
|
||||||
|
assert_f ISMASMGRATB_PSA_INI_FILE
|
||||||
|
assert_f ISMASMGRAPP_PSA_INI_FILE
|
||||||
|
assert_f ISMASMGRETC_PSA_INI_FILE
|
||||||
|
assert_f ISMASMGRSCF_PSA_INI_FILE
|
||||||
|
assert_f SYSCONF_ETC_PSA_INI_FILE
|
||||||
|
assert_f SYSCONF_ATB_PSA_INI_FILE
|
||||||
|
assert_f SYSCONF_SCF_PSA_INI_FILE
|
||||||
|
assert_f SYSCTRL_ETC_PSA_INI_FILE
|
||||||
|
assert_f SYSCTRL_ATB_PSA_INI_FILE
|
||||||
|
assert_f SYSCTRL_SCF_PSA_INI_FILE
|
||||||
|
assert_f TC_PSA_TC_FILE
|
||||||
|
# assert_f PSA_UPDATE_CONF
|
||||||
|
assert_f OPKG_CMDS_PSA_FILE
|
||||||
|
assert_f DC2C_PSA_CONF_JSON
|
||||||
|
assert_f DC2C_PSA_SERIAL_JSON
|
||||||
|
assert_f DC2C_PSA_CASH_JSON
|
||||||
|
assert_f OPKG_CMDS_PSA_FILE
|
||||||
|
|
||||||
|
readonly KNOWN_SYS_DIRS=($ETC_SYS_DIR
|
||||||
|
$ATB_SYS_DIR
|
||||||
|
$DC_SYS_DIR
|
||||||
|
$TARIFF_SYS_DIR
|
||||||
|
$OPKG_SYS_DIR
|
||||||
|
$CONF_SYS_DIR
|
||||||
|
$OPT_SYS_DIR
|
||||||
|
$APP_SYS_DIR
|
||||||
|
$ATBAPP_SYS_DIR
|
||||||
|
$SYSCONFIG_SYS_DIR)
|
||||||
|
|
||||||
|
readonly KNOWN_PSA_DIRS=($ETC_PSA_DIR
|
||||||
|
$ATB_PSA_DIR
|
||||||
|
$DC_PSA_DIR
|
||||||
|
$TARIFF_PSA_DIR
|
||||||
|
$OPKG_PSA_DIR
|
||||||
|
$CONF_PSA_DIR
|
||||||
|
$OPT_PSA_DIR
|
||||||
|
$APP_PSA_DIR
|
||||||
|
$ATBAPP_PSA_DIR
|
||||||
|
$SYSCONFIG_PSA_DIR)
|
||||||
|
|
||||||
|
local DC2C_PRINT_JSON=()
|
||||||
|
for i in {1..32}; do # up to 32 print-json-files
|
||||||
|
local __f=${CONF_PSA_DIR}/DC2C_print$(printf "%02d" $i).json
|
||||||
|
readonly DC2C_PRINT$(printf "%02d" $i)_JSON=$__f
|
||||||
|
assert_f DC2C_PRINT$(printf "%02d" $i)_JSON
|
||||||
|
DC2C_PRINT_JSON+=($__f)
|
||||||
|
done
|
||||||
|
|
||||||
|
local TARIFF_FILES_JSON=()
|
||||||
|
for i in {1..32}; do # up to 32 tariff-json-files
|
||||||
|
local __f=${TARIFF_PSA_DIR}/tariff$(printf "%02d" $i).json
|
||||||
|
readonly TARIFF$(printf "%02d" $i)_JSON=$__f
|
||||||
|
assert_f TARIFF$(printf "%02d" $i)_JSON
|
||||||
|
TARIFF_FILES_JSON+=($__f)
|
||||||
|
done
|
||||||
|
|
||||||
|
readonly KNOWN_CONF_FILES=(${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \
|
||||||
|
${DC2C_PSA_CONF_JSON##*${CUSTOMER_ID}/} \
|
||||||
|
${DC2C_PSA_CASH_JSON##*${CUSTOMER_ID}/} \
|
||||||
|
${DC2C_PSA_SERIAL_JSON##*${CUSTOMER_ID}/})
|
||||||
|
|
||||||
|
readonly KNOWN_TARIFF_FILES=(${TARIFF_FILES_JSON[@]##*${CUSTOMER_ID}/})
|
||||||
|
|
||||||
|
readonly KNOWN_INI_FILES=(${ATBAPP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${ISMASMGRATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${ISMASMGRAPP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${ISMASMGRETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${ISMASMGRSCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${SYSCONF_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${SYSCONF_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${SYSCONF_SCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${SYSCTRL_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${SYSCTRL_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${SYSCTRL_SCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${ATBQT_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${ATBQT_APP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${ATBQT_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/})
|
||||||
|
|
||||||
|
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
|
||||||
|
${KNOWN_INI_FILES[@]} \
|
||||||
|
${KNOWN_TARIFF_FILES[@]} \
|
||||||
|
${DC_PSA_DC_FILE##*${CUSTOMER_ID}/} \
|
||||||
|
${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/})
|
||||||
|
|
||||||
|
# log_debug "known json/ini/hex_files ->"
|
||||||
|
# for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
|
||||||
|
# tab=$'\t'
|
||||||
|
# log_debug "$tab$tab ${KNOWN_FILES[$i]}"
|
||||||
|
# done
|
||||||
|
log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
|
||||||
|
|
||||||
|
# compute version string for current (i.e. previous) version
|
||||||
|
compute_version
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
# read_config UpdateController.conf
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
228
update_psa
228
update_psa
@@ -1,181 +1,42 @@
|
|||||||
#!/bin/bash
|
#! /bin/bash -
|
||||||
# set -x
|
# Implementing update functionality for an PSA.
|
||||||
|
|
||||||
source ./general_utils
|
|
||||||
source ./log_helpers
|
|
||||||
source ./git_helpers
|
|
||||||
|
|
||||||
# source ./update_helpers.sh
|
|
||||||
# source ./opkg_helpers.sh
|
|
||||||
source ./update_psa_helpers
|
|
||||||
|
|
||||||
source ./read_config
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# update_psa
|
|
||||||
#
|
|
||||||
# Implementing the UpdateController (see below). UpdateController is waiting
|
|
||||||
# for an external trigger by the DeviceController (DC). The trigger is sent via
|
|
||||||
# an UNIX-pipe (=fifo). When DC triggers UpdateController, it has to check if
|
|
||||||
# an update is possible, i.e. is has to lock the PSA for the update procedure.
|
|
||||||
# UpdateController will send back the update-result to DeviceController
|
|
||||||
# which unlocks the PSA to return to nomal operation.
|
|
||||||
#
|
|
||||||
# If UpdateController has been triggered, it checks out a predefined git-
|
|
||||||
# repository. As a sanity check it makes sure that there are some changes in
|
|
||||||
# the repository. In case there are no changes, it issues an error message
|
|
||||||
# to DC and returns to its wait-state.
|
|
||||||
#
|
|
||||||
# Otherwise it checks if the changed files are correct (using md5) and if
|
|
||||||
# the new files are valid for the PSA. If there is some problem, it issues an
|
|
||||||
# error message to DC, reverts the git-repository to its previous state and
|
|
||||||
# returns to its wait-state.
|
|
||||||
#
|
|
||||||
# Otherwise it makes a backup of the current state of the PSA, and if there
|
|
||||||
# are opkg-packages to install it runs a dry installation process using opkg.
|
|
||||||
# In case of error, it issues an error message to DC, deletes the backup,
|
|
||||||
# reverts # the git-repository to its previous state and returns to its
|
|
||||||
# wait-state.
|
|
||||||
#
|
|
||||||
# Otherwise, it copies all new files to their target locations and in case
|
|
||||||
# of opkg-packages, it installs the packages.
|
|
||||||
#
|
|
||||||
# In case of error it restores the previous state using the backup and
|
|
||||||
# reinstalls the previous opkg-package(s). It issues an error message to
|
|
||||||
# DC and returns to its wait-state.
|
|
||||||
#
|
|
||||||
# Otherwise the update went well, and it does some cleanup, sends a success
|
|
||||||
# message to DC and returns to its wait-state.
|
|
||||||
#
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# UPDATE PROCEDURE
|
# UPDATE PSA
|
||||||
|
# Usage:
|
||||||
|
# update_psa [ --? ]
|
||||||
|
# [ --help ]
|
||||||
|
# [ --wdir "working_directory" ]
|
||||||
|
# [ --file "config_file" ]
|
||||||
|
# [ --dbg ]
|
||||||
|
# [ --version ]
|
||||||
#
|
#
|
||||||
|
# ./update_psa --file $PWD/update_psa.conf --wdir $PWD
|
||||||
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
update() {
|
# if [ $# -eq 0 ]; then
|
||||||
local try_update_count=0
|
# no parameters given -> nothing to do
|
||||||
local func="${FUNCNAME[0]}"
|
# exit 0
|
||||||
|
#fi
|
||||||
# read config parameters
|
|
||||||
# read_config
|
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: fetch/merge updates..."
|
|
||||||
|
|
||||||
# Fetch new updates (using git)
|
|
||||||
while :
|
|
||||||
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"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
try_updates_count=$((try_updates_count+1))
|
|
||||||
if [[ "$try_updates_count" -eq 5 ]]; then
|
|
||||||
log_error "$func:${LINENO}: fetch/merging failed" ; exit 1
|
|
||||||
fi
|
|
||||||
sleep 60s
|
|
||||||
else
|
|
||||||
# Fetched updates successfully
|
|
||||||
try_updates_count=0
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# TODO: backup implementieren
|
|
||||||
# Backup before any updates in case some previous test was wrong
|
|
||||||
if ! backup_previous_version; then
|
|
||||||
log_error "$func:${LINENO}: backup failed"
|
|
||||||
revert_customer_repository ; exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local changed_files=$(changed_file_names)
|
|
||||||
local conf_ini_files=$(filter_conf_ini_files "$changed_files")
|
|
||||||
|
|
||||||
# check if *.conf and/or *.ini-files have to md5-sum as denoted
|
|
||||||
# in update.conf
|
|
||||||
if ! check_md5_for_changed_conf_and_ini_files "$conf_ini_files" ; then
|
|
||||||
log_error "$func:${LINENO}: new customer files wrong"
|
|
||||||
revert_customer_repository ; exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# copy *.conf and/or *.ini-files to their corresponding system-directories
|
|
||||||
if ! copy $conf_ini_files; then
|
|
||||||
log_error "$func:${LINENO}: copy operation failed"
|
|
||||||
revert_customer_repository ; exit 1
|
|
||||||
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_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 commnds to execute"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cleanup.
|
|
||||||
if ! cleanup_previous_version; then
|
|
||||||
log_error "$func:${LINENO}: cleanup_previous_version failed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_info "$func:${LINENO}: success"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
if [ -z $IFS ]; then
|
if [ -z $IFS ]; then
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly PROGRAM=`basename $0`
|
# parse commandline parameters
|
||||||
readonly VERSION="0.8.0"
|
|
||||||
|
|
||||||
config_filename=""
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
while test $# -gt 0; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--file | --fil | --fi | --f | -file | -fil | -fi | -f )
|
--file | --fil | --fi | --f | -file | -fil | -fi | -f )
|
||||||
__conf_file=yes
|
shift
|
||||||
|
CONFIGFILENAME="$1"
|
||||||
|
;;
|
||||||
|
--zone | --zon | --zo | --z | -zone | -zon | -zo | -z )
|
||||||
|
shift
|
||||||
|
ZONE="$1"
|
||||||
|
;;
|
||||||
|
--wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w )
|
||||||
|
shift
|
||||||
|
WORKING_DIRECTORY="$1"
|
||||||
;;
|
;;
|
||||||
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
|
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
|
||||||
usage_and_exit 0
|
usage_and_exit 0
|
||||||
@@ -183,6 +44,7 @@ while test $# -gt 0; do
|
|||||||
--version | --versio | --versi | --vers | --ver | --ve | --v | \
|
--version | --versio | --versi | --vers | --ver | --ve | --v | \
|
||||||
-version | -versio | -versi | -vers | -ver | -ve | -v )
|
-version | -versio | -versi | -vers | -ver | -ve | -v )
|
||||||
version
|
version
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
--dbg | --db | --d | -dbg | -db | -d )
|
--dbg | --db | --d | -dbg | -db | -d )
|
||||||
set_dbg_level $DEBUG
|
set_dbg_level $DEBUG
|
||||||
@@ -191,26 +53,34 @@ while test $# -gt 0; do
|
|||||||
error "Unrecognized option: $1"
|
error "Unrecognized option: $1"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ "$__conf_file" = "yes" ]; then
|
|
||||||
config_filename="$1"
|
|
||||||
__conf_file=""
|
|
||||||
else
|
|
||||||
error "Unrecognized parameter string: $1"
|
|
||||||
fi
|
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! [ -z "$config_filename" ]; then
|
if cd "$WORKING_DIRECTORY"; then
|
||||||
if read_config "$config_filename" ; then
|
source ./update_psa_impl
|
||||||
# set -x
|
|
||||||
if clone_customer_repository $customer_repository_path ; then
|
if read_config
|
||||||
|
then
|
||||||
|
if clone_customer_repository ${CUSTOMER_REPOSITORY_PATH}
|
||||||
|
then
|
||||||
check_sanity_of_repository
|
check_sanity_of_repository
|
||||||
update
|
|
||||||
|
#set_updates_available
|
||||||
|
#while :
|
||||||
|
#do
|
||||||
|
# sleep 5
|
||||||
|
# updates_available && break
|
||||||
|
#done
|
||||||
|
|
||||||
|
# update_psa "testing"
|
||||||
|
update_psa
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
exit 0
|
||||||
error "config-file missing"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
exit -1
|
||||||
|
###############################################################################
|
||||||
|
@@ -1,26 +1,33 @@
|
|||||||
{
|
{
|
||||||
"c1" : "use git without certificates",
|
"" : "use git without certificates",
|
||||||
"GIT_SSL_NO_VERIFY" : 1,
|
"GIT_SSL_NO_VERIFY" : 1,
|
||||||
|
|
||||||
"c2" : "start in working_directory",
|
"" : "explicit location of customer-project",
|
||||||
"working_directory" : "/home/root/szeged/UpdateController",
|
|
||||||
|
|
||||||
"c3" : "directory for customer repository",
|
|
||||||
"workspace_dir" : "workspace",
|
|
||||||
|
|
||||||
"c4" : "explicit location of customer-project",
|
|
||||||
"customer_location" : "szeged",
|
"customer_location" : "szeged",
|
||||||
|
|
||||||
"c5" : "unique customer identifier",
|
"" : "unique customer identifier",
|
||||||
"customer_id" : "281",
|
"customer_id" : "customer_281",
|
||||||
|
|
||||||
"c6" : "each location can have multiple",
|
"" : "zone file for PSA",
|
||||||
"c7" : "zone-groups and/or zones",
|
"zone" : "/etc/zone_nr",
|
||||||
"c8" : "0-index used as size of following array",
|
|
||||||
"c9" : ".zone_group[0]: #n of zones_groups",
|
|
||||||
"c10" : ".zone_group[1].zone[0]: #n of zones in zg[1]",
|
|
||||||
"zone_group" : [ 1, { "zone" : [ 1, "1"] } ],
|
|
||||||
|
|
||||||
"c11" : "url of customer repository",
|
"" : "local branches",
|
||||||
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann"
|
"local_branches" : ["master",
|
||||||
|
"zg1/zone1", "zg1/zone2", "zg1/zone3"],
|
||||||
|
|
||||||
|
"" : "customer number of PSA",
|
||||||
|
"customer_id_" : "/etc/cust_nr",
|
||||||
|
|
||||||
|
"" : "machine id of PSA",
|
||||||
|
"machine_nr" : "/etc/mach_nr",
|
||||||
|
|
||||||
|
"" : "each location can have multiple",
|
||||||
|
"" : "zone-groups and/or zones",
|
||||||
|
"" : "0-index used as size of following array",
|
||||||
|
"" : ".zg[0]: #n of zones_groups",
|
||||||
|
"" : ".zg[1].z[0]: #n of zones in zg[1]",
|
||||||
|
"zg" : [ 1, { "z" : [ 3, 1, 2, 3] } ],
|
||||||
|
|
||||||
|
"" : "url of customer repository",
|
||||||
|
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_281.git"
|
||||||
}
|
}
|
||||||
|
@@ -24,8 +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() {
|
||||||
local func="${FUNCNAME[0]}"
|
if ! pull_customer_repository; then
|
||||||
if ! pull_customer_repository $1; then
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
@@ -33,47 +32,122 @@ fetch_customer_updates() {
|
|||||||
|
|
||||||
copy () {
|
copy () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
local copy_necessary=0
|
||||||
|
|
||||||
readarray -td' ' files <<< "$1"
|
readarray -td' ' files <<< "$1"
|
||||||
for f in ${files[@]}; do
|
for f in ${files[@]}; do
|
||||||
if [[ "$f" =~ .*update[.]conf.* ]] || [[ "$f" =~ .*current[.]conf.* ]]
|
log_debug "$func:${LINENO}: $f"
|
||||||
then
|
# $f is determined by git
|
||||||
|
if [[ "$f" =~ .*update[.]conf.* ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if grep -qE "^.*[.]conf\s*$" <<< ${f}; then
|
|
||||||
local __f=${f#*etc/}
|
# TODO: szeged darf nicht sein
|
||||||
if ! cp "${customer_id_base_dir}/${f}" "/etc/${__f}"; then
|
# local readonlt __cl=$CUSTOMER_LOCATION
|
||||||
log_error "$func:${LINENO}: cannot "\
|
# local readonly __q="'"
|
||||||
"cp ${customer_id_base_dir}/${f} /etc/${__f}"
|
# xxx='$('"echo $f | sed -E -e ${__q}s=(.*$__cl/[0-9]/[0-9])(.*)(/.*)=\2=g$__q"')'
|
||||||
return 1
|
# echo $xxx
|
||||||
|
# eval "echo $xxx"
|
||||||
|
|
||||||
|
local readonly __sysdir=$(echo $f |
|
||||||
|
sed -E -e s'=(.*szeged/[0-9]/[0-9])(.*)(/.*)=\2=g')
|
||||||
|
|
||||||
|
# TODO: kuerzen
|
||||||
|
|
||||||
|
copy_necessary=1
|
||||||
|
|
||||||
|
PERCENT=$((PERCENT+1))
|
||||||
|
test $PERCENT -gt 100 && PERCENT=100
|
||||||
|
|
||||||
|
local readonly __f=${f##*/}
|
||||||
|
local readonly __m="${CUSTOMER_ID_BASE_DIR}/${f}"
|
||||||
|
local __p="${__sysdir}/${__f}"
|
||||||
|
|
||||||
|
# echo "TEST -> $sysdir/$__f"
|
||||||
|
|
||||||
|
# TODO: das kopieren in die system-verzeichnisse muss noch getestet
|
||||||
|
# werden. stimmt noch nicht so ganz.
|
||||||
|
|
||||||
|
#if grep -qE "^.*$DC\s*$" <<< ${f}; then
|
||||||
|
# __p="${DC_SYS_DIR}/${__f}"
|
||||||
|
# log_debug "$func:${LINENO}: __m=$__m"
|
||||||
|
#elif grep -qE "^.*tariff[0-9][0-9][.]json\s*$" <<< ${f}; then
|
||||||
|
# __p="${TARIFF_SYS_DIR}/${__f}"
|
||||||
|
#elif grep -qE "^.*[.]json\s*$" <<< ${f}; then
|
||||||
|
# __p="${CONF_SYS_DIR}/${__f}"
|
||||||
|
# log_debug "$func:${LINENO}: __m=$__m"
|
||||||
|
#elif grep -qE "^.*[.]ini\s*$" <<< ${f}; then
|
||||||
|
# if [ "$__f" = "$ATBQT_INI" ]; then
|
||||||
|
# log_debug "$func:${LINENO}: __m=$__m $ATB_SYS_DIR/$__f ${f%/*}"
|
||||||
|
# if grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
|
||||||
|
# __p="$ATB_SYS_DIR/${__f}"
|
||||||
|
# else
|
||||||
|
# __p="$ATBAPP_SYS_DIR/${__f}"
|
||||||
|
# fi
|
||||||
|
# elif [ "$__f" = "$SYSTEM_CONTROL_INI" ]; then
|
||||||
|
# if grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
|
||||||
|
# __p="$ATB_SYS_DIR/${__f}"
|
||||||
|
# else
|
||||||
|
# __p="$SYSCONFIG_SYS_DIR/${__f}"
|
||||||
|
# fi
|
||||||
|
# elif [ "$__f" = "$SYS_CONFIG_INI" ]; then
|
||||||
|
# if grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
|
||||||
|
# __p="$ATB_SYS_DIR/${__f}"
|
||||||
|
# else
|
||||||
|
# __p="$SYSCONFIG_SYS_DIR/${__f}"
|
||||||
|
# fi
|
||||||
|
# elif [ "$__f" = "$ISMASMGR_INI" ]; then
|
||||||
|
# if grep -qE "$ISMASMGR_SYS_DIR" <<< "${f%/*}"; then
|
||||||
|
# __p="$ISMASMGR_SYS_DIR/${__f}"
|
||||||
|
# elif grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
|
||||||
|
# __p="$ATB_SYS_DIR/${__f}"
|
||||||
|
# else
|
||||||
|
# __p="$SYSCONFIG_SYS_DIR/${__f}"
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
#fi
|
||||||
|
|
||||||
|
echo "XXX-- __p=$__p"
|
||||||
|
|
||||||
|
if [ ! -z "$__p" ]; then
|
||||||
|
if cp "$__m" "$__p"; then
|
||||||
|
log_info "$func:${LINENO}: cp $__m $__p ok"
|
||||||
|
update_psa_copy_conf_and_ini_files $UPDATE_ISMAS_PROGRESS \
|
||||||
|
$RC_SUCCESS "cp $__m $__p ok"
|
||||||
|
else
|
||||||
|
log_error "$func:${LINENO}: cp $__m $__p failed: error-code=$?"
|
||||||
|
update_psa_copy_conf_and_ini_files \
|
||||||
|
$UPDATE_ISMAS_ERROR $RC_COPY_ERROR "cp $__m $__p failed"
|
||||||
|
return $?
|
||||||
fi
|
fi
|
||||||
log_info "$func:${LINENO}: copied $f to /etc/${__f}"
|
else
|
||||||
elif grep -qE "^.*[.]ini\s*$" <<< ${f}; then
|
log_error "$func:${LINENO}: __p still empty"
|
||||||
# TODO: die anderen system-verzeichnisse werden gebraucht
|
update_psa_copy_conf_and_ini_files \
|
||||||
local __f=${f#*opt/app/ATBAPP/}
|
$UPDATE_ISMAS_ERROR $RC_COPY_ERROR "__p still empty"
|
||||||
if [ "$__f" = "ATBQT.ini" ]; then
|
EXITCODE=$((EXITCODE+1))
|
||||||
if ! cp "${customer_id_base_dir}/${f}" /opt/app/ATBAPP/${__f}
|
return $EXITCODE
|
||||||
then
|
|
||||||
log_error "$func:${LINENO}: cannot "\
|
|
||||||
"cp ${customer_id_base_dir}/${f} /opt/app/ATBAPP/${__f}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
log_info "$func:${LINENO}: copied $f to /opt/app/ATBAPP/${__f}"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ $copy_necessary -eq 0 ]; then
|
||||||
|
update_psa_copy_conf_and_ini_files $UPDATE_ISMAS_PROGRESS $RC_SUCCESS \
|
||||||
|
"no copy of json/ini-files necessary"
|
||||||
|
log_debug "$func:${LINENO}: no copy of conf/ini-files necessary"
|
||||||
|
else
|
||||||
|
log_debug "$func:${LINENO}: copied *conf/*ini-files to system-dirs"
|
||||||
|
fi
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: copied *conf/*ini-files to system-dirs"
|
return 0
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filter_conf_ini_files () {
|
filter_changed_files () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
log_debug "$func:${LINENO} $1"
|
log_debug "$func:${LINENO} $1"
|
||||||
readarray -td' ' files <<< "$1"
|
readarray -td' ' files <<< "$1"
|
||||||
local __system_files=""
|
local __system_files=""
|
||||||
for f in ${files[@]}; do
|
for f in ${files[@]}; do
|
||||||
if grep -qE "^.*[.](conf|ini)\s*$" <<< $f; then
|
log_debug "$func:${LINENO} $f"
|
||||||
|
if grep -qE "^.*[.]($2)\s*$" <<< $f; then
|
||||||
if [ -z $__system_files ]; then
|
if [ -z $__system_files ]; then
|
||||||
__system_files="${f}"
|
__system_files="${f}"
|
||||||
else
|
else
|
||||||
@@ -94,7 +168,7 @@ md5_of () {
|
|||||||
# Check if the fetched/merged files have the correct md5 and are
|
# Check if the fetched/merged files have the correct md5 and are
|
||||||
# valid for the PSA.
|
# valid for the PSA.
|
||||||
#
|
#
|
||||||
check_md5_for_changed_conf_and_ini_files () {
|
check_md5_for_changed_json_and_ini_files () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
local js_key="" # used by json-parser 'jq'
|
local js_key="" # used by json-parser 'jq'
|
||||||
local md5sum_update_conf=""
|
local md5sum_update_conf=""
|
||||||
@@ -103,52 +177,44 @@ check_md5_for_changed_conf_and_ini_files () {
|
|||||||
log_debug "$func:${LINENO} files=$1"
|
log_debug "$func:${LINENO} files=$1"
|
||||||
if ! [ -z $1 ]; then
|
if ! [ -z $1 ]; then
|
||||||
readarray -td' ' files <<< "$1"
|
readarray -td' ' files <<< "$1"
|
||||||
|
local readonly __cl=$CUSTOMER_LOCATION
|
||||||
for file in ${files[@]}; do
|
for file in ${files[@]}; do
|
||||||
log_debug "$func:${LINENO} file=$file"
|
# .../szeged/1/1...
|
||||||
if [[ "$file" =~ .*emp[.]conf.* ]]; then
|
log_debug "$func:${LINENO} checking file=${file}..."
|
||||||
js_key=".conf.szeged.zg[1].z[1].etc.psa_config.emp"
|
local __fs=${file##*.}
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
|
||||||
md5sum_repository="$(md5_of $emp_conf)"
|
js_key=""
|
||||||
elif [[ "$file" =~ .*printer[.]conf.* ]]; then
|
|
||||||
js_key=".conf.szeged.zg[1].z[1].etc.psa_config.printer"
|
case $file in
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
*.ini | *.json | *.hex)
|
||||||
md5sum_repository="$(md5_of $printer_conf)"
|
local __key_suffix=$(echo $file |
|
||||||
elif [[ "$file" =~ .*device[.]conf.* ]]; then
|
sed -E -e 's=(.*[0-9]/[0-9])([^.]+)(.*)=\2=g' -e 's=/=.=g')
|
||||||
js_key=".conf.szeged.zg[1].z[1].etc.psa_config.device"
|
js_key=".$__fs.$__cl.zg[$ZONE_GROUP].z[$ZONE]$__key_suffix"
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
md5sum_update_conf=$(cat $PSA_UPDATE_CONF | jq -r $js_key)
|
||||||
md5sum_repository="$(md5_of $device_conf)"
|
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
|
||||||
elif [[ "$file" =~ .*ATBQT[.]ini.* ]]; then
|
;;
|
||||||
js_key=".ini.szeged.zg[1].z[1].opt.app.ATBAPP.ATBQT"
|
*)
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
log_crit "$func:${LINENO} unknown file=${file}"
|
||||||
md5sum_repository="$(md5_of $atbqt_ini)"
|
;;
|
||||||
elif [[ "$file" =~ .*sysconfig[.]ini.* ]]; then
|
esac
|
||||||
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.sysconfig"
|
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
test -z $js_key && continue
|
||||||
md5sum_repository=$(md5_of $sysconfig_sysconfig_ini)
|
|
||||||
elif [[ "$file" =~ .*SystemControl[.]ini.* ]]; then
|
PERCENT=$((PERCENT+1))
|
||||||
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.SystemControl"
|
test $PERCENT -gt 100 && PERCENT=100
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
|
||||||
md5sum_repository=$(md5_of $sysconfig_sysctrl_ini)
|
|
||||||
elif [[ "$file" =~ .*ISMASMgr/ISMASMgr[.]ini.* ]]; then
|
|
||||||
js_key=".ini.szeged.zg[1].z[1].opt.app.ISMASMgr.ISMASMgr"
|
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
|
||||||
md5sum_repository=$(md5_of $ismasmgr_ismasmgr_ini)
|
|
||||||
elif [[ "$file" =~ .*sysconfig/ISMASMgr[.]ini.* ]]; then
|
|
||||||
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.ISMASMgr"
|
|
||||||
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
|
|
||||||
md5sum_repository=$(md5_of $sysconfig_ismasmgr_ini)
|
|
||||||
else
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$md5sum_repository" = "$md5sum_update_conf" ]; then
|
if [ "$md5sum_repository" = "$md5sum_update_conf" ]; then
|
||||||
log_info "$func:${LINENO}: md5sum for $file ok"
|
log_info "$func:${LINENO}: md5sum for $file ok"
|
||||||
|
update_psa_check_hash $UPDATE_ISMAS_PROGRESS $RC_SUCCESS \
|
||||||
|
"md5sum -|$md5sum_repository|- for $file ok"
|
||||||
else
|
else
|
||||||
local __r="repository: $md5sum_repository"
|
local __r="repository: $md5sum_repository"
|
||||||
local __u="update.conf=$md5sum_update_conf"
|
local __u="update.conf=$md5sum_update_conf"
|
||||||
local __m="$__r != $__u"
|
local __m="$__r != $__u"
|
||||||
log_error "$func:${LINENO}: md5sum for $file wrong: $__m"
|
log_error "$func:${LINENO}: md5sum for $file wrong: $__m"
|
||||||
return 1
|
update_psa_check_hash $UPDATE_ISMAS_ERROR $RC_HASH_VALUE_ERROR \
|
||||||
|
"md5sum -|$md5sum_repository|- for $file wrong"
|
||||||
|
return $?
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
@@ -157,6 +223,14 @@ check_md5_for_changed_conf_and_ini_files () {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_hardware_compatibility () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
# RC_HW_COMPATIBILITY_ERROR=6
|
||||||
|
update_psa_check_hardware_compatibility $UPDATE_ISMAS_PROGRESS \
|
||||||
|
$RC_SUCCESS "TODO: hardware compatibility"
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
check_md5_for_opkg_packages () {
|
check_md5_for_opkg_packages () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
local -n opkg_output_ref=$1
|
local -n opkg_output_ref=$1
|
||||||
@@ -174,7 +248,7 @@ check_md5_for_opkg_packages () {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
local __update_conf="${customer_location_dir}/update.conf"
|
local __update_conf="${CUSTOMER_LOCATION_DIR}/update.conf"
|
||||||
md5sum_repo=$(cat $__update_conf | jq -r .opkg.${package}.MD5Sum)
|
md5sum_repo=$(cat $__update_conf | jq -r .opkg.${package}.MD5Sum)
|
||||||
if ! [ -z $md5sum_repo ]; then
|
if ! [ -z $md5sum_repo ]; then
|
||||||
if [ "$md5sum_opkg_info" = "$md5sum_repo" ]; then
|
if [ "$md5sum_opkg_info" = "$md5sum_repo" ]; then
|
||||||
@@ -196,6 +270,7 @@ check_md5_for_opkg_packages () {
|
|||||||
#
|
#
|
||||||
revert_customer_repository () {
|
revert_customer_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
# TODO
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +278,7 @@ revert_customer_repository () {
|
|||||||
#
|
#
|
||||||
backup_previous_version () {
|
backup_previous_version () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
# TODO
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,6 +361,7 @@ exec_opkg () {
|
|||||||
#
|
#
|
||||||
fallback_to_previous_version() {
|
fallback_to_previous_version() {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
# TODO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,5 +369,38 @@ fallback_to_previous_version() {
|
|||||||
#
|
#
|
||||||
cleanup_previous_version() {
|
cleanup_previous_version() {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
# TODO
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_for_apism () {
|
||||||
|
nc localhost 7778
|
||||||
|
}
|
||||||
|
|
||||||
|
get_customer_id () {
|
||||||
|
echo $(cat CUST_ID_FILE)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_zone_nr () {
|
||||||
|
echo $(cat ZONE_FILE)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_plugins () {
|
||||||
|
local __plugins=""
|
||||||
|
for __f in /opt/app/ATBAPP/plugins/*; do
|
||||||
|
local plugin=$__f
|
||||||
|
plugins+="
|
||||||
|
\"${plugin##*/}\": {
|
||||||
|
"
|
||||||
|
plugins+=$(strings $__f |
|
||||||
|
grep -A4 \"Interface\": |
|
||||||
|
grep \"Version\" |
|
||||||
|
sed -E -e 's/^\s*/\n/g')
|
||||||
|
# remove trailing ',' which is already contained in returned value
|
||||||
|
plugins=${plugins/%,}
|
||||||
|
plugins+="
|
||||||
|
},"
|
||||||
|
done
|
||||||
|
printf '%s' ${plugins/%,}
|
||||||
|
}
|
||||||
|
# get_plugins
|
||||||
|
147
update_psa_impl
Executable file
147
update_psa_impl
Executable file
@@ -0,0 +1,147 @@
|
|||||||
|
# !/bin/bash -
|
||||||
|
|
||||||
|
source ./general_utils
|
||||||
|
source ./log_helpers
|
||||||
|
source ./git_helpers
|
||||||
|
source ./update_psa_helpers
|
||||||
|
source ./read_config
|
||||||
|
source ./news_to_ismas
|
||||||
|
source ./news_from_ismas
|
||||||
|
|
||||||
|
trap collect_current_configuration EXIT
|
||||||
|
|
||||||
|
collect_current_configuration () {
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
# TODO: eventuell muss die version neu berechnet werden
|
||||||
|
current_settings_to_ismas
|
||||||
|
|
||||||
|
#for line in $(cat $PSA_UPDATE_CONF |\
|
||||||
|
# jq -r .conf.szeged.zg[$ZONE_GROUP].z[$ZONE].etc.psa_config)
|
||||||
|
#do
|
||||||
|
# conf_file="$(echo $line |
|
||||||
|
# sed -E -ne 's/^[^{}]\s+\"(DC2C_[[:alnum:]]+)\".*$/\1/gp')"
|
||||||
|
# if ! [ -z $conf_file ]; then
|
||||||
|
# local v=$(cat "$psa_config_dir/${conf_file}.json" | jq -r .version)
|
||||||
|
# echo "$conf_file.json version=$v"
|
||||||
|
# fi
|
||||||
|
#done
|
||||||
|
}
|
||||||
|
|
||||||
|
update_psa() { # calling with a parameter is used for testing
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
if ! updates_available; then # check for false alarm
|
||||||
|
update_psa_false_alarm "update requested, but no WAIT state detected"
|
||||||
|
exit $EXITCODE
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
update_psa_activated # message to ISMAS
|
||||||
|
|
||||||
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
log_debug "$func:${LINENO}: fetch/merge updates..."
|
||||||
|
|
||||||
|
# Fetch new updates (using git). but only when repository has already been
|
||||||
|
# cloned.
|
||||||
|
if [ $GIT_CLONE_EXECUTED -eq 0 ]; then
|
||||||
|
if ! fetch_customer_updates; then
|
||||||
|
log_error "$func:${LINENO}: fetch no data for $customer_id"\
|
||||||
|
"-> no files to update -> no psa update"
|
||||||
|
update_psa_false_alarm \
|
||||||
|
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
|
||||||
|
# TODO
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
update_psa_pull_customer_repository # message to ISMAS
|
||||||
|
|
||||||
|
# no backup necessary as saved in git-repo
|
||||||
|
|
||||||
|
# local changed_files=$(changed_file_names)
|
||||||
|
|
||||||
|
if [[ -f "$GIT_PULL_TMP" ]]; then
|
||||||
|
# TODO
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f "$OPKG_CMDS_TMP" ]]; then
|
||||||
|
local commands="$(cat ${OPKG_CMDS_TMP} | tr '\n' '; ')"
|
||||||
|
log_info "$func:${LINENO}: executed opkg commands"
|
||||||
|
update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
|
||||||
|
$RC_SUCCESS "$commands"
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user