Alex Deymo | e07875e | 2015-09-21 16:49:23 -0700 | [diff] [blame] | 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 |
Alex Deymo | c4aecef | 2016-03-02 18:02:17 -0800 | [diff] [blame] | 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 | |
Alex Deymo | e07875e | 2015-09-21 16:49:23 -0700 | [diff] [blame] | 29 | # This script receives no arguments. argv[0] will include the absolute path to |
Alex Deymo | c4aecef | 2016-03-02 18:02:17 -0800 | [diff] [blame] | 30 | # the script, including the directory where the new partition was mounted. |
Alex Deymo | e07875e | 2015-09-21 16:49:23 -0700 | [diff] [blame] | 31 | # |
Alex Deymo | c4aecef | 2016-03-02 18:02:17 -0800 | [diff] [blame] | 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 | |
Alex Deymo | 74ef144 | 2016-03-30 18:50:59 -0700 | [diff] [blame] | 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 | |
Alex Deymo | c4aecef | 2016-03-02 18:02:17 -0800 | [diff] [blame] | 53 | my_dir=$(dirname "$0") |
| 54 | |
Alex Deymo | 74ef144 | 2016-03-30 18:50:59 -0700 | [diff] [blame] | 55 | # We can notify the updater of the progress of our program by writing to the |
Alex Deymo | d51ad4d | 2016-06-09 18:09:43 -0700 | [diff] [blame] | 56 | # status file descriptor "global_progress <frac>\n". |
Alex Deymo | 74ef144 | 2016-03-30 18:50:59 -0700 | [diff] [blame] | 57 | print -u${status_fd} "global_progress 0" |
| 58 | |
Alex Deymo | c4aecef | 2016-03-02 18:02:17 -0800 | [diff] [blame] | 59 | echo "The output of this program will show up in the logs." >&2 |
Alex Deymo | 74ef144 | 2016-03-30 18:50:59 -0700 | [diff] [blame] | 60 | |
| 61 | # We are half way done, so we set 0.5. |
| 62 | print -u${status_fd} "global_progress 0.5" |
| 63 | |
Alex Deymo | c4aecef | 2016-03-02 18:02:17 -0800 | [diff] [blame] | 64 | echo "Note that this program runs from ${my_dir}" |
| 65 | |
Alex Deymo | 74ef144 | 2016-03-30 18:50:59 -0700 | [diff] [blame] | 66 | # Actually, we were done. |
| 67 | print -u${status_fd} "global_progress 1.0" |
| 68 | |
Alex Deymo | e07875e | 2015-09-21 16:49:23 -0700 | [diff] [blame] | 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 |