#!/system/bin/sh
# Automatic ZipAlign for Fly-On Mod by Slaid480
# ZipAlign files in /data that have not been previously


#============ Copyright (C) 2013 Salah Abouabdallah(Slaid480)===========#
 
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
 
#  You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
#=======================================================================#

#Interval between ZipAlign runs, in seconds, 108000=30 hours
RUN_EVERY=108000

LOG_FILE=/data/Fly-On/10zipaligndata.log
    if [ -e $LOG_FILE ]; then
      rm $LOG_FILE;
    fi;



echo "Starting Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
    for apk in /data/app/*.apk ; do
  zipalign -c 4 $apk;
  ZIPCHECK=$?;
  if [ $ZIPCHECK -eq 1 ]; then
    echo ZipAligning $(basename $apk)  | tee -a $LOG_FILE;
    zipalign -f 4 $apk /cache/$(basename $apk);
      if [ -e /cache/$(basename $apk) ]; then
        cp -f -p /cache/$(basename $apk) $apk  | tee -a $LOG_FILE;
        rm /cache/$(basename $apk);
      else
        echo ZipAligning $(basename $apk) Failed  | tee -a $LOG_FILE;
      fi;
  else
    echo ZipAlign already completed on $apk  | tee -a $LOG_FILE;
  fi;
       done;

echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;