2022-06-13 19:44:01 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-06-02 18:19:05 +02:00
|
|
|
# set -x
|
|
|
|
|
|
|
|
compute_md5 () {
|
2022-06-02 20:08:44 +02:00
|
|
|
execdownload_opkg {fd}< <(md5sum "$1") # open fd readable for P.S.
|
2022-06-02 18:19:05 +02:00
|
|
|
cs_pid=$! # remember pid of P.S.
|
|
|
|
md5=""
|
|
|
|
while read t <&$fd; do
|
|
|
|
if ! [ -z "$t" ]; then
|
|
|
|
t=($t) # md5sum returns two values:
|
|
|
|
# the hash plus the filename
|
|
|
|
md5="${md5}$t"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exec {fd}>&- # close fd (i.e. process substitution)
|
|
|
|
wait $cs_pid # wait for the subshell to finish
|
|
|
|
echo $md5
|
|
|
|
}
|
|
|
|
|
|
|
|
md5_for_ini_files() {
|
|
|
|
ini_directory="$1"
|
|
|
|
ini_files=("ISMASMgr.ini" "sysconfig.ini" "SystemControl.ini")
|
|
|
|
|
|
|
|
local data="\"ini\": {"$'\n'
|
|
|
|
|
|
|
|
for f in "${ini_files[@]}"; do
|
|
|
|
ini_file=${ini_directory}/$f
|
|
|
|
md5=`compute_md5 $ini_file`
|
|
|
|
data+="\"$ini_file\":\"$md5\","
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$data" =~ ^.*,$ ]]; then
|
|
|
|
data=${data%?}
|
|
|
|
fi
|
|
|
|
|
|
|
|
data+="},"
|
|
|
|
echo $data
|
|
|
|
}
|
|
|
|
|
|
|
|
md5_for_conf_files() {
|
|
|
|
conf_directory="$1"
|
|
|
|
conf_files=("emp.conf" "printer.conf" "device.conf")
|
|
|
|
|
|
|
|
local data="\"conf\": {"$'\n'
|
|
|
|
|
|
|
|
for f in "${conf_files[@]}"; do
|
|
|
|
conf_file=${conf_directory}/$f
|
|
|
|
md5=`compute_md5 $conf_file`
|
|
|
|
data+="\"$conf_file\":\"$md5\","
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$data" =~ ^.*,$ ]]; then
|
|
|
|
data=${data%?}
|
|
|
|
fi
|
|
|
|
|
|
|
|
data+="},"
|
|
|
|
echo $data
|
|
|
|
}
|
|
|
|
|
2022-06-13 19:44:01 +02:00
|
|
|
write_config() {
|
|
|
|
local path="$1"
|
2022-06-02 18:19:05 +02:00
|
|
|
if [ "${path: -1}" == "/" ]; then # remove trailing '/'
|
|
|
|
path=${path%?}
|
|
|
|
fi
|
2022-06-13 19:44:01 +02:00
|
|
|
|
2022-06-02 18:19:05 +02:00
|
|
|
local data="{ "$'\n'
|
|
|
|
data+=`md5_for_ini_files "$path/opt/app/sysconfig"`
|
|
|
|
data+=`md5_for_conf_files "$path/etc/psa_config"`
|
|
|
|
data+="
|
|
|
|
\"opkg\" : {"
|
2022-06-13 19:44:01 +02:00
|
|
|
local cnt=0
|
|
|
|
for package_name in $(opkg list-installed); # list names of installed packages
|
|
|
|
do
|
|
|
|
if ! grep -q "^[a-zA-Z]" <<< $package_name; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$package_name" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
cnt=$((cnt+1))
|
|
|
|
|
|
|
|
printf "%3d:%s\n" "$cnt" "$package_name"
|
|
|
|
|
|
|
|
# Format of package info:
|
|
|
|
#
|
|
|
|
# Package: openssh-scp
|
|
|
|
# Version: 7.8p1+git-r0
|
|
|
|
# Depends: libc6 (>= 2.28), update-alternatives-opkg
|
|
|
|
# Status: install ok installed
|
|
|
|
# Section: console/network
|
|
|
|
# Architecture: cortexa9t2hf-neon
|
|
|
|
# Maintainer: Poky <poky@yoctoproject.org>
|
|
|
|
# MD5Sum: dfffcbb088cd5f180be5e9ee2ad030fe
|
|
|
|
# Size: 32700
|
|
|
|
# Filename: openssh-scp_7.8p1+git-r0_cortexa9t2hf-neon.ipk
|
|
|
|
# Source: openssh_7.8p1+git.bb
|
|
|
|
# Description: A suite of security-related network....
|
|
|
|
# Installed-Size: 58920
|
|
|
|
# Installed-Time: 1654699615
|
|
|
|
#
|
|
|
|
# process substitution (P.S):
|
|
|
|
# run 'opkg info' synchronously to parent script
|
|
|
|
|
|
|
|
exec {fd}< <(opkg info "$package_name") # open fd readable for P.S.
|
|
|
|
cs_pid=$! # remember pid of P.S.
|
|
|
|
|
|
|
|
while read package_info_line <&$fd; do
|
|
|
|
if [[ $package_info_line == Package* ]]; then
|
|
|
|
package=(${package_info_line// / })
|
|
|
|
package="\"${package[1]}\": {"
|
|
|
|
elif [[ $package_info_line == MD5Sum* ]]; then
|
|
|
|
md5sum=(${package_info_line// / })
|
|
|
|
md5sum="\"${md5sum[0]%?}\": \"${md5sum[1]}\","
|
|
|
|
elif [[ $package_info_line == Filename* ]]; then
|
|
|
|
filename=(${package_info_line// / })
|
|
|
|
filename="\"${filename[0]%?}\": \"${filename[1]}\","
|
|
|
|
elif [[ $package_info_line == Installed-Time* ]]; then
|
|
|
|
installed_time=(${package_info_line// / })
|
|
|
|
installed_time="\"${installed_time[0]%?}\": \"${installed_time[1]}\"
|
|
|
|
},"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exec {fd}>&- # close fd (i.e. process substitution)
|
|
|
|
wait $cs_pid # wait for the subshell to finish
|
|
|
|
|
|
|
|
# use 8 spaces
|
|
|
|
data="$data
|
|
|
|
$package
|
|
|
|
$md5sum
|
|
|
|
$filename
|
|
|
|
$installed_time"
|
2022-06-02 18:19:05 +02:00
|
|
|
|
|
|
|
# break
|
2022-06-13 19:44:01 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$data" =~ ^.*,$ ]]; then
|
|
|
|
data=${data%?}
|
|
|
|
fi
|
|
|
|
|
|
|
|
data="$data
|
|
|
|
}
|
|
|
|
}"
|
2022-06-02 18:19:05 +02:00
|
|
|
echo "$data" > "${path}/$2"
|
|
|
|
# echo $(cat "/tmp/test.txt" | jq -C --indent 4 '.') > /tmp/test2.txt
|
2022-06-13 19:44:01 +02:00
|
|
|
}
|
2022-06-02 20:08:44 +02:00
|
|
|
# write_config "/home/root/szeged/customer_281/szeged/1/1/" "test.txt"
|
2022-06-02 18:19:05 +02:00
|
|
|
|
2022-06-02 20:08:44 +02:00
|
|
|
# Download opkg-package. After the download, extract data.tar.gz to
|
|
|
|
# access e.g. atbqt.
|
|
|
|
download_opkg_package () {
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
atbqt) # hier weitere packete eintragen
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
printf "ERROR $1 has wrong format\n" >&2
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exec {fdd}< <(opkg --download-only download "$1") # open fd readable for P.S.
|
|
|
|
cs_pid=$! # remember pid of P.S.
|
|
|
|
|
|
|
|
opkg_result=""
|
|
|
|
while read result <&$fdd; do
|
|
|
|
if ! [ -z "$result" ]; then
|
|
|
|
opkg_result+="$result"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exec {fdd}>&- # close fd (i.e. process substitution)
|
|
|
|
wait $cs_pid # wait for the subshell to finish
|
|
|
|
|
|
|
|
if [ -z "$opkg_result" ]; then
|
|
|
|
printf "ERROR empty opkg_result\n" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -qF "$1" <<< $opkg_result; then
|
|
|
|
printf "ERROR opkg_result [$opkg_result] does not contain $1\n" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -qF "$2" <<< $opkg_result; then
|
|
|
|
printf "ERROR opkg_result [$opkg_result] does not contain $2\n" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# printf "%s\n" $opkg_result
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
# download_opkg_package "atbqt" "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk"
|
2022-06-13 19:44:01 +02:00
|
|
|
|
2022-06-02 22:24:11 +02:00
|
|
|
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"
|
|
|
|
|