replicant-vendor_replicant/prebuilt/common/bin/backuptool.sh

181 lines
3.8 KiB
Bash
Raw Normal View History

2010-06-25 03:36:11 +00:00
#!/sbin/sh
#
# Backup and restore proprietary Android system files
#
C=/tmp/backupdir
S=/system
V=CyanogenMod-7
2010-06-25 03:36:11 +00:00
PROCEED=1;
check_prereq() {
if ( ! grep -q "^ro.modversion=.*$V.*" /system/build.prop );
then
echo "Not backing up files from incompatible version.";
PROCEED=0;
fi
}
check_installscript() {
Update backuptool.sh to correctly process force_backuptool flag/file. This is regarding the following patch: https://github.com/CyanogenMod/android_vendor_cyanogen/commit/5cdb4ec653b06721dcc6f0b486943d62a1a4c8c2 The patch which was to allow custom_backup_list.txt to be maintained while flashing via ROMManager WHILE the flag/file force_backuptool is set/present still has issues. There are 2 reasons for this. 1) The flag is only checked during the first pass (backuptool.sh backup), as once /etc/force_backuptool is known to exist, all files are moved to /tmp/backupdir as designated, but when the script is ran again once /system has been wiped and updated, the file /etc/force_backuptool no longer exists as it was moved to /tmp/backupdir/force_backuptool, so the script fails as it is not checking that location. 2) When the backuptool.sh script is called, the above function (checking for force_backuptool) is called *before* the /system partition is mounted. This therefor ignores the file regardless of whether it exists or not. This is caused by check_installscript being called at the wrong point of the script. There are therefor 2(two) main changes to this script to allow the force_backuptool override to work. The first being within the main function of check_installscript, and the second being the location of where check_installscript is called (ie, I moved it to below check_prereq call in the case statement, as mounting is called before the check_prereq function checks if the ROM version is the same). This affects *all* devices. Change-Id: Ia7438f396eaa91b0723e56bb32ce98725e2b2025
2011-05-13 11:56:19 +00:00
if [ -f "/tmp/.installscript" ] && [ $PROCEED -ne 0 ];
2010-06-25 03:36:11 +00:00
then
Update backuptool.sh to correctly process force_backuptool flag/file. This is regarding the following patch: https://github.com/CyanogenMod/android_vendor_cyanogen/commit/5cdb4ec653b06721dcc6f0b486943d62a1a4c8c2 The patch which was to allow custom_backup_list.txt to be maintained while flashing via ROMManager WHILE the flag/file force_backuptool is set/present still has issues. There are 2 reasons for this. 1) The flag is only checked during the first pass (backuptool.sh backup), as once /etc/force_backuptool is known to exist, all files are moved to /tmp/backupdir as designated, but when the script is ran again once /system has been wiped and updated, the file /etc/force_backuptool no longer exists as it was moved to /tmp/backupdir/force_backuptool, so the script fails as it is not checking that location. 2) When the backuptool.sh script is called, the above function (checking for force_backuptool) is called *before* the /system partition is mounted. This therefor ignores the file regardless of whether it exists or not. This is caused by check_installscript being called at the wrong point of the script. There are therefor 2(two) main changes to this script to allow the force_backuptool override to work. The first being within the main function of check_installscript, and the second being the location of where check_installscript is called (ie, I moved it to below check_prereq call in the case statement, as mounting is called before the check_prereq function checks if the ROM version is the same). This affects *all* devices. Change-Id: Ia7438f396eaa91b0723e56bb32ce98725e2b2025
2011-05-13 11:56:19 +00:00
# We have an install script, and ROM versions match!
# We now need to check and see if we have force_backup
# in either /etc or /tmp/backupdir
if [ -f "$S/etc/force_backuptool" ] || [ -f "$C/force_backuptool" ];
then
echo "force_backuptool file found, Forcing backuptool."
else
echo "/tmp/.installscript found. Skipping backuptool."
PROCEED=0;
fi
2010-06-25 03:36:11 +00:00
fi
}
get_files() {
cat <<EOF
app/BooksPhone.apk
2010-06-25 03:36:11 +00:00
app/CarHomeGoogle.apk
app/CarHomeLauncher.apk
app/Facebook.apk
app/FOTAKill.apk
2010-06-25 03:36:11 +00:00
app/GenieWidget.apk
app/Gmail.apk
app/GoogleBackupTransport.apk
app/GoogleCalendarSyncAdapter.apk
app/GoogleContactsSyncAdapter.apk
app/GoogleFeedback.apk
app/GooglePartnerSetup.apk
2010-07-02 20:33:54 +00:00
app/GoogleQuickSearchBox.apk app/QuickSearchBox.apk
2010-06-25 03:36:11 +00:00
app/GoogleServicesFramework.apk
app/googlevoice.apk
app/HtcCopyright.apk
app/HtcEmailPolicy.apk
app/HtcSettings.apk
app/kickback.apk
app/LatinImeTutorial.apk
2010-06-29 06:46:10 +00:00
app/Maps.apk
app/MapsSapphire.apk
2010-06-25 03:36:11 +00:00
app/MarketUpdater.apk
app/MediaUploader.apk
app/NetworkLocation.apk
app/OneTimeInitializer.apk
app/PassionQuickOffice.apk
app/Quickoffice.apk
2010-07-02 20:33:54 +00:00
app/SetupWizard.apk app/Provision.apk
2010-06-25 03:36:11 +00:00
app/soundback.apk
app/Street.apk
app/Talk.apk
app/Talk2.apk
2010-06-25 03:36:11 +00:00
app/talkback.apk
app/Twitter.apk
app/Vending.apk
app/VoiceSearch.apk
app/YouTube.apk
etc/permissions/com.google.android.maps.xml
2010-06-29 01:16:14 +00:00
etc/permissions/features.xml
2010-06-25 03:36:11 +00:00
framework/com.google.android.maps.jar
lib/libspeech.so
lib/libtalk_jni.so
2010-08-16 22:55:59 +00:00
lib/libvoicesearch.so
2010-07-11 06:49:36 +00:00
etc/hosts
2010-08-14 21:46:34 +00:00
etc/custom_backup_list.txt
etc/force_backuptool
2010-06-25 03:36:11 +00:00
EOF
}
2010-08-14 21:46:34 +00:00
get_custom_files() {
local L
if [ -f "$C/custom_backup_list.txt" ];
then
[ ! -f $C/fixed_custom_backup_list.txt ] && tr -d '\r' < $C/custom_backup_list.txt \
> $C/fixed_custom_backup_list.txt
L=`cat $C/fixed_custom_backup_list.txt`
cat <<EOF
$L
EOF
fi
}
2010-06-25 03:36:11 +00:00
backup_file() {
if [ -e "$1" ];
then
if [ -n "$2" ];
then
echo "$2 $1" | md5sum -c -
if [ $? -ne 0 ];
then
echo "MD5Sum check for $1 failed!";
exit $?;
fi
fi
local F=`basename $1`
# dont backup any apps that have odex files, they are useless
if ( echo $F | grep -q "\.apk$" ) && [ -e `echo $1 | sed -e 's/\.apk$/\.odex/'` ];
then
echo "Skipping odexed apk $1";
else
2010-07-05 23:36:33 +00:00
cp -p $1 $C/$F
2010-06-25 03:36:11 +00:00
fi
fi
}
restore_file() {
local FILE=`basename $1`
local DIR=`dirname $1`
if [ -e "$C/$FILE" ];
then
if [ ! -d "$DIR" ];
then
mkdir -p $DIR;
fi
cp -p $C/$FILE $1;
if [ -n "$2" ];
then
rm $2;
fi
fi
}
case "$1" in
backup)
mount $S
check_prereq;
Update backuptool.sh to correctly process force_backuptool flag/file. This is regarding the following patch: https://github.com/CyanogenMod/android_vendor_cyanogen/commit/5cdb4ec653b06721dcc6f0b486943d62a1a4c8c2 The patch which was to allow custom_backup_list.txt to be maintained while flashing via ROMManager WHILE the flag/file force_backuptool is set/present still has issues. There are 2 reasons for this. 1) The flag is only checked during the first pass (backuptool.sh backup), as once /etc/force_backuptool is known to exist, all files are moved to /tmp/backupdir as designated, but when the script is ran again once /system has been wiped and updated, the file /etc/force_backuptool no longer exists as it was moved to /tmp/backupdir/force_backuptool, so the script fails as it is not checking that location. 2) When the backuptool.sh script is called, the above function (checking for force_backuptool) is called *before* the /system partition is mounted. This therefor ignores the file regardless of whether it exists or not. This is caused by check_installscript being called at the wrong point of the script. There are therefor 2(two) main changes to this script to allow the force_backuptool override to work. The first being within the main function of check_installscript, and the second being the location of where check_installscript is called (ie, I moved it to below check_prereq call in the case statement, as mounting is called before the check_prereq function checks if the ROM version is the same). This affects *all* devices. Change-Id: Ia7438f396eaa91b0723e56bb32ce98725e2b2025
2011-05-13 11:56:19 +00:00
check_installscript;
2010-06-25 03:36:11 +00:00
if [ $PROCEED -ne 0 ];
then
rm -rf $C
mkdir -p $C
2010-08-14 21:46:34 +00:00
for file_list in get_files get_custom_files; do
$file_list | while read FILE REPLACEMENT; do
backup_file $S/$FILE
done
2010-06-25 03:36:11 +00:00
done
fi
umount $S
;;
restore)
check_prereq;
Update backuptool.sh to correctly process force_backuptool flag/file. This is regarding the following patch: https://github.com/CyanogenMod/android_vendor_cyanogen/commit/5cdb4ec653b06721dcc6f0b486943d62a1a4c8c2 The patch which was to allow custom_backup_list.txt to be maintained while flashing via ROMManager WHILE the flag/file force_backuptool is set/present still has issues. There are 2 reasons for this. 1) The flag is only checked during the first pass (backuptool.sh backup), as once /etc/force_backuptool is known to exist, all files are moved to /tmp/backupdir as designated, but when the script is ran again once /system has been wiped and updated, the file /etc/force_backuptool no longer exists as it was moved to /tmp/backupdir/force_backuptool, so the script fails as it is not checking that location. 2) When the backuptool.sh script is called, the above function (checking for force_backuptool) is called *before* the /system partition is mounted. This therefor ignores the file regardless of whether it exists or not. This is caused by check_installscript being called at the wrong point of the script. There are therefor 2(two) main changes to this script to allow the force_backuptool override to work. The first being within the main function of check_installscript, and the second being the location of where check_installscript is called (ie, I moved it to below check_prereq call in the case statement, as mounting is called before the check_prereq function checks if the ROM version is the same). This affects *all* devices. Change-Id: Ia7438f396eaa91b0723e56bb32ce98725e2b2025
2011-05-13 11:56:19 +00:00
check_installscript;
2010-06-25 03:36:11 +00:00
if [ $PROCEED -ne 0 ];
then
2010-08-14 21:46:34 +00:00
for file_list in get_files get_custom_files; do
$file_list | while read FILE REPLACEMENT; do
R=""
[ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
restore_file $S/$FILE $R
done
2010-06-25 03:36:11 +00:00
done
rm -rf $C
fi
;;
*)
echo "Usage: $0 {backup|restore}"
exit 1
esac
exit 0