Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam committed Aug 13, 2023
1 parent cc64f40 commit a91a7be
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions internal/extra_ota.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ TOOLS_DIR="$DIR/../tools"

AGNOS_UPDATE_URL=${AGNOS_UPDATE_URL:-https://commadist.azureedge.net/agnosupdate}
AGNOS_STAGING_UPDATE_URL=${AGNOS_STAGING_UPDATE_URL:-https://commadist.azureedge.net/agnosupdate-staging}
OTA_JSON="$OTA_OUTPUT_DIR/ota.json"
OTA_STAGING_JSON="$OTA_OUTPUT_DIR/ota-staging.json"
EXTRA_JSON="$OTA_OUTPUT_DIR/extra.json"
EXTRA_STAGING_JSON="$OTA_OUTPUT_DIR/extra-staging.json"
OTA_JSON="$OTA_DIR/ota.json"
OTA_STAGING_JSON="$OTA_DIR/ota-staging.json"
EXTRA_JSON="$OTA_DIR/extra.json"
EXTRA_STAGING_JSON="$OTA_DIR/extra-staging.json"

process_file() {
local NAME=$1
local HASH_RAW=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .hash_raw")

local IMAGE_FILE="$OTA_DIR/$NAME-$HASH_RAW.img"
local GZ_FILE="$IMAGE_FILE.gz"
local FILE_NAME="$NAME-$HASH_RAW.img"
local GZ_FILE_NAME="$IMAGE_FILE.gz"

if [ ! -f "$IMAGE_FILE" ]; then
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")
Expand All @@ -33,48 +34,72 @@ process_file() {

echo "Decompressing $NAME..."
xz --decompress --stdout $XZ_FILE > $IMAGE_FILE
else
echo "$NAME downloaded"
fi

local ACTUAL_HASH_RAW=$(sha256sum $IMAGE_FILE | cut -c 1-64)
if [ "$ACTUAL_HASH_RAW" != "$HASH_RAW" ]; then
local HASH=$(cat $OTA_JSON | jq -r ".[] | select(.name == \"$NAME\") | .hash")
local ACTUAL_HASH=$(sha256sum $IMAGE_FILE | cut -c 1-64)
if [ "$ACTUAL_HASH" != "$HASH" ]; then
echo "$NAME hash mismatch!"
echo " Expected: $HASH_RAW"
echo " Actual: $ACTUAL_HASH_RAW"
echo " Expected: $HASH"
echo " Actual: $ACTUAL_HASH"
exit 1
else
echo "$NAME hash verified"
fi

if [ $NAME == "system" ]; then
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
echo "Optimizing $NAME..."
$TOOLS_DIR/simg2dontcare.py $IMAGE_FILE $OPTIMIZED_IMAGE_FILE
else
echo "$NAME optimized"
fi

# TODO: output
fi

local GZ_FILE="$OTA_DIR/$GZ_FILE_NAME"
if [ ! -f "$GZ_FILE" ]; then
echo "Compressing $NAME..."
gzip -c $IMAGE_FILE > $GZ_FILE

# TODO: output
else
echo "$NAME compressed"
fi

cat <<EOF > $EXTRA_JSON
{
"name": "$NAME",
"url": "$AGNOS_UPDATE_URL/$GZ_FILE_NAME",
"hash_raw": "$HASH_RAW",
},
EOF
}

cd $ROOT

mkdir -p $OTA_DIR

echo "[" > $EXTRA_JSON
echo "[" > $EXTRA_STAGING_JSON

if [ ! -f $OTA_JSON ]; then
echo "Downloading $OTA_JSON..."
wget -O $OTA_JSON https://raw.githubusercontent.com/commaai/openpilot/master/system/hardware/tici/agnos.json
fi

for image in $(cat $OTA_JSON | jq -r '.[] | .name'); do
process_file $image
done

# remove trailing comma
sed -i '$ s/.$//' $OUTPUT_JSON
sed -i '$ s/.$//' $OUTPUT_STAGING_JSON
sed -i '$ s/.$//' $EXTRA_JSON
sed -i '$ s/.$//' $EXTRA_STAGING_JSON

echo "]" >> $OUTPUT_JSON
echo "]" >> $OUTPUT_STAGING_JSON
echo "]" >> $EXTRA_JSON
echo "]" >> $EXTRA_STAGING_JSON

echo "Done!"

0 comments on commit a91a7be

Please sign in to comment.