blob: dc4590aa725aac7994e75ad786926e2609ac0d51 [file] [log] [blame]
kmobse051cf32010-06-24 22:36:11 -05001#!/sbin/sh
2#
3# Backup and restore proprietary Android system files
4#
5
6C=/tmp/backupdir
7S=/system
Diogo Ferreira7d3ab802010-12-22 01:44:54 +00008V=CyanogenMod-7
kmobse051cf32010-06-24 22:36:11 -05009
10PROCEED=1;
11
12check_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
20check_installscript() {
ladiose7cc3542011-01-24 13:47:14 +080021 if [ -f "/tmp/.installscript" -a ! -f "$S/etc/force_backuptool" ];
kmobse051cf32010-06-24 22:36:11 -050022 then
23 echo "/tmp/.installscript found. Skipping backuptool."
24 PROCEED=0;
25 fi
26}
27
28get_files() {
29 cat <<EOF
blundenb07bc182011-03-02 02:29:01 +010030app/BooksPhone.apk
kmobse051cf32010-06-24 22:36:11 -050031app/CarHomeGoogle.apk
32app/CarHomeLauncher.apk
kmobse051cf32010-06-24 22:36:11 -050033app/Facebook.apk
Steve Kondik6e12dad2010-12-14 21:11:23 -050034app/FOTAKill.apk
kmobse051cf32010-06-24 22:36:11 -050035app/GenieWidget.apk
36app/Gmail.apk
37app/GoogleBackupTransport.apk
38app/GoogleCalendarSyncAdapter.apk
39app/GoogleContactsSyncAdapter.apk
40app/GoogleFeedback.apk
kmobse051cf32010-06-24 22:36:11 -050041app/GooglePartnerSetup.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040042app/GoogleQuickSearchBox.apk app/QuickSearchBox.apk
kmobse051cf32010-06-24 22:36:11 -050043app/GoogleServicesFramework.apk
44app/googlevoice.apk
45app/HtcCopyright.apk
46app/HtcEmailPolicy.apk
47app/HtcSettings.apk
48app/kickback.apk
kmobse051cf32010-06-24 22:36:11 -050049app/LatinImeTutorial.apk
Steve Kondikd89a39c2010-06-29 02:46:10 -040050app/Maps.apk
Patrick Jacques13ce18b2010-11-29 23:24:12 -070051app/MapsSapphire.apk
kmobse051cf32010-06-24 22:36:11 -050052app/MarketUpdater.apk
53app/MediaUploader.apk
54app/NetworkLocation.apk
55app/OneTimeInitializer.apk
56app/PassionQuickOffice.apk
Patrick Jacques13ce18b2010-11-29 23:24:12 -070057app/Quickoffice.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040058app/SetupWizard.apk app/Provision.apk
kmobse051cf32010-06-24 22:36:11 -050059app/soundback.apk
60app/Street.apk
61app/Talk.apk
blunden05bd2e32011-05-04 12:56:18 +020062app/Talk2.apk
kmobse051cf32010-06-24 22:36:11 -050063app/talkback.apk
64app/Twitter.apk
65app/Vending.apk
66app/VoiceSearch.apk
67app/YouTube.apk
68etc/permissions/com.google.android.maps.xml
Steve Kondik1bfa1322010-06-28 21:16:14 -040069etc/permissions/features.xml
kmobse051cf32010-06-24 22:36:11 -050070framework/com.google.android.maps.jar
kmobse051cf32010-06-24 22:36:11 -050071lib/libspeech.so
blunden05bd2e32011-05-04 12:56:18 +020072lib/libtalk_jni.so
Steve Kondik6721ac92010-08-16 18:55:59 -040073lib/libvoicesearch.so
Steve Kondik94ca1ae2010-07-11 02:49:36 -040074etc/hosts
Kali-9f1dab02010-08-14 23:46:34 +020075etc/custom_backup_list.txt
ladiose7cc3542011-01-24 13:47:14 +080076etc/force_backuptool
kmobse051cf32010-06-24 22:36:11 -050077EOF
78}
79
Kali-9f1dab02010-08-14 23:46:34 +020080get_custom_files() {
81 local L
82 if [ -f "$C/custom_backup_list.txt" ];
83 then
84 [ ! -f $C/fixed_custom_backup_list.txt ] && tr -d '\r' < $C/custom_backup_list.txt \
85 > $C/fixed_custom_backup_list.txt
86 L=`cat $C/fixed_custom_backup_list.txt`
87 cat <<EOF
88$L
89EOF
90 fi
91}
92
kmobse051cf32010-06-24 22:36:11 -050093backup_file() {
94 if [ -e "$1" ];
95 then
96 if [ -n "$2" ];
97 then
98 echo "$2 $1" | md5sum -c -
99 if [ $? -ne 0 ];
100 then
101 echo "MD5Sum check for $1 failed!";
102 exit $?;
103 fi
104 fi
105
106 local F=`basename $1`
107
108 # dont backup any apps that have odex files, they are useless
109 if ( echo $F | grep -q "\.apk$" ) && [ -e `echo $1 | sed -e 's/\.apk$/\.odex/'` ];
110 then
111 echo "Skipping odexed apk $1";
112 else
Steve Kondik715f2d52010-07-05 19:36:33 -0400113 cp -p $1 $C/$F
kmobse051cf32010-06-24 22:36:11 -0500114 fi
115 fi
116}
117
118restore_file() {
119 local FILE=`basename $1`
120 local DIR=`dirname $1`
121 if [ -e "$C/$FILE" ];
122 then
123 if [ ! -d "$DIR" ];
124 then
125 mkdir -p $DIR;
126 fi
127 cp -p $C/$FILE $1;
128 if [ -n "$2" ];
129 then
130 rm $2;
131 fi
132 fi
133}
134
135check_installscript;
136
137case "$1" in
138 backup)
139 mount $S
140 check_prereq;
141 if [ $PROCEED -ne 0 ];
142 then
143 rm -rf $C
144 mkdir -p $C
Kali-9f1dab02010-08-14 23:46:34 +0200145 for file_list in get_files get_custom_files; do
146 $file_list | while read FILE REPLACEMENT; do
147 backup_file $S/$FILE
148 done
kmobse051cf32010-06-24 22:36:11 -0500149 done
150 fi
151 umount $S
152 ;;
153 restore)
154 check_prereq;
155 if [ $PROCEED -ne 0 ];
156 then
Kali-9f1dab02010-08-14 23:46:34 +0200157 for file_list in get_files get_custom_files; do
158 $file_list | while read FILE REPLACEMENT; do
159 R=""
160 [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
161 restore_file $S/$FILE $R
162 done
kmobse051cf32010-06-24 22:36:11 -0500163 done
164 rm -rf $C
165 fi
166 ;;
167 *)
168 echo "Usage: $0 {backup|restore}"
169 exit 1
170esac
171
172exit 0