#!/usr/bin/env bash

printf "device: "
read device
if [ ! -e "${device}" ]; then
    echo "Please reconfirm typos, device ${device} doesn't exist."
    exit
else
    echo "All contents of the device ${device} are deleted."
    echo "Are you sure you want to proceed? [Yy]/[Nn]: "
    while :
    do
        read YesNo
        case "${YesNo}" in
          [Nn] ) echo "Cancelled by user's operation."; exit ;;
          [Yy] ) echo "Continued by user's operation."; break ;;
          * ) echo "You must enter \"Y\", \"y\", \"N\" or \"n\"." ;;
        esac
    done
fi

printf "password: "
read password
(cd output/images/ ; echo "${password}" | sudo -S dd if=SPL of=${device} bs=512 seek=2 oflag=dsync)
(cd output/images/ ; echo "${password}" | sudo -S dd if=u-boot.img of=${device} bs=512 seek=138 oflag=dsync)

