move update_psa to own file
This commit is contained in:
parent
34ffefd45f
commit
d890ff9f07
117
update_psa_impl
Executable file
117
update_psa_impl
Executable file
@ -0,0 +1,117 @@
|
||||
# !/bin/bash -
|
||||
|
||||
source ./general_utils
|
||||
source ./log_helpers
|
||||
source ./git_helpers
|
||||
source ./update_psa_helpers
|
||||
source ./read_config
|
||||
|
||||
update_psa() {
|
||||
local try_update_count=0
|
||||
local func="${FUNCNAME[0]}"
|
||||
|
||||
# read config parameters
|
||||
# read_config
|
||||
|
||||
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"
|
||||
exit 1
|
||||
fi
|
||||
try_updates_count=$((try_updates_count+1))
|
||||
if [[ "$try_updates_count" -eq 5 ]]; then
|
||||
log_error "$func:${LINENO}: fetch/merging failed" ; exit 1
|
||||
fi
|
||||
sleep 60s
|
||||
else
|
||||
# Fetched updates successfully
|
||||
try_updates_count=0
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 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"
|
||||
revert_customer_repository ; exit 1
|
||||
fi
|
||||
|
||||
local changed_files=$(changed_file_names)
|
||||
local conf_ini_files=$(filter_conf_ini_files "$changed_files")
|
||||
|
||||
# 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
|
||||
log_error "$func:${LINENO}: new customer files wrong"
|
||||
revert_customer_repository ; exit 1
|
||||
fi
|
||||
|
||||
# copy *.conf and/or *.ini-files to their corresponding system-directories
|
||||
if ! copy $conf_ini_files; then
|
||||
log_error "$func:${LINENO}: copy operation failed"
|
||||
revert_customer_repository ; exit 1
|
||||
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
|
||||
log_info "$func:${LINENO}: no opkg commnds to execute"
|
||||
fi
|
||||
|
||||
# Cleanup.
|
||||
if ! cleanup_previous_version; then
|
||||
log_error "$func:${LINENO}: cleanup_previous_version failed"
|
||||
fi
|
||||
|
||||
log_info "$func:${LINENO}: success"
|
||||
exit 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user