Skip to content

Commit

Permalink
Replaced all grep with awk commands for searching through lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
DevShaft committed Jul 7, 2013
1 parent d5cf7df commit ab54381
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
19 changes: 10 additions & 9 deletions scripts/backup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ echo.
echo =======================================
echo FIND TA PARTITION
echo =======================================
tools\adb shell su -c "%BB% ls -l %PARTITION_BY_NAME% | %BB% grep -o 'TA ->' | %BB% grep -o 'TA'">tmpbak\backup_TAByName
set /p backup_TAByName=<tmpbak\backup_TAByName
if "!backup_TAByName!" == "TA" (
tools\adb shell su -c "%BB% ls -l %PARTITION_BY_NAME% | %BB% grep -o '/dev/block/mmc.*'">tmpbak\backup_defaultTA
set /p backup_defaultTA=<tmpbak\backup_defaultTA
tools\adb shell su -c "%BB% ls -l %PARTITION_BY_NAME% | %BB% awk '{print \$11}'">tmpbak\backup_defaultTA
set /p backup_defaultTA=<tmpbak\backup_defaultTA
tools\adb shell su -c "if [ -b '!backup_defaultTA!' ]; then echo '1'; else echo '0'; fi">tmpbak\backup_defaultTAvalid
set /p backup_defaultTAvalid=<tmpbak\backup_defaultTAvalid
if "!backup_defaultTAvalid!" == "1" (
set partition=!backup_defaultTA!
echo Partition found^^!
) else (
Expand All @@ -67,8 +67,7 @@ if "!backup_TAByName!" == "TA" (
echo INSPECTING PARTITIONS
echo =======================================
set backup_taPartitionName=

tools\adb shell su -c "%BB% cat /proc/partitions | %BB% grep -o ' [0-9]\{1,4\} mmc.*' | %BB% grep -o 'mmc.*'">tmpbak\backup_potentialPartitions
tools\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!" == "" (
Expand All @@ -92,14 +91,14 @@ echo.
echo =======================================
echo BACKUP TA PARTITION
echo =======================================
tools\adb shell su -c "%BB% md5sum !partition! | %BB% grep -o '^^[^^ ]*'">tmpbak\backup_currentPartitionMD5
tools\adb shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\backup_currentPartitionMD5
tools\adb shell su -c "%BB% dd if=!partition! of=/sdcard/backupTA.img"

echo.
echo =======================================
echo INTEGRITY CHECK
echo =======================================
tools\adb shell su -c "%BB% md5sum /sdcard/backupTA.img | %BB% grep -o '^[^ ]*'">tmpbak\backup_backupMD5
tools\adb shell su -c "%BB% md5sum /sdcard/backupTA.img | %BB% awk {'print \$1'}">tmpbak\backup_backupMD5
set /p backup_currentPartitionMD5=<tmpbak\backup_currentPartitionMD5
set /p backup_backupMD5=<tmpbak\backup_backupMD5
verify > nul
Expand Down Expand Up @@ -182,6 +181,8 @@ REM #####################
set backup_currentPartitionMD5=
set backup_backupMD5=
set backup_backupPulledMD5=
set backup_defaultTA=
set backup_defaultTAvalid=
set backup_matchSerial=
set backup_matchMarlin=
set backup_taPartitionName=
Expand Down
8 changes: 4 additions & 4 deletions scripts/restore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ echo.
echo =======================================
echo COMPARE TA PARTITION WITH BACKUP
echo =======================================
tools\adb shell su -c "%BB% md5sum !partition! | %BB% grep -o '^^[^^ ]*'">tmpbak\restore_currentPartitionMD5
tools\adb shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\restore_currentPartitionMD5
set /p restore_currentPartitionMD5=<tmpbak\restore_currentPartitionMD5
verify > nul
if "!restore_currentPartitionMD5!" == "!restore_savedBackupMD5!" (
Expand Down Expand Up @@ -117,7 +117,7 @@ echo.
echo =======================================
echo INTEGRITY CHECK
echo =======================================
tools\adb shell su -c "%BB% md5sum /sdcard/restoreTA.img | %BB% grep -o '^[^ ]*'">tmpbak\restore_pushedBackupMD5
tools\adb shell su -c "%BB% md5sum /sdcard/restoreTA.img | %BB% awk {'print \$1'}">tmpbak\restore_pushedBackupMD5
if NOT "%errorlevel%" == "0" goto onRestoreFailed
set /p restore_pushedBackupMD5=<tmpbak\restore_pushedBackupMD5
verify > nul
Expand Down Expand Up @@ -164,7 +164,7 @@ echo.
echo =======================================
echo COMPARE NEW TA PARTITION WITH BACKUP
echo =======================================
tools\adb shell su -c "%BB% md5sum !partition! | %BB% grep -o '^^[^^ ]*'">tmpbak\restore_restoredMD5
tools\adb shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\restore_restoredMD5
if NOT "%restore_dryRun%" == "1" (
set /p restore_restoredMD5=<tmpbak\restore_restoredMD5
verify > nul
Expand Down Expand Up @@ -220,7 +220,7 @@ echo.
echo =======================================
echo REVERT VERIFICATION
echo =======================================
tools\adb shell su -c "%BB% md5sum !partition! | %BB% grep -o '^^[^^ ]*'">tmpbak\restore_revertedMD5
tools\adb shell su -c "%BB% md5sum !partition! | %BB% awk {'print \$1'}">tmpbak\restore_revertedMD5
if NOT "%restore_dryRun%" == "1" (
set /p restore_revertedMD5=<tmpbak\restore_revertedMD5
) else (
Expand Down

0 comments on commit ab54381

Please sign in to comment.