summaryrefslogtreecommitdiff
path: root/tools/ak3-core.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ak3-core.sh')
-rwxr-xr-xtools/ak3-core.sh117
1 files changed, 68 insertions, 49 deletions
diff --git a/tools/ak3-core.sh b/tools/ak3-core.sh
index af32439..2e361b5 100755
--- a/tools/ak3-core.sh
+++ b/tools/ak3-core.sh
@@ -4,7 +4,7 @@
OUTFD=$1;
# set up working directory variables
-test "$home" || home=$PWD;
+[ "$home" ] || home=$PWD;
bootimg=$home/boot.img;
bin=$home/tools;
patch=$home/patch;
@@ -15,7 +15,8 @@ split_img=$home/split_img;
# ui_print "<text>" [...]
ui_print() {
until [ ! "$1" ]; do
- echo -e "ui_print $1\nui_print" > /proc/self/fd/$OUTFD;
+ echo "ui_print $1
+ ui_print" >> /proc/self/fd/$OUTFD;
shift;
done;
}
@@ -28,7 +29,7 @@ abort() {
# contains <string> <substring>
contains() {
- test "${1#*$2}" != "$1";
+ [ "${1#*$2}" != "$1" ];
}
# file_getprop <file> <property>
@@ -80,7 +81,7 @@ split_boot() {
else
dd if=$block of=$bootimg $customdd;
fi;
- test $? != 0 && dumpfail=1;
+ [ $? != 0 ] && dumpfail=1;
mkdir -p $split_img;
cd $split_img;
@@ -90,9 +91,9 @@ split_boot() {
$bin/elftool unpack -i $bootimg -o elftool_out;
fi;
$bin/unpackelf -i $bootimg;
- test $? != 0 && dumpfail=1;
- mv -f boot.img-zImage kernel.gz;
- mv -f boot.img-ramdisk.cpio.gz ramdisk.cpio.gz;
+ [ $? != 0 ] && dumpfail=1;
+ mv -f boot.img-kernel kernel.gz;
+ mv -f boot.img-ramdisk ramdisk.cpio.gz;
mv -f boot.img-cmdline cmdline.txt 2>/dev/null;
if [ -f boot.img-dt -a ! -f "$bin/elftool" ]; then
case $(od -ta -An -N4 boot.img-dt | sed -e 's/ del//' -e 's/ //g') in
@@ -117,7 +118,7 @@ split_boot() {
grep "Address:" header | cut -c15- > boot.img-addr;
grep "Point:" header | cut -c15- > boot.img-ep;
$bin/dumpimage -p 0 -o kernel.gz boot-trimmed.img;
- test $? != 0 && dumpfail=1;
+ [ $? != 0 ] && dumpfail=1;
case $(cat boot.img-type) in
Multi) $bin/dumpimage -p 1 -o ramdisk.cpio.gz boot-trimmed.img;;
RAMDisk) mv -f kernel.gz ramdisk.cpio.gz;;
@@ -165,7 +166,7 @@ unpack_ramdisk() {
fi;
fi;
- test -d $ramdisk && mv -f $ramdisk $home/rdtmp;
+ [ -d $ramdisk ] && mv -f $ramdisk $home/rdtmp;
mkdir -p $ramdisk;
chmod 755 $ramdisk;
@@ -207,18 +208,18 @@ repack_ramdisk() {
cd $ramdisk;
find . | cpio -H newc -o > $home/ramdisk-new.cpio;
fi;
- test $? != 0 && packfail=1;
+ [ $? != 0 ] && packfail=1;
cd $home;
$bin/magiskboot cpio ramdisk-new.cpio test;
magisk_patched=$?;
- test $((magisk_patched & 3)) -eq 1 && $bin/magiskboot cpio ramdisk-new.cpio "extract .backup/.magisk $split_img/.magisk";
+ [ $((magisk_patched & 3)) -eq 1 ] && $bin/magiskboot cpio ramdisk-new.cpio "extract .backup/.magisk $split_img/.magisk";
if [ "$comp" ]; then
$bin/magiskboot compress=$comp ramdisk-new.cpio;
if [ $? != 0 ]; then
echo "Attempting ramdisk repack with busybox $comp..." >&2;
$comp -9c ramdisk-new.cpio > ramdisk-new.cpio.$comp;
- test $? != 0 && packfail=1;
+ [ $? != 0 ] && packfail=1;
rm -f ramdisk-new.cpio;
fi;
fi;
@@ -243,7 +244,7 @@ flash_boot() {
varlist="name arch os type comp addr ep";
elif [ -f "$bin/mkbootimg" -a -f "$bin/unpackelf" -a -f boot.img-base ]; then
mv -f cmdline.txt boot.img-cmdline 2>/dev/null;
- varlist="cmdline base pagesize kerneloff ramdiskoff tagsoff";
+ varlist="cmdline base pagesize kernel_offset ramdisk_offset tags_offset";
fi;
for i in $varlist; do
if [ -f boot.img-$i ]; then
@@ -284,7 +285,7 @@ flash_boot() {
cd $split_img;
if [ -f "$bin/mkimage" ]; then
- test "$comp" == "uncompressed" && comp=none;
+ [ "$comp" == "uncompressed" ] && comp=none;
part0=$kernel;
case $type in
Multi) part1=":$ramdisk";;
@@ -292,8 +293,8 @@ flash_boot() {
esac;
$bin/mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n "$name" -d $part0$part1 $home/boot-new.img;
elif [ -f "$bin/elftool" ]; then
- test "$dt" && dt="$dt,rpm";
- test -f cmdline.txt && cmdline="cmdline.txt@cmdline";
+ [ "$dt" ] && dt="$dt,rpm";
+ [ -f cmdline.txt ] && cmdline="cmdline.txt@cmdline";
$bin/elftool pack -o $home/boot-new.img header=elftool_out/header $kernel $ramdisk,ramdisk $dt $cmdline;
elif [ -f "$bin/mboot" ]; then
cp -f $kernel kernel;
@@ -302,14 +303,14 @@ flash_boot() {
elif [ -f "$bin/rkcrc" ]; then
$bin/rkcrc -k $ramdisk $home/boot-new.img;
elif [ -f "$bin/mkbootimg" -a -f "$bin/unpackelf" -a -f boot.img-base ]; then
- test "$dt" && dt="--dt $dt";
- $bin/mkbootimg --kernel $kernel --ramdisk $ramdisk --cmdline "$cmdline" --base $home --pagesize $pagesize --kernel_offset $kerneloff --ramdisk_offset $ramdiskoff --tags_offset "$tagsoff" $dt --output $home/boot-new.img;
+ [ "$dt" ] && dt="--dt $dt";
+ $bin/mkbootimg --kernel $kernel --ramdisk $ramdisk --cmdline "$cmdline" --base $base --pagesize $pagesize --kernel_offset $kernel_offset --ramdisk_offset $ramdisk_offset --tags_offset "$tags_offset" $dt --output $home/boot-new.img;
else
- test "$kernel" && cp -f $kernel kernel;
- test "$ramdisk" && cp -f $ramdisk ramdisk.cpio;
- test "$dt" -a -f extra && cp -f $dt extra;
+ [ "$kernel" ] && cp -f $kernel kernel;
+ [ "$ramdisk" ] && cp -f $ramdisk ramdisk.cpio;
+ [ "$dt" -a -f extra ] && cp -f $dt extra;
for i in dtb recovery_dtbo; do
- test "$(eval echo \$$i)" -a -f $i && cp -f $(eval echo \$$i) $i;
+ [ "$(eval echo \$$i)" -a -f $i ] && cp -f $(eval echo \$$i) $i;
done;
case $kernel in
*Image*)
@@ -318,8 +319,7 @@ flash_boot() {
magisk_patched=$?;
fi;
if [ $((magisk_patched & 3)) -eq 1 ]; then
- ui_print " - Magisk detected! Patching kernel";
- ui_print " so reflashing Magisk is not necessary...";
+ ui_print " " "Magisk detected! Patching kernel so reflashing Magisk is not necessary...";
comp=$($bin/magiskboot decompress kernel 2>&1 | grep -v 'raw' | sed -n 's;.*\[\(.*\)\];\1;p');
($bin/magiskboot split $kernel || $bin/magiskboot decompress $kernel kernel) 2>/dev/null;
if [ $? != 0 -a "$comp" ]; then
@@ -327,6 +327,9 @@ flash_boot() {
$comp -dc $kernel > kernel;
fi;
$bin/magiskboot hexpatch kernel 736B69705F696E697472616D667300 77616E745F696E697472616D667300;
+ if [ "$(file_getprop $home/anykernel.sh do.systemless)" == 1 ]; then
+ strings kernel | grep -E 'Linux version.*#' > $home/vertmp;
+ fi;
if [ "$comp" ]; then
$bin/magiskboot compress=$comp kernel kernel.$comp;
if [ $? != 0 ]; then
@@ -335,11 +338,11 @@ flash_boot() {
fi;
mv -f kernel.$comp kernel;
fi;
- test ! -f .magisk && $bin/magiskboot cpio ramdisk.cpio "extract .backup/.magisk .magisk";
+ [ ! -f .magisk ] && $bin/magiskboot cpio ramdisk.cpio "extract .backup/.magisk .magisk";
export $(cat .magisk);
- test $((magisk_patched & 8)) -ne 0 && export TWOSTAGEINIT=true;
+ [ $((magisk_patched & 8)) -ne 0 ] && export TWOSTAGEINIT=true;
for fdt in dtb extra kernel_dtb recovery_dtbo; do
- test -f $fdt && $bin/magiskboot dtb $fdt patch;
+ [ -f $fdt ] && $bin/magiskboot dtb $fdt patch;
done;
else
case $kernel in
@@ -364,18 +367,18 @@ flash_boot() {
echo "Signing with CHROMEOS..." >&2;
$bin/futility vbutil_kernel --pack boot-new-signed.img --keyblock $bin/chromeos/kernel.keyblock --signprivate $bin/chromeos/kernel_data_key.vbprivk --version 1 --vmlinuz boot-new.img --bootloader $bin/chromeos/empty --config $bin/chromeos/empty --arch arm --flags 0x1;
fi;
- test $? != 0 && signfail=1;
+ [ $? != 0 ] && signfail=1;
fi;
- if [ -f "$bin/BootSignature_Android.jar" -a -d "$bin/avb" ]; then
+ if [ -f "$bin/boot_signer-dexed.jar" -a -d "$bin/avb" ]; then
pk8=$(ls $bin/avb/*.pk8);
cert=$(ls $bin/avb/*.x509.*);
case $block in
*recovery*|*SOS*) avbtype=recovery;;
*) avbtype=boot;;
esac;
- if [ "$(/system/bin/dalvikvm -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature -verify boot.img 2>&1 | grep VALID)" ]; then
+ if [ "$(/system/bin/dalvikvm -Xnoimage-dex2oat -cp $bin/boot_signer-dexed.jar com.android.verity.BootSignature -verify boot.img 2>&1 | grep VALID)" ]; then
echo "Signing with AVBv1..." >&2;
- /system/bin/dalvikvm -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature /$avbtype boot-new.img $pk8 $cert boot-new-signed.img;
+ /system/bin/dalvikvm -Xnoimage-dex2oat -cp $bin/boot_signer-dexed.jar com.android.verity.BootSignature /$avbtype boot-new.img $pk8 $cert boot-new-signed.img;
fi;
fi;
if [ $? != 0 -o "$signfail" ]; then
@@ -388,6 +391,7 @@ flash_boot() {
elif [ "$(wc -c < boot-new.img)" -gt "$(wc -c < boot.img)" ]; then
abort "New image larger than boot partition. Aborting...";
fi;
+ blockdev --setrw $block 2>/dev/null;
if [ -f "$bin/flash_erase" -a -f "$bin/nandwrite" ]; then
$bin/flash_erase $block 0 0;
$bin/nandwrite -p $block boot-new.img;
@@ -419,6 +423,7 @@ flash_dtbo() {
if [ ! -e "$dtboblock" ]; then
abort "dtbo partition could not be found. Aborting...";
fi;
+ blockdev --setrw $dtboblock 2>/dev/null;
if [ -f "$bin/flash_erase" -a -f "$bin/nandwrite" ]; then
$bin/flash_erase $dtboblock 0 0;
$bin/nandwrite -p $dtboblock $dtbo;
@@ -443,14 +448,14 @@ write_boot() {
### file editing functions:
# backup_file <file>
-backup_file() { test ! -f $1~ && cp -fp $1 $1~; }
+backup_file() { [ ! -f $1~ ] && cp -fp $1 $1~; }
# restore_file <file>
-restore_file() { test -f $1~ && cp -fp $1~ $1; rm -f $1~; }
+restore_file() { [ -f $1~ ] && cp -fp $1~ $1; rm -f $1~; }
# replace_string <file> <if search string> <original string> <replacement string> <scope>
replace_string() {
- test "$5" == "global" && local scope=g;
+ [ "$5" == "global" ] && local scope=g;
if ! grep -q "$2" $1; then
sed -i "s;${3};${4};${scope}" $1;
fi;
@@ -470,7 +475,7 @@ replace_section() {
for end in $(grep -n "$endstr" $1 | cut -d: -f1) $last; do
if [ "$end" ] && [ "$begin" -lt "$end" ]; then
sed -i "${begin},${end}d" $1;
- test "$end" == "$last" && echo >> $1;
+ [ "$end" == "$last" ] && echo >> $1;
sed -i "${begin}s;^;${4}\n;" $1;
break;
fi;
@@ -515,19 +520,27 @@ insert_line() {
fi;
}
-# replace_line <file> <line replace string> <replacement line>
+# replace_line <file> <line replace string> <replacement line> <scope>
replace_line() {
+ local lines line;
if grep -q "$2" $1; then
- local line=$(grep -n "$2" $1 | head -n1 | cut -d: -f1);
- sed -i "${line}s;.*;${3};" $1;
+ lines=$(grep -n "$2" $1 | cut -d: -f1 | sort -nr);
+ [ "$4" == "global" ] || lines=$(echo "$lines" | tail -n1);
+ for line in $lines; do
+ sed -i "${line}s;.*;${3};" $1;
+ done;
fi;
}
-# remove_line <file> <line match string>
+# remove_line <file> <line match string> <scope>
remove_line() {
+ local lines line;
if grep -q "$2" $1; then
- local line=$(grep -n "$2" $1 | head -n1 | cut -d: -f1);
- sed -i "${line}d" $1;
+ lines=$(grep -n "$2" $1 | cut -d: -f1 | sort -nr);
+ [ "$3" == "global" ] || lines=$(echo "$lines" | tail -n1);
+ for line in $lines; do
+ sed -i "${line}d" $1;
+ done;
fi;
}
@@ -643,14 +656,14 @@ reset_ak() {
if [ -d "$current" ]; then
rm -rf $current/ramdisk;
for i in $bootimg boot-new.img; do
- test -e $i && cp -af $i $current;
+ [ -e $i ] && cp -af $i $current;
done;
fi;
- test -d $split_img && rm -rf $ramdisk;
+ [ -d $split_img ] && rm -rf $ramdisk;
rm -rf $bootimg $split_img $home/*-new* $home/*-files/current;
if [ "$1" == "keep" ]; then
- test -d $home/rdtmp && mv -f $home/rdtmp $ramdisk;
+ [ -d $home/rdtmp ] && mv -f $home/rdtmp $ramdisk;
else
rm -rf $patch $home/rdtmp;
fi;
@@ -676,13 +689,16 @@ setup_ak() {
case $is_slot_device in
1|auto)
slot=$(getprop ro.boot.slot_suffix 2>/dev/null);
- test "$slot" || slot=$(grep -o 'androidboot.slot_suffix=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2);
+ [ "$slot" ] || slot=$(grep -o 'androidboot.slot_suffix=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2);
if [ ! "$slot" ]; then
slot=$(getprop ro.boot.slot 2>/dev/null);
- test "$slot" || slot=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2);
- test "$slot" && slot=_$slot;
+ [ "$slot" ] || slot=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2);
+ [ "$slot" ] && slot=_$slot;
fi;
if [ "$slot" ]; then
+ if [ -d /postinstall/tmp -a ! "$slot_select" ]; then
+ slot_select=inactive;
+ fi;
case $slot_select in
inactive)
case $slot in
@@ -732,7 +748,7 @@ setup_ak() {
elif [ -e /dev/$part ]; then
target=/dev/$part;
fi;
- test "$target" && break 2;
+ [ "$target" ] && break 2;
done;
done;
if [ "$target" ]; then
@@ -743,10 +759,13 @@ setup_ak() {
;;
*)
if [ "$slot" ]; then
- test -e "$block$slot" && block=$block$slot;
+ [ -e "$block$slot" ] && block=$block$slot;
fi;
;;
esac;
+ if [ ! "$no_block_display" ]; then
+ ui_print "$block";
+ fi;
}
###