#!/bin/bash
#set -e -u
[ "$DEBUG" == "true" ] && set -x

DEV=/dev/mmcblk1p1
device=${device:-"frontier"}
codename=${codename:-"unstable"}

ARGS="$@"

tempcfg="$(mktemp)"
cfgfile=${cfgfile:-"/usr/share/mkos-frontier/mkos-frontier.mstrap"}
tempmnt=$(mktemp -d)
trap "rm -f $tempcfg; umount $tempmnt; rm -rf $tempmnt" EXIT

DEV=$DEV mkos-mlo-config -i $cfgfile -o $tempcfg -t mkos-${device}.tar.gz -p device-${device} $ARGS
DEV=$DEV mkos-mlo-prehooks $tempmnt $@ && DEV=$DEV multistrap -f $tempcfg -d $tempmnt && shutdown -h now
