blob: cd3107bf6e66b5f50aa3ed94f555d9ca6f3dde29 [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
30app/CarHomeGoogle.apk
31app/CarHomeLauncher.apk
kmobse051cf32010-06-24 22:36:11 -050032app/Facebook.apk
Steve Kondik6e12dad2010-12-14 21:11:23 -050033app/FOTAKill.apk
kmobse051cf32010-06-24 22:36:11 -050034app/GenieWidget.apk
35app/Gmail.apk
36app/GoogleBackupTransport.apk
37app/GoogleCalendarSyncAdapter.apk
38app/GoogleContactsSyncAdapter.apk
39app/GoogleFeedback.apk
kmobse051cf32010-06-24 22:36:11 -050040app/GooglePartnerSetup.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040041app/GoogleQuickSearchBox.apk app/QuickSearchBox.apk
kmobse051cf32010-06-24 22:36:11 -050042app/GoogleServicesFramework.apk
43app/googlevoice.apk
44app/HtcCopyright.apk
45app/HtcEmailPolicy.apk
46app/HtcSettings.apk
47app/kickback.apk
kmobse051cf32010-06-24 22:36:11 -050048app/LatinImeTutorial.apk
Steve Kondikd89a39c2010-06-29 02:46:10 -040049app/Maps.apk
Patrick Jacques13ce18b2010-11-29 23:24:12 -070050app/MapsSapphire.apk
kmobse051cf32010-06-24 22:36:11 -050051app/MarketUpdater.apk
52app/MediaUploader.apk
53app/NetworkLocation.apk
54app/OneTimeInitializer.apk
55app/PassionQuickOffice.apk
Patrick Jacques13ce18b2010-11-29 23:24:12 -070056app/Quickoffice.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040057app/SetupWizard.apk app/Provision.apk
kmobse051cf32010-06-24 22:36:11 -050058app/soundback.apk
59app/Street.apk
60app/Talk.apk
61app/talkback.apk
62app/Twitter.apk
63app/Vending.apk
64app/VoiceSearch.apk
65app/YouTube.apk
66etc/permissions/com.google.android.maps.xml
Steve Kondik1bfa1322010-06-28 21:16:14 -040067etc/permissions/features.xml
kmobse051cf32010-06-24 22:36:11 -050068framework/com.google.android.maps.jar
kmobse051cf32010-06-24 22:36:11 -050069lib/libspeech.so
Steve Kondik6721ac92010-08-16 18:55:59 -040070lib/libvoicesearch.so
Steve Kondik94ca1ae2010-07-11 02:49:36 -040071etc/hosts
Kali-9f1dab02010-08-14 23:46:34 +020072etc/custom_backup_list.txt
ladiose7cc3542011-01-24 13:47:14 +080073etc/force_backuptool
kmobse051cf32010-06-24 22:36:11 -050074EOF
75}
76
Kali-9f1dab02010-08-14 23:46:34 +020077get_custom_files() {
78 local L
79 if [ -f "$C/custom_backup_list.txt" ];
80 then
81 [ ! -f $C/fixed_custom_backup_list.txt ] && tr -d '\r' < $C/custom_backup_list.txt \
82 > $C/fixed_custom_backup_list.txt
83 L=`cat $C/fixed_custom_backup_list.txt`
84 cat <<EOF
85$L
86EOF
87 fi
88}
89
kmobse051cf32010-06-24 22:36:11 -050090backup_file() {
91 if [ -e "$1" ];
92 then
93 if [ -n "$2" ];
94 then
95 echo "$2 $1" | md5sum -c -
96 if [ $? -ne 0 ];
97 then
98 echo "MD5Sum check for $1 failed!";
99 exit $?;
100 fi
101 fi
102
103 local F=`basename $1`
104
105 # dont backup any apps that have odex files, they are useless
106 if ( echo $F | grep -q "\.apk$" ) && [ -e `echo $1 | sed -e 's/\.apk$/\.odex/'` ];
107 then
108 echo "Skipping odexed apk $1";
109 else
Steve Kondik715f2d52010-07-05 19:36:33 -0400110 cp -p $1 $C/$F
kmobse051cf32010-06-24 22:36:11 -0500111 fi
112 fi
113}
114
115restore_file() {
116 local FILE=`basename $1`
117 local DIR=`dirname $1`
118 if [ -e "$C/$FILE" ];
119 then
120 if [ ! -d "$DIR" ];
121 then
122 mkdir -p $DIR;
123 fi
124 cp -p $C/$FILE $1;
125 if [ -n "$2" ];
126 then
127 rm $2;
128 fi
129 fi
130}
131
132check_installscript;
133
134case "$1" in
135 backup)
136 mount $S
137 check_prereq;
138 if [ $PROCEED -ne 0 ];
139 then
140 rm -rf $C
141 mkdir -p $C
Kali-9f1dab02010-08-14 23:46:34 +0200142 for file_list in get_files get_custom_files; do
143 $file_list | while read FILE REPLACEMENT; do
144 backup_file $S/$FILE
145 done
kmobse051cf32010-06-24 22:36:11 -0500146 done
147 fi
148 umount $S
149 ;;
150 restore)
151 check_prereq;
152 if [ $PROCEED -ne 0 ];
153 then
Kali-9f1dab02010-08-14 23:46:34 +0200154 for file_list in get_files get_custom_files; do
155 $file_list | while read FILE REPLACEMENT; do
156 R=""
157 [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
158 restore_file $S/$FILE $R
159 done
kmobse051cf32010-06-24 22:36:11 -0500160 done
161 rm -rf $C
162 fi
163 ;;
164 *)
165 echo "Usage: $0 {backup|restore}"
166 exit 1
167esac
168
169exit 0