kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # |
| 3 | # Backup and restore proprietary Android system files |
| 4 | # |
| 5 | |
| 6 | C=/tmp/backupdir |
| 7 | S=/system |
Diogo Ferreira | 7d3ab80 | 2010-12-22 01:44:54 +0000 | [diff] [blame] | 8 | V=CyanogenMod-7 |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 9 | |
| 10 | PROCEED=1; |
| 11 | |
| 12 | check_prereq() { |
| 13 | if ( ! grep -q "^ro.modversion=.*$V.*" /system/build.prop ); |
| 14 | then |
| 15 | echo "Not backing up files from incompatible version."; |
| 16 | PROCEED=0; |
| 17 | fi |
| 18 | } |
| 19 | |
| 20 | check_installscript() { |
PaulW | cfe876c | 2011-05-13 12:56:19 +0100 | [diff] [blame] | 21 | if [ -f "/tmp/.installscript" ] && [ $PROCEED -ne 0 ]; |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 22 | then |
PaulW | cfe876c | 2011-05-13 12:56:19 +0100 | [diff] [blame] | 23 | # We have an install script, and ROM versions match! |
| 24 | # We now need to check and see if we have force_backup |
| 25 | # in either /etc or /tmp/backupdir |
| 26 | if [ -f "$S/etc/force_backuptool" ] || [ -f "$C/force_backuptool" ]; |
| 27 | then |
| 28 | echo "force_backuptool file found, Forcing backuptool." |
| 29 | else |
| 30 | echo "/tmp/.installscript found. Skipping backuptool." |
| 31 | PROCEED=0; |
| 32 | fi |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 33 | fi |
| 34 | } |
| 35 | |
| 36 | get_files() { |
| 37 | cat <<EOF |
blunden | b07bc18 | 2011-03-02 02:29:01 +0100 | [diff] [blame] | 38 | app/BooksPhone.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 39 | app/CarHomeGoogle.apk |
| 40 | app/CarHomeLauncher.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 41 | app/Facebook.apk |
Steve Kondik | 6e12dad | 2010-12-14 21:11:23 -0500 | [diff] [blame] | 42 | app/FOTAKill.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 43 | app/GenieWidget.apk |
| 44 | app/Gmail.apk |
| 45 | app/GoogleBackupTransport.apk |
| 46 | app/GoogleCalendarSyncAdapter.apk |
| 47 | app/GoogleContactsSyncAdapter.apk |
| 48 | app/GoogleFeedback.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 49 | app/GooglePartnerSetup.apk |
Steve Kondik | e0b98d0 | 2010-07-02 16:33:54 -0400 | [diff] [blame] | 50 | app/GoogleQuickSearchBox.apk app/QuickSearchBox.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 51 | app/GoogleServicesFramework.apk |
| 52 | app/googlevoice.apk |
| 53 | app/HtcCopyright.apk |
| 54 | app/HtcEmailPolicy.apk |
| 55 | app/HtcSettings.apk |
| 56 | app/kickback.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 57 | app/LatinImeTutorial.apk |
Steve Kondik | d89a39c | 2010-06-29 02:46:10 -0400 | [diff] [blame] | 58 | app/Maps.apk |
Patrick Jacques | 13ce18b | 2010-11-29 23:24:12 -0700 | [diff] [blame] | 59 | app/MapsSapphire.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 60 | app/MarketUpdater.apk |
| 61 | app/MediaUploader.apk |
| 62 | app/NetworkLocation.apk |
| 63 | app/OneTimeInitializer.apk |
| 64 | app/PassionQuickOffice.apk |
Patrick Jacques | 13ce18b | 2010-11-29 23:24:12 -0700 | [diff] [blame] | 65 | app/Quickoffice.apk |
Steve Kondik | e0b98d0 | 2010-07-02 16:33:54 -0400 | [diff] [blame] | 66 | app/SetupWizard.apk app/Provision.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 67 | app/soundback.apk |
| 68 | app/Street.apk |
| 69 | app/Talk.apk |
blunden | 05bd2e3 | 2011-05-04 12:56:18 +0200 | [diff] [blame] | 70 | app/Talk2.apk |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 71 | app/talkback.apk |
| 72 | app/Twitter.apk |
| 73 | app/Vending.apk |
| 74 | app/VoiceSearch.apk |
| 75 | app/YouTube.apk |
| 76 | etc/permissions/com.google.android.maps.xml |
Steve Kondik | 1bfa132 | 2010-06-28 21:16:14 -0400 | [diff] [blame] | 77 | etc/permissions/features.xml |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 78 | framework/com.google.android.maps.jar |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 79 | lib/libspeech.so |
blunden | 05bd2e3 | 2011-05-04 12:56:18 +0200 | [diff] [blame] | 80 | lib/libtalk_jni.so |
Steve Kondik | 6721ac9 | 2010-08-16 18:55:59 -0400 | [diff] [blame] | 81 | lib/libvoicesearch.so |
Steve Kondik | 94ca1ae | 2010-07-11 02:49:36 -0400 | [diff] [blame] | 82 | etc/hosts |
Kali- | 9f1dab0 | 2010-08-14 23:46:34 +0200 | [diff] [blame] | 83 | etc/custom_backup_list.txt |
ladios | e7cc354 | 2011-01-24 13:47:14 +0800 | [diff] [blame] | 84 | etc/force_backuptool |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 85 | EOF |
| 86 | } |
| 87 | |
Kali- | 9f1dab0 | 2010-08-14 23:46:34 +0200 | [diff] [blame] | 88 | get_custom_files() { |
| 89 | local L |
| 90 | if [ -f "$C/custom_backup_list.txt" ]; |
| 91 | then |
| 92 | [ ! -f $C/fixed_custom_backup_list.txt ] && tr -d '\r' < $C/custom_backup_list.txt \ |
| 93 | > $C/fixed_custom_backup_list.txt |
| 94 | L=`cat $C/fixed_custom_backup_list.txt` |
| 95 | cat <<EOF |
| 96 | $L |
| 97 | EOF |
| 98 | fi |
| 99 | } |
| 100 | |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 101 | backup_file() { |
| 102 | if [ -e "$1" ]; |
| 103 | then |
| 104 | if [ -n "$2" ]; |
| 105 | then |
| 106 | echo "$2 $1" | md5sum -c - |
| 107 | if [ $? -ne 0 ]; |
| 108 | then |
| 109 | echo "MD5Sum check for $1 failed!"; |
| 110 | exit $?; |
| 111 | fi |
| 112 | fi |
| 113 | |
| 114 | local F=`basename $1` |
| 115 | |
| 116 | # dont backup any apps that have odex files, they are useless |
| 117 | if ( echo $F | grep -q "\.apk$" ) && [ -e `echo $1 | sed -e 's/\.apk$/\.odex/'` ]; |
| 118 | then |
| 119 | echo "Skipping odexed apk $1"; |
| 120 | else |
Steve Kondik | 715f2d5 | 2010-07-05 19:36:33 -0400 | [diff] [blame] | 121 | cp -p $1 $C/$F |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 122 | fi |
| 123 | fi |
| 124 | } |
| 125 | |
| 126 | restore_file() { |
| 127 | local FILE=`basename $1` |
| 128 | local DIR=`dirname $1` |
| 129 | if [ -e "$C/$FILE" ]; |
| 130 | then |
| 131 | if [ ! -d "$DIR" ]; |
| 132 | then |
| 133 | mkdir -p $DIR; |
| 134 | fi |
| 135 | cp -p $C/$FILE $1; |
| 136 | if [ -n "$2" ]; |
| 137 | then |
| 138 | rm $2; |
| 139 | fi |
| 140 | fi |
| 141 | } |
| 142 | |
Tanguy Pruvot | 1ef5075 | 2011-06-15 10:40:23 +0200 | [diff] [blame] | 143 | # don't (u)mount system if already done |
| 144 | UMOUNT=0 |
| 145 | |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 146 | case "$1" in |
| 147 | backup) |
Tanguy Pruvot | 1ef5075 | 2011-06-15 10:40:23 +0200 | [diff] [blame] | 148 | if [ ! -f "$S/build.prop" ]; then |
| 149 | mount $S |
| 150 | UMOUNT=1 |
| 151 | fi |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 152 | check_prereq; |
PaulW | cfe876c | 2011-05-13 12:56:19 +0100 | [diff] [blame] | 153 | check_installscript; |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 154 | if [ $PROCEED -ne 0 ]; |
| 155 | then |
| 156 | rm -rf $C |
| 157 | mkdir -p $C |
Kali- | 9f1dab0 | 2010-08-14 23:46:34 +0200 | [diff] [blame] | 158 | for file_list in get_files get_custom_files; do |
| 159 | $file_list | while read FILE REPLACEMENT; do |
| 160 | backup_file $S/$FILE |
| 161 | done |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 162 | done |
| 163 | fi |
Tanguy Pruvot | 1ef5075 | 2011-06-15 10:40:23 +0200 | [diff] [blame] | 164 | if [ $UMOUNT -ne 0 ]; then |
| 165 | umount $S |
| 166 | fi |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 167 | ;; |
| 168 | restore) |
Tanguy Pruvot | 1ef5075 | 2011-06-15 10:40:23 +0200 | [diff] [blame] | 169 | if [ ! -f "$S/build.prop" ]; then |
| 170 | mount $S |
| 171 | UMOUNT=1 |
| 172 | fi |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 173 | check_prereq; |
PaulW | cfe876c | 2011-05-13 12:56:19 +0100 | [diff] [blame] | 174 | check_installscript; |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 175 | if [ $PROCEED -ne 0 ]; |
| 176 | then |
Kali- | 9f1dab0 | 2010-08-14 23:46:34 +0200 | [diff] [blame] | 177 | for file_list in get_files get_custom_files; do |
| 178 | $file_list | while read FILE REPLACEMENT; do |
| 179 | R="" |
| 180 | [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT" |
| 181 | restore_file $S/$FILE $R |
| 182 | done |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 183 | done |
| 184 | rm -rf $C |
| 185 | fi |
Tanguy Pruvot | 1ef5075 | 2011-06-15 10:40:23 +0200 | [diff] [blame] | 186 | if [ $UMOUNT -ne 0 ]; then |
| 187 | umount $S |
| 188 | fi |
| 189 | sync |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 190 | ;; |
| 191 | *) |
| 192 | echo "Usage: $0 {backup|restore}" |
| 193 | exit 1 |
| 194 | esac |
| 195 | |
| 196 | exit 0 |