Skip to content

Commit

Permalink
Merging with experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
elfametesar committed Jun 21, 2023
1 parent 8daa65f commit 2cc939c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
26 changes: 15 additions & 11 deletions pay2sup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export BACK_TO_EROFS=0
export RECOVERY=0

trap "exit" INT
trap "{ umount -d $TEMP || umount -d -l $TEMP; sed -i 's/+/[ DEBUG ]/g' $LOG_FILE; } 2> /dev/null" EXIT
trap "{ umount -d $TEMP || umount -d -l $TEMP; sed -i 's/^+*/[ DEBUG ]/g' $LOG_FILE; } 2> /dev/null" EXIT

[ "$PWD" = "/" ] && { echo "Working directory cannot be the root of your file system, it is dangerous"; exit 1; }

Expand All @@ -25,6 +25,8 @@ trap "{ umount -d $TEMP || umount -d -l $TEMP; sed -i 's/+/[ DEBUG ]/g' $LOG_FIL
exit
}

setenforce 0

TOOLCHAIN="make_ext4fs \
mkfs.erofs \
mke2fs \
Expand Down Expand Up @@ -124,6 +126,7 @@ toolchain_download() {
echo
mkdir "$HOME"/bin
tar xf ${URL##*/} -C "$HOME"/bin/
chmod +x -R "$HOME"/bin
rm ${URL##*/}
}

Expand Down Expand Up @@ -180,21 +183,21 @@ super_extract() {

echo "Unpacking super"
echo
case $SLOT in
_a) slot_param="--slot=0";;
_b) slot_param="--slot=1";;
esac
if [ -b "$ROM" ]; then
case $SLOT in
_a) slot_num=0;;
_b) slot_num=1;;
esac
if lpunpack --slot=$slot_num "$ROM" extracted 2>&1 | grep -q "sparse"; then
if lpunpack $slot_param "$ROM" extracted 2>&1 | grep -q "sparse"; then
echo "But extracting it from super block first because it is sparse"
echo
dd if=/dev/block/by-name/super of=super_sparse.img
simg2img super_sparse.img super.img
rm super_sparse.img
lpunpack --slot=$slot_num super.img extracted 1> /dev/null || { echo "This is not a valid super image or block"; cleanup; exit 1; }
lpunpack $slot_param super.img extracted 1> /dev/null || { echo "This is not a valid super image or block"; cleanup; exit 1; }
fi
else
lpunpack "$ROM" extracted 1> /dev/null || { echo "This is not a valid super image or block"; cleanup; exit 1; }
lpunpack $slot_param "$ROM" extracted 1> /dev/null || { echo "This is not a valid super image or block"; cleanup; exit 1; }
fi
rm "$HOME"/super* >/dev/null 2>&1
cd extracted
Expand Down Expand Up @@ -358,8 +361,8 @@ pack() {
umount "$TEMP" || umount -l "$TEMP"
done
echo
getenforce >/dev/null 2>&1 && [ $READ_ONLY -eq 0 ] && $SHELL "$HOME"/pay2sup_helper.sh restore_secontext
}
getenforce >/dev/null 2>&1 && [ $READ_ONLY -eq 0 ] && $SHELL "$HOME"/pay2sup_helper.sh restore_secontext
if [ $BACK_TO_EROFS -eq 0 ] && [ $RESIZE -eq 0 ] && [ $READ_ONLY -eq 0 ] && [ $RECOVERY -eq 0 ]; then
printf "Do you want to shrink partitions to their minimum sizes before repacking? (y/n): "
read shrink
Expand Down Expand Up @@ -516,7 +519,9 @@ recovery() {
main() {
set -x
ROM=$1
{ get_os_type; toolchain_check; }
get_os_type
toolchain_check
get_super_size
[ -z $CONTINUE ] && {
cleanup
if [ -z "$ROM" ] || [ ! -f "$ROM" ] && [ ! -b "$ROM" ]; then
Expand Down Expand Up @@ -548,7 +553,6 @@ main() {
esac
} || cd "$HOME"/extracted
{
get_super_size
get_partitions
get_read_write_state
[ $GRANT_RW -eq 1 ] && read_write
Expand Down
1 change: 0 additions & 1 deletion pay2sup_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ remove_overlay() {
echo "$fstab_contexts" | while read context file; do
chcon $context $file
done
shrink "$vendor" 1> /dev/null
}

disable_encryption() {
Expand Down

0 comments on commit 2cc939c

Please sign in to comment.