97 Commits

Author SHA1 Message Date
0a428d8756 update_psa():
if called without -m (without MAINTENANCE):
check for ISMAS updates 3 times. If no response by ISMAS, end update process with FAILURE (exit script)
if called with -m:
check for ISMAS updates 10 times. If no response by ISMAS, end update process with FAILURE (exit script)
2023-06-29 13:38:41 +02:00
1ecabe79ca fetch_customer_updates(): add debug output.
check_for_running_apism(): use port 7777 instead of port 7778.
2023-06-29 13:36:56 +02:00
3affefe82a Remove usage of the following variables:
TARIFF_CURRENT
TARIFF_SUMMER
TARIFF_WINTER
TC_PSA_TC_FILE
TC_SYS_TC_FILE
2023-06-29 13:34:24 +02:00
a957894d9a Removed usage of obsolete variable TC_PSA_TC_FILE (=tariff.current) and
ATBQT_ATB_SYS_BIN_FILE.
For ATBQT_ATB_SYS_BIN_FILE use /opt/app/ATBAPP/ATBQT directly.
2023-06-29 13:30:37 +02:00
0e7f5938c7 1: Wait 5 seconds for ISMAS response.
2: For ISMAS response: check if device_id (=machine_nr) sent from ISMAS
is the same as the local machine_nr. If NO, return 1 (fail).
2023-06-29 13:27:01 +02:00
fcf179bee1 clone_customer_repository(): add additional debug-output. 2023-06-29 13:23:51 +02:00
f7badfea2e Add empty_file()-helper. To be used later. 2023-06-29 13:22:19 +02:00
4921cb9f06 Merge branch 'master' of https://git.mimbach49.de/GerhardHoffmann/UpdateController 2023-06-20 09:15:14 +02:00
ff2ea6b8f2 Check sanity of WORKING_DIRECTORY variable. cd into $WORKING_DIRECTORY before sourcing other scripts. 2023-06-20 09:14:20 +02:00
0cbd5f523f „update_psa.conf“ ändern
Fix: path to machine_nr in config file
2023-06-09 17:24:51 +02:00
5bca1f498b set WORKING_DIRECTORY explicitly to PWD if . is passed 2023-06-05 15:34:46 +02:00
2d1f11fd74 replaced dc2c.hex with dc2c.bin 2023-06-05 15:07:05 +02:00
2d76b37e5d removed if-GIT_CLONE_EXECUTED branch 2023-05-30 16:42:03 +02:00
b5b3aa7e34 fixed wong shift of arguments for maintenance flag 2023-05-30 16:41:08 +02:00
e3403b2ddd removed typo and initialized variable 2023-05-30 16:40:25 +02:00
82d6dc643a Extended debug output 2023-05-30 16:39:42 +02:00
ef4d27eb91 Taken over some parts from update_psa:
cloning of customer_repository, some sanity checks, check for available
updates.
2023-05-26 15:07:40 +02:00
215b155f2d Moved main parts to update_psa_impl. 2023-05-26 15:07:13 +02:00
901fa4c319 Replaced CLONE_CUSTOMER_REPOSITORY by INITIAL_CLONE.
Added some sanity checks at end of read_config().
2023-05-26 15:05:25 +02:00
e356456fb5 added update_psa_clone_customer_repository().w 2023-05-26 15:04:52 +02:00
bcc96a388f Restructered clone_customer_repository() and cd_customer_repository().
Fixed cd_home() to return explicitly to the customer repository, not
only to -.
2023-05-26 15:01:48 +02:00
8f50f62a52 Moved changing to WORKING_DIRECTORY here 2023-05-24 17:29:15 +02:00
847c58afc8 Moved changing to WORKING_DIRECTORY into update_psa 2023-05-24 17:28:28 +02:00
2abdf963ac Added zone4 for szeged 2023-05-24 17:27:36 +02:00
96d76b856a Added MAINTENANCE flag (-m). If set, simulate WAIT-button in ISMAS 2023-05-24 16:47:54 +02:00
9eff70b780 fixed typo 2023-05-24 16:46:52 +02:00
2a8be547a8 Added FATAL_FAILURE to log_helpers. Do not send to APIS in case of FATAL_FAILURE. 2023-05-24 16:46:21 +02:00
17521771e3 Use log_info instead of log_debug for some debug messages 2023-05-24 16:45:01 +02:00
515c77bed4 Use GIT_UPDATE_LOG instaed of GIT_PULL_TMP / OPKG_CMDS_TMP. 2023-05-24 13:06:25 +02:00
f2617d8151 Use GIT_UPDATE_LOG.
pull_customer_repository():
    Check the file GIT_UPDATE_LOG for keywords DOWNLOAD or EXECUTE.
2023-05-24 13:04:39 +02:00
4f9c6155e1 Always log to file. Log to terminal depending on debug level. 2023-05-24 13:02:56 +02:00
33511a5bcb simulate WAIT-button 2023-04-25 14:26:36 +02:00
bd0d07f56f Added git_branch() and git_customer_branch() 2022-07-08 17:23:03 +02:00
b8bc61daea Set log_level to INFO 2022-07-08 13:50:16 +02:00
27cd99f96a Add update_psa with parameter to skip WAIT-test 2022-07-08 13:21:47 +02:00
729778043a Removed syntactic errors. 2022-06-25 21:27:14 +02:00
31e1aad762 Removed the copy operation for the githooks aunder .githooks. 2022-06-25 21:26:20 +02:00
f8c091ad0c Add get_blob and get_commit_for_blob 2022-06-25 17:18:13 +02:00
e5e6c4c1cd Minor change: check_for_running_apism 2022-06-25 15:22:34 +02:00
95a9307631 check_for_apism, check_default_route and check_for_route_to_repository
exit the script if condition is not fulfilled.
2022-06-25 15:19:43 +02:00
fc1c2221b1 Added check_default_route and check_route_for_repository. 2022-06-25 15:11:49 +02:00
9b1549306d Added checks:
check_default_route -> exit if no route set
check_route_to_repository -> exit if no such route
check_for_apism
2022-06-25 15:08:44 +02:00
a8f691741b Added APISM running 2022-06-25 15:07:23 +02:00
c229f7072c added (commented) line for 'update_psa testing' 2022-06-16 15:52:44 +02:00
7a35039dad update_psa: when called with an argument, skip test for available
updates, executing 'git pull' in any case.
2022-06-16 15:49:34 +02:00
42fb74a041 deactivate some debug output 2022-06-16 15:49:00 +02:00
d69f767002 deactivate output 2022-06-16 15:48:11 +02:00
7c2d78e6db return 0 as exit code 2023-03-31 12:17:08 +02:00
9dd7eb7a3c Activate colored output 2023-03-31 09:45:57 +02:00
87be571e43 Remove GIT_PULL_TMP and OPKG_CMDS_TMP when cloning 2023-03-31 09:05:21 +02:00
2045dcedf5 Change to passed working directory 2023-03-30 14:56:49 +02:00
9d6bb99963 Set working directory to PWD 2023-03-30 14:55:13 +02:00
8b5cda7f73 After clone: fetch the reposiry again, follwed by a git reset --hard.
The effect is that git crates all diretories and files in /etc and /opt.
2023-03-30 13:59:38 +02:00
52271bef21 do not assert missing files. git will create them in <clone> 2023-03-30 13:40:53 +02:00
f080f34bb3 Added GIT_CLONE_EXECUTE 2022-06-12 13:10:48 +02:00
6f8ba186dd Set GIT_CLONE_EXECUTED to show that git clone was run 2022-06-12 13:10:16 +02:00
0541206033 Use of GIT_CLONE_EXECUTED to check if clone was running 2022-06-12 13:07:57 +02:00
b3eed36db8 added local branches 2022-06-12 13:06:31 +02:00
966a779065 create workspace in any case 2022-06-09 21:18:38 +02:00
da3c9abbf5 reusing customer_281 2022-06-09 21:17:18 +02:00
3574453066 'git pull' calls the hook post-merge when new data arrive.
If this is the case, write a file /tmp/git-pull which contains the names
of changed files.
Do not search for any special output of git.
2022-06-09 18:41:33 +02:00
27445f354a call pull_customer_repository without parameters 2022-06-09 18:40:40 +02:00
83aa2dbd5c clone_customer_repository: re-initailize repository after cloning. Copy
.githhoks/post-merge hook into .git/hooks/. post-merge will list the
names of changed files and write them to /tmp/git-pull.
The existence of /tmp/git-pull shows that there have been received changed files.
2022-06-09 18:34:31 +02:00
cfce4ae53c remove opkg-part 2022-06-07 22:33:05 +02:00
7a77d03c7e Add some vars 2022-06-07 22:32:46 +02:00
103952bdb9 use customer_szeged_281 for testing 2022-06-06 20:42:48 +02:00
0516843837 removed all needless parts: git is doing the working 2022-06-06 20:41:55 +02:00
d538f21a57 Minor change 2022-06-06 20:13:04 +02:00
f860c901f5 update.conf has been removed 2022-06-06 20:08:31 +02:00
8f07fbcf53 moved some code into read_config() to make sure proper initialization 2022-06-06 20:07:47 +02:00
326c6ea001 We use a different work-tree as usual when creatinng the repository.
Cloning the rep. does not save this setting. So we have to re-init the
rep:

