Home | History | Annotate | Download | only in postinst
      1 #!/system/bin/sh
      2 
      3 #
      4 # Copyright (C) 2015 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 is an example post-install script. This script will be executed by the
     20 # update_engine right after finishing writing all the partitions, but before
     21 # marking the new slot as active. To enable running this program, insert these
     22 # lines in your product's .mk file (without the # at the beginning):
     23 
     24 # AB_OTA_POSTINSTALL_CONFIG += \
     25 #   RUN_POSTINSTALL_system=true \
     26 #   POSTINSTALL_PATH_system=bin/postinst_example \
     27 #   FILESYSTEM_TYPE_system=ext4 \
     28 
     29 # This script receives no arguments. argv[0] will include the absolute path to
     30 # the script, including the directory where the new partition was mounted.
     31 #
     32 # The script will run from the "postinstall" SELinux domain, from the old system
     33 # environment (kernel, SELinux rules, etc). New rules and domains introduced by
     34 # the new system won't be available when this script runs, instead, all the
     35 # files in the mounted directory will have the attribute "postinstall_file". All
     36 # the files accessed from here would need to be allowed in the old system or
     37 # those accesses will fail. For example, the absolute path used in the first
     38 # line of this script (/system/bin/sh) is indeed the old system's sh binary. If
     39 # you use a compiled program, you might want to link it statically or use a
     40 # wrapper script to use the new ldso to run your program (see the
     41 # --generate-wrappers option in lddtree.py for an example).
     42 
     43 # We get called with two parameters: <target_slot> <status_fd>
     44 # * <target_slot> is the slot where the new system was just copied. This is
     45 #   normally either 0 or 1. You can get the target suffix running
     46 #   `bootctl get-suffix ${target_slot}`
     47 # * <status_fd> is a file descriptor number where this script can write to to
     48 #   report the progress of the process. See examples below.
     49 
     50 target_slot="$1"
     51 status_fd="$2"
     52 
     53 my_dir=$(dirname "$0")
     54 
     55 # We can notify the updater of the progress of our program by writing to the
     56 # status file descriptor "global_progress <frac>\n".
     57 print -u${status_fd} "global_progress 0"
     58 
     59 echo "The output of this program will show up in the logs." >&2
     60 
     61 # We are half way done, so we set 0.5.
     62 print -u${status_fd} "global_progress 0.5"
     63 
     64 echo "Note that this program runs from ${my_dir}"
     65 
     66 # Actually, we were done.
     67 print -u${status_fd} "global_progress 1.0"
     68 
     69 # If the exit code of this program is an error code (different from 0), the
     70 # update will fail and the new slot will not be marked as active.
     71 
     72 exit 0
     73