#!/system/bin/sh
# Automatic ZipAlign by Pete
echo "Starting Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )" 
		for apk in /data/app/*.apk ; do
		/system/xbin/zipalign -c 4 $apk;
		ZIPCHECK=$?;
		if busybox [ $ZIPCHECK -eq 1 ]; then
		echo ZipAligning $(busybox basename $apk)  
		/system/xbin/zipalign -f 4 $apk /cache/$(busybox basename $apk);
		if busybox [ -e /cache/$(busybox basename $apk) ]; then
		busybox cp -f -p /cache/$(busybox basename $apk) $apk  
		busybox rm /cache/$(busybox basename $apk);
		else
		echo ZipAligning $(busybox basename $apk) Failed  
		fi;
		else
		echo ZipAlign already completed on $apk  
		fi;
		done;
		for apk in /data/app-private/*.apk ; do
		/system/xbin/zipalign -c 4 $apk;
		ZIPCHECK=$?;
		if busybox [ $ZIPCHECK -eq 1 ]; then
		echo ZipAligning $(busybox basename $apk)  
		/system/xbin/zipalign -f 4 $apk /cache/$(busybox basename $apk);
		if busybox [ -e /cache/$(busybox basename $apk) ]; then
		busybox cp -f -p /cache/$(busybox basename $apk) $apk  
		busybox rm /cache/$(busybox basename $apk);
		else
		echo ZipAligning $(busybox basename $apk) Failed  
		fi;
		else
		echo ZipAlign already completed on $apk 
		fi;
		done;
		/system/bin/sysrw;
		for apk in /system/app/*.apk ; do
		/system/xbin/zipalign -c 4 $apk;
		ZIPCHECK=$?;
		if busybox [ $ZIPCHECK -eq 1 ]; then
		echo ZipAligning $(busybox basename $apk)  
		/system/xbin/zipalign -f 4 $apk /cache/$(busybox basename $apk);
		if busybox [ -e /cache/$(busybox basename $apk) ]; then
		busybox cp -f /cache/$(busybox basename $apk) $apk  
		busybox rm /cache/$(busybox basename $apk);
		else
		echo ZipAligning $(busybox basename $apk) Failed  
		fi;
		else
		echo ZipAlign already completed on $apk  
		fi;
		done;
		sync
		for apk in /system/framework/*.apk ; do
		/system/xbin/zipalign -c 4 $apk;
		ZIPCHECK=$?;
		if busybox [ $ZIPCHECK -eq 1 ]; then
		echo ZipAligning $(busybox basename $apk)  
		/system/xbin/zipalign -f 4 $apk /cache/$(busybox basename $apk);
		if busybox [ -e /cache/$(busybox basename $apk) ]; then
		busybox cp -f /cache/$(busybox basename $apk) $apk  
		busybox rm /cache/$(busybox basename $apk);
		else
		echo ZipAligning $(busybox basename $apk) Failed  
		fi;
		else
		echo ZipAlign already completed on $apk  
		fi;
		done;
		sync
		echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )" 
		echo "Bugless Beast by Pete"
