Added exec_opkg_command(). Added check_md5-functions. Added exec_opkg_info(). Renamed do_update() to exec_opkg. Renamed do_update_dry_run() to exec_opkg_no_action().
This commit is contained in:
		@@ -6,11 +6,32 @@
 | 
			
		||||
#    return 0
 | 
			
		||||
#fi
 | 
			
		||||
 | 
			
		||||
exec_opkg_command () {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    
 | 
			
		||||
    log_debug "$func:${LINENO} exec-ing [$*]"
 | 
			
		||||
 | 
			
		||||
    exec {fd}< <($@)
 | 
			
		||||
    local ps_pid=$!             # remember pid of process substitution
 | 
			
		||||
 | 
			
		||||
    local opkg_result=""
 | 
			
		||||
    while read tmp <&$fd; do
 | 
			
		||||
        if ! [ -z "$tmp" ]; then
 | 
			
		||||
            opkg_result="${opkg_result}$tmp"
 | 
			
		||||
        fi
 | 
			
		||||
    done
 | 
			
		||||
        
 | 
			
		||||
    exec {fd}>&-                # close fd (i.e. process substitution)
 | 
			
		||||
    wait $ps_pid                # wait for the subshell to finish
 | 
			
		||||
 | 
			
		||||
    printf '%s' "$opkg_result"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Fetch/merge updates from predefined repository using git.
 | 
			
		||||
# 
 | 
			
		||||
fetch_customer_updates() {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    if ! pull_customer_repository customer_281; then
 | 
			
		||||
    if ! pull_customer_repository $1; then
 | 
			
		||||
        return 1
 | 
			
		||||
    fi
 | 
			
		||||
    return 0
 | 
			
		||||
@@ -19,8 +40,37 @@ fetch_customer_updates() {
 | 
			
		||||
# Check if the fetched/merged files have the correct md5 and are
 | 
			
		||||
# valid for the PSA.
 | 
			
		||||
#
 | 
			
		||||
check_new_customer_files() {
 | 
			
		||||
check_md5_for_changed_customer_files () {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    #for file in ($1); do
 | 
			
		||||
        # Check the updates for correct MD5
 | 
			
		||||
        # log_error "$func:${LINENO}: new customer files wrong"
 | 
			
		||||
        #    revert_customer_repository ; exit 1
 | 
			
		||||
        # fi
 | 
			
		||||
    #done
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
check_md5_for_opkg_packages () {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    local -n opkg_output_ref=$1
 | 
			
		||||
    local package=""
 | 
			
		||||
    local md5sum=""
 | 
			
		||||
    local filename=""
 | 
			
		||||
    for line in ${opkg_output_ref[@]}; do
 | 
			
		||||
        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"
 | 
			
		||||
        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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -34,22 +84,59 @@ revert_customer_repository() {
 | 
			
		||||
 | 
			
		||||
# Backup before the update-process. 
 | 
			
		||||
#
 | 
			
		||||
backup_previous_version() {
 | 
			
		||||
backup_previous_version () {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exec_opkg_info () {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    log_info "$func:${LINENO}: executing $opkg_command"
 | 
			
		||||
    
 | 
			
		||||
    opkg_result=$(exec_opkg_command "opkg info $1")
 | 
			
		||||
    
 | 
			
		||||
    # 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
 | 
			
		||||
    
 | 
			
		||||
    log_info "$func:${LINENO}: ... done"
 | 
			
		||||
    log_info "$func:${LINENO}: opkg_result=${output_ref[@]}"
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Try to install new opkg-packages (in case the are some
 | 
			
		||||
# in the new git-checkout).
 | 
			
		||||
#
 | 
			
		||||
do_update_dry_run() {
 | 
			
		||||
exec_opkg_no_action() {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    local opkg_command_no_action="opkg --noaction $1"
 | 
			
		||||
    log_info "$func:${LINENO}: executing $opkg_command_no_action"
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Install the new packages using opkg. 
 | 
			
		||||
#
 | 
			
		||||
do_update() {
 | 
			
		||||
exec_opkg () {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user