Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam committed Aug 13, 2023
1 parent d395fa1 commit acdc83e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions internal/extra_ota.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ EXTRA_STAGING_JSON="$OTA_DIR/extra-staging.json"

process_file() {
local NAME=$1

local URL=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .url")
local HASH=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .hash")
local HASH_RAW=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .hash_raw")
local SIZE=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .size")
local SPARSE=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .sparse")
local FULL_CHECK=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .full_check")
local HAS_AB=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .has_ab")

local FILE_NAME="$NAME-$HASH_RAW.img"

local IMAGE_FILE="$OTA_DIR/$FILE_NAME"
if [ ! -f $IMAGE_FILE ]; then
local XZ_FILE="$IMAGE_FILE.xz"
if [ ! -f "$XZ_FILE" ]; then
local URL=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .url")
echo "Downloading $NAME..."
wget -O $XZ_FILE $URL
fi
Expand All @@ -35,7 +40,16 @@ process_file() {
xz --decompress --stdout $XZ_FILE > $IMAGE_FILE
fi

local HASH=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .hash")
local ACTUAL_SIZE=$(wc -c < $IMAGE_FILE)
if [ $ACTUAL_SIZE != $SIZE ]; then
echo "$NAME size mismatch!"
echo " Expected: $SIZE"
echo " Actual: $ACTUAL_SIZE"
exit 1
else
echo "$NAME size verified"
fi

local ACTUAL_HASH=$(sha256sum $IMAGE_FILE | cut -c 1-64)
if [ "$ACTUAL_HASH" != "$HASH" ]; then
echo "$NAME hash mismatch!"
Expand All @@ -46,7 +60,6 @@ process_file() {
echo "$NAME hash verified"
fi

local SPARSE=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .sparse")
if [ $SPARSE == "true" ] && [ $NAME == "system" ]; then
local OPTIMIZED_IMAGE_FILE=${IMAGE_FILE%.img}-optimized.img
if [ ! -f "$OPTIMIZED_IMAGE_FILE" ]; then
Expand All @@ -63,9 +76,6 @@ process_file() {
gzip -c $IMAGE_FILE > $GZ_FILE
fi

local SIZE=$(wc -c < $GZ_FILE)
local FULL_CHECK=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .full_check")
local HAS_AB=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .has_ab")
cat <<EOF >> $EXTRA_JSON
{
"name": "$NAME",
Expand All @@ -78,7 +88,6 @@ process_file() {
"has_ab": $HAS_AB
},
EOF

cat <<EOF >> $EXTRA_STAGING_JSON
{
"name": "$NAME",
Expand Down

0 comments on commit acdc83e

Please sign in to comment.