git --git-dir=.git --work-tree=/ init
2022-06-06 20:05:05 +02:00
66511262e1 use OPKG_CMDS_PSA_FILE 2022-06-04 22:08:01 +02:00
21591d8e3d testing copy() 2022-06-04 22:07:27 +02:00
a3e311e375 ZONE=1, check OPKG_CMDS_PSA_FILE 2022-06-04 22:06:44 +02:00
73a18d5615 minor changes in comment 2022-06-03 18:09:16 +02:00
a769fe0e12 Add test case for TARIFF 2022-06-03 18:08:44 +02:00
0285fed0a1 Add TARIFF-variables 2022-06-03 18:08:13 +02:00
ba556f02bd shortened check_md5sum....() 2022-06-02 22:13:23 +02:00
e46f596270 shortened check_md5sum....() 2022-06-02 22:11:12 +02:00
c3def117a5 Added some variables for DC 2022-06-02 22:09:21 +02:00
fcef0f6ed6 ATBQT_ATB_PSA_BIN_FILE does not exist 2022-06-02 15:08:19 +02:00
729c0f8c18 add ATBQT_ATB_SYS_BIN_FILE 2022-06-02 15:05:34 +02:00
ba1f70fec4 add ATBQT_ATB_SYS_BIN_FILE 2022-06-02 15:04:24 +02:00
dc6226bbb7 replaced ATBQT_SYS_FULL -> ATBQT_ATB_SYS_BIN_FILE 2022-06-02 15:03:41 +02:00
6bf95ba131 adapted because of changes in read_config 2022-06-07 21:51:47 +02:00
7a06811aa5 adapted because of changes in read_config 2022-06-07 21:51:24 +02:00
259b61cda5 adapted because of changes in read_config 2022-06-07 21:50:48 +02:00
fe52f263a8 restructed file for readability 2022-06-07 21:50:03 +02:00
7e0eccc8d0 Minor changes 2022-06-02 16:06:07 +02:00
e941af6420 Added call for compute_version 2022-06-02 16:04:25 +02:00
4b6723b8e6 Added compute_hash() and compute_version() 2022-06-02 16:03:24 +02:00
ec660a9fad Added HASH and VERSION 2022-06-02 16:02:38 +02:00
a884019431 use assert-helpers 2022-06-05 21:42:53 +02:00
da32f34b4e use customer_281 instead of only 281 2022-06-05 21:42:10 +02:00
e419b74e46 added assert_* helpers 2022-06-05 21:41:22 +02:00
a0602c820c Add utility to clone customer repository in workspace-directory 2022-06-05 17:13:18 +02:00
fa5bbc76a5 Added comments 2022-06-05 16:58:39 +02:00
12 changed files with 779 additions and 753 deletions

9
clone_customer_repository Executable file
View 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>

View File

@@ -80,4 +80,47 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
echo "INFO: $2 completed successfully" >&2
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"
:
}
empty_file () {
if [[ -f "$1" ]]; then
echo -n "" > $1
else
log_error "$1 does not exist"
fi
}
fi

View File

