#!/bin/sh
major=$(mountpoint -d / | cut -f 1 -d ':')
minor=$(mountpoint -d / | cut -f 2 -d ':')
device=$(cat /proc/partitions | awk {'if ($1 == "'${major}'" && $2 == "'${minor}'") print $4 '})
device="/dev/${device%?}1"
kernel="vmlinux-av.fit"

if ! $(lsblk -o PARTTYPENAME $device | busybox grep -q "ChromeOS kernel"); then
  echo "*** Warning ***"
  echo "$device is not a ChromeOS kernel partition"
  echo "kernel is *** not *** flashed, machine will NOT boot properly"
  echo "you can do this later by finding ChromeOS kernel partition and running:"
  echo "dd if=/boot/$kernel of=/dev/\$partition"
  echo "where \$partition is proper ChromeOS kernel partition"
else
  echo "flashing new kernel version to ${device}."
  dd if=/boot/$kernel of=${device}
  sync
  echo "if it is not successfuly flashed you can do this later by running:"
  echo "dd if=/boot/$kernel of=${device}"
fi

