wackman/validatevhd.sh
2025-09-14 21:33:21 +02:00

34 lines
No EOL
1.3 KiB
Bash
Executable file

#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <profile>"
exit 1
fi
profile="$1"
while IFS=, read -r version backingversion url
do
vhd=$(basename "$url" | sed -E "s/.app/.vhd/")
if [ -f "images/vhd/$vhd" ]; then
input=$(vhdiinfo images/vhd/$vhd)
identifier=$(echo "$input" | grep -i "Identifier" | head -1 | awk '{print $NF}')
parent_identifier=$(echo "$input" | grep -i "Parent identifier" | awk '{print $NF}')
parent_filename=$(echo "$input" | grep -i "Parent filename" | awk -F': ' '{print $2}')
if [ -n "$(printf "%s" "$parent_filename" | tr -d '\000-\177')" ]; then
echo "Parent filename contains non-ASCII characters"
str=$(strings -e l images/vhd/$vhd | head -n 1)
be=$(echo -n $str | iconv -f UTF-8 -t UTF-16BE | xxd -p -c1 | tr -d '\n ' | sed 's/../\\x&/g')
le=$(echo -n $str | iconv -f UTF-8 -t UTF-16LE | xxd -p -c1 | tr -d '\n ' | sed 's/../\\x&/g')
mv images/vhd/$vhd images/vhd/$vhd.old
bbe -e "s/$le/$be/" images/vhd/$vhd.old | pv -s $(stat --printf="%s" images/vhd/$vhd.old) > images/vhd/$vhd
echo $parent_filename
else
echo "Parent filename contains only ASCII characters"
fi
else
echo "images/vhd/$vhd not found"
fi
done < profiles/$profile/apps.csv