#!/bin/sh
# Given a ramdisk filename in $1, and a syslinux or other config file on
# stdin, substitutes ${RAMDISK_SIZE} in the input with an appropriave
# ramdisk_size value for the given initrd. If a second ramdisk is given as
# $2, then ${RAMDISK_SIZE_26} is replaced with its size.
set -e
# expr's round down is ok, I think; ext2 disks are a multiple of 1024 bytes
ramdisk_size=$(expr $(zcat "$1" | wc --bytes) / 1024)
if [ -n "$2" ]; then
	ramdisk_size_26=$(expr $(zcat "$2" | wc --bytes) / 1024)
	sed -e s/'${RAMDISK_SIZE}'/$ramdisk_size/g \
	    -e s/'${RAMDISK_SIZE_26}'/$ramdisk_size_26/g
else
	sed s/'${RAMDISK_SIZE}'/$ramdisk_size/g
fi
