Andreas Gampe | df5496a | 2017-03-21 19:36:48 -0700 | [diff] [blame] | 1 | #!/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 | |
| 26 | SRC=/system/asan.tar.bz2 |
| 27 | MD5_FILE=/data/asan.md5sum |
Andreas Gampe | 4542eda | 2017-04-03 10:14:49 -0700 | [diff] [blame] | 28 | ASAN_DIR=/data/asan |
Andreas Gampe | cb46b01 | 2017-04-18 15:19:36 -0700 | [diff] [blame^] | 29 | # Minimum /data size in blocks. Arbitrarily 512M. |
| 30 | MIN_DATA_SIZE=131072 |
| 31 | |
| 32 | # Checks for FDE pre-decrypt state. |
| 33 | |
| 34 | VOLD_STATUS=$(getprop vold.decrypt) |
| 35 | if [ "$VOLD_STATUS" = "trigger_restart_min_framework" ] ; then |
| 36 | log -p i -t asan_install "Pre-decrypt FDE detected (by vold property)!" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | STATFS_BLOCKS=$(stat -f -c '%b' /data) |
| 41 | if [ "$STATFS_BLOCKS" -le "$MIN_DATA_SIZE" ] ; then |
| 42 | log -p i -t asan_install "Pre-decrypt FDE detected (by /data size)!" |
| 43 | exit 1 |
| 44 | fi |
| 45 | |
| 46 | # Check for ASAN source. |
Andreas Gampe | df5496a | 2017-03-21 19:36:48 -0700 | [diff] [blame] | 47 | |
| 48 | if ! test -f $SRC ; then |
| 49 | log -p i -t asan_install "Did not find $SRC!" |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
| 53 | log -p i -t asan_install "Found $SRC, checking whether we need to apply it." |
| 54 | |
Andreas Gampe | cb46b01 | 2017-04-18 15:19:36 -0700 | [diff] [blame^] | 55 | # Checksum check. |
| 56 | |
Andreas Gampe | df5496a | 2017-03-21 19:36:48 -0700 | [diff] [blame] | 57 | ASAN_TAR_MD5=$(md5sum $SRC) |
| 58 | if 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 |
| 64 | fi |
| 65 | |
Andreas Gampe | cb46b01 | 2017-04-18 15:19:36 -0700 | [diff] [blame^] | 66 | # Actually apply the source. |
| 67 | |
Andreas Gampe | df5496a | 2017-03-21 19:36:48 -0700 | [diff] [blame] | 68 | # Just clean up, helps with restorecon. |
Andreas Gampe | 4542eda | 2017-04-03 10:14:49 -0700 | [diff] [blame] | 69 | rm -rf $ASAN_DIR |
Andreas Gampe | df5496a | 2017-03-21 19:36:48 -0700 | [diff] [blame] | 70 | |
| 71 | log -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. |
| 74 | bzip2 -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 Gampe | 4542eda | 2017-04-03 10:14:49 -0700 | [diff] [blame] | 78 | restorecon -R -F $ASAN_DIR/*/lib* |
Andreas Gampe | df5496a | 2017-03-21 19:36:48 -0700 | [diff] [blame] | 79 | |
| 80 | log -p i -t asan_install "Fixed selinux labels..." |
| 81 | |
| 82 | echo "$ASAN_TAR_MD5" > $MD5_FILE |
| 83 | |
| 84 | # We want to reboot now. It seems it is not possible to run "reboot" here, the device will |
| 85 | # just be stuck. |
| 86 | |
| 87 | log -p i -t asan_install "Signaling init to reboot..." |
| 88 | |
| 89 | setprop asan.restore_reboot 1 |