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 |
| 28 | |
| 29 | if ! test -f $SRC ; then |
| 30 | log -p i -t asan_install "Did not find $SRC!" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | log -p i -t asan_install "Found $SRC, checking whether we need to apply it." |
| 35 | |
| 36 | ASAN_TAR_MD5=$(md5sum $SRC) |
| 37 | if test -f $MD5_FILE ; then |
| 38 | INSTALLED_MD5=$(cat $MD5_FILE) |
| 39 | if [ "x$ASAN_TAR_MD5" = "x$INSTALLED_MD5" ] ; then |
| 40 | log -p i -t asan_install "Checksums match, nothing to be done here." |
| 41 | exit 0 |
| 42 | fi |
| 43 | fi |
| 44 | |
| 45 | # Just clean up, helps with restorecon. |
| 46 | rm -rf /data/lib /data/lib64 /data/vendor/lib* |
| 47 | |
| 48 | log -p i -t asan_install "Untarring $SRC..." |
| 49 | |
| 50 | # Unzip from /system/asan.tar.gz into data. Need to pipe as gunzip is not on device. |
| 51 | bzip2 -c -d $SRC | tar -x -f - --no-same-owner -C / || exit 1 |
| 52 | |
| 53 | # Cannot log here, log would run with system_data_file. |
| 54 | |
| 55 | restorecon -R -F /data/lib* /data/vendor/lib* |
| 56 | |
| 57 | log -p i -t asan_install "Fixed selinux labels..." |
| 58 | |
| 59 | echo "$ASAN_TAR_MD5" > $MD5_FILE |
| 60 | |
| 61 | # We want to reboot now. It seems it is not possible to run "reboot" here, the device will |
| 62 | # just be stuck. |
| 63 | |
| 64 | log -p i -t asan_install "Signaling init to reboot..." |
| 65 | |
| 66 | setprop asan.restore_reboot 1 |