From 35cfcb1dcc31fcbe1f7620231a769641eb1d1082 Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Sat, 1 Nov 2014 17:06:53 +0000 Subject: [PATCH 01/10] Initial version that can add and remove the busybox shell and verify a functioning su binary --- scripts/linux/backup.sh | 70 ++++++++++++++++++++++++++++++++++++ scripts/linux/busybox-off.sh | 1 + scripts/linux/busybox-on.sh | 2 ++ scripts/linux/check-root.sh | 27 ++++++++++++++ scripts/linux/find.sh | 56 +++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100755 scripts/linux/backup.sh create mode 100755 scripts/linux/busybox-off.sh create mode 100755 scripts/linux/busybox-on.sh create mode 100755 scripts/linux/check-root.sh create mode 100755 scripts/linux/find.sh diff --git a/scripts/linux/backup.sh b/scripts/linux/backup.sh new file mode 100755 index 0000000..081bfda --- /dev/null +++ b/scripts/linux/backup.sh @@ -0,0 +1,70 @@ +sudo adb kill-server +sudo adb start-server +adb wait-for-device + +./busybox-on.sh + +partition=`./find.sh` + +#if empty, abort + +./busybox-off.sh +#debug +exit -1 + +echo ======================================= +echo BACKUP TA PARTITION +echo ======================================= +adb shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\backup_currentPartitionMD5 +adb shell su -c "%BB% dd if=!partition! of=/sdcard/backupTA.img" + +echo. +echo ======================================= +echo INTEGRITY CHECK +echo ======================================= +adb shell su -c "%BB% md5sum /sdcard/backupTA.img | %BB% awk {'print \$1'}">tmpbak\backup_backupMD5 +set /p backup_currentPartitionMD5= nul +if NOT "!backup_currentPartitionMD5!" == "!backup_backupMD5!" ( + echo FAILED - Backup does not match TA Partition. Please try again. + goto onBackupFailed +) else ( + echo OK +) + +echo. +echo ======================================= +echo PULL BACKUP FROM SDCARD +echo ======================================= +adb pull /sdcard/backupTA.img tmpbak\TA.img +if NOT "!errorlevel!" == "0" goto onBackupFailed + +echo. +echo ======================================= +echo INTEGRITY CHECK +echo ======================================= +tools\md5.exe -l -n tmpbak\TA.img>tmpbak\backup_backupPulledMD5 +if NOT "!errorlevel!" == "0" goto onBackupFailed +set /p backup_backupPulledMD5= nul +if NOT "!backup_currentPartitionMD5!" == "!backup_backupPulledMD5!" ( + echo FAILED - Backup has gone corrupted while pulling. Please try again. + goto onBackupFailed +) else ( + echo OK +) + +echo. +echo ======================================= +echo PACKAGE BACKUP +echo ======================================= +adb get-serialno>tmpbak\TA.serial +echo !partition!>tmpbak\TA.blk +echo !backup_backupPulledMD5!>tmpbak\TA.md5 +echo %VERSION%>tmpbak\TA.version +adb shell su -c "%BB% date +%%Y%%m%%d.%%H%%M%%S">tmpbak\TA.timestamp +set /p backup_timestamp=tmpbak\backup_potentialPartitions + for /F "tokens=*" %%A in (tmpbak\backup_potentialPartitions) do call:inspectPartition %%A + + if NOT "!backup_taPartitionName!" == "" ( + if NOT "!backup_taPartitionName!" == "-1" ( + echo Partition found^^! + set partition=/dev/block/!backup_taPartitionName! + ) else ( + echo *** More than one partition match the TA partition search criteria. *** + echo *** Therefore it is not possible to determine which one or ones to use. *** + echo *** Contact DevShaft @XDA-forums for support. *** + goto onBackupCancelled + ) + ) else ( + echo *** No compatible TA partition found on your device. *** + goto onBackupCancelled + ) + +) \ No newline at end of file From cb6de264e349b5af4bb338ff730cfb817c002c8e Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Sat, 1 Nov 2014 17:33:37 +0000 Subject: [PATCH 02/10] Find the TA partition, but the check fails for some reason --- scripts/linux/find.sh | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/scripts/linux/find.sh b/scripts/linux/find.sh index da7c5fe..d7905b2 100755 --- a/scripts/linux/find.sh +++ b/scripts/linux/find.sh @@ -2,18 +2,19 @@ PARTITION_BY_NAME=/dev/block/platform/msm_sdcc.1/by-name/TA root=`./check-root.sh` -#if not root, exit +#if not rooted, exit if [ "$root" == "" ] then echo "not rooted" exit 1 fi +backup_defaultTA=`adb shell su -c "$BB ls -l --color=never $PARTITION_BY_NAME" | tr -s ' ' | awk '{print $11}'` +backup_defaultTAvalid=`adb shell su -c "if [ -b $backup_defaultTA ]; then echo '1'; else echo '0'; fi"` +#TODO works by hand ! +#$ adb shell su -c "if [ -b /dev/block/mmcblk0p1 ]; then echo '1'; else echo '0'; fi" +#1 -echo FIND TA PARTITION - -backup_defaultTA=`adb shell su -c "$BB ls -l $PARTITION_BY_NAME | $BB awk '{print \$11}'"` -backup_defaultTAvalid=`adb shell su -c "if [ -b '!backup_defaultTA!' ]; then echo '1'; else echo '0'; fi"` echo backup_defaultTA $backup_defaultTA echo backup_defaultTAvalid $backup_defaultTAvalid @@ -22,35 +23,9 @@ echo debug exit exit 1 if "!backup_defaultTAvalid!" == "1" ( - set partition=!backup_defaultTA! - echo Partition found^^! + echo $backup_defaultTA ) else ( echo Partition not found by name. - echo. - %CHOICE% /c:yn %CHOICE_TEXT_PARAM% "Do you want to perform an extensive search for the TA?" - if "!errorlevel!" == "2" goto onBackupCancelled - - echo. - echo ======================================= - echo INSPECTING PARTITIONS - echo ======================================= - set backup_taPartitionName= - adb shell su -c "%BB% cat /proc/partitions | %BB% awk '{if (\$3<=9999 && match (\$4, \"'\"mmcblk\"'\")) print \$4}'">tmpbak\backup_potentialPartitions - for /F "tokens=*" %%A in (tmpbak\backup_potentialPartitions) do call:inspectPartition %%A - - if NOT "!backup_taPartitionName!" == "" ( - if NOT "!backup_taPartitionName!" == "-1" ( - echo Partition found^^! - set partition=/dev/block/!backup_taPartitionName! - ) else ( - echo *** More than one partition match the TA partition search criteria. *** - echo *** Therefore it is not possible to determine which one or ones to use. *** - echo *** Contact DevShaft @XDA-forums for support. *** - goto onBackupCancelled - ) - ) else ( - echo *** No compatible TA partition found on your device. *** - goto onBackupCancelled - ) - + echo No support yet for finding by other methods + exit 1 ) \ No newline at end of file From 801f25e5668ead0180719d744b0a7cf7655b220e Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Sat, 1 Nov 2014 17:45:18 +0000 Subject: [PATCH 03/10] basic automated syntax changes --- scripts/linux/backup.sh | 56 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/scripts/linux/backup.sh b/scripts/linux/backup.sh index 081bfda..796af6b 100755 --- a/scripts/linux/backup.sh +++ b/scripts/linux/backup.sh @@ -15,56 +15,46 @@ exit -1 echo ======================================= echo BACKUP TA PARTITION echo ======================================= -adb shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\backup_currentPartitionMD5 -adb shell su -c "%BB% dd if=!partition! of=/sdcard/backupTA.img" +backup_currentPartitionMD5=`adb shell su -c "$BB md5 $partition" | awk {'print $1'}` +adb shell su -c "$BB dd if=$partition of=/sdcard/backupTA.img" -echo. +echo echo ======================================= echo INTEGRITY CHECK echo ======================================= -adb shell su -c "%BB% md5sum /sdcard/backupTA.img | %BB% awk {'print \$1'}">tmpbak\backup_backupMD5 -set /p backup_currentPartitionMD5= nul -if NOT "!backup_currentPartitionMD5!" == "!backup_backupMD5!" ( +backup_backupMD5=`adb shell su -c "$BB md5 /sdcard/backupTA.img" | awk {'print $1'} + +if [ "$backup_currentPartitionMD5" != "$backup_backupMD5" ] +then echo FAILED - Backup does not match TA Partition. Please try again. - goto onBackupFailed -) else ( - echo OK -) + echo $backup_currentPartitionMD5 + echo $backup_backupMD5 + exit 1 +fi -echo. +echo echo ======================================= echo PULL BACKUP FROM SDCARD echo ======================================= adb pull /sdcard/backupTA.img tmpbak\TA.img -if NOT "!errorlevel!" == "0" goto onBackupFailed -echo. +echo echo ======================================= echo INTEGRITY CHECK echo ======================================= -tools\md5.exe -l -n tmpbak\TA.img>tmpbak\backup_backupPulledMD5 -if NOT "!errorlevel!" == "0" goto onBackupFailed -set /p backup_backupPulledMD5= nul -if NOT "!backup_currentPartitionMD5!" == "!backup_backupPulledMD5!" ( +localmd5=`md5sum tmpbak\TA.img` + +if [ "$localmd5" != "$backup_backupPulledMD5" ] +then echo FAILED - Backup has gone corrupted while pulling. Please try again. - goto onBackupFailed -) else ( - echo OK -) + exit 1 +fi -echo. +echo echo ======================================= echo PACKAGE BACKUP echo ======================================= -adb get-serialno>tmpbak\TA.serial -echo !partition!>tmpbak\TA.blk -echo !backup_backupPulledMD5!>tmpbak\TA.md5 -echo %VERSION%>tmpbak\TA.version -adb shell su -c "%BB% date +%%Y%%m%%d.%%H%%M%%S">tmpbak\TA.timestamp -set /p backup_timestamp= Date: Sun, 2 Nov 2014 11:29:16 +0000 Subject: [PATCH 04/10] Correct partition detection logic and checks --- scripts/linux/backup.sh | 9 +++++++++ scripts/linux/busybox-off.sh | 2 ++ scripts/linux/busybox-on.sh | 2 ++ scripts/linux/check-root.sh | 2 ++ scripts/linux/find.sh | 33 +++++++++++++++++++-------------- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/scripts/linux/backup.sh b/scripts/linux/backup.sh index 796af6b..af86cb9 100755 --- a/scripts/linux/backup.sh +++ b/scripts/linux/backup.sh @@ -1,3 +1,5 @@ +#!/bin/bash + sudo adb kill-server sudo adb start-server adb wait-for-device @@ -7,6 +9,13 @@ adb wait-for-device partition=`./find.sh` #if empty, abort +echo partition $partition + +if [[ $partition == "" ]] +then + echo No partition found + exit -1 +fi ./busybox-off.sh #debug diff --git a/scripts/linux/busybox-off.sh b/scripts/linux/busybox-off.sh index 0e24e1b..e0bcfaa 100755 --- a/scripts/linux/busybox-off.sh +++ b/scripts/linux/busybox-off.sh @@ -1 +1,3 @@ +#!/bin/bash + adb shell rm /data/local/tmp/busybox-backup-ta \ No newline at end of file diff --git a/scripts/linux/busybox-on.sh b/scripts/linux/busybox-on.sh index c6994c9..63e95a7 100755 --- a/scripts/linux/busybox-on.sh +++ b/scripts/linux/busybox-on.sh @@ -1,2 +1,4 @@ +#!/bin/bash + adb push ../../tools/busybox /data/local/tmp/busybox-backup-ta adb shell chmod 755 /data/local/tmp/busybox-backup-ta \ No newline at end of file diff --git a/scripts/linux/check-root.sh b/scripts/linux/check-root.sh index 20a4b78..ef7712b 100755 --- a/scripts/linux/check-root.sh +++ b/scripts/linux/check-root.sh @@ -1,3 +1,5 @@ +#!/bin/bash + export BB=/data/local/tmp/busybox-backup-ta SU=/system/bin/su diff --git a/scripts/linux/find.sh b/scripts/linux/find.sh index d7905b2..865a743 100755 --- a/scripts/linux/find.sh +++ b/scripts/linux/find.sh @@ -1,3 +1,5 @@ +#!/bin/bash + PARTITION_BY_NAME=/dev/block/platform/msm_sdcc.1/by-name/TA root=`./check-root.sh` @@ -9,23 +11,26 @@ then exit 1 fi -backup_defaultTA=`adb shell su -c "$BB ls -l --color=never $PARTITION_BY_NAME" | tr -s ' ' | awk '{print $11}'` +backup_defaultTA=`adb shell su -c "$BB ls -l --color=never $PARTITION_BY_NAME" | tr -s ' ' | awk '{print $11}' ` +#remove invalid head/tail chars +backup_defaultTA=`expr match "$backup_defaultTA" '\([0-9a-z\/]*\)'` backup_defaultTAvalid=`adb shell su -c "if [ -b $backup_defaultTA ]; then echo '1'; else echo '0'; fi"` -#TODO works by hand ! -#$ adb shell su -c "if [ -b /dev/block/mmcblk0p1 ]; then echo '1'; else echo '0'; fi" -#1 - - -echo backup_defaultTA $backup_defaultTA -echo backup_defaultTAvalid $backup_defaultTAvalid -echo debug exit -exit 1 +if [[ $backup_defaultTA != /* ]] +then + echo Partition not found by name. + echo $backup_defaultTA + echo No support yet for finding by other methods + exit 1 +fi -if "!backup_defaultTAvalid!" == "1" ( +if [[ "$backup_defaultTAvalid" =~ "1" ]] +then echo $backup_defaultTA -) else ( - echo Partition not found by name. +else + echo Partition found but not valid + echo backup_defaultTA $backup_defaultTA + echo backup_defaultTAvalid $backup_defaultTAvalid echo No support yet for finding by other methods exit 1 -) \ No newline at end of file +fi \ No newline at end of file From e002897ff533f99e09f873d2f7a182b329261643 Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Sun, 2 Nov 2014 12:10:39 +0000 Subject: [PATCH 05/10] Initial menu support and creation of final .zip archive --- Backup-TA.sh | 35 ++++++++++++++++++++++++++++++ scripts/linux/backup.sh | 47 ++++++++++++++++++++++++++++++----------- 2 files changed, 70 insertions(+), 12 deletions(-) create mode 100755 Backup-TA.sh diff --git a/Backup-TA.sh b/Backup-TA.sh new file mode 100755 index 0000000..517e198 --- /dev/null +++ b/Backup-TA.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +VERSION=9.11 + +echo "[ ------------------------------------------------------------ ]" +echo "[ Backup TA v$VERSION for Sony Xperia ]" +echo "[ ------------------------------------------------------------ ]" +echo "[ Initialization ]" +echo "[ ]" +echo "[ Make sure that you have USB Debugging enabled, you do ]" +echo "[ allow your computer ADB access by accepting its RSA key ]" +echo "[ \(only needed for Android 4.2.2 or higher\) and grant this ]" +echo "[ ADB process root permissions through superuser. ]" +echo "[ ]" +echo "[ On your computer, you need adb installed and working ]" +echo "[ ------------------------------------------------------------ ]" +echo + +PS3='Please enter your choice: ' +options=("Backup" "Exit") +select opt in "${options[@]}" + +do + case $opt in + "Backup") + cd scripts/linux + ./backup.sh $VERSION + exit + ;; + "Exit") + break + ;; + *) echo invalid option;; + esac +done \ No newline at end of file diff --git a/scripts/linux/backup.sh b/scripts/linux/backup.sh index af86cb9..960e9cd 100755 --- a/scripts/linux/backup.sh +++ b/scripts/linux/backup.sh @@ -1,5 +1,7 @@ #!/bin/bash +TMP=../../tmpbak + sudo adb kill-server sudo adb start-server adb wait-for-device @@ -8,7 +10,9 @@ adb wait-for-device partition=`./find.sh` -#if empty, abort +echo ======================================= +echo FIND TA PARTITION +echo ======================================= echo partition $partition if [[ $partition == "" ]] @@ -17,21 +21,17 @@ then exit -1 fi -./busybox-off.sh -#debug -exit -1 - echo ======================================= echo BACKUP TA PARTITION echo ======================================= -backup_currentPartitionMD5=`adb shell su -c "$BB md5 $partition" | awk {'print $1'}` +backup_currentPartitionMD5=`adb shell su -c "$BB md5sum $partition" | awk {'print $1'}` adb shell su -c "$BB dd if=$partition of=/sdcard/backupTA.img" echo echo ======================================= echo INTEGRITY CHECK echo ======================================= -backup_backupMD5=`adb shell su -c "$BB md5 /sdcard/backupTA.img" | awk {'print $1'} +backup_backupMD5=`adb shell su -c "$BB md5sum /sdcard/backupTA.img" | awk {'print $1'}` if [ "$backup_currentPartitionMD5" != "$backup_backupMD5" ] then @@ -41,21 +41,29 @@ then exit 1 fi +if [ -d $TMP ] +then + mkdir $TMP +fi + echo echo ======================================= echo PULL BACKUP FROM SDCARD echo ======================================= -adb pull /sdcard/backupTA.img tmpbak\TA.img +adb pull /sdcard/backupTA.img $TMP/TA.img echo echo ======================================= echo INTEGRITY CHECK echo ======================================= -localmd5=`md5sum tmpbak\TA.img` +localmd5=`md5sum $TMP/TA.img | awk {'print $1'} ` -if [ "$localmd5" != "$backup_backupPulledMD5" ] +if [ "$localmd5" != "$backup_backupMD5" ] then echo FAILED - Backup has gone corrupted while pulling. Please try again. + echo $backup_currentPartitionMD5 + echo $backup_backupMD5 + echo $localmd5 exit 1 fi @@ -65,5 +73,20 @@ echo PACKAGE BACKUP echo ======================================= serial=`adb get-serialno` -cd tmpbak -echo TODO ..\tools\zip.exe a ..\backup\TA-backup-!backup_timestamp!.zip TA.img TA.md5 TA.blk TA.serial TA.timestamp TA.version +cd $TMP + +backup_timestamp=`date +%Y-%m-%d.%H%M%S` +echo $backup_backupMD5 > TA.md5 +echo $partition > TA.blk +echo $serial > TA.serial +echo $backup_timestamp > TA.timestamp +echo $1 > TA.version +uname -sp > TA.platform + +zip ../TA-backup-$backup_timestamp.zip TA.img TA.md5 TA.blk TA.serial TA.timestamp TA.version TA.platform + +cd .. + +rm -rf $TMP + +./scripts/linux/busybox-off.sh \ No newline at end of file From f39188e634205416087064de0720e9be3394fdd4 Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Wed, 5 Nov 2014 19:53:56 +0000 Subject: [PATCH 06/10] Rewrite the partition found checking code and begin the non-by-name find method --- scripts/linux/backup.sh | 7 +++++- scripts/linux/find.sh | 51 ++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/scripts/linux/backup.sh b/scripts/linux/backup.sh index 960e9cd..2ce880a 100755 --- a/scripts/linux/backup.sh +++ b/scripts/linux/backup.sh @@ -8,7 +8,9 @@ adb wait-for-device ./busybox-on.sh -partition=`./find.sh` + +partition="" +./find.sh echo ======================================= echo FIND TA PARTITION @@ -21,6 +23,9 @@ then exit -1 fi +echo debug exit +exit 1 + echo ======================================= echo BACKUP TA PARTITION echo ======================================= diff --git a/scripts/linux/find.sh b/scripts/linux/find.sh index 865a743..5824e3e 100755 --- a/scripts/linux/find.sh +++ b/scripts/linux/find.sh @@ -4,6 +4,20 @@ PARTITION_BY_NAME=/dev/block/platform/msm_sdcc.1/by-name/TA root=`./check-root.sh` +inspectPartition (){ + opId=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'OP_ID='"` + opname=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'OP_NAME='"` + rooting=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'ROOTING_ALLOWED='"` + s1Boot=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_Boot'"` + s1Loader=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_Loader'"` + s1Hw=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_HWConf'"` + + if [ "$opId" == "1" ] + then + echo $1 + fi +} + #if not rooted, exit if [ "$root" == "" ] then @@ -11,26 +25,47 @@ then exit 1 fi -backup_defaultTA=`adb shell su -c "$BB ls -l --color=never $PARTITION_BY_NAME" | tr -s ' ' | awk '{print $11}' ` +backup_defaultTA=`adb shell su -c "$BB ls -l --color=never $PARTITION_BY_NAME" | tr -s ' ' | awk '{print $11}'` #remove invalid head/tail chars backup_defaultTA=`expr match "$backup_defaultTA" '\([0-9a-z\/]*\)'` -backup_defaultTAvalid=`adb shell su -c "if [ -b $backup_defaultTA ]; then echo '1'; else echo '0'; fi"` if [[ $backup_defaultTA != /* ]] then - echo Partition not found by name. - echo $backup_defaultTA - echo No support yet for finding by other methods + echo Partition not found by name, trying harder + + partition=""; + + for part in `adb shell su -c "$BB cat /proc/partitions " | awk '{if ($3<=9999) print $4}'|grep --color=never mmcblk` + do + echo ? $part + possible=$(inspectPartition "$part") + echo = $possible + done + + echo + + #more than one match - fail + + #one - OK + + echo found /dev/$part + export partition=/dev/$part + + #else + + echo No partitions found found. exit 1 fi +backup_defaultTAvalid=`adb shell su -c "if [ -b $backup_defaultTA ]; then echo '1'; else echo '0'; fi"` + if [[ "$backup_defaultTAvalid" =~ "1" ]] then - echo $backup_defaultTA -else + export partition=$backup_defaultTA + echo found $partition +else echo Partition found but not valid echo backup_defaultTA $backup_defaultTA echo backup_defaultTAvalid $backup_defaultTAvalid - echo No support yet for finding by other methods exit 1 fi \ No newline at end of file From 6779683e5e0c452de72aa43321218b2082007013 Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Wed, 5 Nov 2014 20:15:22 +0000 Subject: [PATCH 07/10] Logic for locating partition complete but not used --- scripts/linux/find.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/linux/find.sh b/scripts/linux/find.sh index 5824e3e..e2cc976 100755 --- a/scripts/linux/find.sh +++ b/scripts/linux/find.sh @@ -2,26 +2,26 @@ PARTITION_BY_NAME=/dev/block/platform/msm_sdcc.1/by-name/TA -root=`./check-root.sh` - -inspectPartition (){ +inspectPartition() { opId=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'OP_ID='"` - opname=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'OP_NAME='"` + opName=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'OP_NAME='"` rooting=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'ROOTING_ALLOWED='"` s1Boot=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_Boot'"` s1Loader=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_Loader'"` s1Hw=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_HWConf'"` - if [ "$opId" == "1" ] + if [[ "$opId" =~ "1" ]] && [[ "$opName" =~ "1" ]] && [[ "$rooting" =~ "1" ]] && [[ "$s1Boot" =~ "1" ]] && [[ "$s1Loader" =~ "1" ]] && [[ "$s1Hw" =~ "1" ]] then echo $1 fi } +root=`./check-root.sh` + #if not rooted, exit if [ "$root" == "" ] then - echo "not rooted" + echo "Not rooted" exit 1 fi @@ -35,11 +35,13 @@ then partition=""; - for part in `adb shell su -c "$BB cat /proc/partitions " | awk '{if ($3<=9999) print $4}'|grep --color=never mmcblk` + for part in `adb shell su -c "$BB cat /proc/partitions " | awk '{if ($3<=9999) print $4}'|grep --color=never mmcblk|xargs` do - echo ? $part - possible=$(inspectPartition "$part") + safepart=`expr match "$part" '\([0-9a-z\/]*\)'` + echo ? $safepart + possible=$(inspectPartition "$safepart") echo = $possible + x=`adb shell su -c "$BB cat /dev/block/$safepart | $BB grep -s -m 1 -c 'OP_ID='"` done echo @@ -48,12 +50,12 @@ then #one - OK - echo found /dev/$part - export partition=/dev/$part + echo found /dev/block/$part + export partition=/dev/block/$part #else - echo No partitions found found. + echo No partitions found. exit 1 fi From 2dc24c7222a0f530902e6091e54721013c700ee2 Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Sat, 8 Nov 2014 14:18:03 +0000 Subject: [PATCH 08/10] complete find by property --- scripts/linux/find.sh | 48 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/scripts/linux/find.sh b/scripts/linux/find.sh index e2cc976..e97ab3a 100755 --- a/scripts/linux/find.sh +++ b/scripts/linux/find.sh @@ -3,12 +3,12 @@ PARTITION_BY_NAME=/dev/block/platform/msm_sdcc.1/by-name/TA inspectPartition() { - opId=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'OP_ID='"` - opName=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'OP_NAME='"` - rooting=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c 'ROOTING_ALLOWED='"` - s1Boot=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_Boot'"` - s1Loader=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_Loader'"` - s1Hw=`adb shell su -c "$BB cat /dev/block/$1 | $BB grep -s -m 1 -c -i 'S1_HWConf'"` + opId=`adb shell su -c "$BB cat /dev/block/$1" | grep -s -m 1 -c 'OP_ID='` + opName=`adb shell su -c "$BB cat /dev/block/$1" | grep -s -m 1 -c 'OP_NAME='` + rooting=`adb shell su -c "$BB cat /dev/block/$1" | grep -s -m 1 -c 'ROOTING_ALLOWED='` + s1Boot=`adb shell su -c "$BB cat /dev/block/$1" | grep -s -m 1 -c -i 'S1_Boot'` + s1Loader=`adb shell su -c "$BB cat /dev/block/$1" | grep -s -m 1 -c -i 'S1_Loader'` + s1Hw=`adb shell su -c "$BB cat /dev/block/$1" | grep -s -m 1 -c -i 'S1_HWConf'` if [[ "$opId" =~ "1" ]] && [[ "$opName" =~ "1" ]] && [[ "$rooting" =~ "1" ]] && [[ "$s1Boot" =~ "1" ]] && [[ "$s1Loader" =~ "1" ]] && [[ "$s1Hw" =~ "1" ]] then @@ -38,25 +38,31 @@ then for part in `adb shell su -c "$BB cat /proc/partitions " | awk '{if ($3<=9999) print $4}'|grep --color=never mmcblk|xargs` do safepart=`expr match "$part" '\([0-9a-z\/]*\)'` - echo ? $safepart + echo Testing $safepart possible=$(inspectPartition "$safepart") - echo = $possible - x=`adb shell su -c "$BB cat /dev/block/$safepart | $BB grep -s -m 1 -c 'OP_ID='"` + + if [[ "$possible" =~ "mmc" ]] && [[ "$partition" =~ "mmc" ]] + then + echo Found more than one partition + exit 1 + fi + + if [[ "$possible" =~ "mmc" ]] && [[ "$partition" == "" ]] + then + partition="$possible" + fi done - echo + echo partition $partition - #more than one match - fail - - #one - OK + if [[ "$partition" == "" ]] + then + echo No partitions found. + exit 1 + fi - echo found /dev/block/$part - export partition=/dev/block/$part - - #else - - echo No partitions found. - exit 1 + echo found by type /dev/block/$partition + export backup_defaultTA=/dev/block/$partition fi backup_defaultTAvalid=`adb shell su -c "if [ -b $backup_defaultTA ]; then echo '1'; else echo '0'; fi"` @@ -64,7 +70,7 @@ backup_defaultTAvalid=`adb shell su -c "if [ -b $backup_defaultTA ]; then echo ' if [[ "$backup_defaultTAvalid" =~ "1" ]] then export partition=$backup_defaultTA - echo found $partition + echo found and valid $partition else echo Partition found but not valid echo backup_defaultTA $backup_defaultTA From 5ba9e4504aeb5f0a857df829e04f296b0579ca59 Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Sun, 9 Nov 2014 12:47:49 +0000 Subject: [PATCH 09/10] Correctly pass found partition from find script Fix escapes on menu script --- Backup-TA.sh | 2 +- scripts/linux/backup.sh | 8 +++----- scripts/linux/find.sh | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Backup-TA.sh b/Backup-TA.sh index 517e198..cc8d1ec 100755 --- a/Backup-TA.sh +++ b/Backup-TA.sh @@ -9,7 +9,7 @@ echo "[ Initialization ]" echo "[ ]" echo "[ Make sure that you have USB Debugging enabled, you do ]" echo "[ allow your computer ADB access by accepting its RSA key ]" -echo "[ \(only needed for Android 4.2.2 or higher\) and grant this ]" +echo "[ (only needed for Android 4.2.2 or higher) and grant this ]" echo "[ ADB process root permissions through superuser. ]" echo "[ ]" echo "[ On your computer, you need adb installed and working ]" diff --git a/scripts/linux/backup.sh b/scripts/linux/backup.sh index 2ce880a..11f50c4 100755 --- a/scripts/linux/backup.sh +++ b/scripts/linux/backup.sh @@ -8,9 +8,10 @@ adb wait-for-device ./busybox-on.sh - -partition="" +touch /tmp/partfile ./find.sh +partition=`cat /tmp/partfile` +rm /tmp/partfile echo ======================================= echo FIND TA PARTITION @@ -23,9 +24,6 @@ then exit -1 fi -echo debug exit -exit 1 - echo ======================================= echo BACKUP TA PARTITION echo ======================================= diff --git a/scripts/linux/find.sh b/scripts/linux/find.sh index e97ab3a..f2050d5 100755 --- a/scripts/linux/find.sh +++ b/scripts/linux/find.sh @@ -69,7 +69,7 @@ backup_defaultTAvalid=`adb shell su -c "if [ -b $backup_defaultTA ]; then echo ' if [[ "$backup_defaultTAvalid" =~ "1" ]] then - export partition=$backup_defaultTA + echo $backup_defaultTA > /tmp/partfile echo found and valid $partition else echo Partition found but not valid From f21f9745c5cc17e08db976b5569c63e91f21575e Mon Sep 17 00:00:00 2001 From: Tom Chiverton Date: Sun, 9 Nov 2014 12:51:33 +0000 Subject: [PATCH 10/10] correct md5sum calls --- scripts/linux/backup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/linux/backup.sh b/scripts/linux/backup.sh index 11f50c4..13d53b4 100755 --- a/scripts/linux/backup.sh +++ b/scripts/linux/backup.sh @@ -27,14 +27,14 @@ fi echo ======================================= echo BACKUP TA PARTITION echo ======================================= -backup_currentPartitionMD5=`adb shell su -c "$BB md5sum $partition" | awk {'print $1'}` +backup_currentPartitionMD5=`adb shell su -c "$BB md5 $partition" | awk {'print $1'}` adb shell su -c "$BB dd if=$partition of=/sdcard/backupTA.img" echo echo ======================================= echo INTEGRITY CHECK echo ======================================= -backup_backupMD5=`adb shell su -c "$BB md5sum /sdcard/backupTA.img" | awk {'print $1'}` +backup_backupMD5=`adb shell su -c "$BB md5 /sdcard/backupTA.img" | awk {'print $1'}` if [ "$backup_currentPartitionMD5" != "$backup_backupMD5" ] then