diff --git a/update_psa_helpers b/update_psa_helpers index d9bde06..8760bf1 100755 --- a/update_psa_helpers +++ b/update_psa_helpers @@ -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" - return 0 + 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,37 +96,42 @@ 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"\ + -e "s/(^.*)(Depends)(.*$)/\1\n\2\3/g"\ + -e "s/(^.*)(Status)(.*$)/\1\n\2\3/g"\ + -e "s/(^.*)(Architecture)(.*$)/\1\n\2\3/g"\ + -e "s/(^.*)(Maintainer)(.*$)/\1\n\2\3/g"\ + -e "s/(^.*)(MD5Sum)(.*$)/\1\n\2\3/g"\ + -e "s/(^.*)(Filename)(.*$)/\1\n\2\3/g"\ + -e "s/(^.*)(Source)(.*$)/\1\n\2\3/g"\ + -e "s/(^.*)(Description)(.*$)/\1\n\2\3/g"\ + -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") + + local -n output_ref=$2 + + readarray -d $'\n' output_ref < <(printf '%s' "$opkg_result") + if [ $? -ne 0 ]; then + log_error "$func:${LINENO}: readarray finished with error" + return 1 + fi - # 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"\ - -e "s/(^.*)(Depends)(.*$)/\1\n\2\3/g"\ - -e "s/(^.*)(Status)(.*$)/\1\n\2\3/g"\ - -e "s/(^.*)(Architecture)(.*$)/\1\n\2\3/g"\ - -e "s/(^.*)(Maintainer)(.*$)/\1\n\2\3/g"\ - -e "s/(^.*)(MD5Sum)(.*$)/\1\n\2\3/g"\ - -e "s/(^.*)(Filename)(.*$)/\1\n\2\3/g"\ - -e "s/(^.*)(Source)(.*$)/\1\n\2\3/g"\ - -e "s/(^.*)(Description)(.*$)/\1\n\2\3/g"\ - -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") - - local -n output_ref=$2 - - readarray -d $'\n' output_ref < <(printf '%s' "$opkg_result") - if [ $? -ne 0 ]; then - log_error "$func:${LINENO}: readarray finished with error" - return 1 + log_info "$func:${LINENO}: ... done" + # log_info "$func:${LINENO}: opkg_result=${output_ref[@]}" + return 0 fi - - log_info "$func:${LINENO}: ... done" - log_info "$func:${LINENO}: opkg_result=${output_ref[@]}" - return 0 + + 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" + log_debug "$func:${LINENO}: executing $1" - local opkg_result=$(exec_opkg_command "opkg $1") + local __opkg_result=$(exec_opkg_command "opkg $1") + if [ $? -eq 0 ]; then + log_info "$func:${LINENO}: opkg_result=$__opkg_result" + return 0 + fi - return 0 + log_error "$func:${LINENO}: error executing $1" + return 1 } # In case there was some error, re-install the previous package(s)