blob: 3953b5ed749db4f1a9825be219ea039a6109d29e [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
62app/talkback.apk
63app/Twitter.apk
64app/Vending.apk
65app/VoiceSearch.apk
66app/YouTube.apk
67etc/permissions/com.google.android.maps.xml
Steve Kondik1bfa1322010-06-28 21:16:14 -040068etc/permissions/features.xml
kmobse051cf32010-06-24 22:36:11 -050069framework/com.google.android.maps.jar
kmobse051cf32010-06-24 22:36:11 -050070lib/libspeech.so
Steve Kondik6721ac92010-08-16 18:55:59 -040071lib/libvoicesearch.so
Steve Kondik94ca1ae2010-07-11 02:49:36 -040072etc/hosts
Kali-9f1dab02010-08-14 23:46:34 +020073etc/custom_backup_list.txt
ladiose7cc3542011-01-24 13:47:14 +080074etc/force_backuptool
kmobse051cf32010-06-24 22:36:11 -050075EOF
76}
77
Kali-9f1dab02010-08-14 23:46:34 +020078get_custom_files() {
79 local L
80 if [ -f "$C/custom_backup_list.txt" ];
81 then
82 [ ! -f $C/fixed_custom_backup_list.txt ] && tr -d '\r' < $C/custom_backup_list.txt \
83 > $C/fixed_custom_backup_list.txt
84 L=`cat $C/fixed_custom_backup_list.txt`
85 cat <<EOF
86$L
87EOF
88 fi
89}
90
kmobse051cf32010-06-24 22:36:11 -050091backup_file() {
92 if [ -e "$1" ];
93 then
94 if [ -n "$2" ];
95 then
96 echo "$2 $1" | md5sum -c -
97 if [ $? -ne 0 ];
98 then
99 echo "MD5Sum check for $1 failed!";
100 exit $?;
101 fi
102 fi
103
104 local F=`basename $1`
105
106 # dont backup any apps that have odex files, they are useless
107 if ( echo $F | grep -q "\.apk$" ) && [ -e `echo $1 | sed -e 's/\.apk$/\.odex/'` ];
108 then
109 echo "Skipping odexed apk $1";
110 else
Steve Kondik715f2d52010-07-05 19:36:33 -0400111 cp -p $1 $C/$F
kmobse051cf32010-06-24 22:36:11 -0500112 fi
113 fi
114}
115
116restore_file() {
117 local FILE=`basename $1`
118 local DIR=`dirname $1`
119 if [ -e "$C/$FILE" ];
120 then
121 if [ ! -d "$DIR" ];
122 then
123 mkdir -p $DIR;
124 fi
125 cp -p $C/$FILE $1;
126 if [ -n "$2" ];
127 then
128 rm $2;
129 fi
130 fi
131}
132
133check_installscript;
134
135case "$1" in
136 backup)
137 mount $S
138 check_prereq;
139 if [ $PROCEED -ne 0 ];
140 then
141 rm -rf $C
142 mkdir -p $C
Kali-9f1dab02010-08-14 23:46:34 +0200143 for file_list in get_files get_custom_files; do
144 $file_list | while read FILE REPLACEMENT; do
145 backup_file $S/$FILE
146 done
kmobse051cf32010-06-24 22:36:11 -0500147 done
148 fi
149 umount $S
150 ;;
151 restore)
152 check_prereq;
153 if [ $PROCEED -ne 0 ];
154 then
Kali-9f1dab02010-08-14 23:46:34 +0200155 for file_list in get_files get_custom_files; do
156 $file_list | while read FILE REPLACEMENT; do
157 R=""
158 [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
159 restore_file $S/$FILE $R
160 done
kmobse051cf32010-06-24 22:36:11 -0500161 done
162 rm -rf $C
163 fi
164 ;;
165 *)
166 echo "Usage: $0 {backup|restore}"
167 exit 1
168esac
169
170exit 0