#!/bin/sh
CC=gcc

set -x
set -e

if [ $# != 3 ] ; then
	echo Usage: $0 release host /dev/norewindtape
	exit 1
fi

release=$1
host=$2
tape=$3

cd ${host}
mt -f ${tape} ret
mt -f ${tape} rew
/bin/tar cf ${tape} Install

cat > /tmp/blockit.c <<'e!o!f'
#include <stdio.h>

#define BLOCKSIZE (1024 * 62)

main() {
  long c;
  long i = 0;
  long j;

  setvbuf (stdout, (char *)NULL, _IOFBF, BLOCKSIZE);

  while ((c = getchar()) != EOF) {
    if (ferror(stdin)) {
      perror("on getchar");
      return(1);
    } /* on error */

    putchar(c);

    if (ferror(stdout)) {
      perror("on putchar");
      return(1);
    } /* on error */

    ++i;
  } /* while there is input */

  for (j = (BLOCKSIZE - (i % BLOCKSIZE)); j; --j) {
    putchar(0);

    if (ferror(stdout)) {
      perror("on putchar");
      return(1);
    } /* on error */
  } /* pad */

  return(0);
}
e!o!f
(cd /tmp; ${CC} -o blockit blockit.c) 
/bin/tar cf - ${release} | compress -vV | /tmp/blockit > ${tape}
mt -f ${tape} asf 0
tar tvf ${tape}
dd bs=62k if=${tape} | compress -d | /bin/tar tvvf -
rm -f /tmp/blockit /tmp/blockit.c
mt -f ${tape} rew
