#!/usr/local/bin/bash # Determine file's CRC hex digest and return it in little-endian format function crc32hex() { file=$1 crc=$(~/bin/crc32 $file) n=() i=0 hex="" while read -r -N4 -n2 n[i]; do b=${n[$i]} hex="\x${n[$i]}${hex}" ((++i)) done < <(echo $crc) echo $hex } CRAMFS=/srv/home/matt/cramfs # Rebuild cramfs image (as root) su - root -c "rm -v $CRAMFS.image; mkcramfs $CRAMFS $CRAMFS.image" cp $CRAMFS.image ./03_cramfs_MODIFIED # Update cramfs crc32 in header echo -ne $(crc32hex 03_cramfs_MODIFIED) | dd of=01_header bs=1 seek=52 count=4 conv=notrunc # Update header's own crc32 dd if=01_header bs=1 skip=4 of=header_for_crc32 echo -ne $(crc32hex header_for_crc32) | dd of=01_header bs=1 seek=0 count=4 conv=notrunc # Construct firmware image cat 01_header 02_before_cramfs 03_cramfs_MODIFIED 04_after_cramfs > firmimg_MODIFIED.d6 # Copy to TFTP location ssh root@deepthought "cp -v ~matt/tmp/firmimg_MODIFIED.d6 /var/tftpd/firmimg.d6" # Initiate firmware upgrade ssh root@deepthought-idrac "racadm fwupdate -g -u -a 192.168.1.3"