check md5sums for opkg packages

This commit is contained in:
Gerhard Hoffmann 2022-06-04 18:16:10 +02:00
parent fab081d212
commit bc4977bf7f

View File

@ -13,9 +13,12 @@ exec_opkg_command () {
log_debug "$func:${LINENO} exec-ing [$*]"
local __result=$(exec_process_substitution $*)
local __result_code=$?
log_debug "$func:${LINENO} result=$__result"
printf '%s' "$__result"
return $__result_code
}
# Fetch/merge updates from predefined repository using git.
@ -46,23 +49,34 @@ check_md5_for_opkg_packages () {
local func="${FUNCNAME[0]}"
local -n opkg_output_ref=$1
local package=""
local md5sum=""
local md5sum_opkg_info=""
local filename=""
for line in ${opkg_output_ref[@]}; do
log_info "$func:${LINENO}: line=$line"
if grep -qE "^\s*Package\s*:.*?$" <<< "$line"; then
package=${line#*:* }
printf 'package=%s\n' "$package"
elif grep -qE "^\s*MD5Sum\s*:.*?$" <<< "$line"; then
md5sum=${line#*:* }
printf 'md5sum=%s\n' "$md5sum"
md5sum_opkg_info=${line#*:* }
elif grep -qE "^\s*Filename\s*:.*?$" <<< "$line"; then
filename=${line#*:* }
printf 'filename=%s\n' "$filename"
fi
done
log_debug "$func:${LINENO}: $package | $md5sum | $filename"
local __update_conf="${customer_location_dir}/update.conf"
md5sum_repo=$(cat $__update_conf | jq -r .opkg.${package}.MD5Sum)
if ! [ -z $md5sum_repo ]; then
if [ "$md5sum_opkg_info" = "$md5sum_repo" ]; then
log_info "$func:${LINENO}: md5 $md5sum_repo OK for $package"
return 0
else
log_error "$func:${LINENO}: md5sum_repo [$md5sum_repo] "\
"!= md5sum_opkg_info [$md5sum_opkg_info] for $package"
fi
else
log_error "$func:${LINENO}: md5sum_repo empty"
fi
return 1
}
# In case the new checked-out files are not correct, revert the git
@ -82,10 +96,10 @@ backup_previous_version () {
exec_opkg_info () {
local func="${FUNCNAME[0]}"
log_info "$func:${LINENO}: executing $opkg_command"
log_info "$func:${LINENO}: executing info $1"
opkg_result=$(exec_opkg_command "opkg info $1")
if [ $? -eq 0 ]; then
# make sure the keywords start with '\n'
opkg_result=$(sed -E -e "s/(^.*)(Package)(.*$)/\n\2\3/g"\
-e "s/(^.*)(Version)(.*$)/\1\n\2\3/g"\
@ -100,7 +114,8 @@ exec_opkg_info () {
-e "s/(^.*)(Installed-Size)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Section)(.*$)/\1\n\2\3/g"\
-e "s/(^.*[^-])(Size)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Installed-Time)(.*$)/\1\n\2\3/g" <<< "$opkg_result")
-e "s/(^.*)(Installed-Time)(.*$)/\1\n\2\3/g"
<<< "$opkg_result")
local -n output_ref=$2
@ -111,8 +126,12 @@ exec_opkg_info () {
fi
log_info "$func:${LINENO}: ... done"
log_info "$func:${LINENO}: opkg_result=${output_ref[@]}"
# log_info "$func:${LINENO}: opkg_result=${output_ref[@]}"
return 0
fi
log_error "$func:${LINENO}: executing info $1"
return 1
}
# Try to install new opkg-packages (in case the are some
@ -129,11 +148,16 @@ exec_opkg_no_action() {
#
exec_opkg () {
local func="${FUNCNAME[0]}"
log_info "$func:${LINENO}: executing $opkg_command"
local opkg_result=$(exec_opkg_command "opkg $1")
log_debug "$func:${LINENO}: executing $1"
local __opkg_result=$(exec_opkg_command "opkg $1")
if [ $? -eq 0 ]; then
log_info "$func:${LINENO}: opkg_result=$__opkg_result"
return 0
fi
log_error "$func:${LINENO}: error executing $1"
return 1
}
# In case there was some error, re-install the previous package(s)