Add helpers compute_md5, md5_for_ini_files and md5_for_conf_files

This commit is contained in:
Gerhard Hoffmann 2022-06-02 18:19:05 +02:00
parent bc118f2c81
commit 53fe8b65eb

90
opkg.sh
View File

@ -1,20 +1,75 @@
#!/bin/bash #!/bin/bash
# set -x
compute_md5 () {
exec {fd}< <(md5sum "$1") # open fd readable for P.S.
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
}
write_config() { write_config() {
local path="$1" local path="$1"
local data="{ if [ "${path: -1}" == "/" ]; then # remove trailing '/'
\"ini\" : { path=${path%?}
\"/opt/app/sysconfig/ISMASMgr.ini\" : \"d41d8cd98f00b204e9800998ecf8427e\", fi
\"/opt/app/sysconfig/sysconfig.ini\" : \"d41d8cd98f00b204e9800998ecf8427e\",
\"/opt/app/sysconfig/SystemControl.ini\" : \"d41d8cd98f00b204e9800998ecf8427e\"
},
\"conf\" : {
\"szeged/1/1/etc/psa_config/emp.conf\" : \"d41d8cd98f00b204e9800998ecf8427e\",
\"szeged/1/1/etc/psa_config/printer.conf\": \"d41d8cd98f00b204e9800998ecf8427e\",
\"szeged/1/1/etc/psa_config/device.conf\" : \"d41d8cd98f00b204e9800998ecf8427e\"
},
\"opkg\" : {"
local data="{ "$'\n'
data+=`md5_for_ini_files "$path/opt/app/sysconfig"`
data+=`md5_for_conf_files "$path/etc/psa_config"`
data+="
\"opkg\" : {"
local cnt=0 local cnt=0
for package_name in $(opkg list-installed); # list names of installed packages for package_name in $(opkg list-installed); # list names of installed packages
do do
@ -79,6 +134,8 @@ write_config() {
$md5sum $md5sum
$filename $filename
$installed_time" $installed_time"
# break
done done
if [[ "$data" =~ ^.*,$ ]]; then if [[ "$data" =~ ^.*,$ ]]; then
@ -88,10 +145,11 @@ write_config() {
data="$data data="$data
} }
}" }"
echo "$data" > "$path/test.txt" echo "$data" > "${path}/$2"
# echo $(cat "/tmp/test.txt" | jq -C --indent 4 '.') > /tmp/test2.txt
} }
ddd={ date -d @10000000 +'%Y'; } write_config "/home/root/szeged/customer_281/szeged/1/1/" "test.txt"
echo $ddd
# write_config "/tmp/customer_281/szeged" "test.txt"