2014-05-09 21:24:12 +00:00
|
|
|
#!/sbin/sh
|
|
|
|
|
|
|
|
# Validate that the incoming OTA is compatible with an already-installed
|
|
|
|
# system
|
|
|
|
|
2014-09-24 19:46:09 +00:00
|
|
|
grep -q "Command:.*\"--wipe\_data\"" /tmp/recovery.log
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Data will be wiped after install; skipping signature check..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2014-11-29 01:39:21 +00:00
|
|
|
grep -q "Command:.*\"--headless\"" /tmp/recovery.log
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Headless mode install; skipping signature check..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-12-02 21:24:54 +00:00
|
|
|
if [ -f "/data/system/packages.xml" -a -f "/tmp/releasekey" ]; then
|
|
|
|
relkey=$(cat "/tmp/releasekey")
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
IFS=""
|
|
|
|
while read line; do
|
2015-12-18 22:45:25 +00:00
|
|
|
if [ "${#line}" -gt 4094 ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2015-12-02 21:24:54 +00:00
|
|
|
params=${line# *<package *}
|
|
|
|
if [ "$line" != "$params" ]; then
|
|
|
|
kvp=${params%% *}
|
|
|
|
params=${params#* }
|
|
|
|
while [ "$kvp" != "$params" ]; do
|
|
|
|
key=${kvp%%=*}
|
|
|
|
val=${kvp#*=}
|
|
|
|
vlen=$(( ${#val} - 2 ))
|
|
|
|
val=${val:1:$vlen}
|
|
|
|
if [ "$key" = "name" ]; then
|
|
|
|
package="$val"
|
|
|
|
fi
|
|
|
|
kvp=${params%% *}
|
|
|
|
params=${params#* }
|
|
|
|
done
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
params=${line# *<cert *}
|
|
|
|
if [ "$line" != "$params" ]; then
|
|
|
|
keyidx=""
|
|
|
|
keyval=""
|
|
|
|
kvp=${params%% *}
|
|
|
|
params=${params#* }
|
|
|
|
while [ "$kvp" != "$params" ]; do
|
|
|
|
key=${kvp%%=*}
|
|
|
|
val=${kvp#*=}
|
|
|
|
vlen=$(( ${#val} - 2 ))
|
|
|
|
val=${val:1:$vlen}
|
|
|
|
if [ "$key" = "index" ]; then
|
|
|
|
keyidx="$val"
|
|
|
|
fi
|
|
|
|
if [ "$key" = "key" ]; then
|
|
|
|
keyval="$val"
|
|
|
|
fi
|
|
|
|
kvp=${params%% *}
|
|
|
|
params=${params#* }
|
|
|
|
done
|
|
|
|
if [ -n "$keyidx" ]; then
|
|
|
|
if [ "$package" = "com.android.htmlviewer" ]; then
|
|
|
|
cert_idx="$keyidx"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -n "$keyval" ]; then
|
|
|
|
eval "key_$keyidx=$keyval"
|
|
|
|
fi
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
done < "/data/system/packages.xml"
|
|
|
|
IFS="$OLDIFS"
|
2014-05-09 21:24:12 +00:00
|
|
|
|
2014-12-01 15:15:15 +00:00
|
|
|
# Tools missing? Err on the side of caution and exit cleanly
|
2015-12-02 21:24:54 +00:00
|
|
|
if [ -z "$cert_idx" ]; then
|
|
|
|
echo "Package cert index not found; skipping signature check..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
varname="key_$cert_idx"
|
|
|
|
eval "pkgkey=\$$varname"
|
2014-12-01 15:15:15 +00:00
|
|
|
|
2015-12-02 21:24:54 +00:00
|
|
|
if [ "$pkgkey" != "$relkey" ]; then
|
2014-05-09 21:24:12 +00:00
|
|
|
echo "You have an installed system that isn't signed with this build's key, aborting..."
|
2014-12-01 15:15:15 +00:00
|
|
|
exit 124
|
2014-05-09 21:24:12 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|