UpdateController/update_psa_impl

164 lines
5.5 KiB
Plaintext
Raw Normal View History

2022-06-02 16:06:17 +02:00
# !/bin/bash -
source ./general_utils
source ./log_helpers
source ./git_helpers
source ./update_psa_helpers
source ./read_config
2022-06-03 21:49:16 +02:00
source ./news_to_ismas
source ./news_from_ismas
2022-06-02 16:06:17 +02:00
update_psa() {
2022-06-04 21:47:52 +02:00
if ! updates_available; then # check for false alarm
update_psa_false_alarm "update requested, but no WAIT state detected"
exit $?
fi
update_psa_activated # message to ISMAS
2022-06-02 16:06:17 +02:00
local try_update_count=0
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO}: fetch/merge updates..."
# Fetch new updates (using git)
while :
do
local repository_is_already_up_to_date=""
if ! fetch_customer_updates repository_is_already_up_to_date; then
if [ "$repository_is_already_up_to_date" = "yes" ]; then
log_error "$func:${LINENO}: $customer_id is up-to-date"\
"-> no files to update -> no psa update"
2022-06-04 21:47:52 +02:00
update_psa_false_alarm \
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
exit $?
2022-06-02 16:06:17 +02:00
fi
try_updates_count=$((try_updates_count+1))
if [[ "$try_updates_count" -eq 5 ]]; then
2022-06-04 21:47:52 +02:00
log_error "$func:${LINENO}: fetch/merging failed"
update_psa_pull_error # message to ISMAS
exit $?
2022-06-02 16:06:17 +02:00
fi
2022-06-04 21:47:52 +02:00
update_psa_pull_error # message to ISMAS
sleep 10s
2022-06-02 16:06:17 +02:00
else
# Fetched updates successfully
try_updates_count=0
break
fi
done
2022-06-04 21:47:52 +02:00
update_psa_pull_customer_repository # message to ISMAS
2022-06-02 16:06:17 +02:00
# TODO: backup implementieren
# Backup before any updates in case some previous test was wrong
if ! backup_previous_version; then
log_error "$func:${LINENO}: backup failed"
2022-06-04 21:47:52 +02:00
revert_customer_repository
update_psa_backup_error # message to ISMAS
exit $?
2022-06-02 16:06:17 +02:00
fi
2022-06-04 21:47:52 +02:00
update_psa_backup # message to ISMAS
2022-06-03 21:49:16 +02:00
# TODO: use CLONE_CUSTOMER_REPOSITORY=true
# d.h. wird das rep geklont, also neu angelegt, dann sind eigentlich alle
# dateinen zu ueberpruefen
2022-06-02 16:06:17 +02:00
local changed_files=$(changed_file_names)
local conf_ini_files=$(filter_conf_ini_files "$changed_files")
2022-06-04 21:47:52 +02:00
update_psa_report_changed_file_names $changed_files # message to ISMAS
2022-06-02 16:06:17 +02:00
# check if *.conf and/or *.ini-files have to md5-sum as denoted
# in update.conf
if ! check_md5_for_changed_conf_and_ini_files "$conf_ini_files" ; then
2022-06-04 21:47:52 +02:00
local __r=$?
2022-06-02 16:06:17 +02:00
log_error "$func:${LINENO}: new customer files wrong"
2022-06-04 21:47:52 +02:00
revert_customer_repository
exit $__r
2022-06-02 16:06:17 +02:00
fi
2022-06-04 21:47:52 +02:00
if ! check_hardware_compatibility "$conf_ini_files" ; then
local __r=$?
log_error "$func:${LINENO}: conf/ini-files not fit for PSA"
revert_customer_repository
exit $__r
fi
2022-06-02 16:06:17 +02:00
# copy *.conf and/or *.ini-files to their corresponding system-directories
if ! copy $conf_ini_files; then
2022-06-04 21:47:52 +02:00
local __r=$?
2022-06-02 16:06:17 +02:00
log_error "$func:${LINENO}: copy operation failed"
2022-06-04 21:47:52 +02:00
revert_customer_repository
exit $__r
2022-06-02 16:06:17 +02:00
fi
# check if the opkg-command-file has been changed during 'git pull'
if grep -qE ".*opkg_commands.*?" <<< $changed_files; then
# read opkg_cmds: each line respresents an opkg-command
readarray opkg_commands < <(cat $opkg_cmds_file)
for opkg_c in "${opkg_commands[@]}"; do
if grep -qE "^\s*[#]+.*$" <<< $opkg_c; then
continue # found comment line
fi
# package manipulation commands without package:
local cwp="update|upgrade|clean"
# informational commands without package:
cwp="${cwp}|list|list-installed|list-upgradable"
if grep -qE "^.*\s+($cwp)\s+.*$" <<< $opkg_c; then
local p=$(printf '%s' "$opkg_c" | awk '{ print $NF }')
local opkg_output=()
if ! exec_opkg_info "$p" opkg_output; then
log_error "$func:${LINENO}: opkg info $opkg_c failed"
revert_customer_repository ; exit 1
fi
if ! check_md5_for_opkg_packages opkg_output; then
log_error "$func:${LINENO}: "\
"wrong md5sum for opkg packages"
revert_customer_repository ; exit 1
fi
fi
# perform a dry-run and check if everything might work as expected.
if ! exec_opkg_noaction $opkg_c; then
log_error "$func:${LINENO}: "\
"opkg --noaction $opkg_c failed"
fi
# Actually execute the opkg command
if ! exec_opkg $opkg_c; then
log_error "$func:${LINENO}: exec_opkg $opkg_c failed"
fallback_to_previous_version
revert_customer_repository ; exit 1
fi
done
else
2022-06-04 21:47:52 +02:00
log_info "$func:${LINENO}: no opkg commands to execute"
update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "no opkg commands to execute"
2022-06-02 16:06:17 +02:00
fi
# Cleanup.
if ! cleanup_previous_version; then
log_error "$func:${LINENO}: cleanup_previous_version failed"
fi
2022-06-04 21:47:52 +02:00
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"
2022-06-02 16:06:17 +02:00
log_info "$func:${LINENO}: success"
exit 0
}