#!/bin/sh

if [ ! -d /tftpboot/noaddversion ]; then
	mkdir -p /tftpboot/noaddversion
fi

if [ -f /tftpboot/$KERNEL ]; then
	echo "Build $KERNEL version $MAJOR.$MINOR.$OEM.$TESTING"
	cp -a /tftpboot/$KERNEL /tftpboot/noaddversion/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING
	./addver /tftpboot/$KERNEL $MAJOR $MINOR $OEM $TESTING

	cp -a /tftpboot/noaddversion/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$KERNEL
	if [ $OEM -eq 0 ]; then
		mv -f /tftpboot/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$KERNEL-$MAJOR.$MINOR.bin
	elif [ $TESTING -eq 0 ]; then
		mv -f /tftpboot/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$KERNEL-$MAJOR.$MINOR.$OEM.bin
	else
		mv -f /tftpboot/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING.bin
	fi
fi


if [ -f /tftpboot/$ROOTDISK ]; then
	echo "Build $ROOTDISK version $MAJOR.$MINOR.$OEM.$TESTING"
	cp -a /tftpboot/$ROOTDISK /tftpboot/noaddversion/$ROOTDISK-$MAJOR.$MINOR.$OEM.$TESTING
	./addver /tftpboot/$ROOTDISK $MAJOR $MINOR $OEM $TESTING
	if [ $OEM -eq 0 ]; then
		mv -f /tftpboot/$ROOTDISK-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$ROOTDISK-$MAJOR.$MINOR.dsk
	elif [ $TESTING -eq 0 ]; then
		mv -f /tftpboot/$ROOTDISK-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$ROOTDISK-$MAJOR.$MINOR.$OEM.dsk
	else
		mv -f /tftpboot/$ROOTDISK-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$ROOTDISK-$MAJOR.$MINOR.$OEM.$TESTING.dsk
	fi
fi

if [ -f /tftpboot/$USRDISK ]; then
	echo "Build $USRDISK version $MAJOR.$MINOR.$OEM.$TESTING"
	cp -a /tftpboot/$USRDISK /tftpboot/noaddversion/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING
	./addver /tftpboot/$USRDISK $MAJOR $MINOR $OEM $TESTING
	if [ $OEM -eq 0 ]; then
		mv -f /tftpboot/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$USRDISK-$MAJOR.$MINOR.dsk
	elif [ $TESTING -eq 0 ]; then
		mv -f /tftpboot/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$USRDISK-$MAJOR.$MINOR.$OEM.dsk
	else
		mv -f /tftpboot/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING /tftpboot/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING.dsk
	fi
fi
