445 lines
16 KiB
Plaintext
Executable File
445 lines
16 KiB
Plaintext
Executable File
# !/bin/bash -
|
|
|
|
source ./log_helpers
|
|
|
|
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
|
|
|
readonly APISM_DB_PORT=7777
|
|
readonly UPDATE_ISMAS_PROGRESS="U0010"
|
|
readonly UPDATE_SUCCEEDED="U0001" # update finished: 100%
|
|
readonly UPDATE_ACTIVATED="U0002" # reset TRG
|
|
readonly UPDATE_ISMAS_ERROR="U0003" # update error
|
|
|
|
# error codes
|
|
readonly RC_SUCCESS=0
|
|
readonly RC_NO_UPDATE_NECESSARY=1
|
|
readonly RC_GIT_CLONE_ERROR=2
|
|
readonly RC_GIT_PULL_ERROR=3
|
|
readonly RC_BACKUP_ERROR=4
|
|
readonly RC_HASH_VALUE_ERROR=5
|
|
readonly RC_HW_COMPATIBILITY_ERROR=6
|
|
readonly RC_COPY_ERROR=7
|
|
readonly RC_OPKG_COMMANDS_ERROR=8
|
|
readonly RC_CLEANUP_ERROR=9
|
|
|
|
PERCENT=1
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_activated () {
|
|
PERCENT=$((PERCENT+1))
|
|
local params=("U0010" # event
|
|
$PERCENT
|
|
$RC_SUCCESS # resultcode
|
|
"activated" # step
|
|
"detected WAIT state" # step_result
|
|
"") # version
|
|
news_to_ismas ${params[*]}
|
|
return $?
|
|
}
|
|
|
|
update_psa_false_alarm () {
|
|
PERCENT=$((PERCENT+1))
|
|
local params=("U0003"
|
|
$PERCENT
|
|
$RC_NO_UPDATE_NECESSARY
|
|
"false_alarm"
|
|
"$1"
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
update_psa_activated_new_software () {
|
|
PERCENT=100
|
|
local params=("U0010"
|
|
$PERCENT
|
|
$RC_SUCCESS
|
|
"activated_new_software"
|
|
"<hier nochmal eine liste was alles installiert wurde>"
|
|
"<zugehoerige versionen>")
|
|
news_to_ismas ${params[*]}
|
|
return $?
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_pull_customer_repository () {
|
|
PERCENT=10
|
|
local params=("U0010" # event
|
|
$PERCENT # percent
|
|
0 # resultcode
|
|
"pull_customer_repository" # step
|
|
"git pulled $CUSTOMER_REPOSITORY_PATH" # step_result
|
|
"") # version
|
|
news_to_ismas ${params[*]}
|
|
return $?
|
|
}
|
|
|
|
update_psa_pull_error () {
|
|
PERCENT=10
|
|
local params=("U0003"
|
|
$PERCENT
|
|
$RC_GIT_PULL_ERROR
|
|
"pull_error"
|
|
"git failed to pull $CUSTOMER_REPOSITORY_PATH"
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
update_psa_clone_error () {
|
|
PERCENT=10
|
|
local params=("U0003"
|
|
$PERCENT
|
|
$RC_GIT_CLONE_ERROR
|
|
"clone_error"
|
|
"git failed to clone $CUSTOMER_REPOSITORY_PATH"
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_backup () {
|
|
PERCENT=20
|
|
local params=("U0010"
|
|
$PERCENT
|
|
$RC_SUCCESS
|
|
"backup"
|
|
"backup of (hier noch alle dateien angeben)"
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
return $?
|
|
}
|
|
|
|
update_psa_backup_error () {
|
|
PERCENT=20
|
|
local params=("U0010"
|
|
$PERCENT
|
|
$RC_BACKUP_ERROR
|
|
"backup_error"
|
|
"backup of (hier noch alle dateien angeben) failed"
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_report_changed_file_names () {
|
|
PERCENT=30
|
|
local params=("U0010"
|
|
$PERCENT
|
|
$RC_SUCCESS
|
|
"report_changed_file_names"
|
|
"changed filenames: [$@]"
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
return $?
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_check_hash () {
|
|
PERCENT=40
|
|
local params=($1 # event
|
|
$PERCENT
|
|
$2 # resultcode
|
|
"check_hash" # step
|
|
"$3" # step_result
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
test $2 -eq $RC_SUCCESS && return $?
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_check_hardware_compatibility () {
|
|
PERCENT=50
|
|
local params=($1 # event
|
|
$PERCENT
|
|
$2 # resultcode
|
|
"check_hardware_compatibility" # step
|
|
"$3" # step_result
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
test $2 -eq $RC_SUCCESS && return $?
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
# conf/ini files
|
|
update_psa_copy_conf_and_ini_files () {
|
|
PERCENT=60
|
|
local params=($1 # event
|
|
$PERCENT
|
|
$2 # resultcode
|
|
"copy_conf_and_ini_files" # step
|
|
"$3" # step_result
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
test $2 -eq $RC_SUCCESS && return $?
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
# exec opkg-commands (dry-run)
|
|
update_psa_install_opkg_packages_dry_run () {
|
|
PERCENT=70
|
|
# TODO
|
|
return 0
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
# exec opkg-commands
|
|
update_psa_install_opkg_packages () {
|
|
PERCENT=80
|
|
local params=($1 # event
|
|
$PERCENT
|
|
$2 # resultcode
|
|
"install_opkg_packages" # step
|
|
"$3" # step_result
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
test $2 -eq $RC_SUCCESS && return $?
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
# remove backup in case of success
|
|
update_psa_cleanup () {
|
|
PERCENT=90
|
|
local params=($1 # event
|
|
$PERCENT
|
|
$2 # resultcode
|
|
"cleanup" # step
|
|
"$3" # step_result
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
test $2 -eq $RC_SUCCESS && return $?
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_update_succeeded () {
|
|
PERCENT=100
|
|
local params=($1 # event
|
|
$PERCENT
|
|
$2 # resultcode
|
|
"update_succeeded" # step
|
|
"$3" # step_result
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
test $2 -eq $RC_SUCCESS && return $?
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
update_psa_activate_update () {
|
|
PERCENT=100
|
|
local params=($1 # event
|
|
$PERCENT
|
|
$2 # resultcode
|
|
"activate_update" # step
|
|
"$3" # step_result
|
|
"")
|
|
news_to_ismas ${params[*]}
|
|
test $2 -eq $RC_SUCCESS && return $?
|
|
|
|
EXITCODE=$((EXITCODE+1))
|
|
test $EXITCODE -gt 125 && EXITCODE=125
|
|
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
|
|
return $EXITCODE
|
|
}
|
|
|
|
# only for testing
|
|
set_updates_available () {
|
|
local params=("U0099" # event
|
|
$PERCENT # percent
|
|
0 # resultcode
|
|
"set_updates_available" # step
|
|
"" # step_result
|
|
"") # version
|
|
news_to_ismas ${params[*]}
|
|
return $?
|
|
}
|
|
|
|
set_update_active () {
|
|
reset_update_trigger
|
|
return $?
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
news_to_ismas () {
|
|
# $1: EVENT: U0001 update finished: 100%
|
|
# U0002 reset TRG
|
|
# U0003 error
|
|
# U0010 for update process
|
|
# $2: PERCENT : "only for ISMAS: 0-100%",
|
|
# $3: RESULTCODE : "only for ISMAS",
|
|
# 0: Success
|
|
# 1: no Update nessesary
|
|
# 2: Backup failed
|
|
# 3: Package error/ Wrong package
|
|
# 4: Install Error
|
|
# $4: STEP : "running step (only for us): update_psa...",
|
|
# $5: STEP_RESULT : "error and result text",
|
|
# $6: VERSION : "opkg and conf info; what will be updated"
|
|
#
|
|
local func="${FUNCNAME[0]}"
|
|
local p=("$@")
|
|
local data="#M=APISM#C=CMD_EVENT#J=
|
|
{
|
|
\"REASON\":\"SW_UP\",
|
|
\"TIMESTAMP\":\"$(date +%Y-%m-%dT%T.000%z)\",
|
|
\"EVENT_ID\":\"0\",
|
|
\"EVENT\":\"${p[0]}\",
|
|
\"EVENTSTATE\":1,
|
|
\"PARAMETER\": {
|
|
\"PERCENT\" : ${p[1]},
|
|
\"RESULTCODE\" : ${p[2]},
|
|
\"STEP\" : \"update_psa_${p[3]}\",
|
|
\"STEP_RESULT\" : \"${p[4]}\",
|
|
\"VERSION\" : \"$VERSION\"
|
|
}
|
|
}"
|
|
log_debug "$func:${LINENO}: data=$data"
|
|
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
|
|
}
|
|
|
|
#
|
|
# send current psa setting to ismas at end of update procedure
|
|
#
|
|
current_settings_to_ismas () {
|
|
local func="${FUNCNAME[0]}"
|
|
local p=("$@")
|
|
|
|
return 0
|
|
|
|
local data="#M=APISM#C=CMD_SENDVERSION#J=
|
|
{
|
|
\"VERSION_INFO\" : {
|
|
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
|
|
\"HASH\":\"$(compute_hash)\"
|
|
},
|
|
\"TARIFF\": {
|
|
$(<$TC_PSA_TC_FILE)
|
|
},
|
|
\"HARDWARE\" : {
|
|
\"DEVICES\" : [
|
|
\"PTU5\", \"DC\", \"PRINTER\", \"BNA\"
|
|
]
|
|
},
|
|
\"OS\" : {
|
|
\"$(uname)\": \"$(uname -a)\"
|
|
},
|
|
\"CONFIG\" : {
|
|
\"PTU5\" : {
|
|
\"CPU_SERIAL\" : \"$(cat /proc/cpuinfo |
|
|
grep Serial |
|
|
sed -E -e 's/.*:\s*(.*)/\1/g')\"
|
|
},
|
|
\"DC\" : {
|
|
\"VERSION\" : \"$(cat $PSA_UPDATE_CONF | jq -r .dc.version)\",
|
|
\"MD5SUM\" : \"$(cat $PSA_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 EXITCODE=$EXITCODE"
|
|
|
|
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
|
|
|
|
# if [ $EXITCODE -eq $RC_SUCCESS ]; then
|
|
update_psa_update_succeeded $UPDATE_SUCCEEDED \
|
|
$RC_SUCCESS "psa update succeeded" $VERSION
|
|
|
|
update_psa_update_succeeded $UPDATE_ACTIVATED \
|
|
$RC_SUCCESS "psa update activated" $VERSION
|
|
|
|
log_info "$func:${LINENO}: success"
|
|
# fi
|
|
}
|
|
fi
|