blob: 99fdaec25ad6bcd1cc06bf23d759ea71017ef74a [file] [log] [blame]
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +01001#!/sbin/sh
2
3# Validate that the incoming OTA is compatible with an already-installed
4# system
5
Brint E. Kriebel84ec9f52014-09-24 12:46:09 -07006grep -q "Command:.*\"--wipe\_data\"" /tmp/recovery.log
7if [ $? -eq 0 ]; then
8 echo "Data will be wiped after install; skipping signature check..."
9 exit 0
10fi
11
Brint E. Kriebel1d055a32014-11-28 17:39:21 -080012grep -q "Command:.*\"--headless\"" /tmp/recovery.log
13if [ $? -eq 0 ]; then
14 echo "Headless mode install; skipping signature check..."
15 exit 0
16fi
17
Tom Marshall322cc5a2015-12-02 13:24:54 -080018if [ -f "/data/system/packages.xml" -a -f "/tmp/releasekey" ]; then
19 relkey=$(cat "/tmp/releasekey")
20 OLDIFS="$IFS"
21 IFS=""
22 while read line; do
23 params=${line# *<package *}
24 if [ "$line" != "$params" ]; then
25 kvp=${params%% *}
26 params=${params#* }
27 while [ "$kvp" != "$params" ]; do
28 key=${kvp%%=*}
29 val=${kvp#*=}
30 vlen=$(( ${#val} - 2 ))
31 val=${val:1:$vlen}
32 if [ "$key" = "name" ]; then
33 package="$val"
34 fi
35 kvp=${params%% *}
36 params=${params#* }
37 done
38 continue
39 fi
40 params=${line# *<cert *}
41 if [ "$line" != "$params" ]; then
42 keyidx=""
43 keyval=""
44 kvp=${params%% *}
45 params=${params#* }
46 while [ "$kvp" != "$params" ]; do
47 key=${kvp%%=*}
48 val=${kvp#*=}
49 vlen=$(( ${#val} - 2 ))
50 val=${val:1:$vlen}
51 if [ "$key" = "index" ]; then
52 keyidx="$val"
53 fi
54 if [ "$key" = "key" ]; then
55 keyval="$val"
56 fi
57 kvp=${params%% *}
58 params=${params#* }
59 done
60 if [ -n "$keyidx" ]; then
61 if [ "$package" = "com.android.htmlviewer" ]; then
62 cert_idx="$keyidx"
63 fi
64 fi
65 if [ -n "$keyval" ]; then
66 eval "key_$keyidx=$keyval"
67 fi
68 continue
69 fi
70 done < "/data/system/packages.xml"
71 IFS="$OLDIFS"
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +010072
Ricardo Cerqueirad2248b22014-12-01 15:15:15 +000073 # Tools missing? Err on the side of caution and exit cleanly
Tom Marshall322cc5a2015-12-02 13:24:54 -080074 if [ -z "$cert_idx" ]; then
75 echo "Package cert index not found; skipping signature check..."
76 exit 0
77 fi
Ricardo Cerqueirad2248b22014-12-01 15:15:15 +000078
Tom Marshall322cc5a2015-12-02 13:24:54 -080079 varname="key_$cert_idx"
80 eval "pkgkey=\$$varname"
81
82 if [ "$pkgkey" != "$relkey" ]; then
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +010083 echo "You have an installed system that isn't signed with this build's key, aborting..."
Ricardo Cerqueirad2248b22014-12-01 15:15:15 +000084 exit 124
Ricardo Cerqueiraaff5e542014-05-09 22:24:12 +010085 fi
86fi
87
88exit 0