#!/bin/bash

SD_PATH="/sdcard/game/legal_support.png"
CACHED_PATH="/userdata/legal_support.png"
EXPECTED_MD5="a64d2cc3a3cc03abba790d84b949e487"

# if file exits on the cart, cache it locally if necessary
if [ -f "$SD_PATH" ] && [ ! -f "$CACHED_PATH" ]; then
    md5=($(md5sum ${SD_PATH}))
    [ "$EXPECTED_MD5" = "$md5" ] && cp -f "$SD_PATH" "$CACHED_PATH"
fi

# if file doesn't exist on the cart and we have it cached, copy it to the cart
[ -f "$CACHED_PATH" ] && [ ! -f "$SD_PATH" ] && cp -f "$CACHED_PATH" "$SD_PATH" && sync