From c428602aa8af953696c374e693324e1e4ef6c305 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 2 Jun 2022 22:24:11 +0200 Subject: [PATCH] Added check_atbqt_version plus helper functions --- opkg.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/opkg.sh b/opkg.sh index 62ef5b9..5c0aa84 100755 --- a/opkg.sh +++ b/opkg.sh @@ -148,12 +148,8 @@ write_config() { echo "$data" > "${path}/$2" # echo $(cat "/tmp/test.txt" | jq -C --indent 4 '.') > /tmp/test2.txt } - # write_config "/home/root/szeged/customer_281/szeged/1/1/" "test.txt" - # x=$(cat "/home/root/szeged/customer_281/szeged/1/1/test.txt" | jq .opkg.atbqt) - #echo $x - # Download opkg-package. After the download, extract data.tar.gz to # access e.g. atbqt. download_opkg_package () { @@ -201,3 +197,83 @@ download_opkg_package () { } # download_opkg_package "atbqt" "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk" +ar_extract_opkg_package_data () { + return 0 + + cp $1 "/tmp" + # mv $1 "/tmp" + cd /tmp + # ar -x $1 + #if [ $? ne 0 ]; then + data_file="data.tar.xz" + if ! [ -f "$data_file" ]; then + printf "ERROR %s does not exist\n" "$data_file" >&2 + return 1 + fi + + cd - + return 0 + + tar -qxvf $data_file + + + echo $pwd +} +# ar_extract_opkg_package_data "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk" + +tar_extract_opkg_package_data () { + exec {ftar}< <(tar -xvf "$2" -C "$1") # use process substitution + cs_pid=$! + exec {ftar}>&- + wait $cs_pid + + binary="$1/$3" + if ! [ -f "$binary" ]; then + printf "ERROR %s does not exist\n" "$binary" >&2 + return 1 + fi + + return 0 +} +# tar_extract_opkg_package_data "/tmp" "data.tar.xz" "opt/app/ATBAPP/ATBQT" + +read_atbqt_version () { + version=$(/tmp/opt/app/ATBAPP/ATBQT -v) + version=(${version// / }) + + if [ ${#version[@]} -lt 7 ]; then + printf "ERROR %s has wrong format\n" "${version[@]}" >&2 + return 1 + fi + + version=("${version[3]}" "${version[6]}") + echo ${version[@]} +} +# xxx=`read_atbqt_version` +# echo $xxx + + +check_atbqt_version () { + if `download_opkg_package "atbqt" "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk"`; then + return 1 + fi + + if `ar_extract_opkg_package_data "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk"`; then + return 1 + fi + + if `tar_extract_opkg_package_data "/tmp" "data.tar.xz" "opt/app/ATBAPP/ATBQT"`; then + return 1 + fi + + version=`read_atbqt_version` + version=(${version// / }) + + if [ "${version[0]}" = "$1" ] && [ "${version[1]}" = "$2" ]; then + return 0 + fi + + return 1 +} +check_atbqt_version "20221220_1038_00318q" "4.5.2-65-gf1799aa3_00318/Nexobility_dev" +