@@ -57,6 +57,18 @@ revert_to_commit_before_pull () {
}
# revert_to_commit_before_pull
git_branch () {
# always relative to a git repository
echo $(git branch -a | grep '*' | awk '{ print $2 }')
}
git_customer_branch () {
if cd_customer_repository; then
customer_branch=$(git_branch)
cd_home;
echo $customer_branch
fi
}
# clone the customer repository in ./workspace.
# this is done only once.
#
@@ -70,67 +82,106 @@ revert_to_commit_before_pull () {
#
clone_customer_repository () {
local func="${FUNCNAME[0]}"
if [ "$PWD" = "$WORKING_DIRECTORY" ]; then
if ! [[ -d "./$WORKSPACE_DIR" ]]; then
{ mkdir -p ./$WORKSPACE_DIR; }
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
fi
mkdir -p "./$WORKSPACE_DIR"
# check if the directory is empty. If so, clone the
# customer repository
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
log_info "$func:${LINENO} cloning ${1} into ${PWD}/${WORKSPACE_DIR}..."
if ! cd "./$WORKSPACE_DIR"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not change to $WORKSPACE_DIR"
fi
# check if the directory is empty. If so, clone the
# customer repository
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
log_debug "$func:${LINENO} cloning ${1} ..."
if cd "./$WORKSPACE_DIR"
then
$(exec_git_command git clone "$1")
if [ $? -eq 0 ]; then
CLONE_CUSTOMER_REPOSITORY=true
log_debug "$func:${LINENO} cloning ${1} done"
cd - ; return 0
fi
cd -
fi
else
# the directory is not empty, so we assume the
# customer-repository has been cloned already
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
else
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
log_debug "$func:${LINENO} $__m"
return 0
fi
if ! exec_git_command git clone "$1"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not clone $1"
fi
########################## CLONING DONE ############################
log_debug "$func:${LINENO} cloning ${1} done"
# after cloning, cd into repository, and re-initialize,
# setting the work-tree as "/". This has the effect that
# a "git pull" will automatically fetched files in the
# corresponding sytem-folders.
####################### CD INTO REPOSITORY ##########################
if ! cd ${CUSTOMER_ID_BASE_DIR}; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not change to $CUSTOMER_ID_BASE_DIR"
fi
log_debug "$func:${LINENO} cd into $CUSTOMER_ID_BASE_DIR"
##################### CONFIGURE HOOKS DIRECTORY ######################
if ! exec_git_command git config core.hooksPath .githooks; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not configure hooks directory"
fi
###################### CHECKOUT LOCAL BRANCH #########################
if ! exec_git_command git checkout "$LOCAL_BRANCH"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not checkout $LOCAL_BRANCH"
fi
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
######################## CONFIGURE WORKTREE ##########################
if ! exec_git_command git config core.worktree "/"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not configure worktree '/'"
fi
log_debug "$func:${LINENO} configured worktree '/'"
########################### FETCH ALL #################################
if ! exec_git_command git fetch --all; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not fetch --all for $LOCAL_BRANCH"
fi
log_debug "$func:${LINENO} fetch repository"
########################## RE-INIT REPOSITORY ########################
if ! exec_git_command git reset --hard "$LOCAL_BRANCH"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} re-init of $LOCAL_BRANCH failed"
fi
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
INITIAL_CLONE=true
log_debug "$func:${LINENO} re-init of ${1} done"
update_psa_clone_customer_repository
else
# the directory is not empty, so we assume the
# customer-repository has been cloned already
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
fi
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
log_info "$func:${LINENO} $__m, no clone necessary"
fi
update_psa_clone_error # message to ISMAS
return $?
cd_home
log_info "$func:${LINENO} nach cd_home $PWD"
}
# clone_customer_repository ->
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
cd_customer_repository () {
local func="${FUNCNAME[0]}"
# has to be called in WORKING_DIRECTORY
if [ "$PWD" = "${WORKING_DIRECTORY}" ]; then
repository_dir="./$WORKSPACE_DIR/$CUSTOMER_ID"
if ! [[ -d "$repository_dir" ]]; then
log_crit "$func:${LINENO}: $repository_dir does not exist!"
return 1
fi
if ! { cd $repository_dir; } ; then
log_crit "$func:${LINENO}: cannot cd to $repository_dir!"
return 1
fi
log_debug "$func:${LINENO}: cd to $repository_dir!"
return 0
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
fi
return 1
if ! [[ -d "$CUSTOMER_ID_BASE_DIR" ]]; then
log_fatal "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR does not exist!"
fi
if ! cd "$CUSTOMER_ID_BASE_DIR"; then
log_fatal "$func:${LINENO}: cannot cd to $CUSTOMER_ID_BASE_DIR !!!"
fi
log_debug "$func:${LINENO}: cd to $CUSTOMER_ID_BASE_DIR"
return 0
}
cd_home () {
if cd - &>/dev/null ; then
if cd "$WORKING_DIRECTORY" &>/dev/null ; then
return 0
fi
return 1
@@ -143,109 +194,20 @@ pull_customer_repository () {
return 1
fi
local commit_before_pull=$(latest_commit)
if [ -z $commit_before_pull ]; then
log_warn "$func:${LINENO}: commit_before_pull empty"
cd_home ; return 1
log_crit "$func:${LINENO}: executing 'git pull'..."
exec_git_command 'git pull'
# GIT_UPDATE_LOG updated by hook post-merge. it contains the names of the
# changed files or opkg-commands to execute.
# If 'git pull' has fetched new data, then there are lines starting with
# DOWNLOAD or EXECUTE.
if grep -qE "^[[:space:]]*(DOWNLOAD|EXECUTE)" "$GIT_UPDATE_LOG"; then
log_info "$func:${LINENO}: new data fetched from repository"
cd_home; return 0
fi
log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
log_debug "$func:${LINENO}: executing 'git pull'..."
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
log_warn "$func:${LINENO}: no data fetched from repository"
cd_home; return 1
}
# pull_customer_repository customer_281
@@ -274,4 +236,20 @@ changed_file_names () {
"while in $PWD"
fi
}
# fi
get_blob () { # get the blob of the file(name) passed as $1
# note: this can be used for any file in the filesystem
echo $(git hash-object $1)
}
get_commit_for_blob () {
blob=$(get_blob $1)
if [ ! -z $blob ]; then
# search for the blob in all commits for the file(name) $1
echo $(echo $(git log --all --pretty=format:%H -- $1) |
xargs -I{} sh -c "git ls-tree {} -- $1 |
grep -q $blob && echo {}")
fi
}

View File

@@ -1,6 +1,23 @@
#! /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)\"",

View File

@@ -17,7 +17,8 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
readonly FATAL=5
readonly MAX_DEBUG_LEVEL=6
log_level=0
log_level=$INFO
FATAL_FAILURE=false
set_dbg_level () {
if [ $1 < $MAX_DEBUG_LEVEL ]; then
@@ -29,50 +30,61 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
return $log_level
}
log() {
log_to_file() {
if [[ $(("$(wc -l < $log_file)")) -ge $((100000)) ]]; then
# remove first line
sed -e 1d -i $log_file
fi
local msg="$(date +'%Y-%m-%d_%T'): $*"
echo "log:$msg" >&2
echo "$msg" >> $log_file
}
log() {
local msg="$(date +'%Y-%m-%d_%T'): $*"
echo "log:$msg" >&2
}
log_debug() {
if [ $log_level = $DEBUG ]; then
log_to_file "DEBUG $*"
if [ $log_level -le $DEBUG ]; then
log "DEBUG $*"
fi
}
log_info() {
log_to_file "INFO $*"
if [ $log_level -le $INFO ]; then
log "INFO $*"
fi
}
log_warn() {
log_to_file "WARN $*"
if [ $log_level -le $WARN ]; then
log "WARN $*"
fi
}
log_crit() {
log_to_file "CRIT $*"
if [ $log_level -le $CRIT ]; then
log "CRIT $*"
fi
}
log_error() {
log_to_file "ERROR $*"
if [ $log_level -le $ERROR ]; then
log "ERROR $*"
fi
}
log_fatal() {
log_to_file "FATAL $*"
if [ $log_level -le $FATAL ]; then
log "FATAL $*"
log "exiting ..."
FATAL_FAILURE=true
exit 1
fi
}

View File

@@ -2,19 +2,34 @@
source ./log_helpers
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
if [ "${news_from_ismas_sourced:-1}" = "1" ]; then # include only once
readonly news_from_ismas_sourced=${BASH_SOURCE[0]}
readonly APISM_DIRECT_PORT=7778
updates_available () {
local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 1) | nc localhost $APISM_DIRECT_PORT)"
sleep 5) | 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
local ismas_device_id="$(echo $json_response | jq -r .Dev_ID.Device_ID)"
local machine_nr=$(cat "/etc/machine_nr")
log_info "$func:${LINENO}: json_response=$json_response"
log_info "$func:${LINENO}: apism_trigger=<$trigger> device_id=<$ismas_device_id> machine_nr=<$machine_nr>"
if [ ! -z "$ismas_device_id" -a "$ismas_device_id" != " " ]; then
if [ ! -z "$machine_nr" -a "$machine_nr" != " " ]; then
if [ "$ismas_device_id" != "$machine_nr" ]; then
log_error "$func:${LINENO}: ISMAS DEVICE ID <$ismas_deviceId> != LOCAL_MACHINE_NUMBER <$machine_nr>"
return 1
fi
fi
fi
if grep -qE "WAIT" <<< "$trigger"; then
log_info "$func:${LINENO}: FOUND WAIT TRIGGER"
return 0
fi
else
log_error "$func:${LINENO}: apism request failed"
log_error "$func:${LINENO}: APISM REQUEST FAILED"
fi
return 1
}
@@ -22,11 +37,11 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
update_status () {
local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 1) | nc localhost $APISM_DIRECT_PORT)"
sleep 5) | 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\""
log_info "$func:${LINENO}: apism_trigger=<$trigger>"
else
log_error "$func:${LINENO}: apism request failed"
fi

