Compare commits

...

12 Commits

8 changed files with 224 additions and 87 deletions

View File

@ -173,7 +173,7 @@ pull_customer_repository () {
log_debug "$func:${LINENO} git-pull-result=${git_result}"
if grep -qE "^Already\s+\up\s+\to\s+date.*$" <<< "$git_result"; then
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

16
load_tariff Executable file
View File

@ -0,0 +1,16 @@
#! /bin/bash -
# set -x
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>"

View File

@ -24,43 +24,6 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
PERCENT=1
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\" : \"${p[5]}\"
}
}"
log_debug "$func:${LINENO}: data=$data"
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
}
###########################################################################
###########################################################################
@ -354,4 +317,109 @@ if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
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\" : \"${p[5]}\"
}
}"
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=
{
\"TARIFF\": {
$(<$TARIFF_CURRENT_FULL)
},
\"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\" : \"$(cat $UPDATE_CONF | jq -r .dc.version)\",
\"MD5SUM\" : \"$(cat $UPDATE_CONF | jq -r .dc.dc2c)\"
},
\"PRINTER\" : {
},
\"BNA\" : {
}
},
\"SOFTWARE\": {
\"RAUC\" : \"$(rauc --version)\",
\"OPKG\" : \"$(opkg --version)\",
\"ATBQT\" : {
\"VERSION\" : \"$($ATBQT_SYS_FULL -v |
grep Version |
sed -E -e 's/.*:\s*(.*)/\1/g')\",
\"GIT_DESCRIBE\" : \"$($ATBQT_SYS_FULL -v |
grep git |
sed -E -e 's/.*:\s*(.*)/\1/g')\"
},
\"PLUGINS\" : {
$(get_plugins)
}
}
}"
log_debug "$func:${LINENO}: data=$data"
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"
update_psa_update_succeeded $UPDATE_ACTIVATED \
$RC_SUCCESS "psa update activated"
log_info "$func:${LINENO}: success"
# fi
}
fi

View File

@ -33,7 +33,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
fi
EXITCODE=0
EXITCODE=$RC_SUCCESS
CLONE_CUSTOMER_REPOSITORY=false
# read config file (JSON syntax)
@ -118,8 +118,17 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
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"
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"
fi
# readonly zone_groups=(${__zone_groups[@]})
# by now (03.03.2023) there is only one zone group.
@ -146,8 +155,8 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
# TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
# TODO
readonly local __zone=1
readonly CUSTOMER_BASE_DIR="${CUSTOMER_BASE_DIRS[$__zone]}"
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"
@ -209,6 +218,15 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
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
@ -217,6 +235,15 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
else
log_fatal "$func:${LINENO}: $ATBQT_INI_FULL does not exist"
fi
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"

View File

@ -30,6 +30,10 @@ while test $# -gt 0; do
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"

View File

@ -8,6 +8,15 @@
"" : "unique customer identifier",
"customer_id" : "281",
"" : "zone file for PSA",
"zone" : "/etc/zone_nr",
"" : "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",

View File

