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