147 lines
4.9 KiB
Plaintext
Executable File
147 lines
4.9 KiB
Plaintext
Executable File
# !/bin/bash -
|
|
|
|
source ./general_utils
|
|
source ./log_helpers
|
|
source ./git_helpers
|
|
source ./update_psa_helpers
|
|
source ./read_config
|
|
source ./news_to_ismas
|
|
source ./news_from_ismas
|
|
|
|
trap collect_current_configuration EXIT
|
|
|
|
collect_current_configuration () {
|
|
local func="${FUNCNAME[0]}"
|
|
|
|
# TODO: eventuell muss die version neu berechnet werden
|
|
current_settings_to_ismas
|
|
|
|
#for line in $(cat $PSA_UPDATE_CONF |\
|
|
# jq -r .conf.szeged.zg[$ZONE_GROUP].z[$ZONE].etc.psa_config)
|
|
#do
|
|
# conf_file="$(echo $line |
|
|
# sed -E -ne 's/^[^{}]\s+\"(DC2C_[[:alnum:]]+)\".*$/\1/gp')"
|
|
# if ! [ -z $conf_file ]; then
|
|
# local v=$(cat "$psa_config_dir/${conf_file}.json" | jq -r .version)
|
|
# echo "$conf_file.json version=$v"
|
|
# fi
|
|
#done
|
|
}
|
|
|
|
update_psa() {
|
|
|
|
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
|
|
|
|
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"
|
|
update_psa_false_alarm \
|
|
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
|
|
exit $?
|
|
fi
|
|
try_updates_count=$((try_updates_count+1))
|
|
if [[ "$try_updates_count" -eq 5 ]]; then
|
|
log_error "$func:${LINENO}: fetch/merging failed"
|
|
update_psa_pull_error # message to ISMAS
|
|
exit $?
|
|
fi
|
|
update_psa_pull_error # message to ISMAS
|
|
sleep 10s
|
|
else
|
|
# Fetched updates successfully
|
|
try_updates_count=0
|
|
break
|
|
fi
|
|
done
|
|
|
|
update_psa_pull_customer_repository # message to ISMAS
|
|
|
|
# no backup necessary as saved in git-repo
|
|
|
|
local changed_files=$(changed_file_names)
|
|
|
|
if ! check_hardware_compatibility "$files_to_copy" ; then
|
|
local __r=$?
|
|
log_error "$func:${LINENO}: json/ini-files not fit for PSA"
|
|
revert_customer_repository
|
|
exit $__r
|
|
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_PSA_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
|
|
log_info "$func:${LINENO}: no opkg commands to execute"
|
|
update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
|
|
$RC_SUCCESS "no opkg commands to execute"
|
|
fi
|
|
|
|
# Cleanup.
|
|
#if ! cleanup_previous_version; then
|
|
# log_error "$func:${LINENO}: cleanup_previous_version failed"
|
|
#fi
|
|
|
|
# compute version string for current (i.e. new) version
|
|
compute_version
|
|
|
|
update_psa_cleanup $UPDATE_ISMAS_PROGRESS \
|
|
$RC_SUCCESS "cleanup after psa update"
|
|
|
|
exit 0
|
|
}
|
|
|