blob: 687d691c786c44c430cb953ea30db8421e7f3eae [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
8V=CyanogenMod-6
9
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() {
21 if [ -f "/tmp/.installscript" ];
22 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
33app/GenieWidget.apk
34app/Gmail.apk
35app/GoogleBackupTransport.apk
36app/GoogleCalendarSyncAdapter.apk
37app/GoogleContactsSyncAdapter.apk
38app/GoogleFeedback.apk
kmobse051cf32010-06-24 22:36:11 -050039app/GooglePartnerSetup.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040040app/GoogleQuickSearchBox.apk app/QuickSearchBox.apk
kmobse051cf32010-06-24 22:36:11 -050041app/GoogleServicesFramework.apk
42app/googlevoice.apk
43app/HtcCopyright.apk
44app/HtcEmailPolicy.apk
45app/HtcSettings.apk
46app/kickback.apk
kmobse051cf32010-06-24 22:36:11 -050047app/LatinImeTutorial.apk
Steve Kondikd89a39c2010-06-29 02:46:10 -040048app/Maps.apk
kmobse051cf32010-06-24 22:36:11 -050049app/MarketUpdater.apk
50app/MediaUploader.apk
51app/NetworkLocation.apk
52app/OneTimeInitializer.apk
53app/PassionQuickOffice.apk
Steve Kondike0b98d02010-07-02 16:33:54 -040054app/SetupWizard.apk app/Provision.apk
kmobse051cf32010-06-24 22:36:11 -050055app/soundback.apk
56app/Street.apk
57app/Talk.apk
58app/talkback.apk
59app/Twitter.apk
60app/Vending.apk
61app/VoiceSearch.apk
62app/YouTube.apk
63etc/permissions/com.google.android.maps.xml
Steve Kondik1bfa1322010-06-28 21:16:14 -040064etc/permissions/features.xml
kmobse051cf32010-06-24 22:36:11 -050065framework/com.google.android.maps.jar
kmobse051cf32010-06-24 22:36:11 -050066lib/libspeech.so
Steve Kondik6721ac92010-08-16 18:55:59 -040067lib/libvoicesearch.so
Steve Kondik94ca1ae2010-07-11 02:49:36 -040068etc/hosts
Kali-9f1dab02010-08-14 23:46:34 +020069etc/custom_backup_list.txt
kmobse051cf32010-06-24 22:36:11 -050070EOF
71}
72
Kali-9f1dab02010-08-14 23:46:34 +020073get_custom_files() {
74 local L
75 if [ -f "$C/custom_backup_list.txt" ];
76 then
77 [ ! -f $C/fixed_custom_backup_list.txt ] && tr -d '\r' < $C/custom_backup_list.txt \
78 > $C/fixed_custom_backup_list.txt
79 L=`cat $C/fixed_custom_backup_list.txt`
80 cat <<EOF
81$L
82EOF
83 fi
84}
85
kmobse051cf32010-06-24 22:36:11 -050086backup_file() {
87 if [ -e "$1" ];
88 then
89 if [ -n "$2" ];
90 then
91 echo "$2 $1" | md5sum -c -
92 if [ $? -ne 0 ];
93 then
94 echo "MD5Sum check for $1 failed!";
95 exit $?;
96 fi
97 fi
98
99 local F=`basename $1`
100
101 # dont backup any apps that have odex files, they are useless
102 if ( echo $F | grep -q "\.apk$" ) && [ -e `echo $1 | sed -e 's/\.apk$/\.odex/'` ];
103 then
104 echo "Skipping odexed apk $1";
105 else
Steve Kondik715f2d52010-07-05 19:36:33 -0400106 cp -p $1 $C/$F
kmobse051cf32010-06-24 22:36:11 -0500107 fi
108 fi
109}
110
111restore_file() {
112 local FILE=`basename $1`
113 local DIR=`dirname $1`
114 if [ -e "$C/$FILE" ];
115 then
116 if [ ! -d "$DIR" ];
117 then
118 mkdir -p $DIR;
119 fi
120 cp -p $C/$FILE $1;
121 if [ -n "$2" ];
122 then
123 rm $2;
124 fi
125 fi
126}
127
128check_installscript;
129
130case "$1" in
131 backup)
132 mount $S
133 check_prereq;
134 if [ $PROCEED -ne 0 ];
135 then
136 rm -rf $C
137 mkdir -p $C
Kali-9f1dab02010-08-14 23:46:34 +0200138 for file_list in get_files get_custom_files; do
139 $file_list | while read FILE REPLACEMENT; do
140 backup_file $S/$FILE
141 done
kmobse051cf32010-06-24 22:36:11 -0500142 done
143 fi
144 umount $S
145 ;;
146 restore)
147 check_prereq;
148 if [ $PROCEED -ne 0 ];
149 then
Kali-9f1dab02010-08-14 23:46:34 +0200150 for file_list in get_files get_custom_files; do
151 $file_list | while read FILE REPLACEMENT; do
152 R=""
153 [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
154 restore_file $S/$FILE $R
155 done
kmobse051cf32010-06-24 22:36:11 -0500156 done
157 rm -rf $C
158 fi
159 ;;
160 *)
161 echo "Usage: $0 {backup|restore}"
162 exit 1
163esac
164
165exit 0