UpdateController/news_to_ismas

455 lines
16 KiB
Plaintext
Raw Permalink Normal View History

2022-06-02 18:11:04 +02:00
# !/bin/bash -
source ./log_helpers
if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
readonly news_to_ismas_sourced=${BASH_SOURCE[0]}
2022-06-04 21:47:04 +02:00
readonly APISM_DB_PORT=7777
2022-06-04 21:47:04 +02:00
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
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
update_psa_activated () {
2022-06-04 21:47:04 +02:00
PERCENT=$((PERCENT+1))
local params=("U0010" # event
$PERCENT
$RC_SUCCESS # resultcode
"activated" # step
"detected WAIT state" # step_result
"") # version
news_to_ismas ${params[*]}
return $?
}
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
}
update_psa_activated_new_software () {
PERCENT=100
local params=("U0010"
$PERCENT
$RC_SUCCESS
"activated_new_software"
"<hier nochmal eine liste was alles installiert wurde>"
"<zugehoerige versionen>")
news_to_ismas ${params[*]}
return $?
}
###########################################################################
###########################################################################
update_psa_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 $?
}
2022-06-03 21:52:57 +02:00
update_psa_pull_customer_repository () {
2022-06-04 21:47:04 +02:00
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 $?
}
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
}
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
update_psa_backup () {
2022-06-04 21:47:04 +02:00
PERCENT=20
local params=("U0010"
$PERCENT
$RC_SUCCESS
"backup"
"backup of (hier noch alle dateien angeben)"
"")
news_to_ismas ${params[*]}
return $?
}
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
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[*]}
2022-06-03 21:52:57 +02:00
return $?
}
2022-06-04 21:47:04 +02:00
###########################################################################
###########################################################################
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
}
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
update_psa_check_hardware_compatibility () {
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
2022-06-03 21:52:57 +02:00
}
2022-06-04 21:47:04 +02:00
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
# conf/ini files
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
2022-06-03 21:52:57 +02:00
}
2022-06-04 21:47:04 +02:00
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
# exec opkg-commands (dry-run)
2022-06-04 21:47:04 +02:00
update_psa_install_opkg_packages_dry_run () {
PERCENT=70
# TODO
return 0
2022-06-03 21:52:57 +02:00
}
2022-06-04 21:47:04 +02:00
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
# exec opkg-commands
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
2022-06-03 21:52:57 +02:00
}
2022-06-04 21:47:04 +02:00
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
# remove backup in case of success
update_psa_cleanup () {
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
2022-06-03 21:52:57 +02:00
}
2022-06-04 21:47:04 +02:00
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
}
2022-06-04 21:47:04 +02:00
###########################################################################
###########################################################################
2022-06-03 21:52:57 +02:00
2022-06-04 21:47:04 +02:00
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
2022-06-05 15:28:55 +02:00
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
2022-06-04 21:47:04 +02:00
return $EXITCODE
2022-06-03 21:52:57 +02:00
}
# only for testing
set_updates_available () {
2022-06-04 21:47:04 +02:00
local params=("U0099" # event
$PERCENT # percent
0 # resultcode
"set_updates_available" # step
"" # step_result
"") # version
news_to_ismas ${params[*]}
2022-06-03 21:52:57 +02:00
return $?
}
set_update_active () {
reset_update_trigger
return $?
}
2022-06-02 21:51:22 +02:00
###########################################################################
###########################################################################
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]}\",
2022-06-02 16:02:38 +02:00
\"VERSION\" : \"$VERSION\"
2022-06-02 21:51:22 +02:00
}
}"
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=("$@")
2022-06-02 21:51:22 +02:00
local data="#M=APISM#C=CMD_SENDVERSION#J=
{
2022-06-05 15:28:55 +02:00
\"VERSION_INFO\" : {
2022-06-02 16:02:38 +02:00
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
\"HASH\":\"$(compute_hash)\"
2022-06-05 15:28:55 +02:00
},
\"TARIFF\" : {
2022-06-02 21:51:22 +02:00
},
\"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\" : {
2022-06-06 20:08:31 +02:00
\"VERSION\" : \"$(compute_hash ${DC_PSA_DC_FILE})\",
\"MD5SUM\" : \"\"
2022-06-02 21:51:22 +02:00
},
\"PRINTER\" : {
},
\"BNA\" : {
}
},
\"SOFTWARE\": {
\"RAUC\" : \"$(rauc --version)\",
\"OPKG\" : \"$(opkg --version)\",
\"ATBQT\" : {
\"VERSION\" : \"$(/opt/app/ATBAPP/ATBQT -v |
grep Version |
2022-06-02 21:51:22 +02:00
sed -E -e 's/.*:\s*(.*)/\1/g')\",
\"GIT_DESCRIBE\" : \"$(/opt/app/ATBAPP/ATBQT -v |
grep git |
2022-06-02 21:51:22 +02:00
sed -E -e 's/.*:\s*(.*)/\1/g')\"
},
\"PLUGINS\" : {
$(get_plugins)
}
}
}"
2022-06-05 15:28:55 +02:00
log_debug "$func:${LINENO}: data=$data EXITCODE=$EXITCODE"
2022-06-02 21:51:22 +02:00
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
2022-06-02 16:02:38 +02:00
2022-06-02 21:51:22 +02:00
# if [ $EXITCODE -eq $RC_SUCCESS ]; then
update_psa_update_succeeded $UPDATE_SUCCEEDED \
2022-06-02 16:02:38 +02:00
$RC_SUCCESS "psa update succeeded" $VERSION
2022-06-02 21:51:22 +02:00
update_psa_update_succeeded $UPDATE_ACTIVATED \
2022-06-02 16:02:38 +02:00
$RC_SUCCESS "psa update activated" $VERSION
2022-06-02 21:51:22 +02:00
log_info "$func:${LINENO}: success"
# fi
}
fi