12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/bin/sh
- set -e
- ME="${0##*/}"
- usage() {
- echo "Usage: $ME <type> <in filename>"
- [ "$IMG_OUT" ] && rm -f "$IMG_OUT"
- exit 1
- }
- [ "$#" -lt 3 ] && usage
- TYPE=$1
- tmpdir="$( mktemp -d 2> /dev/null )"
- if [ -z "$tmpdir" ]; then
-
- tmpdir="$( mktemp -t 'ubitmp' -d )"
- fi
- if [ -z "$tmpdir" ]; then
- exit 1
- fi
- trap "rm -rf $tmpdir" EXIT
- IMG_TMP_OUT="${tmpdir}/out"
- IMG_IN=$2
- IMG_OUT="${IMG_IN}.new"
- [ ! -f "$IMG_IN" ] && echo "$ME: Not a valid image: $IMG_IN" && usage
- dd if="${IMG_IN}" of="${IMG_TMP_OUT}"
- CRC=$(printf "%08X" $(dd if="${IMG_IN}" bs=$(stat -c%s "${IMG_IN}") count=1|cksum| cut -d ' ' -f1))
- printf ".LINKSYS.01000409%-15s%-8s%-8s%-16s" "${TYPE}" "${CRC}" "0" "K0000000F0246434" >> "${IMG_TMP_OUT}"
- dd if=/dev/zero bs=1 count=192 conv=notrunc >> "${IMG_TMP_OUT}"
- cp "${IMG_TMP_OUT}" "${IMG_OUT}"
|