View File

@@ -2,7 +2,8 @@
source ./log_helpers
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
readonly news_to_ismas_sourced=${BASH_SOURCE[0]}
readonly APISM_DB_PORT=7777
readonly UPDATE_ISMAS_PROGRESS="U0010"
@@ -69,6 +70,18 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
###########################################################################
###########################################################################
update_psa_clone_customer_repository () {
PERCENT=10
local params=("U0010" # event
$PERCENT # percent
$RC_SUCCESS # resultcode
"clone_customer_repository" # step
"git cloned $CUSTOMER_REPOSITORY_PATH" # step_result
"") # version
news_to_ismas ${params[*]}
return $?
}
update_psa_pull_customer_repository () {
PERCENT=10
@@ -362,7 +375,7 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
\"RESULTCODE\" : ${p[2]},
\"STEP\" : \"update_psa_${p[3]}\",
\"STEP_RESULT\" : \"${p[4]}\",
\"VERSION\" : \"${p[5]}\"
\"VERSION\" : \"$VERSION\"
}
}"
log_debug "$func:${LINENO}: data=$data"
@@ -375,13 +388,14 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
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)\"
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
\"HASH\":\"$(compute_hash)\"
},
\"TARIFF\": {
$(<$TARIFF_CURRENT_FULL)
\"TARIFF\" : {
},
\"HARDWARE\" : {
\"DEVICES\" : [
@@ -398,8 +412,8 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
sed -E -e 's/.*:\s*(.*)/\1/g')\"
},
\"DC\" : {
\"VERSION\" : \"$(cat $UPDATE_CONF | jq -r .dc.version)\",
\"MD5SUM\" : \"$(cat $UPDATE_CONF | jq -r .dc.dc2c)\"
\"VERSION\" : \"$(compute_hash ${DC_PSA_DC_FILE})\",
\"MD5SUM\" : \"\"
},
\"PRINTER\" : {
},
@@ -410,11 +424,11 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
\"RAUC\" : \"$(rauc --version)\",
\"OPKG\" : \"$(opkg --version)\",
\"ATBQT\" : {
\"VERSION\" : \"$($ATBQT_SYS_FULL -v |
grep Version |
\"VERSION\" : \"$(/opt/app/ATBAPP/ATBQT -v |
grep Version |
sed -E -e 's/.*:\s*(.*)/\1/g')\",
\"GIT_DESCRIBE\" : \"$($ATBQT_SYS_FULL -v |
grep git |
\"GIT_DESCRIBE\" : \"$(/opt/app/ATBAPP/ATBQT -v |
grep git |
sed -E -e 's/.*:\s*(.*)/\1/g')\"
},
\"PLUGINS\" : {
@@ -426,13 +440,13 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
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"
$RC_SUCCESS "psa update succeeded" $VERSION
update_psa_update_succeeded $UPDATE_ACTIVATED \
$RC_SUCCESS "psa update activated"
$RC_SUCCESS "psa update activated" $VERSION
log_info "$func:${LINENO}: success"
# fi

View File

