blob: 85f800e5963d31738a28d708843044de036f35b9 [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() {
PaulWcfe876c2011-05-13 12:56:19 +010021 if [ -f "/tmp/.installscript" ] && [ $PROCEED -ne 0 ];
kmobse051cf32010-06-24 22:36:11 -050022 then
PaulWcfe876c2011-05-13 12:56:19 +010023 # 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
kmobse051cf32010-06-24 22:36:11 -050033 fi
34}
35
36get_files() {
37 cat <<EOF
blundenb07bc182011-03-02 02:29:01 +010038app/BooksPhone.apk
kmobse051cf32010-06-24 22:36:11 -050039app/CarHomeGoogle.apk
40app/CarHomeLauncher.apk
kmobse051cf32010-06-24 22:36:11 -050041app/Facebook.apk
Steve Kondik6e12dad2010-12-14 21:11:23 -050042app/FOTAKill.apk
kmobse051cf32010-06-24 22:36:11 -050043app/GenieWidget.apk
44app/Gmail.apk
45app/GoogleBackupTransport.apk
46app/GoogleCalendarSyncAdapter.apk
47app/GoogleContactsSyncAdapter.apk
48app/GoogleFeedback.apk
kmobse051cf32010-06-24 22:36:11 -050049app/GooglePartnerSetup.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040050app/GoogleQuickSearchBox.apk app/QuickSearchBox.apk
kmobse051cf32010-06-24 22:36:11 -050051app/GoogleServicesFramework.apk
52app/googlevoice.apk
53app/HtcCopyright.apk
54app/HtcEmailPolicy.apk
55app/HtcSettings.apk
56app/kickback.apk
kmobse051cf32010-06-24 22:36:11 -050057app/LatinImeTutorial.apk
Steve Kondikd89a39c2010-06-29 02:46:10 -040058app/Maps.apk
Patrick Jacques13ce18b2010-11-29 23:24:12 -070059app/MapsSapphire.apk
kmobse051cf32010-06-24 22:36:11 -050060app/MarketUpdater.apk
61app/MediaUploader.apk
62app/NetworkLocation.apk
63app/OneTimeInitializer.apk
64app/PassionQuickOffice.apk
Patrick Jacques13ce18b2010-11-29 23:24:12 -070065app/Quickoffice.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040066app/SetupWizard.apk app/Provision.apk
kmobse051cf32010-06-24 22:36:11 -050067app/soundback.apk
68app/Street.apk
69app/Talk.apk
blunden05bd2e32011-05-04 12:56:18 +020070app/Talk2.apk
kmobse051cf32010-06-24 22:36:11 -050071app/talkback.apk
72app/Twitter.apk
73app/Vending.apk
74app/VoiceSearch.apk
75app/YouTube.apk
76etc/permissions/com.google.android.maps.xml
Steve Kondik1bfa1322010-06-28 21:16:14 -040077etc/permissions/features.xml
kmobse051cf32010-06-24 22:36:11 -050078framework/com.google.android.maps.jar
kmobse051cf32010-06-24 22:36:11 -050079lib/libspeech.so
blunden05bd2e32011-05-04 12:56:18 +020080lib/libtalk_jni.so
Steve Kondik6721ac92010-08-16 18:55:59 -040081lib/libvoicesearch.so
Steve Kondik94ca1ae2010-07-11 02:49:36 -040082etc/hosts
Kali-9f1dab02010-08-14 23:46:34 +020083etc/custom_backup_list.txt
ladiose7cc3542011-01-24 13:47:14 +080084etc/force_backuptool
kmobse051cf32010-06-24 22:36:11 -050085EOF
86}
87
Kali-9f1dab02010-08-14 23:46:34 +020088get_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
97EOF
98 fi
99}
100
kmobse051cf32010-06-24 22:36:11 -0500101backup_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 Kondik715f2d52010-07-05 19:36:33 -0400121 cp -p $1 $C/$F
kmobse051cf32010-06-24 22:36:11 -0500122 fi
123 fi
124}
125
126restore_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 Pruvot1ef50752011-06-15 10:40:23 +0200143# don't (u)mount system if already done
144UMOUNT=0
145
kmobse051cf32010-06-24 22:36:11 -0500146case "$1" in
147 backup)
Tanguy Pruvot1ef50752011-06-15 10:40:23 +0200148 if [ ! -f "$S/build.prop" ]; then
149 mount $S
150 UMOUNT=1
151 fi
kmobse051cf32010-06-24 22:36:11 -0500152 check_prereq;
PaulWcfe876c2011-05-13 12:56:19 +0100153 check_installscript;
kmobse051cf32010-06-24 22:36:11 -0500154 if [ $PROCEED -ne 0 ];
155 then
156 rm -rf $C
157 mkdir -p $C
Kali-9f1dab02010-08-14 23:46:34 +0200158 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
kmobse051cf32010-06-24 22:36:11 -0500162 done
163 fi
Tanguy Pruvot1ef50752011-06-15 10:40:23 +0200164 if [ $UMOUNT -ne 0 ]; then
165 umount $S
166 fi
kmobse051cf32010-06-24 22:36:11 -0500167 ;;
168 restore)
Tanguy Pruvot1ef50752011-06-15 10:40:23 +0200169 if [ ! -f "$S/build.prop" ]; then
170 mount $S
171 UMOUNT=1
172 fi
kmobse051cf32010-06-24 22:36:11 -0500173 check_prereq;
PaulWcfe876c2011-05-13 12:56:19 +0100174 check_installscript;
kmobse051cf32010-06-24 22:36:11 -0500175 if [ $PROCEED -ne 0 ];
176 then
Kali-9f1dab02010-08-14 23:46:34 +0200177 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
kmobse051cf32010-06-24 22:36:11 -0500183 done
184 rm -rf $C
185 fi
Tanguy Pruvot1ef50752011-06-15 10:40:23 +0200186 if [ $UMOUNT -ne 0 ]; then
187 umount $S
188 fi
189 sync
kmobse051cf32010-06-24 22:36:11 -0500190 ;;
191 *)
192 echo "Usage: $0 {backup|restore}"
193 exit 1
194esac
195
196exit 0