1+ # # AnyKernel3 (AK3), and AnyKernel2/AnyKernel 2.0 (AK2) Scripts License:
2+ #
3+ # AnyKernel (versions 2.0/2 and later) Android image modifying scripts.
4+ # Copyright (c) 2019 Chris Renshaw (osm0sis @ xda-developers),
5+ # and additional contributors per readily available commit history/credits.
6+ # All rights reserved.
7+ #
8+ # Redistribution and use in source and binary forms, with or without
9+ # modification, are permitted (subject to the limitations in the disclaimer
10+ # below) provided that the following conditions are met:
11+ #
12+ # * Redistributions of source code must retain the above copyright notice,
13+ # this list of conditions and the following disclaimer.
14+ #
15+ # * Redistributions in binary form must reproduce the above copyright
16+ # notice, this list of conditions and the following disclaimer in the
17+ # documentation and/or other materials provided with the distribution.
18+ #
19+ # * Neither the name of the copyright holder nor the names of its
20+ # contributors may be used to endorse or promote products derived from this
21+ # software without specific prior written permission.
22+ #
23+ # NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
24+ # THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25+ # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+ # POSSIBILITY OF SUCH DAMAGE.
35+ #
36+
37+ if [ -z " $AK3TMPFS " ]; then
38+ echo " AK3TMPFS is not defined? Are you running FoxMMM?"
39+ exit 1
40+ fi
41+
42+ if [ ! -e " $AK3TMPFS " ]; then
43+ mkdir $AK3TMPFS
44+ chmod 755 $AK3TMPFS
45+ fi
46+
47+ ZIPFILE=$3 ;
48+
49+ # Mount tmpfs early
50+ mount -t tmpfs -o size=400M,noatime tmpfs $AK3TMPFS ;
51+ mount | grep -q " $AK3TMPFS " || exit 1;
52+
53+ unzip -p $Z tools* /busybox > $AK3TMPFS /busybox;
54+ unzip -p $Z META-INF/com/google/android/update-binary > $AK3TMPFS /update-binary;
55+ # #
56+
57+ chmod 755 $AK3TMPFS /busybox;
58+ $AK3TMPFS /busybox chmod 755 $AK3TMPFS /update-binary;
59+ $AK3TMPFS /busybox chown root:root $AK3TMPFS /busybox $AK3TMPFS /update-binary;
60+
61+ # work around Android passing the app what is actually a non-absolute path
62+ AK3TMPFS=$( $AK3TMPFS /busybox readlink -f $AK3TMPFS ) ;
63+
64+ # AK3 allows the zip to be flashed from anywhere so avoids any need to remount /
65+ if $AK3TMPFS /busybox grep -q AnyKernel3 $AK3TMPFS /update-binary; then
66+ # work around more restrictive upstream SELinux policies for Magisk <19306
67+ magiskpolicy --live " allow kernel app_data_file file write" || true ;
68+ TMP=$AK3TMPFS /tmp;
69+ else
70+ echo " Module is not an AnyKernel3 module!"
71+ exit 1
72+ fi ;
73+
74+ # update-binary <RECOVERY_API_VERSION> <OUTFD> <ZIPFILE>
75+ ASH_STANDALONE=1 AKHOME=$AK3TMPFS /anykernel $AK3TMPFS /busybox ash $AK3TMPFS /update-binary 3 1 " $Z " ;
76+ RC=$? ;
77+
78+ # Original script delete all generated files,
79+ # But we just need to unmount as we store everything inside tmpfs
80+ umount $TMP ;
81+
82+ return $RC ;
0 commit comments