@@ -2,9 +2,14 @@
# set -x
source ./log_helpers
source ./general_utils
if [ ${read_config_sourced:-1} = "1" ]; then # include only once
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'
@@ -17,73 +22,54 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly UPDATEPSABEGIN=./.updatepsa/begin
readonly UPDATEPSAEND=./.updatepsa/end
readonly PROGRAM=`basename $0`
readonly VERSION="0.8.0"
# name of file containing the logs following a 'git pull':
# basically, there are two kinds of entries:
readonly GIT_UPDATE_LOG=/opt/app/tools/atbupdate/update_log.csv
readonly PROGRAM=`basename $0`
readonly WORKSPACE_DIR=workspace
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME}
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
fi
if ! [ -d "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
fi
EXITCODE=$RC_SUCCESS
CLONE_CUSTOMER_REPOSITORY=false
INITIAL_CLONE=false
APISM_RUNNING=0
# read config file (JSON syntax)
read_config() {
local func="${FUNCNAME[0]}"
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
fi
log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME"
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
local readonly cf="$CONFIGFILENAME"
if cd $WORKING_DIRECTORY ; then
log_debug "$func:${LINENO}: cd to $WORKING_DIRECTORY"
else
log_fatal "$func:${LINENO}: cannot cd to $WORKING_DIRECTORY"
fi
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
if [ -z "$GIT_SSL_NO_VERIFY" ]; then
log_fatal "$func:${LINENO} GIT_SSL_NO_VERIFY not set in $cf"
fi
log_debug "$func:${LINENO}: GIT_SSL_NO_VERIFY=$GIT_SSL_NO_VERIFY"
log_debug "$func:${LINENO}: WORKSPACE_DIR=$WORKSPACE_DIR"
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
if [ -z "$CUSTOMER_LOCATION" ]; then
log_fatal "$func:${LINENO}: CUSTOMER_LOCATION not set in $cf"
fi
log_debug "$func:${LINENO}: customer-location=$CUSTOMER_LOCATION"
assert_s GIT_SSL_NO_VERIFY
readonly CUST_ID="$(cat "$cf" | jq -r .customer_id)"
if [ -z "$CUST_ID" ]; then
log_fatal "$func:${LINENO} CUST_ID not set in $cf"
fi
readonly CUSTOMER_ID="customer_$CUST_ID"
log_debug "$func:${LINENO}: CUSTOMER-ID=$CUSTOMER_ID"
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
assert_s CUSTOMER_LOCATION
readonly CUSTOMER_ID="$(cat "$cf" | jq -r .customer_id)"
assert_s CUSTOMER_ID
local __r_path="$(cat "$cf" | jq -r .cust_repository_path)"
if [ -z "$__r_path" ]; then
log_fatal "$func:${LINENO}: customer repository path not set in $cf"
fi
readonly CUSTOMER_REPOSITORY_PATH="${__r_path}/${CUSTOMER_ID}.git"
log_debug "$func:${LINENO}: customer-r-path=$CUSTOMER_REPOSITORY_PATH"
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"
# 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
@@ -94,312 +80,313 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
done
readonly ZONE_GROUPS=(${__zone_groups[@]})
log_debug "$func:${LINENO}: ZONE_GROUPS=${ZONE_GROUPS[@]}"
log_debug "$func:${LINENO}: reading ${wd} done"
assert_a ZONE_GROUPS
# TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
# TODO
# Zone aus /etc/zone_nr auslesen
#
readonly ZONE_GROUP=1
local __zone=1
readonly ZONE_FILE="$(cat "$cf" | jq -r .zone)"
if [ -f "$ZONE_FILE" ]; then
__zone=$(cat "$ZONE_FILE")
__zone=$((__zone))
fi
readonly ZONE=$__zone
readonly LOCAL_BRANCH="$(cat "$cf" | jq -r .local_branches[$ZONE])"
if [ -z "$WORKING_DIRECTORY" ]; then
log_fatal "${func}:${LINENO}: empty WORKING_DIRECTORY"
fi
if ! cd "$WORKING_DIRECTORY"; then
log_fatal "${func}:${LINENO}: cannot cd to $WORKING_DIRECTORY"
fi
log_debug "${func}:${LINENO}: cd to $WORKING_DIRECTORY"
return 0
}
###############################################################################
########################## 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 () {
local func="${FUNCNAME[0]}"
local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
readonly CUSTOMER_ID_BASE_DIR="${__customer_id_base_dir}/${CUSTOMER_ID}"
log_debug "$func:${LINENO}: CUSTOMER_ID_BASE_DIR="
log_debug "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR"
CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}"
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=$UPDATE_CONF"
readonly DC="dc2c.hex"
readonly DC_SYS_DIR="/etc/dc"
readonly DC_DIR="${CUSTOMER_LOCATION_DIR}/dc"
readonly DC_FULL="${DC_DIR}/$DC"
if [ -f "$DC_FULL" ]; then
log_debug "$func:${LINENO}: d2dc.hex=$DC_FULL"
else
log_fatal "$func:${LINENO}: $DC_FULL does not exist"
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
fi
assert_d CUSTOMER_ID_BASE_DIR
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[@]})
# by now (03.03.2023) there is only one zone group.
readonly local __zgroup=1
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
#readonly local __zgroup=1
#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
readonly CUSTOMER_BASE_DIRS=(${__customer_base_dirs[@]})
if [ ${#CUSTOMER_BASE_DIRS[@]} -eq 0 ]; then
log_fatal "$func:${LINENO}: CUSTOMER_BASE_DIRS empty"
fi
# TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
# TODO
readonly ZONE=1
readonly CUSTOMER_BASE_DIR="${CUSTOMER_BASE_DIRS[$ZONE]}"
if [ -d "$CUSTOMER_BASE_DIR" ]; then
log_debug "$func:${LINENO}: CUSTOMER-BASE-DIR="
log_debug "$func:${LINENO}: $CUSTOMER_BASE_DIR"
else
log_fatal "$func:${LINENO}: $CUSTOMER_BASE_DIR does not exist"
fi
# for szeged:
# placeholder
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/1
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/2
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/3
# readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
# assert_a CUST_BASE_DIRS
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 ATB_SYS_DIR="/etc/atb"
readonly PSA_ATB_SYS_DIR="${CUSTOMER_BASE_DIR}${ATB_SYS_DIR}"
if [ -d "$PSA_ATB_SYS_DIR" ]; then
log_debug "$func:${LINENO}: PSA_ATB_SYS_DIR=$PSA_ATB_SYS_DIR"
else
log_fatal "$func:${LINENO}: $PSA_ATB_SYS_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 CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
#readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
#assert_d CUST_BASE_DIR
readonly ETC_SYS_DIR="/etc"
readonly ATB_SYS_DIR="/etc/atb"
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 SYSCONFIG_SYS_DIR="/opt/app/sysconfig"
readonly PSA_SYSCONFIG_DIR="$CUSTOMER_BASE_DIR$SYSCONFIG_SYS_DIR"
# 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"
if [ -d "$psa_ismasmgr_dir" ]; then
log_debug "$func:${LINENO}: psa_ismasmgr_dir="
log_debug "$func:${LINENO}: $psa_ismasmgr_dir"
else
log_fatal "$func:${LINENO}: $psa_ismasmgr_dir does not exist"
fi
readonly CONF_SYS_DIR="/etc/psa_config"
readonly OPKG_SYS_DIR="/etc/psa_update"
readonly ATBAPP_SYS_DIR="/opt/app/ATBAPP"
readonly ETC_PSA_DIR=${CUST_BASE_DIR}${ETC_SYS_DIR}
readonly ATB_PSA_DIR=${CUST_BASE_DIR}${ATB_SYS_DIR}
readonly DC_PSA_DIR=${CUST_BASE_DIR}${DC_SYS_DIR}
readonly TARIFF_PSA_DIR=${CUST_BASE_DIR}${TARIFF_SYS_DIR}
readonly OPKG_PSA_DIR=${CUST_BASE_DIR}${OPKG_SYS_DIR}
readonly CONF_PSA_DIR=${CUST_BASE_DIR}${CONF_SYS_DIR}
readonly OPT_PSA_DIR=${CUST_BASE_DIR}${OPT_SYS_DIR}
readonly APP_PSA_DIR=${CUST_BASE_DIR}${APP_SYS_DIR}
readonly ATBAPP_PSA_DIR=${CUST_BASE_DIR}${ATBAPP_SYS_DIR}
readonly SYSCONFIG_PSA_DIR=${CUST_BASE_DIR}${SYSCONFIG_SYS_DIR}
readonly ISMASMGR_PSA_DIR=${CUST_BASE_DIR}${ISMASMGR_SYS_DIR}
readonly psa_atbqt_dir="$CUSTOMER_BASE_DIR$ATBAPP_SYS_DIR"
if [ -d "$psa_atbqt_dir" ]; then
log_debug "$func:${LINENO}: psa_atbqt_dir="
log_debug "$func:${LINENO}: $psa_atbqt_dir"
else
log_fatal "$func:${LINENO}: $psa_atbqt_dir does not exist"
fi
readonly TARIFF_CURRENT="tariff.current"
readonly TARIFF_CURRENT_FULL="${psa_atbqt_dir}/$TARIFF_CURRENT"
if [ -f "$TARIFF_CURRENT_FULL" ]; then
log_debug "$func:${LINENO}: tariff.current="
log_debug "$func:${LINENO}: $TARIFF_CURRENT_FULL"
else
log_fatal "$func:${LINENO}: $TARIFF_CURRENT_FULL does not exist"
fi
readonly ATBQT_INI="ATBQT.ini"
readonly ATBQT_INI_FULL="${psa_atbqt_dir}/$ATBQT_INI"
if [ -f "$ATBQT_INI_FULL" ]; then
log_debug "$func:${LINENO}: ATBTQT.ini="
log_debug "$func:${LINENO}: $ATBQT_INI_FULL"
else
log_fatal "$func:${LINENO}: $ATBQT_INI_FULL does not exist"
fi
readonly ATBQT_BIN="ATBQT"
readonly ATBQT_INI="ATBQT.ini"
readonly ISMASMGR_INI="ISMASMgr.ini"
readonly SYSCONF_INI="sysconfig.ini"
readonly SYSCTRL_INI="SystemControl.ini"
readonly DC="dc2c.bin"
readonly ATBQT="ATBQT"
readonly ATBQT_SYS_FULL="${ATBAPP_SYS_DIR}/$ATBQT"
if [ -f "$ATBQT_SYS_FULL" ]; then
log_debug "$func:${LINENO}: ATBQT="
log_debug "$func:${LINENO}: $ATBQT_SYS_FULL"
else
log_fatal "$func:${LINENO}: $ATBQT_SYS_FULL does not exist"
fi
readonly ISMASMGR_INI="ISMASMgr.ini"
readonly ISMASMGR_SYS_DIR="/opt/app/ISMASMgr"
readonly DC_SYS_DC_FILE="${DC_SYS_DIR}/$DC"
readonly ATBQT_ATB_SYS_BIN_FILE="${ATBAPP_SYS_DIR}/$ATBQT_BIN"
readonly ATBQT_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_APP_SYS_INI_FILE="${ATBAPP_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ATBQT_INI"
readonly ISMASMGRATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRAPP_SYS_INI_FILE="${ISMASMGR_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRSCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$ISMASMGR_INI"
readonly SYSCONF_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCONF_INI"
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 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 ISMASMGR_ISMASMGR_INI_FULL="${psa_ismasmgr_dir}/$ISMASMGR_INI"
if [ -f "$ISMASMGR_ISMASMGR_INI_FULL" ]; then
log_debug "$func:${LINENO}: ismasmgr_ismasmgr.ini="
log_debug "$func:${LINENO}: $ISMASMGR_ISMASMGR_INI_FULL"
else
log_fatal "$func:${LINENO}: $ISMASMGR_ISMASMGR_INI_FULL "\
"does not exist"
fi
readonly ATBQT_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$ATBQT_INI"
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 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"
readonly SYSCONFIG_ISMASMGR_INI_FULL="${PSA_SYSCONFIG_DIR}/ISMASMgr.ini"
if [ -f "$SYSCONFIG_ISMASMGR_INI_FULL" ]; then
log_debug "$func:${LINENO}: sysconfig_ismasmgr.ini="
log_debug "$func:${LINENO}: $SYSCONFIG_ISMASMGR_INI_FULL"
else
log_fatal "$func:${LINENO}: $SYSCONFIG_ISMASMGR_INI_FULL "\
"does not exist"
fi
readonly ATB_ISMASMGR_INI_FULL="${PSA_ATB_SYS_DIR}/$ISMASMGR_INI"
if [ -f "$ATB_ISMASMGR_INI_FULL" ]; then
log_debug "$func:${LINENO}: atb_ismasmgr.ini="
log_debug "$func:${LINENO}: $ATB_ISMASMGR_INI_FULL"
else
log_fatal "$func:${LINENO}: $ATB_ISMASMGR_INI_FULL does not exist"
fi
readonly SYS_CONFIG_INI="sysconfig.ini"
readonly __sysc_sysc_full="${PSA_SYSCONFIG_DIR}/$SYS_CONFIG_INI"
readonly SYSCONFIG_SYSCONFIG_INI_FULL="$__sysc_sysc_full"
if [ -f "$SYSCONFIG_SYSCONFIG_INI_FULL" ]; then
log_debug "$func:${LINENO}: sysconfig_sysconfig.ini="
log_debug "$func:${LINENO}: $SYSCONFIG_SYSCONFIG_INI_FULL"
else
log_fatal "$func:${LINENO}: "\
"$SYSCONFIG_SYSCONFIG_INI_FULL does not exist"
fi
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
readonly ATB_SYSCONFIG_INI_FULL="${PSA_ATB_SYS_DIR}/$SYS_CONFIG_INI"
if [ -f "$ATB_SYSCONFIG_INI_FULL" ]; then
log_debug "$func:${LINENO}: atb_sysconfig.ini="
log_debug "$func:${LINENO}: $ATB_SYSCONFIG_INI_FULL"
else
log_fatal "$func:${LINENO}: $ATB_SYSCONFIG_INI_FULL does not exist"
fi
readonly "SYSTEM_CONTROL_INI"="SystemControl.ini"
local __sysctrl_ini_full="${PSA_SYSCONFIG_DIR}/$SYSTEM_CONTROL_INI"
readonly SYSCONFIG_SYSCTRL_INI_FULL="$__sysctrl_ini_full"
if [ -f "$SYSCONFIG_SYSCTRL_INI_FULL" ]; then
log_debug "$func:${LINENO}: sysconfig_systemcontrol.ini="
log_debug "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL"
else
log_fatal "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL does not exist"
fi
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
readonly ATB_SYSCTRL_INI_FULL="${PSA_ATB_SYS_DIR}/$SYSTEM_CONTROL_INI"
if [ -f "$ATB_SYSCTRL_INI_FULL" ]; then
log_debug "$func:${LINENO}: atb_systemcontrol.ini="
log_debug "$func:${LINENO}: $ATB_SYSCTRL_INI_FULL"
else
log_fatal "$func:${LINENO}: $ATB_SYSCTRL_INI_FULL does not exist"
fi
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 OPKG_CMDS_SYS_FILE
assert_f DC2C_SYS_CONF_JSON
assert_f DC2C_SYS_SERIAL_JSON
assert_f DC2C_SYS_CASH_JSON
readonly ATB_ATBQT_INI_FULL="${PSA_ATB_SYS_DIR}/$ATBQT_INI"
if [ -f "$ATB_ATBQT_INI_FULL" ]; then
log_debug "$func:${LINENO}: ATBQT.ini="
log_debug "$func:${LINENO}: $ATB_ATBQT_INI_FULL"
else
log_fatal "$func:${LINENO}: $ATB_ATBQT_INI_FULL does not exist"
fi
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 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 DC2C_SERIAL_JSON="${psa_config_dir}/DC2C_serial.json"
if [ -f "$DC2C_SERIAL_JSON" ]; then
log_debug "$func:${LINENO}: DC2C_SERIAL_JSON="
log_debug "$func:${LINENO}: $DC2C_SERIAL_JSON"
else
log_fatal "$func:${LINENO}: $DC2C_SERIAL_JSON does not exist"
fi
readonly DC2C_CASH_JSON="${psa_config_dir}/DC2C_cash.json"
if [ -f "$DC2C_CASH_JSON" ]; then
log_debug "$func:${LINENO}: DC2C_CASH_JSON="
log_debug "$func:${LINENO}: $DC2C_CASH_JSON"
else
log_debug "$func:${LINENO}: $DC2C_CASH_JSON does not exist"
fi
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)
readonly DC2C_CONF_JSON="${psa_config_dir}/DC2C_conf.json"
if [ -f "$DC2C_CONF_JSON" ]; then
log_debug "$func:${LINENO}: DC2C_CONF_JSON="
log_debug "$func:${LINENO}: $DC2C_CONF_JSON"
else
log_fatal "$func:${LINENO}: $DC2C_CONF_JSON does not exist"
fi
local DC2C_PRINT_JSON=()
for i in {1..32}; do # up to 32 print-json-files
local __f=${psa_config_dir}/DC2C_print$(printf "%02d" $i).json
local __f=${CONF_PSA_DIR}/DC2C_print$(printf "%02d" $i).json
readonly DC2C_PRINT$(printf "%02d" $i)_JSON=$__f
# local __g=$(eval echo '$'DC2C_PRINT$(printf "%02d" $i)_JSON)
if [ -f $__f ]; then
log_debug "$func:${LINENO}: DC2C_PRINT$(printf "%02d" $i)_JSON="
log_debug "$func:${LINENO}: $__f"
else
log_fatal "$func:${LINENO}: $__f does not exist"
fi
DC2C_PRINT_JSON+=($__f)
assert_f DC2C_PRINT$(printf "%02d" $i)_JSON
DC2C_PRINT_JSON+=($__f)
done
readonly opkg_cmds_file="${psa_update_dir}/opkg_commands"
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
# TODO: anpassen, da z.B. fuer szeged mehrere zonen vorhanden sind
readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \
${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \
${DC2C_CONF_JSON##*${CUSTOMER_ID}/} \
${DC2C_CASH_JSON##*${CUSTOMER_ID}/} \
${DC2C_SERIAL_JSON##*${CUSTOMER_ID}/})
readonly KNOWN_INI_FILES=(${ATBQT_INI_FULL##*${CUSTOMER_ID}/} \
${ISMASMGR_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
${SYSCONFIG_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
${SYSCONFIG_SYSCONFIG_INI_FULL##*${CUSTOMER_ID}/} \
${SYSCONFIG_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/} \
${ATB_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
${ATB_SYSCONFIG_INI_FULL##*${CUSTOMER_ID}/} \
${ATB_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/} \
${ATB_ATBQT_INI_FULL##*${CUSTOMER_ID}/})
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
${KNOWN_INI_FILES[@]} \
${opkg_cmds_file##*${CUSTOMER_ID}/})
log_debug "$func:${LINENO}: known conf/ini_files ->"
for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
tab=$'\t'
log_debug "$func:${LINENO}: $tab$tab ${KNOWN_FILES[$i]}"
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
log_debug "$func:${LINENO}: sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
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
}

View File

@@ -5,6 +5,7 @@
# UPDATE PSA
# Usage:
# update_psa [ --? ]
# [ -m ]
# [ --help ]
# [ --wdir "working_directory" ]
# [ --file "config_file" ]
@@ -14,18 +15,24 @@
# ./update_psa --file $PWD/update_psa.conf --wdir $PWD
#
###############################################################################
if [ $# -eq 0 ]; then
# if [ $# -eq 0 ]; then
# no parameters given -> nothing to do
exit 0
fi
# exit 0
#fi
if [ -z $IFS ]; then
IFS=$'\n'
fi
MAINTENANCE="NO"
WORKING_DIRECTORY=${PWD}
# parse commandline parameters
while test $# -gt 0; do
case $1 in
--maintenance | -m )
MAINTENANCE="YES"
;;
--file | --fil | --fi | --f | -file | -fil | -fi | -f )
shift
CONFIGFILENAME="$1"
@@ -36,7 +43,11 @@ while test $# -gt 0; do
;;
--wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w )
shift
WORKING_DIRECTORY="$1"
if [ "$1" = "." ]; then
WORKING_DIRECTORY="$PWD"
else
WORKING_DIRECTORY="$1"
fi
;;
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
usage_and_exit 0
@@ -47,6 +58,7 @@ while test $# -gt 0; do
exit 0
;;
--dbg | --db | --d | -dbg | -db | -d )
shift
set_dbg_level $DEBUG
;;
-*)
@@ -58,25 +70,24 @@ while test $# -gt 0; do
esac
shift
done
if [ -z "$WORKING_DIRECTORY" ]; then
echo "WORKING_DIRECTORY empty. exiting..."
exit 1
fi
if [ ! -d "$WORKING_DIRECTORY" ]; then
echo "WORKING_DIRECTORY $WORKING_DIRECTORY does not exist! exiting..."
exit 1
fi
cd "$WORKING_DIRECTORY"
source ./update_psa_impl
if read_config
then
if clone_customer_repository $CUSTOMER_REPOSITORY_PATH
then
check_sanity_of_repository
#set_updates_available
#while :
#do
# sleep 5
# updates_available && break
#done
update_psa
fi
if read_config; then
update_psa
exit 0
fi
exit $EXIT_CODE
exit 1
###############################################################################

View File

@@ -6,24 +6,28 @@
"customer_location" : "szeged",
"" : "unique customer identifier",
"customer_id" : "281",
"customer_id" : "customer_281",
"" : "zone file for PSA",
"zone" : "/etc/zone_nr",
"" : "local branches",
"local_branches" : ["master",
"zg1/zone1", "zg1/zone2", "zg1/zone3", "zg1/zone4"],
"" : "customer number of PSA",
"customer_id_" : "/etc/cust_nr",
"" : "machine id of PSA",
"machine_nr" : "/etc/mach_nr",
"machine_nr" : "/etc/machine_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] } ],
"zg" : [ 1, { "z" : [ 4, 1, 2, 4] } ],
"" : "url of customer repository",
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann"
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_281.git"
}

View File

@@ -24,9 +24,12 @@ exec_opkg_command () {
# Fetch/merge updates from predefined repository using git.
#
fetch_customer_updates() {
if ! pull_customer_repository $1; then
local func="${FUNCNAME[0]}"
if ! pull_customer_repository; then
log_warn "$func:${LINENO} NO pull_customer_repository"
return 1
fi
log_debug "$func:${LINENO} pull_customer_repository SUCCESS"
return 0
}
@@ -41,6 +44,18 @@ copy () {
if [[ "$f" =~ .*update[.]conf.* ]]; then
continue
fi
# TODO: szeged darf nicht sein
# local readonlt __cl=$CUSTOMER_LOCATION
# local readonly __q="'"
# xxx='$('"echo $f | sed -E -e ${__q}s=(.*$__cl/[0-9]/[0-9])(.*)(/.*)=\2=g$__q"')'
# 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
@@ -49,44 +64,53 @@ copy () {
local readonly __f=${f##*/}
local readonly __m="${CUSTOMER_ID_BASE_DIR}/${f}"
local __p=""
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 "^.*[.]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
#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
@@ -158,68 +182,26 @@ check_md5_for_changed_json_and_ini_files () {
readarray -td' ' files <<< "$1"
local readonly __cl=$CUSTOMER_LOCATION
for file in ${files[@]}; do
# .../szeged/1/1...
log_debug "$func:${LINENO} checking file=${file}..."
local __fsuffix=${file##*.}
local __bn=$(basename $file .$__fsuffix)
if [[ "$file" =~ .*dc2c.hex.* ]]; then
js_key=".dc.dc2c.$__bn"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
elif [[ "$file" =~ .*cash[.]json.* ]]; then
js_key=".conf.$__cl.zg[1].z[1].etc.psa_config.$__bn"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
elif [[ "$file" =~ .*print[0-9][0-9][.]json.* ]]; then
js_key=".conf.$__cl.zg[1].z[1].etc.psa_config.$__bn"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
elif [[ "$file" =~ .*conf[.]json.* ]]; then
js_key=".conf.$__cl.zg[1].z[1].etc.psa_config.DC2C_conf"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
elif [[ "$file" =~ .*serial[.]json.* ]]; then
js_key=".conf.$__cl.zg[1].z[1].etc.psa_config.DC2C_serial"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
elif [[ "$file" =~ .*atb/ATBQT[.]ini.* ]]; then
js_key=".ini.$__cl.zg[1].z[1].etc.atb.ATBQT"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $ATB_ATBQT_INI_FULL)"
elif [[ "$file" =~ .*ATBQT[.]ini.* ]]; then
js_key=".ini.$__cl.zg[1].z[1].opt.app.ATBAPP.ATBQT"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $ATBQT_INI_FULL)"
elif [[ "$file" =~ .*atb/sysconfig[.]ini.* ]]; then
js_key=".ini.$__cl.zg[1].z[1].etc.atb.sysconfig"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $ATB_SYSCONFIG_INI_FULL)"
elif [[ "$file" =~ .*sysconfig[.]ini.* ]]; then
js_key=".ini.$__cl.zg[1].z[1].opt.app.sysconfig.sysconfig"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository=$(md5_of $SYSCONFIG_SYSCONFIG_INI_FULL)
elif [[ "$file" =~ .*atb/SystemControl[.]ini.* ]]; then
js_key=".ini.$__cl.zg[1].z[1].etc.atb.SystemControl"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $ATB_SYSCTRL_INI_FULL)"
elif [[ "$file" =~ .*SystemControl[.]ini.* ]]; then
js_key=".ini.$__cl.zg[1].z[1].opt.app.sysconfig.SystemControl"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository=$(md5_of $SYSCONFIG_SYSCTRL_INI_FULL)
elif [[ "$file" =~ .*atb/ISMASMgr[.]ini.* ]]; then
js_key=".ini.$__cl.zg[1].z[1].etc.atb.ISMASMgr"
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $ATB_ISMASMGR_INI_FULL)"
elif [[ "$file" =~ .*ISMASMgr/ISMASMgr[.]ini.* ]]; then
js_key=".ini.$__cl.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_FULL)
elif [[ "$file" =~ .*sysconfig/ISMASMgr[.]ini.* ]]; then
js_key=".ini.$__cl.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_FULL)
else
continue
fi
local __fs=${file##*.}
js_key=""
case $file in
*.ini | *.json | *.hex)
local __key_suffix=$(echo $file |
sed -E -e 's=(.*[0-9]/[0-9])([^.]+)(.*)=\2=g' -e 's=/=.=g')
js_key=".$__fs.$__cl.zg[$ZONE_GROUP].z[$ZONE]$__key_suffix"
md5sum_update_conf=$(cat $PSA_UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
;;
*)
log_crit "$func:${LINENO} unknown file=${file}"
;;
esac
test -z $js_key && continue
PERCENT=$((PERCENT+1))
test $PERCENT -gt 100 && PERCENT=100
@@ -394,8 +376,45 @@ cleanup_previous_version() {
return 0
}
check_for_apism () {
nc localhost 7778
check_for_running_apism () {
local func="${FUNCNAME[0]}"
if nc localhost 7777
then
APISM_RUNNING=1
log_info "$func:${LINENO}: APISM is running..."
return 0
fi
log_fatal "$func:${LINENO}: !!! APISM NOT RUNNING !!!"
}
check_default_route () {
local func="${FUNCNAME[0]}"
if ip route | head -n 1 | grep -q '^default'
then
log_info "$func:${LINENO}: default route set"
return 0
fi
log_fatal "$func:${LINENO}: !!! NO DEFAULT ROUTE SET !!!"
}
check_route_to_repository () {
local func="${FUNCNAME[0]}"
# ip_address=$1, e.g. git.mimbach.de (185.191.219.134)
# 185.191.219.134 via 192.168.5.254 ...
if test "$#" -eq 1 && ip route get "$1" | head -n 1 | grep -q "^$1"
then
log_info "$func:${LINENO}: route to repository available"
return 0
fi
log_fatal "$func:${LINENO}: !!! NO ROUTE TO REPO SET !!!"
}
get_customer_id () {
echo $(cat CUST_ID_FILE)
}
get_zone_nr () {
echo $(cat ZONE_FILE)
}
get_plugins () {

View File

@@ -13,10 +13,13 @@ trap collect_current_configuration EXIT
collect_current_configuration () {
local func="${FUNCNAME[0]}"
$FATAL_FAILURE && return 1
# TODO: eventuell muss die version neu berechnet werden
current_settings_to_ismas
#for line in $(cat $UPDATE_CONF |\
# jq -r .conf.szeged.zg[1].z[1].etc.psa_config)
#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')"
@@ -28,148 +31,62 @@ collect_current_configuration () {
}
update_psa() {
if ! updates_available; then # check for false alarm
update_psa_false_alarm "update requested, but no WAIT state detected"
exit $?
fi
update_psa_activated # message to ISMAS
local try_update_count=0
local func="${FUNCNAME[0]}"
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"
update_psa_false_alarm \
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
exit $?
fi
try_updates_count=$((try_updates_count+1))
if [[ "$try_updates_count" -eq 5 ]]; then
log_error "$func:${LINENO}: fetch/merging failed"
update_psa_pull_error # message to ISMAS
exit $?
fi
update_psa_pull_error # message to ISMAS
sleep 10s
else
# Fetched updates successfully
try_updates_count=0
break
fi
done
update_psa_pull_customer_repository # message to ISMAS
# 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
update_psa_backup_error # message to ISMAS
exit $?
fi
update_psa_backup # message to ISMAS
check_default_route
check_route_to_repository "185.191.219.134" # git.mimbach.de
# even for a git clone a running APISM is needed
check_for_running_apism
# TODO: use CLONE_CUSTOMER_REPOSITORY=true
# d.h. wird das rep geklont, also neu angelegt, dann sind eigentlich alle
# dateinen zu ueberpruefen
# an initial clone of the customer-repository (e.g. customer_281) is
# always possible, even without a ISMAS-WAIT-button
clone_customer_repository ${CUSTOMER_REPOSITORY_PATH}
check_sanity_of_repository
$INITIAL_CLONE && return 0
local changed_files=$(changed_file_names)
local files_to_copy=$(filter_changed_files "$changed_files" 'json|ini|hex')
local ismas_requests=0
update_psa_report_changed_file_names $changed_files # message to ISMAS
# check if *.conf and/or *.ini-files have to md5-sum as denoted
# in update.conf
if ! check_md5_for_changed_json_and_ini_files "$files_to_copy" ; then
local __r=$?
log_error "$func:${LINENO}: new customer files wrong"
revert_customer_repository
exit $__r
fi
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
# copy *.conf and/or *.ini-files to their corresponding system-directories
if ! copy $files_to_copy; then
local __r=$?
log_error "$func:${LINENO}: copy operation failed"
revert_customer_repository
exit $__r
fi
# check if the opkg-command-file has been changed during 'git pull'
if grep -qE ".*opkg_commands.*?" <<< $changed_files; then
# read opkg_cmds: each line respresents an opkg-command
readarray opkg_commands < <(cat $opkg_cmds_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
if [ "$MAINTENANCE" = "NO" ]; then
log_info "${func}:${LINENO}: MAINTENANCE OFF. Checking for updates..."
# someone must have activated the WAIT-button in ISMAS.
# Request the status of this button in updates_available().
while [ $ismas_requests -le 3 ]; do
ismas_requests=$(( $ismas_requests + 1 ))
updates_available && break
update_psa_false_alarm "update requested, but no WAIT state detected <$ismas_requests>"
done
if [ $ismas_requests -gt 3 ]; then
log_fatal "update_psa:${LINENO}: update requested, but no WAIT state detected !!!"
fi
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"
log_info "${func}:${LINENO}: MAINTENANCE ON. Emulate ISMAS updates..."
# simulate an activated WAIT-button in ISMAS
set_updates_available
while [ $ismas_requests -le 10 ]; do
sleep 5
updates_available && break
ismas_requests=$(( $ismas_requests + 1 ))
log_info "${func}:${LINENO}: updates_requested <$ismas_requests>"
done
if [ $ismas_requests -gt 10 ]; then
log_fatal "${func}:${LINENO}: NO ISMAS UPDATES AVAILABLE"
fi
fi
update_psa_cleanup $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "cleanup after psa update"
log_debug "$func:${LINENO}: before fetch/merge updates..."
# Fetch new updates (using git). but only when repository has already been
# cloned.
if ! fetch_customer_updates; then
update_psa_false_alarm \
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
log_fatal "$func:${LINENO}: fetch no data for $customer_id"\
"-> no files to update -> no psa update"
else
log_debug "$func:${LINENO}: after successful fetch_customer_repository..."
fi
exit 0
update_psa_pull_customer_repository # message to ISMAS
}