#!/bin/sh
#
# Copyright (C) 2019 Dream Property GmbH
#

source librecovery

compatible one two seven

xgetopts $@
shift $((${OPTIND} - 1))
[ "$#" -eq 0 ] || usage 1

create_workspace

case "$(uname -m)" in
	aarch64)
		arch=arm64
		;;
	*)
		abort "Unsupported platform!"
		;;
esac

LC_ALL=C grep -h ^[a-zA-Z0-9] /etc/u-boot.scr.d/*.scr >autoexec 2>/dev/null || true
if [ -s autoexec ]; then
	if is_gpt; then
		sed -i "s/mmc 1:6/mmc 1:5/g" autoexec
		safe_mount "${DATA_PARTITION}" "${DATA_MOUNTPOINT}" || info "Failed to mount '${DATA_PARTITION}' to '${DATA_MOUNTPOINT}' - Your device will still boot but bootlogo and resolution may wrong/missing"
		cp autoexec /data/autoexec.txt
	fi
	mkimage -A $arch -O linux -T script -C none -n autoexec -d autoexec /boot/autoexec.img.tmp
	mv /boot/autoexec.img.tmp /boot/autoexec.img
else
	rm -f /boot/autoexec.img
fi
