Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another version of linux backup #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Backup-TA.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
VERSION="9.11"
path=`dirname $0`

for i in scripts/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

cd $path
[ ! -d "tmpbak" ] && mkdir tmpbak > /dev/null 2>&1
showLicense

initialize
wakeDevice
pushBusyBox
hasRoot
showMenu
quit
5 changes: 5 additions & 0 deletions scripts/adb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function wakeDevice {
echo -n "Waiting for USB Debugging... "
$ADB wait-for-device > /dev/null
echo "OK"
}
1 change: 1 addition & 0 deletions scripts/android/adb_root_shell.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ADB shell su -c "$BB $(< $ANDROID/$1)$2"
1 change: 1 addition & 0 deletions scripts/android/adb_shell.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ADB shell $BB $(< $ANDROID/$1)
1 change: 1 addition & 0 deletions scripts/android/check_su_binary
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
which su
1 change: 1 addition & 0 deletions scripts/android/list_partitions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
awk '{if (\$3<=9999 && match (\$4, \"mmcblk\")) printf \"%s\n\", \$4}' /proc/partitions
1 change: 1 addition & 0 deletions scripts/android/readlink
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
readlink -n
1 change: 1 addition & 0 deletions scripts/android/request_root
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo true
1 change: 1 addition & 0 deletions scripts/android/search_operator_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grep -s -m 1 -c 'OP_ID=' /dev/block/
1 change: 1 addition & 0 deletions scripts/android/search_operator_name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grep -s -m 1 -c 'OP_NAME=' /dev/block/
1 change: 1 addition & 0 deletions scripts/android/search_rooting_allowed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grep -s -m 1 -c 'ROOTING_ALLOWED=' /dev/block/
1 change: 1 addition & 0 deletions scripts/android/search_s1_boot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grep -s -m 1 -c 'S1_Boot' /dev/block/
1 change: 1 addition & 0 deletions scripts/android/search_s1_hwconf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grep -s -m 1 -c 'S1_HWConf' /dev/block/
1 change: 1 addition & 0 deletions scripts/android/search_s1_loader
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grep -s -m 1 -c 'S1_Loader' /dev/block/
179 changes: 179 additions & 0 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#####################
## BACKUP
#####################
function inspectPartition() {
part=$1
echo " --- $part --- "
echo -n "Searching for Operator Identifier... "
if [[ "`. $ADB_ROOT_SHELL search_operator_id $part`" == *1* ]]; then
echo "+"
echo -n "Searching for Operator Name... "
if [[ "`. $ADB_ROOT_SHELL search_operator_name $part`" == *1* ]]; then
echo "+"
echo -n "Searching for Rooting Status... "
if [[ "`. $ADB_ROOT_SHELL search_rooting_allowed $part`" == *1* ]]; then
echo "+"
echo -n "Searching for S1 Boot... "
if [[ "`. $ADB_ROOT_SHELL search_s1_boot $part`" == *1* ]]; then
echo "+"
echo -n "Searching for S1 Loader... "
if [[ "`. $ADB_ROOT_SHELL search_s1_loader $part`" == *1* ]]; then
echo "+"
echo -n "Searching for S1 Hardware Configuration... "
if [[ "`. $ADB_ROOT_SHELL search_s1_hwconf $part`" == *1* ]]; then
echo "+"
return 0
fi
fi
fi
fi
fi
fi
echo "-"
return 1
}

function backupTA {
echo
[ ! -d backup ] && mkdir backup > /dev/null 2>&1
wakeDevice
echo
echo "======================================="
echo " FIND TA PARTITION"
echo "======================================="
partition=`. $ADB_ROOT_SHELL readlink $PARTITION_BY_NAME`
if [ "`$ADB shell su -c \"[ -b '$partition' ] && echo -n 1\"`" == "1" ]; then
echo "Partition found!"
else
echo "Partition not found by name."
echo
read -n1 -s -p "Do you want to perform an extensive search for the TA? Y/n" CHOICE
case $CHOICE in
[Nn]) onBackupCancelled ;;
esac

echo
echo "======================================="
echo " INSPECTING PARTITIONS"
echo "======================================="
backup_taPartitionName=
while read partition; do
partition=$(echo "$partition" | tr -dc "[:alnum:]")
inspectPartition $partition
if [ "$?" == "0" ]; then
if [ "$backup_taPartitionName" == "" ]; then
backup_taPartitionName="/dev/block/$partition"
echo "Partition found^^!"
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. ***"
onBackupCancelled
fi
fi
done < <(. $ADB_ROOT_SHELL list_partitions)

if [ "$backup_taPartitionName" == "" ]; then
echo "*** No compatible TA partition found on your device. ***"
onBackupCancelled
fi
partition=$backup_taPartitionName
fi

echo
echo "======================================="
echo " BACKUP TA PARTITION"
echo "======================================="
echo "Partition: $partition"
realSdCard=$($ADB shell su -c "$BB readlink -n /sdcard1")
currentPartitionMD5=$($ADB shell su -c "$BB md5sum $partition | $BB awk {'printf \\\$1'}")
$ADB shell su -c "$BB dd if=$partition of=$realSdCard/backupTA.img"

echo
echo "======================================="
echo " INTEGRITY CHECK"
echo "======================================="
backupMD5=$($ADB shell su -c "$BB md5sum $realSdCard/backupTA.img | $BB awk {'printf \\\$1'}")
echo -n "Backup checksum matches partition checksum... "
if [ "$currentPartitionMD5" != "$backupMD5" ]; then
echo "FAILED"
onBackupFailed
else
echo "OK"
fi

