Added update_psa-ismas messages

This commit is contained in:
Gerhard Hoffmann 2022-06-04 21:47:04 +02:00
parent d351f4485c
commit 6bc2854e78

View File

@ -3,121 +3,350 @@
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
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\":\"$1\",
\"TIMESTAMP\":\"$(date +%Y-%m-%dT%T.000%z)\",
\"EVENT_ID\":\"0\",
\"EVENT\":\"${p[0]}\",
\"EVENTSTATE\":1,
\"PARAMETER\":\"Testdaten\"
\"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)
}
# WAIT
###########################################################################
###########################################################################
update_psa_activated () {
news_to_ismas "U0010"
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
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 $?
}
###########################################################################
###########################################################################
# git pull
update_psa_pull_customer_repository () {
# text im PARAMETER?
news_to_ismas "U0011" "git 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
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
return $EXITCODE
}
###########################################################################
###########################################################################
update_psa_backup () {
news_to_ismas "U0011" "backup before update steps"
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
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_values () {
news_to_ismas "U0011" "checking file integrity"
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
return $EXITCODE
}
###########################################################################
###########################################################################
update_psa_check_hardware_compatibility () {
news_to_ismas "U0011" "check hardware compatiblity"
return $?
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
return $EXITCODE
}
###########################################################################
###########################################################################
# conf/ini files
update_psa_copy_files () {
news_to_ismas "U0011" "copy conf/ini-files"
return $?
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
return $EXITCODE
}
###########################################################################
###########################################################################
# exec opkg-commands (dry-run)
update_psa_install_packages_dry_run () {
news_to_ismas "U0011" "install opkg-packages (dry-run)"
return $?
update_psa_install_opkg_packages_dry_run () {
PERCENT=70
# TODO
return 0
}
###########################################################################
###########################################################################
# exec opkg-commands
update_psa_install_packages () {
news_to_ismas "U0011" "install opkg-packages"
return $?
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
return $EXITCODE
}
###########################################################################
###########################################################################
# remove backup in case of success
update_psa_cleanup () {
news_to_ismas "U0011" "cleanup"
return $?
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
return $EXITCODE
}
update_psa_finished () {
news_to_ismas "U0012"
return $?
###########################################################################
###########################################################################
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
return $EXITCODE
}
# results
update_psa_succeeded () {
news_to_ismas "U0001" "updates installed"
return $?
###########################################################################
###########################################################################
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
return $EXITCODE
}
reset_update_trigger () {
news_to_ismas "U0002" "updates activated"
return $?
}
update_psa_canceled_no_updates_available () {
# text im PARAMETER?
news_to_ismas "U0003" # "No updates available, but 'WAIT' active. Missing check-in?"
return $?
}
update_psa_backup_failed () {
news_to_ismas "U0003" # "Backup failed"
return $?
}
update_psa_wrong_hash_values () {
news_to_ismas "U0003" # "Wrong hash value for file <xxx>. Missing check-in?"
return $?
}
update_psa_hardware_not_compatible () {
news_to_ismas "U0003" "conf/ini-file <xxx> and psa hardware <yyy> not compatible"
return $?
}
update_psa_opkg_command_failure () {
news_to_ismas "U0003" "opkg-command <xxx> failed"
return $?
}
update_psa_failed () {
news_to_ismas "U0003" "Unknown error"
return $?
}
# only for testing
set_updates_available () {
news_to_ismas "U0099"
local params=("U0099" # event
$PERCENT # percent
0 # resultcode
"set_updates_available" # step
"" # step_result
"") # version
news_to_ismas ${params[*]}
return $?
}