Autodetect fstab column order and support flashing to e.g. userdata

Before, flashing was just possible to system / external_sd and not to
userdata ("data").
This commit is contained in:
Attila Szöllősi 2018-06-13 13:01:55 +02:00 committed by Oliver Smith
parent 5db8fd724c
commit ea341e8b2f
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 25 additions and 26 deletions

View file

@ -1,6 +1,6 @@
pkgname=postmarketos-android-recovery-installer pkgname=postmarketos-android-recovery-installer
pkgver=0.1.8 pkgver=0.1.9
pkgrel=3 pkgrel=0
pkgdesc="TWRP compatible postmarketOS installer script" pkgdesc="TWRP compatible postmarketOS installer script"
url="https://postmarketos.org" url="https://postmarketos.org"
# multipath-tools: kpartx # multipath-tools: kpartx
@ -30,5 +30,5 @@ sha512sums="924f961e1a488134d265f43724d2b06a908ac1522706dc3f7118f0dec16453aa0a92
6390fc1b1c7dc8e917bb675d2e59e479782ac7754e97c4781866360ff704afe2d04f173a0ac74e3129db45328fab4b6b77a8717ee2e17c6ff79febadaa8ea034 update-binary 6390fc1b1c7dc8e917bb675d2e59e479782ac7754e97c4781866360ff704afe2d04f173a0ac74e3129db45328fab4b6b77a8717ee2e17c6ff79febadaa8ea034 update-binary
2400d18734d08b3d2f5ec2fe4e802cdcacddea851644b47505eff1aac47302699c171b880bca55dd1704cc9cef9ac26082ac89cee802b6bf57ff8cf649373328 pmos_chroot 2400d18734d08b3d2f5ec2fe4e802cdcacddea851644b47505eff1aac47302699c171b880bca55dd1704cc9cef9ac26082ac89cee802b6bf57ff8cf649373328 pmos_chroot
ef6377f6c062b9a86eb9dfb2aa2c0049fda20f24ec75865a682a50e4655710a18bd7a470deab527e1dd4c273f9ea6a003ec03fc5748d44b1c4fbfc91baa9e358 pmos_install ef6377f6c062b9a86eb9dfb2aa2c0049fda20f24ec75865a682a50e4655710a18bd7a470deab527e1dd4c273f9ea6a003ec03fc5748d44b1c4fbfc91baa9e358 pmos_install
4ba66b336372b23252673f0929ea4f706ec287b5a902c8cb392a9cafb832db445bb7aecc9a7fac34f855babba057c56e3b10c015a1d055a66f0bfd42fef5828e pmos_install_functions 1b19d507a9142e537d052037a0c0768f064ad9131ac8019b234178dc15c0590dbc549ccf553b7a7d55e977df269d4dc0567b520c890738cb80184fc8235222aa pmos_install_functions
c6355b6d823dac883e1a352f59a9a2199e2934d78a73df72dc3c4fc14ef93765a15179203d4a8a2ca0d841b63cd4c25c4689b63c8cf4d4da2bcec1f8ff76bff5 pmos_setpw" c6355b6d823dac883e1a352f59a9a2199e2934d78a73df72dc3c4fc14ef93765a15179203d4a8a2ca0d841b63cd4c25c4689b63c8cf4d4da2bcec1f8ff76bff5 pmos_setpw"

View file

@ -30,6 +30,16 @@ ui_print() {
echo "ui_print" > /proc/self/fd/"$OUTFD" echo "ui_print" > /proc/self/fd/"$OUTFD"
} }
# $1: fstab filename
# $2: partition
get_fstab_device() {
src_column=$(awk '{for (i=1; i<=NF; ++i) { if ($i ~ /^\/dev/) {print i; exit;} }}' /"$1")
[ -z "$src_column" ] && src_column=3
# Warning: partition name is not escaped
awk -v src="$src_column" \
'!/^#/ && /(^|\s*)\/'"$2"'/ {print $src; exit;}' /"$1"
}
extract_partition_table() { extract_partition_table() {
fstab_recovery="recovery.fstab" fstab_recovery="recovery.fstab"
# TWRP can use twrp.fstab instead of recovery.fstab (device specific) # TWRP can use twrp.fstab instead of recovery.fstab (device specific)
@ -38,24 +48,13 @@ extract_partition_table() {
fstab_recovery="twrp.fstab" fstab_recovery="twrp.fstab"
fi fi
case "$INSTALL_PARTITION" in dev=$(findfs PARTLABEL="$SYSTEM_PARTLABEL") || \
"system")
_INSTALL_DEVICE=$(findfs PARTLABEL="$SYSTEM_PARTLABEL") || \
# We need to resolve symlinks, to make set_subpartitions() work. # We need to resolve symlinks, to make set_subpartitions() work.
_INSTALL_DEVICE=$(readlink -fn "$(awk '$1 == "/system" {print $3; exit;}' /$fstab_recovery)") dev=$(readlink -fn "$(get_fstab_device "$fstab_recovery" "$INSTALL_PARTITION")")
;; if [ -n "$dev" ]
"external_sd")
_INSTALL_DEVICE=$(readlink -fn "$(awk '$1 == "/external_sd" {print $4; exit;}' /$fstab_recovery)")
;;
*)
echo "No support for flashing $INSTALL_PARTITION."
return 1
;;
esac
if [ ! -z "$_INSTALL_DEVICE" ]
then then
echo "install device found at $_INSTALL_DEVICE" echo "install device found at $dev"
export INSTALL_DEVICE=$_INSTALL_DEVICE export INSTALL_DEVICE=$dev
else else
echo "Couldn't find $INSTALL_PARTITION partition." echo "Couldn't find $INSTALL_PARTITION partition."
return 1 return 1
@ -67,12 +66,12 @@ extract_partition_table() {
export INITFS_PARTITION export INITFS_PARTITION
INITFS_PARTITION=$(findfs PARTLABEL="$INITFS_PARTLABEL") INITFS_PARTITION=$(findfs PARTLABEL="$INITFS_PARTLABEL")
else else
_BOOT_PARTITION=$(findfs PARTLABEL="boot") || \ dev=$(findfs PARTLABEL="boot") || \
_BOOT_PARTITION=$(awk '$1 == "/boot" {print $3; exit;}' /$fstab_recovery) dev=$(readlink -fn "$(get_fstab_device "$fstab_recovery" boot)")
if [ ! -z "$_BOOT_PARTITION" ] if [ -n "$dev" ]
then then
echo "boot partition found at $_BOOT_PARTITION" echo "boot partition found at $dev"
export BOOT_PARTITION=$_BOOT_PARTITION export BOOT_PARTITION=$dev
else else
echo "Couldn't find boot partition." echo "Couldn't find boot partition."
return 1 return 1
@ -89,7 +88,7 @@ partition_install_device() {
parted -s "$INSTALL_DEVICE" "$command" parted -s "$INSTALL_DEVICE" "$command"
done done
partprobe partprobe
if [ "$INSTALL_PARTITION" = "system" ] if [ "$INSTALL_PARTITION" != "external_sd" ]
then then
kpartx -afs "$INSTALL_DEVICE" kpartx -afs "$INSTALL_DEVICE"
fi fi