2017-11-16 22:20:57 +00:00
|
|
|
#!/bin/sh
|
2017-08-24 21:07:36 +00:00
|
|
|
|
2017-11-16 22:20:57 +00:00
|
|
|
# Copyright 2017 Attila Szollosi
|
2017-08-24 21:07:36 +00:00
|
|
|
#
|
|
|
|
# This file is part of postmarketos-android-recovery-installer.
|
|
|
|
#
|
|
|
|
# postmarketos-android-recovery-installer is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# postmarketos-android-recovery-installer is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with postmarketos-android-recovery-installer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-11-16 22:20:57 +00:00
|
|
|
export PATH="/bin"
|
|
|
|
export LD_LIBRARY_PATH="/lib"
|
2017-09-28 22:05:00 +00:00
|
|
|
|
2017-08-24 21:07:36 +00:00
|
|
|
# shellcheck source=/dev/null
|
2017-11-16 22:20:57 +00:00
|
|
|
. /install_options
|
2017-08-24 21:07:36 +00:00
|
|
|
|
|
|
|
# taken from https://github.com/Debuffer-XDA/Gov-Tuner/blob/master/META-INF/com/google/android/update-binary
|
|
|
|
# Copyright (c) 2016 - 2017 Debuffer
|
|
|
|
ui_print() {
|
2017-11-16 22:20:57 +00:00
|
|
|
echo "ui_print $1" > /proc/self/fd/"$OUTFD"
|
|
|
|
echo "ui_print" > /proc/self/fd/"$OUTFD"
|
2017-08-24 21:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract_partition_table() {
|
|
|
|
case "$INSTALL_PARTITION" in
|
|
|
|
"system")
|
2017-09-28 22:05:00 +00:00
|
|
|
_INSTALL_DEVICE=$(findfs PARTLABEL="$SYSTEM_PARTLABEL") || \
|
|
|
|
# We need to resolve symlinks, to make set_subpartitions() work.
|
2018-03-17 18:25:39 +00:00
|
|
|
_INSTALL_DEVICE=$(readlink -fn "$(awk '$1 == "/system" {print $3; exit;}' /recovery.fstab)")
|
2017-08-24 21:07:36 +00:00
|
|
|
;;
|
|
|
|
"external_sd")
|
2018-03-17 18:25:39 +00:00
|
|
|
_INSTALL_DEVICE=$(readlink -fn "$(awk '$1 == "/external_sd" {print $4; exit;}' /recovery.fstab)")
|
2017-08-24 21:07:36 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "No support for flashing $INSTALL_PARTITION."
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ ! -z "$_INSTALL_DEVICE" ]
|
|
|
|
then
|
|
|
|
echo "install device found at $_INSTALL_DEVICE"
|
|
|
|
export INSTALL_DEVICE=$_INSTALL_DEVICE
|
|
|
|
else
|
2017-09-28 22:05:00 +00:00
|
|
|
echo "Couldn't find $INSTALL_PARTITION partition."
|
2017-08-24 21:07:36 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2017-09-28 22:05:00 +00:00
|
|
|
if [ "$ISOREC" = "true" ]
|
2017-08-24 21:07:36 +00:00
|
|
|
then
|
2017-09-28 22:05:00 +00:00
|
|
|
export KERNEL_PARTITION
|
|
|
|
KERNEL_PARTITION=$(findfs PARTLABEL="$KERNEL_PARTLABEL")
|
|
|
|
export INITFS_PARTITION
|
|
|
|
INITFS_PARTITION=$(findfs PARTLABEL="$INITFS_PARTLABEL")
|
2017-08-24 21:07:36 +00:00
|
|
|
else
|
2017-09-28 22:05:00 +00:00
|
|
|
_BOOT_PARTITION=$(findfs PARTLABEL="boot") || \
|
2018-03-17 18:25:39 +00:00
|
|
|
_BOOT_PARTITION=$(awk '$1 == "/boot" {print $3; exit;}' /recovery.fstab)
|
2017-09-28 22:05:00 +00:00
|
|
|
if [ ! -z "$_BOOT_PARTITION" ]
|
|
|
|
then
|
|
|
|
echo "boot partition found at $_BOOT_PARTITION"
|
|
|
|
export BOOT_PARTITION=$_BOOT_PARTITION
|
|
|
|
else
|
|
|
|
echo "Couldn't find boot partition."
|
|
|
|
return 1
|
|
|
|
fi
|
2017-08-24 21:07:36 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
partition_install_device() {
|
|
|
|
for command in "mktable msdos" \
|
|
|
|
"mkpart primary ext2 2048s 100M" \
|
|
|
|
"mkpart primary 100M 100%" \
|
|
|
|
"set 1 boot on"
|
|
|
|
do
|
|
|
|
parted -s "$INSTALL_DEVICE" "$command"
|
|
|
|
done
|
|
|
|
partprobe
|
|
|
|
if [ "$INSTALL_PARTITION" = "system" ]
|
|
|
|
then
|
|
|
|
kpartx -afs "$INSTALL_DEVICE"
|
|
|
|
fi
|
|
|
|
set_subpartitions
|
|
|
|
}
|
|
|
|
|
|
|
|
set_subpartitions() {
|
2017-09-28 22:05:00 +00:00
|
|
|
export PMOS_BOOT
|
2017-11-16 22:20:57 +00:00
|
|
|
PMOS_BOOT=/dev/mapper/"$(basename "$INSTALL_DEVICE")"p1
|
2017-09-28 22:05:00 +00:00
|
|
|
export ROOT_PARTITION
|
2017-11-16 22:20:57 +00:00
|
|
|
ROOT_PARTITION=/dev/mapper/"$(basename "$INSTALL_DEVICE")"p2
|
2017-08-24 21:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
umount_install_partition() {
|
2017-11-16 22:20:57 +00:00
|
|
|
if [ -n "$(awk '$1 == install_part' install_part="$INSTALL_DEVICE" /proc/mounts)" ]
|
2017-08-24 21:07:36 +00:00
|
|
|
then
|
2017-11-16 22:20:57 +00:00
|
|
|
umount "$INSTALL_DEVICE"
|
2017-08-24 21:07:36 +00:00
|
|
|
else
|
2017-11-16 22:20:57 +00:00
|
|
|
echo "$INSTALL_DEVICE is not mounted, continuing..."
|
2017-08-24 21:07:36 +00:00
|
|
|
fi
|
|
|
|
}
|