392 lines
13 KiB
Plaintext
Executable File
392 lines
13 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
|
|
|
|
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)
|
|
}
|
|
|
|
current_settings_to_ismas () {
|
|
local func="${FUNCNAME[0]}"
|
|
local p=("$@")
|
|
local data="#M=APISM#C=CMD_SENDVERSION#J=
|
|
{
|
|
\"TARIFF\": {
|
|
\"VERSION\" : \"\",
|
|
\"PROJECT\" : \"\",
|
|
\"ZONE\" : 0,
|
|
\"INFO\" : \"\"
|
|
},
|
|
\"HARDWARE\" : {
|
|
\"DEVICES\" : [
|
|
\"PTU5\", \"DC\", \"PRINTER\", \"BNA\"
|
|
]
|
|
},
|
|
\"OS\" : {
|
|
\"$(uname)\": \"$(uname -a)\"
|
|
},
|
|
\"CONFIG\" : {
|
|
\"PTU5\" : {
|
|
},
|
|
\"DC\" : {
|
|
},
|
|
\"PRINTER\" : {
|
|
},
|
|
\"BNA\" : {
|
|
}
|
|
}
|
|
}"
|
|
log_debug "$func:${LINENO}: data=$data"
|
|
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
|
|
}
|
|
|
|
###########################################################################
|
|
###########################################################################
|
|
|
|
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
|
|
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
|
|
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 () {
|
|
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 () {
|
|
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 () {
|
|
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_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_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
|
|
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
|
|
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
|
|
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
|
|
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 $?
|
|
}
|
|
fi
|