Skip to content

Commit 8d244f3

Browse files
committed
scripts: save to download when failed to flash
1 parent 7a0b05f commit 8d244f3

3 files changed

Lines changed: 31 additions & 18 deletions

File tree

module/boot_patch.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ BOOTIMAGE=$2
3131
FLASH_TO_DEVICE=$3
3232
shift 2
3333

34-
[ -z "$SUPERKEY" ] && { >&2 echo "- SuperKey empty!"; exit 1; }
35-
[ -e "$BOOTIMAGE" ] || { >&2 echo "- $BOOTIMAGE does not exist!"; exit 1; }
34+
[ -z "$SUPERKEY" ] && { >&2 echo "! SuperKey empty"; exit 1; }
35+
[ -e "$BOOTIMAGE" ] || { >&2 echo "! $BOOTIMAGE does not exist"; exit 1; }
3636

3737
# Check for dependencies
38-
command -v magiskboot >/dev/null 2>&1 || { >&2 echo "- Command magiskboot not found!"; exit 1; }
39-
command -v kptools >/dev/null 2>&1 || { >&2 echo "- Command kptools not found!"; exit 1; }
38+
command -v magiskboot >/dev/null 2>&1 || { >&2 echo "! Command magiskboot not found"; exit 1; }
39+
command -v kptools >/dev/null 2>&1 || { >&2 echo "! Command kptools not found"; exit 1; }
4040

4141
if [ ! -f kernel ]; then
4242
echo "- Unpacking boot image"
4343
magiskboot unpack "$BOOTIMAGE" >/dev/null 2>&1
4444
if [ $? -ne 0 ]; then
45-
>&2 echo "- Unpack error: $?"
45+
>&2 echo "! Unpack error: $?"
4646
exit 1
4747
fi
4848
fi
4949

5050
if [ ! $(kptools -i kernel -f | grep CONFIG_KALLSYMS=y) ]; then
51-
echo "- Patcher has Aborted!"
52-
echo "- APatch requires CONFIG_KALLSYMS to be Enabled."
53-
echo "- But your kernel seems NOT enabled it."
51+
echo "! Patcher has Aborted."
52+
echo "! APatch requires CONFIG_KALLSYMS to be Enabled."
53+
echo "! But your kernel seems NOT enabled it."
5454
exit 1
5555
fi
5656

@@ -69,21 +69,21 @@ patch_rc=$?
6969
set +x
7070

7171
if [ $patch_rc -ne 0 ]; then
72-
>&2 echo "- Patch kernel error: $patch_rc"
72+
>&2 echo "! Patch kernel error: $patch_rc"
7373
exit 1
7474
fi
7575

7676
echo "- Repacking boot image"
7777
magiskboot repack "$BOOTIMAGE" >/dev/null 2>&1
7878

7979
if [ ! $(kptools -i kernel.ori -f | grep CONFIG_KALLSYMS_ALL=y) ]; then
80-
echo "- Detected CONFIG_KALLSYMS_ALL is not set!"
81-
echo "- APatch has patched but maybe your device won't boot."
82-
echo "- Make sure you have original boot image backup."
80+
echo "! Detected CONFIG_KALLSYMS_ALL is not set!"
81+
echo "! APatch has patched but maybe your device won't boot."
82+
echo "! Make sure you have original boot image backup."
8383
fi
8484

8585
if [ $? -ne 0 ]; then
86-
>&2 echo "- Repack error: $?"
86+
>&2 echo "! Repack error: $?"
8787
exit 1
8888
fi
8989

@@ -93,13 +93,15 @@ if [ "$FLASH_TO_DEVICE" = "true" ]; then
9393
echo "- Flashing new boot image"
9494
flash_image new-boot.img "$BOOTIMAGE"
9595
if [ $? -ne 0 ]; then
96-
>&2 echo "- Flash error: $?"
96+
>&2 echo "! Flash error: $?"
97+
save_image_to_storage "new-boot.img"
9798
exit 1
9899
fi
99100
fi
100101

101102
echo "- Successfully Flashed!"
102103
else
104+
save_image_to_storage "new-boot.img"
103105
echo "- Successfully Patched!"
104106
fi
105107

module/boot_unpatch.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if [ ! -f kernel ]; then
2424
echo "- Unpacking boot image"
2525
magiskboot unpack "$BOOTIMAGE" >/dev/null 2>&1
2626
if [ $? -ne 0 ]; then
27-
>&2 echo "- Unpack error: $?"
27+
>&2 echo "! Unpack error: $?"
2828
exit 1
2929
fi
3030
fi
@@ -38,13 +38,13 @@ if [ ! $(kptools -i kernel -l | grep patched=false) ]; then
3838
echo "- Unpatching kernel"
3939
kptools -u --image kernel.ori --out kernel
4040
if [ $? -ne 0 ]; then
41-
>&2 echo "- Unpatch error: $?"
41+
>&2 echo "! Unpatch error: $?"
4242
exit 1
4343
fi
4444
echo "- Repacking boot image"
4545
magiskboot repack "$BOOTIMAGE" >/dev/null 2>&1
4646
if [ $? -ne 0 ]; then
47-
>&2 echo "- Repack error: $?"
47+
>&2 echo "! Repack error: $?"
4848
exit 1
4949
fi
5050
fi
@@ -59,7 +59,8 @@ if [ -f "new-boot.img" ]; then
5959
flash_image new-boot.img "$BOOTIMAGE"
6060

6161
if [ $? -ne 0 ]; then
62-
>&2 echo "- Flash error: $?"
62+
>&2 echo "! Flash error: $?"
63+
save_image_to_storage "new-boot.img"
6364
exit 1
6465
fi
6566
fi

module/util_functions.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ flash_image() {
278278
return 0
279279
}
280280

281+
save_image_to_storage() {
282+
local IMAGE=$1
283+
local DATE=$(date +%y%m%d%H%M)
284+
local FILENAME="kpatch_next_patched_$DATE.img"
285+
local OUT="/storage/emulated/0/Download/$FILENAME"
286+
287+
cp -f "$IMAGE" "$OUT"
288+
echo "- Patched image saved to $OUT"
289+
}
290+
281291
setup_mntpoint() {
282292
local POINT=$1
283293
[ -L $POINT ] && mv -f $POINT ${POINT}_link

0 commit comments

Comments
 (0)