#!/bin/sh

##
## Copyright 2013 Cumulus Networks, Inc.
## All rights reserved.
##
## Platform specific install fragment for Accton as4600_54t.
##
##

# install kernel uImage into ext2 partion /dev/kernel[12]
install_kernel()
{
    slot=$1
    kimage=$2

    if [ "$slot" = "1" ] ; then
        dst="/dev/$kernel_part1"
    else
        dst="/dev/$kernel_part2"
    fi

    [ -b "$dst" ] || {
        log_failure_msg "kernel destination is not a valid block device: $dst"
        return 1
    }

    if [ "$dry_run" = "y" ] ; then
        _log_msg "${log_pre}Installing $kimage to $dst.\n"
        return 0
    fi

    # copy kernel uImage into raw partition
    log_begin_msg "Copying kernel uImage into $dst"
    $DD if=$kimage of=$dst bs=1M 2> /dev/null
    if [ $? -ne 0 ] ; then
        _log_msg "Failed.\n"
        log_failure_msg "Unable to copy kernel uImage to $dst"
        return 1
    fi
    sync
    log_end_msg

    # extract the size of the kernel uImage
    kernel_size=$(stat -c '%s' $kimage)
    # capture sha1 after copy
    new_kernel_sha1=$($DD if=$dst bs=1M | head -c $kernel_size | $SHA1SUM | awk '{ print $1 }')
    [ $? -eq 0 ] || {
        log_failure_msg "Unabled to extract new kernel uImage checksum."
        return 1
    }
    # compare sha1 to original
    org_kernel_sha1=$(cat ${kimage}.sha1 | awk '{ print $1 }')
    if [ "$org_kernel_sha1" != "$new_kernel_sha1" ] ; then
        return 1
    fi

    return 0
}

# Local Variables:
# mode: shell-script
# eval: (sh-set-shell "/bin/sh" t nil)
# End:
