#!/bin/bash

# Modify the image to use eMMC paths
IMAGE=${1:maemo-leste-*-arm64-pinephone-*.img}
SDCARD=/dev/mmcblk0
EMMC=/dev/mmcblk2

fdisk -u -l maemo-leste-*-arm64-pinephone-*.img.xz

sudo mount -o loop,offset=<Partition 1 offset> ${IMAGE} /mnt


cd /mnt

sed -i /${SDCARD}/${EMMC}/g boot.scr

sudo mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d boot.txt boot.scr

cd / && umount /mnt


sudo mount -o loop,offset=<Partition 2 offset> ${IMAGE} /mnt

cd /mnt

sed -i /${SDCARD}/${EMMC}/g etc/fstab

cd / && umount /mnt