@ -51,7 +51,11 @@ copy () {
local __m=""
local __copy_error=0
if grep -qE "^.*[.]json\s*$" <<< ${f}; then
if grep -qE "^.*$DC\s*$" <<< ${f}; then
__m="cp ${CUSTOMER_ID_BASE_DIR}/${f} to ${DC_SYS_DIR}/${__f}"
cp "${CUSTOMER_ID_BASE_DIR}/${f}" "${DC_SYS_DIR}/${__f}"
__copy_error=$?
elif grep -qE "^.*[.]json\s*$" <<< ${f}; then
__m="cp ${CUSTOMER_ID_BASE_DIR}/${f} to ${CONF_SYS_DIR}/${__f}"
cp "${CUSTOMER_ID_BASE_DIR}/${f}" "${CONF_SYS_DIR}/${__f}"
__copy_error=$?
@ -105,14 +109,14 @@ copy () {
return 0
}
filter_json_ini_files () {
filter_changed_files () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} $1"
readarray -td' ' files <<< "$1"
local __system_files=""
for f in ${files[@]}; do
log_debug "$func:${LINENO} $f"
if grep -qE "^.*[.](json|ini)\s*$" <<< $f; then
if grep -qE "^.*[.]($2)\s*$" <<< $f; then
if [ -z $__system_files ]; then
__system_files="${f}"
else
@ -142,47 +146,49 @@ check_md5_for_changed_json_and_ini_files () {
log_debug "$func:${LINENO} files=$1"
if ! [ -z $1 ]; then
readarray -td' ' files <<< "$1"
local readonly __cl=$CUSTOMER_LOCATION
for file in ${files[@]}; do
log_debug "$func:${LINENO} checking file=${file}..."
local __fsuffix=${file##*.}
local __bn=$(basename $file .$__fsuffix)
if [[ "$file" =~ .*cash[.]json.* ]]; then
js_key=".conf.szeged.zg[1].z[1].etc.psa_config.$__bn"
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.szeged.zg[1].z[1].etc.psa_config.$__bn"
echo "$js_key"
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.szeged.zg[1].z[1].etc.psa_config.DC2C_conf"
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.szeged.zg[1].z[1].etc.psa_config.DC2C_serial"
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" =~ .*ATBQT[.]ini.* ]]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.ATBAPP.ATBQT"
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" =~ .*sysconfig[.]ini.* ]]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.sysconfig"
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" =~ .*SystemControl[.]ini.* ]]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.SystemControl"
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" =~ .*ISMASMgr/ISMASMgr[.]ini.* ]]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.ISMASMgr.ISMASMgr"
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.szeged.zg[1].z[1].opt.app.sysconfig.ISMASMgr"
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
@ -366,3 +372,22 @@ check_for_apism () {
nc localhost 7778
}
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

View File

@ -12,20 +12,19 @@ trap collect_current_configuration EXIT
collect_current_configuration () {
local func="${FUNCNAME[0]}"
echo $func
return 0
current_settings_to_ismas
for line in $(cat $UPDATE_CONF |\
jq -r .conf.szeged.zg[1].z[1].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
#for line in $(cat $UPDATE_CONF |\
# jq -r .conf.szeged.zg[1].z[1].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() {
@ -87,20 +86,20 @@ update_psa() {
# dateinen zu ueberpruefen
local changed_files=$(changed_file_names)
local json_ini_files=$(filter_json_ini_files "$changed_files")
local files_to_copy=$(filter_changed_files "$changed_files" 'json|ini|hex')
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 "$json_ini_files" ; then
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 "$json_ini_files" ; then
if ! check_hardware_compatibility "$files_to_copy" ; then
local __r=$?
log_error "$func:${LINENO}: json/ini-files not fit for PSA"
revert_customer_repository
@ -108,7 +107,7 @@ update_psa() {
fi
# copy *.conf and/or *.ini-files to their corresponding system-directories
if ! copy $json_ini_files; then
if ! copy $files_to_copy; then
local __r=$?
log_error "$func:${LINENO}: copy operation failed"
revert_customer_repository
@ -168,20 +167,9 @@ update_psa() {
log_error "$func:${LINENO}: cleanup_previous_version failed"
fi
# TODO: nach (erfolgreichem) abschluss sollte man immer das aktuelle setting
# ans ISMAS schicken. ISMAS sollte immer wissen, was gerade auf dem
# Automaten steht.
update_psa_cleanup $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "cleanup after psa update"
update_psa_update_succeeded $UPDATE_SUCCEEDED \
$RC_SUCCESS "psa update succeeded"
update_psa_update_succeeded $UPDATE_ACTIVATED \
$RC_SUCCESS "psa update activated"
log_info "$func:${LINENO}: success"
exit 0
}