blob: 2d723207bef34a1857cdce612c5ff5549362ae2e [file] [log] [blame]
Andreas Gampedf5496a2017-03-21 19:36:48 -07001#!/system/bin/sh
2
3#
4# Copyright (C) 2017 The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19# This script will extract ASAN libraries from /system/asan.tar.gz to /data and then reboot.
20
21# TODO:
22# * Timestamp or something to know when to run this again. Right now take the existence of
23# /data/lib as we're already done.
24# * Need to distinguish pre- from post-decryption for FDE.
25
26SRC=/system/asan.tar.bz2
27MD5_FILE=/data/asan.md5sum
Andreas Gampe4542eda2017-04-03 10:14:49 -070028ASAN_DIR=/data/asan
Andreas Gampecb46b012017-04-18 15:19:36 -070029# Minimum /data size in blocks. Arbitrarily 512M.
30MIN_DATA_SIZE=131072
31
32# Checks for FDE pre-decrypt state.
33
34VOLD_STATUS=$(getprop vold.decrypt)
35if [ "$VOLD_STATUS" = "trigger_restart_min_framework" ] ; then
36 log -p i -t asan_install "Pre-decrypt FDE detected (by vold property)!"
37 exit 1
38fi
39
40STATFS_BLOCKS=$(stat -f -c '%b' /data)
41if [ "$STATFS_BLOCKS" -le "$MIN_DATA_SIZE" ] ; then
42 log -p i -t asan_install "Pre-decrypt FDE detected (by /data size)!"
43 exit 1
44fi
45
46# Check for ASAN source.
Andreas Gampedf5496a2017-03-21 19:36:48 -070047
48if ! test -f $SRC ; then
49 log -p i -t asan_install "Did not find $SRC!"
50 exit 1
51fi
52
53log -p i -t asan_install "Found $SRC, checking whether we need to apply it."
54
Andreas Gampecb46b012017-04-18 15:19:36 -070055# Checksum check.
56
Andreas Gampedf5496a2017-03-21 19:36:48 -070057ASAN_TAR_MD5=$(md5sum $SRC)
58if test -f $MD5_FILE ; then
59 INSTALLED_MD5=$(cat $MD5_FILE)
60 if [ "x$ASAN_TAR_MD5" = "x$INSTALLED_MD5" ] ; then
61 log -p i -t asan_install "Checksums match, nothing to be done here."
62 exit 0
63 fi
64fi
65
Andreas Gampecb46b012017-04-18 15:19:36 -070066# Actually apply the source.
67
Andreas Gampedf5496a2017-03-21 19:36:48 -070068# Just clean up, helps with restorecon.
Andreas Gampe4542eda2017-04-03 10:14:49 -070069rm -rf $ASAN_DIR
Andreas Gampedf5496a2017-03-21 19:36:48 -070070
71log -p i -t asan_install "Untarring $SRC..."
72
73# Unzip from /system/asan.tar.gz into data. Need to pipe as gunzip is not on device.
74bzip2 -c -d $SRC | tar -x -f - --no-same-owner -C / || exit 1
75
76# Cannot log here, log would run with system_data_file.
77
Andreas Gampe46487922017-04-05 08:31:49 -070078# Set correct permission bits.
79chmod -R 744 $ASAN_DIR
80cd $ASAN_DIR ; find . -type d -exec chmod 755 {} \;
81
Andreas Gampe4542eda2017-04-03 10:14:49 -070082restorecon -R -F $ASAN_DIR/*/lib*
Andreas Gampedf5496a2017-03-21 19:36:48 -070083
84log -p i -t asan_install "Fixed selinux labels..."
85
Andreas Gampe46487922017-04-05 08:31:49 -070086
87# Now write down our checksum to mark the extraction complete.
Andreas Gampedf5496a2017-03-21 19:36:48 -070088echo "$ASAN_TAR_MD5" > $MD5_FILE
89
90# We want to reboot now. It seems it is not possible to run "reboot" here, the device will
91# just be stuck.
92
93log -p i -t asan_install "Signaling init to reboot..."
94
Andreas Gampea2b67d62017-04-19 18:17:18 -070095setprop sys.powerctl reboot