Skip to content

Instantly share code, notes, and snippets.

@DMzda
Forked from pulser/Autoflash.bat
Created August 8, 2010 10:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DMzda/bb78f238ca6c28bfb03e to your computer and use it in GitHub Desktop.
Save DMzda/bb78f238ca6c28bfb03e to your computer and use it in GitHub Desktop.
A Script to make simple update.zips
show_progress 0.1 0
copy_dir PACKAGE:system SYSTEM:
delete DATA:app
copy_dir PACKAGE:data DATA:app
set_perm 1000 1000 0771 DATA:app
show_progress 0.1 10
show_progress 0.1 0
delete DATA:app
copy_dir PACKAGE:data DATA:app
set_perm 1000 1000 0771 DATA:app
show_progress 0.1 10
show_progress 0.1 0
copy_dir PACKAGE:system SYSTEM:
show_progress 0.1 10
@echo off
echo --------------------------------------
echo -- --
echo -- Update .zip maker v1.0 --
echo -- by DMzda and daentech --
echo -- --
echo --------------------------------------
:SetVariables
SET updatescriptpath=C:\Android\SDK\tools\NOTSDK\Updatezipmaker
SET testsignpath=C:\Android\SDK\tools\testsign.jar
SET zippath="C:\Program Files\7-zip"
IF NOT EXIST %updatescriptpath% echo Invalid update script path
IF NOT EXIST %updatescriptpath% goto end
IF NOT EXIST %updatescriptpath%\update-script-system echo update-script-system missing
IF NOT EXIST %updatescriptpath%\update-script-system goto end
IF NOT EXIST %updatescriptpath%\update-script-data echo update-script-data missing
IF NOT EXIST %updatescriptpath%\update-script-data goto end
IF NOT EXIST %updatescriptpath%\update-script-both echo update-script-both missing
IF NOT EXIST %updatescriptpath%\update-script-both goto end
IF NOT EXIST %testsignpath% echo Invalid testsign.jar path
IF NOT EXIST %testsignpath% goto end
IF NOT EXIST %zippath%\7z.exe echo Invalid 7z Path
IF NOT EXIST %zippath%\7z.exe goto end
IF "%1"=="" goto usage
IF NOT EXIST %1 echo Invalid path
IF NOT EXIST %1 goto setfolder
SET folder=%1
SET filename=%~n1
echo %folder%
goto metainf
:usage
IF "%folder%"=="" ECHO Invalid argument: %1
IF NOT EXIST %folder% echo Invalid arguments: %1 (%folder%)
ECHO.
ECHO Usage: %~n0 folder
ECHO.
ECHO Where folder contains the files as they will be on the root of your phone.
ECHO e.g. folder contains system\app\Settings.apk
ECHO So settings.apk will be copied to system/app on the phone.
ECHO.
goto end
:setfolder
SET /P folder=Please enter path:
IF "%folder%"=="" goto usage
IF NOT EXIST %folder% echo Invalid path
IF NOT EXIST %folder% goto usage
SET filename=%~nfolder
:metainf
echo Making META-INF directory
mkdir %folder%\META-INF\com\google\android
:scriptselect
IF EXIST %folder%\system\* (
IF EXIST %folder%\data\* (
goto both
) ELSE (
goto system
)
) ELSE (
IF EXIST %folder%\data\* (
goto data
) ELSE (
echo Empty folder, not doing anything
goto end
)
)
:system
echo File(s) found in /system only
echo Copying update script
COPY %updatescriptpath%\update-script-system %folder%\META-INF\com\google\android\update-script
goto zip
:data
echo File(s) found in /data only
echo Copying update script
COPY %updatescriptpath%\update-script-data %folder%\META-INF\com\google\android\update-script
goto zip
:both
echo File(s) found in /system and /data
echo Copying update script
COPY %updatescriptpath%\update-script-both %folder%\META-INF\com\google\android\update-script
goto zip
:zip
echo Zipping update
%zippath%\7z a -r %folder%.zip %folder%\*
echo Signing update.zip
java -jar %testsignpath% %folder%.zip %folder%-signed.zip
:phonepluggedin
@adb devices|find "device"|find /v "List"
IF %ERRORLEVEL% NEQ 0 (
echo phone not plugged in.
goto phone_no
) ELSE (
echo phone plugged in
goto phone_yes
)
:phone_yes
echo Do you wish to push the file to the phones SD card?
set /p push=[Y/N]
if /I %push%==n goto phone_no
echo Pushing zip to sdcard
adb push %folder%-signed.zip /sdcard/
echo Do you wish to autoflash?
set /p autoflash=[Y/N]
if /I %autoflash%==y goto autoflash
if /I %autoflash%==n echo Do you wish to reboot into recovery?
set /p reboot=[Y/N]
if /I %reboot%==y goto reboot
goto end
:phone_no
echo Update .zip created!
echo at %folder%
goto end
:autoflash
echo Preparing to autoflash
adb shell mkdir -p /cache/recovery/
echo boot-recovery>recoverycommand
echo --update_package=SDCARD:%filename%-signed.zip>>recoverycommand
adb push recoverycommand /cache/recovery/command
del recoverycommand
goto reboot
:reboot
echo Rebooting your phone into recovery now
adb reboot recovery
goto end
:end
echo Thanks for using this script
#!/bin/bash
set +v
echo --------------------------------------
echo -- --
echo -- Update .zip maker v1.0 --
echo -- by DMzda and daentech --
echo -- and Tj --
echo --------------------------------------
echo -n "Please input path to android-sdk folder: "
read sdkpath
export phone=0
function Checks {
echo "::Checking Files..."
##fail variable
fail=0
##check #1
echo "::Android sdk folder "
if [ -d "$sdkpath" ]
then
echo "OK"
else
echo "FAIL"
fail=1
echo "sdk folder not found, exiting."
exit 1
fi
echo "::adb in path "
if [ ! -z $(which adb) ]
then
echo "OK"
else
echo "FAIL"
#android sdk folder in place
echo "***sdk folder exists, putting adb into the path"
export PATH=PATH:$sdkfolder/tools
fi
##assigning some variables
updatescriptpath=$sdkpath/tools/NOTSDK/updatescript
testsignpath=$sdkpath/tools/testsign.jar
#needed for input folder function as well.
export folder="$1"
echo -n "::Update Script Path "
if [ -e "$updatescriptpath" ]
then
echo "OK"
else
echo "FAIL"
fail=1
fi
echo -n "::System update script "
if [ -f "$updatescriptpath"/update-script-system ]
then
echo "OK"
else
echo "FAIL"
fail=1
fi
echo -n "::Data update script "
if [ -f "$updatescriptpath"/update-script-data ]
then
echo "OK"
else
echo "FAIL"
fail=1
fi
echo -n "::Data+system update script "
if [ -f "$updatescript"/update-script-both ]
then
echo "OK"
else
echo "FAIL"
fail=1
fi
echo -n "::zip executable "
if [ ! -z "$(which zip)" ]
then
echo "OK"
else
echo "FAIL"
fail=1
fi
echo -n "::Java "
if [ ! -z "$(which java)" ]
then
echo "OK"
else
echo "FAIL"
fail=1
fi
echo -n "::testsign.jar "
if [ -e "$testsignpath" ]
then
echo "OK"
else
echo "FAIL"
fail=1
fi
echo -n "::argument input "
if [ -n "$@" ]
then
echo "OK"
else
echo "FAIL"
echo "please input path name for the folder with the files to be converted to update.zip: "
read folder
fi
echo -n "::update folder "
if [ -e "$folder" ]
then
echo "OK"
else
#update folder has been inputted but does not exist, create it.
echo "FAIL"
echo "***Upate folder succesfully inputted, but does not exist...creating."
mkdir -p folder
fi
echo -n "::Phone plugged in "
if [ $(adb devices|wc -l) -lt 2 ]
then
#less that 2 lines which means no devices found
echo "FAIL"
export phone=0
else
echo "OK"
export phone=1
fi
#filename is jsut the name of the folder.
filename="$(folder##*/}"
if [ $fail -eq 0 ]
then
echo "All tests passed"
else
echo "One of more critical tests failed/missing programmes, exiting."
exit 1
fi
}
function metainf {
#creating metainf
if [ -e $folder/META-INF/com/google/android ]
then
echo "subfolder META-INF/com/google/android already exists, not recreating"
else
echo "Making META-INF/com/google/android directory, creating parents as needed."
mkdir -p $folder/META-INF/com/google/android
fi
}
function scriptselect {
#select the correct script.
echo "Checking for files in either system or data folder, or both"
data=$(ls "$folder"/data/* 2> /dev/null | wc -l)
system=$(ls "$folder"/system/* 2> /dev/null | wc -l)
if [ $data -ne 0 ]
then
#files found in data
if [ $system -ne 0 ]
then
#...AND in system
echo "files found both system and data."
cp %updatescriptpath%/update-script-both %folder%/META-INF/com/google/android/update-script
else
#no none in system, only data then.
echo "files found in data only, assuming you want the data update script"
cp %updatescriptpath%/update-script-data %folder%/META-INF/com/google/android/update-script
fi
else
#there are no files in data
if [ $system -ne 0 ]
then
#but there are in system
echo "files found in system folder only, assuming you want the system update script"
cp %updatescriptpath%/update-script-system %folder%/META-INF/com/google/android/update-script
else
echo "...you dont have files in either system or data? so you want me to create an empty update.zip...not gonna happen"
exit 1
fi
fi
}
function zip {
#zipping up the folder now
echo "Zipping the update folder"
zip -r "$folder".zip $folder
echo -n "update.zip created at "
echo "$folder".zip
echo "signing the zip"
java -jar "$testsignpath" "$folder".zip "$folder"-signed.zip
echo -n "signed update.zip created at "
echo "$folder"-signed.zip
echo -n "md5sum for signed zip: "
set -v
md5sum "$folder"-signed.zip
set +v
}
function phone_yes {
##phone found in adb
echo "phone connected to adb, would you like to autoflash [y/N]: "
read autoflash
if [ $autoflash == "y"] || [ $autoflash == "Y" ]
then
echo "Preparing to autoflash"
adb shell mkdir -p /cache/recovery/
echo "boot-recovery">recoverycommand
echo --update_package=SDCARD:"$filename"-signed.zip>>recoverycommand
adb push recoverycommand /cache/recovery/command
rm recoverycommand
echo "Rebooting your phone into recovery now"
adb reboot recovery
fi
}
##finally, run these functions.
Checks
metainf
scriptselect
zip
if [ $phone -eq 1 ]
then
phone_yes
else
echo "***Phone not connected, move the update zip to sdcard and flash at your own leisure."
fi
echo "***Thank you for using this script***"
exit 0
@DMzda
Copy link
Author

DMzda commented Aug 8, 2010

Usage: updatemaker C:\Path\to\folder
Where folder contains the files as they will be on the root of your phone.
e.g. folder contains system\app\Settings.apk
So settings.apk will be copied to system/app on the phone.
This needs the three update scripts, placed in the same folder. Replace SET updatescriptpath=C:\Android\SDK\tools\NOTSDK\Updatezipmaker with the path for that folder.

MAKE SURE THEY HAVE UNIX LINE ENDINGS :)

Replace SET testsignpath=C:\Android\SDK\tools\testsign.jar with the path to your testsign.jar

Get the right version here: http://villainrom.co.uk/homersp/testsign.jar

Replace SET 7zippath="C:\Program Files\7-zip" with the path to where 7-zip is installed

The script assumes Java and the SDK tools folder are in your path

@Tjphysicist
Copy link

Note:

  • Windows version: Please replace the updatescriptpath, testsignpath and zippath assignment with your respectful paths. This means what comes after the = sign should actually be true for you, no trailing 's either, just follow whats on there. quotation marks are a good habit especially since so many windows paths have spaces and odd symbols in them so for example:
    SET testsignpath="C:\Program Files\android-sdk\tools\testsign.jar"

    at least until I can get windows to play nice with inputs and quotations...cuz a lot of paths have spaces...

  • Linux version: The script asks you for the location of the android-sdk-path. change lines 45 and 46 to reflect where updatescript and testsign.jar lies. ($sdkpath will automatically expand to sdk-path. Again use qutoation marks if you have spaces in the path).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment