Architectural bug (function prepare_dir) This is the weakest link of the script. Look at this block:
prepare_dir() {
mkdir -p /storage/emulated/"$USR"/Android/data/$PKG/cache
mkdir -p /storage/emulated/"$USR"/Android/data/$PKG/files
}
You run the script from the su (on behalf of the root superuser). Accordingly, the mkdir command creates these folders with the owner of root:root. Android uses FUSE (or sdcardfs) to emulate the file system. When Google Photos (working under its local user, such as u0_a154), tries to record a cache in a directory created by a rout, it will get the failure of the kernel: Permission Denied. Instead of repairing the storage, this script is highly likely to make the application fall (crash) when trying to save data.