echo
echo "======================================="
echo " PULL BACKUP FROM SDCARD"
echo "======================================="
$ADB pull $realSdCard/backupTA.img tmpbak/TA.img || onBackupFailed

echo
echo "======================================="
echo " INTEGRITY CHECK"
echo "======================================="
backupPulledMD5=$(md5sum tmpbak/TA.img | awk {'printf $1'})
echo -n "Local backup checksum matches partition checksum... "
if [ "$currentPartitionMD5" != "$backupPulledMD5" ]; then
echo "FAILED"
onBackupFailed
else
echo "OK"
fi

echo
echo "======================================="
echo " PACKAGE BACKUP"
echo "======================================="
$ADB get-serialno > tmpbak/TA.serial
echo $partition > tmpbak/TA.blk
echo $backupPulledMD5 > tmpbak/TA.md5
echo $VERSION > tmpbak/TA.version
timestamp=$($ADB shell su -c \"$BB date +%Y%m%d.%H%M%S\")
echo $timestamp > tmpbak/TA.timestamp
cd tmpbak
zip ../backup/TA-backup-$timestamp.zip TA.img TA.md5 TA.blk TA.serial TA.timestamp TA.version || onBackupFailed
cd ..
exit_backup 1
}

#####################
## BACKUP CANCELLED
######################
function onBackupCancelled {
exit_backup 2
}

#####################
## BACKUP FAILED
#####################
function onBackupFailed {
exit_backup 3
}

#####################
## EXIT BACKUP
#####################
function exit_backup () {
dispose $1
echo
case $1 in
"1") echo "*** Backup successful. ***" ;;
"2") echo "*** Backup cancelled. ***" ;;
"3") echo "*** Backup failed. ***" ;;
esac
echo
read -n1 -s
exit $1
}

#####################
## DISPOSE BACKUP
#####################
function backup_dispose {
if [ "$1" == "1" ]; then
rm -rf tmpbak/backup_*.* > /dev/null 2>&1
rm -rf tmpbak\TA.* > /dev/null 2>&1
fi
$ADB shell rm /sdcard/backupTA.img > /dev/null 2>&1
}
22 changes: 22 additions & 0 deletions scripts/busybox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#####################
## PUSH BUSYBOX
#####################
function pushBusyBox {
echo -n "Pushing Backup TA Tools... "
$ADB push tools/busybox $BB > /dev/null 2>&1
$ADB shell chmod 755 $BB > /dev/null 2>&1
echo "OK"
}

#####################
## REMOVE BUSYBOX
#####################
function removeBusyBox {
echo -n "Removing Backup TA Tools... "
$ADB shell rm $BB > /dev/null 2>&1
echo "OK"
}

function busybox_dispose {
removeBusyBox
}
61 changes: 61 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
#####################
## INITIALIZE
#####################
function initialize {
clear
echo
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
PARTITION_BY_NAME="/dev/block/platform/msm_sdcc.1/by-name/TA"
BB="/data/local/tmp/busybox-backup-ta"
ADB="tools/adb.linux"
SCRIPTS="./scripts"
ANDROID="$SCRIPTS/android"
ADB_SHELL="$ANDROID/adb_shell.linux"
ADB_ROOT_SHELL="$ANDROID/adb_root_shell.linux"
}

#####################
## DISPOSE
#####################
function dispose {
echo
echo "======================================="
echo " CLEAN UP"
echo "======================================="
partition=
choiceTextParam=
choice=

backup_dispose
restore_dispose
convert_dispose

[ -d "tmpbak" ] && rm -rf tmpbak

busybox_dispose

echo "=Killing ADB Daemon..."
$ADB kill-server > nul 2>&1

echo "OK"
}

#####################
## QUIT
#####################
function quit {
dispose
echo
read -p "Press any key to exit" -n1 -s
}
38 changes: 38 additions & 0 deletions scripts/license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
####################
## LICENSE
#####################
function showLicense {
clear
echo
echo "[ ———––––----------------------------------------------––––——— ]"
echo "[ Backup TA v$VERSION for Sony Xperia MIT License ]"
echo "[ ———––––----------------------------------------------––––——— ]"
echo "[ Copyright (C) 2013 DevShaft ]"
echo "[ ]"
echo "[ Permission is hereby granted, free of charge, ]"
echo "[ to any person obtaining a copy of this software ]"
echo "[ and associated documentation files (the \"Software\"), ]"
echo "[ to deal in the Software without restriction, ]"
echo "[ including without limitation the rights to use, ]"
echo "[ copy, modify, merge, publish, distribute, sublicense, ]"
echo "[ and/or sell copies of the Software, and to permit ]"
echo "[ persons to whom the Software is furnished to do so, ]"
echo "[ subject to the following conditions: ]"
echo "[ ]"
echo "[ The above copyright notice and this permission notice ]"
echo "[ shall be included in all copies or substantial portions ]"
echo "[ of the Software. ]"
echo "[ ]"
echo "[ THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY ]"
echo "[ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ]"
echo "[ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR ]"
echo "[ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ]"
echo "[ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR ]"
echo "[ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ]"
echo "[ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ]"
echo "[ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]"
echo "[ ———––––----------------------------------------------––––——— ]"
echo
read -n1 -s -t5
# -p $'Press N to abort\n' ESC || exit && [ $ESC == 'N' ] && exit
}
Loading