#! /bin/sh
#
# $Id: mkppp,v 1.89 2003/12/30 23:05:52 brian Exp $

createtmp() {
  # Create a .tmp file, and a .orig if it doesn't already exist
  test -f $1.orig || cp -p $1 $1.orig
  mv $1 $1.tmp
  echo Patching $1...
}

sshargs=
while getopts i: c
do
  case "$c" in
    i) sshargs="-i $OPTARG";;
    *) echo "Usage: mkppp [-i identity] [account]..." >&2
       exit 1;;
  esac
done
shift $(($OPTIND - 1))

oCVSROOT= pppctl=src/usr.sbin/pppctl
for d in /home/repo/OpenBSD/cvs /cvs/OpenBSD
do
  [ -d $d ] && oCVSROOT="-d $d" pppctl=src/usr.sbin/ppp/pppctl
done

[ $# -eq 0 ] && machines=localhost || machines=$*
cd /tmp
top=$PWD/ppp$$
test -e $top && { echo "$top: directory exists" >&2; exit; }
mkdir -p $top || { echo "$top: Cannot create" >&2; exit; }
cd $top

# Get the sources
cvs -R co ppp
cvs -R $oCVSROOT co -d pppctl $pppctl
cvs -R co examples/ppp
cvs -R co libutil/uucplock.c libutil/libutil.h
cvs -R co libradius/radlib.c libradius/radlib.h libradius/radlib_vs.h \
          libradius/radlib_private.h
cvs -R co libalias
rm -fr CVS ppp/CVS pppctl/CVS examples/CVS examples/ppp/CVS libutil/CVS \
       libalias/CVS

# The version we're making
name=ppp-$(TZ=GMT0 date +%y%m%d)
m=$(TZ=GMT0 date +%B)
ver=$(uname -r)

# Build our hierarchy
mkdir $name
mv ppp pppctl examples $name/.
mv libalias $name/libhack
mv libutil/uucplock.c libutil/libutil.h libradius/radlib.c libradius/radlib.h \
  libradius/radlib_vs.h libradius/radlib_private.h $name/libhack/.
rm -fr libutil libradius

# Mangle the sources

# Add BINDIR=, BINOWN=, libutil and FW punching to the pppctl Makefile
createtmp $name/pppctl/Makefile
(
  echo 'OS!=	uname -s'
  fgrep -q MAN8 $name/pppctl/Makefile.tmp || echo 'MAN8=	pppctl.8'
  cat $name/pppctl/Makefile.tmp
  echo 'LDADD+=	-lutil'
  echo 'DPADD+= ${LIBUTIL}'
) | sed -e 's/^\(\.include.*\)/# To install correctly:\
BINDIR=\/usr\/sbin\
BINOWN=root\
NOGCCERROR=true\
\
\1/' -e 's/^MAN8=\(.*\)\.\(.*\)/.if \${OS} == FreeBSD\
MAN8=	\1.\2\
MANSECT=\2\
.else\
MAN=	\1.\2\
.endif/' >$name/pppctl/Makefile
rm $name/pppctl/Makefile.tmp

# Fix history #ifdefs in pppctl.c
createtmp $name/pppctl/pppctl.c
sed -e 's/ifdef __NetBSD__/if defined __NetBSD__ || __FreeBSD_version >= 500025/' \
    -e 's/ifdef __OpenBSD__/if defined __OpenBSD__ || __FreeBSD_version < 500025/' \
    -e 's/ifndef __OpenBSD__/if !defined(__OpenBSD__) \&\& __FreeBSD_version >= 500025/' \
    -e 's,<sys/types.h>,<sys/param.h>,' \
    $name/pppctl/pppctl.c.tmp >$name/pppctl/pppctl.c
rm $name/pppctl/pppctl.c.tmp

# The ppp Makefile:
#   Add uucplock.c and radlib.c (from ../libhack)
#   Don't do firewall punching
#   add BINDIR=
#   Make -lz conditional on /usr/lib/libz.a
#   Change -lalias to ../libhack/libalias.a
#   Drop -lradius
#   Make .if secure path absolute
#   Add -DNOINET6 if /usr/include/netinet6/in6.h doesn't exist
#   Add -DNOATM if /usr/include/netnatm/natm.h doesn't exist
#   Change -lcrypto to -lcrypt where necessary
#   .if ${OS} for libs & man pages
createtmp $name/ppp/Makefile
(
  echo 'OS!=	uname -s'
  fgrep -q MAN8 $name/ppp/Makefile.tmp || echo 'MAN8=	ppp.8'
  cat $name/ppp/Makefile.tmp
) | sed -e 's/^MAN8.*/.if \${OS} == FreeBSD\
MAN8=	ppp.8\
MANSECT=8\
.else\
MAN=	ppp.8\
.endif/' -e 's/^\(\.include.*\)/\# To cope with uucplock changes:\
\# Note, uucplock.c, radlib* and libutil.h do not really belong here !\
SRCS+=uucplock.c radlib.c \
CFLAGS+=-I. -I..\/libhack\
BINDIR=\/usr\/sbin\
NOGCCERROR=true\
\
.PATH: \${.CURDIR}\/..\/libhack\
\
\1/' -e '/-lz/{h; i\
.if ${OS} == FreeBSD \
.if exists(/usr/lib/libz.a) || exists(/usr/lib/aout/libz.a)
p; i\
.else
s/-lz//p; i\
.endif\
.else\
.if ${OS} == NetBSD
g; s/-lmd //p; i\
.else
s/crypt/crypto/p; i\
.endif\
.endif
d;}' -e 's,!exists(${\.CURDIR}/\.\./\.\./secure),(defined(__FreeBSD__) \&\& !exists(/usr/src/secure)),' \
     -e 's,\(\.if defined(NOI4B)\) || ${MACHINE_ARCH} != "i386",\1 || (!exists(/usr/include/machine/i4b_rbch_ioctl.h) \&\& !exists(/usr/include/i4b/i4b_rbch_ioctl.h) \&\& !exists(/usr/include/netisdn/i4b_rbch_ioctl.h)),' \
     -e 's,\(\.if defined(NONETGRAPH)\),\1 || !exists(/usr/include/netgraph/ng_pppoe.h),' \
     -e 's,-lalias,../libhack/libalias.a,' \
     -e 's,-lradius,,' \
     -e 's,\(defined(NOKLDLOAD)\),\1 || !exists(/usr/include/sys/module.h),' \
     -e 's,\(defined(NOINET6)\),\1 || !exists(/usr/include/netinet6/in6.h),' \
     -e 's,\(defined(NOATM)\),\1 || !exists(/usr/include/netnatm/natm.h),' \
     -e '/-lcrypto/{h; i\
.if defined(LIBCRYPTO)
p; i\
.else\
LDADD+=	-ldes\
.endif
d;}' >$name/ppp/Makefile
rm $name/ppp/Makefile.tmp

# Get rid of printf0like() stuff
createtmp $name/libhack/libutil.h
cat >$name/libhack/libutil.h <<EOF
#ifndef __printf0like
#define __printf0like(a, b)
#endif
EOF
cat $name/libhack/libutil.h.tmp >>$name/libhack/libutil.h
rm $name/libhack/libutil.h.tmp

# And printflike()
createtmp $name/libhack/radlib.c
sed -e '/radlib_private.h/{ p; i\
\#include <termios.h>\
\#include "defs.h"\
\#ifndef __printflike\
\#define __printflike(a, b)\
\#endif
d; }' -e 's/srandomdev()/randinit()/' \
  $name/libhack/radlib.c.tmp >$name/libhack/radlib.c
rm $name/libhack/radlib.c.tmp

# Fix MAN variables
# Add -DNO_FW_PUNCH to CFLAGS
# Add MKPIC, MKLINT, MKPROFILE and install: for NetBSD
# Add NOPIC and NOPROFILE for others
# $(INSTALL) -c on NetBSD (don't they have -C ?)
createtmp $name/libhack/Makefile
sed -e 's/^MAN\(.*\)/OS!=	uname -s\
.if \${OS} == FreeBSD\
MAN3\1\
INSTALL_FLG=	-C\
.else\
MAN\1\
.if \$(OS) == NetBSD\
MKPIC=	no\
MKLINT=	no\
MKPROFILE=	no\
INSTALL_FLG=	-c\
NOGCCERROR=	true\
install:\
.else\
NOPIC=		1\
NOPROFILE=	1\
INSTALL_FLG=	-C\
.endif\
.endif/' $name/libhack/Makefile.tmp |
  sed 's/\(INSTALL.\) -C/\1 \$(INSTALL_FLG)/' >$name/libhack/Makefile
echo CFLAGS+=-DNO_FW_PUNCH >>$name/libhack/Makefile
rm $name/libhack/Makefile.tmp

# Fix any NG_*SIZ defines
for n in $(grep -l 'NG_[A-Z]*SIZ' $name/*/*.[ch])
do
  createtmp $n
  sed '/NG_\([A-Z]*\)SIZ/{h; s/.*NG_\([A-Z]*\)SIZ.*/#ifndef NG_\1SIZ\
\#define NG_\1SIZ (NG_\1LEN - 1)\
\#endif/p; g; }' $n.tmp >$n
  rm $n.tmp
done

# Fix any __FBSDID defines
for n in $(fgrep -l __FBSDID $name/*/*.[ch])
do
  createtmp $n
  sed '/^__FBSDID/{i\
\#ifndef __FBSDID\
\#define __FBSDID(s) struct __hack\
\#endif
}' $n.tmp >$n
  rm $n.tmp
done

# Catch usage of NGM_PPPOE_ACNAME and NGM_PPPOE_SESSIONID
createtmp $name/ppp/ether.c
sed -e '/NGM_PPPOE_ACNAME/{i\
\#ifndef NGM_PPPOE_ACNAME\
\#define NGM_PPPOE_ACNAME -10\
\#endif
}' -e '/NGM_PPPOE_SESSIONID/{i\
\#ifndef NGM_PPPOE_SESSIONID\
\#define NGM_PPPOE_SESSIONID -11\
\#endif
}' $name/ppp/ether.c.tmp >$name/ppp/ether.c
rm $name/ppp/ether.c.tmp

# Comment out lines with ifr_flagshigh if necessary
for n in $(fgrep -l ifr_flagshigh $name/ppp/*.c)
do
  createtmp $n
  sed 's/\(.*ifr_flagshigh.*\)/\
\#ifdef ifr_flagshigh\
\1\
\#endif/' $n.tmp >$n
  rm $n.tmp
done

# Add a <arpa/nameser.h> before <resolv.h> in case resolv.h wants
# MAXDNAME defined.
for n in $(fgrep -l resolv.h $name/ppp/*.c)
do
  fgrep arpa/nameser.h $n >/dev/null && continue
  createtmp $n
  sed '/resolv\.h/{i\
\#include <arpa/nameser.h>
}' $n.tmp >$n
  rm $n.tmp
done

# Define LIST_FOREACH if required
for n in $(fgrep -l sys/queue.h $name/libhack/*.c)
do
  createtmp $n
  sed '/sys\/queue\.h/{p; i\
\#if !defined(LIST_FOREACH) && defined(LIST_FIRST) && defined(LIST_NEXT)\
\#define LIST_FOREACH(var, head, field) \\\
	for((var) = LIST_FIRST(head); (var); (var) = LIST_NEXT(var, field))\
\#endif
d; }' $n.tmp >$n
  rm $n.tmp
done

# Define IPPROTO_GRE if it's not already defined
for n in $(fgrep -l IPPROTO_GRE $name/ppp/*.c)
do
  fgrep arpa/nameser.h $n >/dev/null && continue
  createtmp $n
  sed '/netinet\/in\.h/{p; i\
\#ifndef IPPROTO_GRE\
\#define IPPROTO_GRE 47\
\#endif
d; }' $n.tmp >$n
  rm $n.tmp
done

# Check that osreldate >= 300000 before including sys/linker.h
for n in $(fgrep -l sys/linker.h $name/ppp/*.c)
do
  createtmp $n
  sed '/sys\/linker\.h/{i\
\#include <osreldate.h>\
\#if __FreeBSD_version >= 300000
p; i\
\#endif
d;}' $n.tmp >>$n
  rm $n.tmp
done

# Check that osreldate >= 500000 before including openssl/des.h
for n in $(fgrep -l openssl/des.h $name/ppp/*.c)
do
  createtmp $n
  sed '/openssl\/des\.h/{h; i\
\#ifdef __FreeBSD__\
\#include <osreldate.h>\
\#endif\
\#if defined(__NetBSD__) || __FreeBSD_version >= 500000
p; i\
\#else
x; s/openssl\///p; i\
\#endif
d;}' $n.tmp >>$n
  rm $n.tmp
done

# Replace <sys/types.h> with <sys/param.h> and add utmp.h in files
# containing <sys/sysctl.h>
for n in $(fgrep -l sys/sysctl.h $name/ppp/*.c)
do
  fgrep sys/types.h $n >/dev/null || continue
  createtmp $n
  sed 's,sys/types.h,sys/param.h,' $n.tmp >$n
  rm $n.tmp
  fgrep utmp.h $n >/dev/null && continue
  createtmp $n
  sed '/sysctl\.h/{i\
\#include <utmp.h>
}' $n.tmp >$n
  rm $n.tmp
done

# Add <net/if.h> in front of <net/if_tun.h> for pre FreeBSD-3.0 releases
for n in $(fgrep -l net/if_tun.h $name/ppp/*.c); do
  fgrep net/if.h $n >/dev/null && continue
  createtmp $n
  sed '/net\/if_tun\.h/{i\
\#include <net/if.h>
}' $n.tmp >$n
  rm $n.tmp
done 

# Add <sys/select.h> before <net/if.h> for older non-OpenBSD releases
for n in $(fgrep -l net/if.h $name/ppp/*.c)
do
  fgrep sys/select.h $n >/dev/null && continue
  createtmp $n
  sed '/net\/if\.h/{i\
\#include <sys/select.h>
}' $n.tmp >$n
  rm $n.tmp
done

# Define NI_WITHSCOPEID if it's not already defined
for n in $(fgrep -l NOINET6 $name/ppp/*.c)
do
  createtmp $n
  sed '/NOINET6/{p; i\
\#ifndef NI_WITHSCOPEID\
\#define NI_WITHSCOPEID 0\
\#endif
d;}' $n.tmp >$n
  rm $n.tmp
done

# Only do DEFLATE for FreeBSD-2.2 and above & OpenBSD - comment out deflate.c
createtmp $name/ppp/deflate.c
echo '#ifdef __FreeBSD__' >$name/ppp/deflate.c
echo '#include <osreldate.h>' >>$name/ppp/deflate.c
echo '#endif' >>$name/ppp/deflate.c
echo '#if !defined(__FreeBSD__) || __FreeBSD_version >= 220000' >>$name/ppp/deflate.c
cat $name/ppp/deflate.c.tmp >>$name/ppp/deflate.c
echo '#endif' >>$name/ppp/deflate.c
rm $name/ppp/deflate.c.tmp

# Also, remove the deflate algorithm from ccp.c
createtmp $name/ppp/ccp.c
echo '#ifdef __FreeBSD__' >$name/ppp/ccp.c
echo '#include <osreldate.h>' >>$name/ppp/ccp.c
echo '#endif' >>$name/ppp/ccp.c
sed '/DeflateAlgorithm/{i\
\#if !defined(__FreeBSD__) || __FreeBSD_version >= 220000
p; i\
\#endif
d;}' $name/ppp/ccp.c.tmp >>$name/ppp/ccp.c
rm $name/ppp/ccp.c.tmp

# Define _PATH_UUCPLOCK if it's not available (some older versions)
createtmp $name/libhack/uucplock.c
sed '/include "libutil\.h"/{p; i\
\#ifndef _PATH_UUCPLOCK\
\#define _PATH_UUCPLOCK "/var/spool/lock/"\
\#endif
d;}' $name/libhack/uucplock.c.tmp >$name/libhack/uucplock.c
rm $name/libhack/uucplock.c.tmp

# Dibble tun.h so that older versions of OpenBSD don't htonl the address
# family.  This is based on TUNMRU being defined.  TUNMRU was added on
# 980802 whereas the byte ordering was changed 980626, so there's a window
# of 1 month where the code won't work !  If anyone comes up with a
# better way of identifying things, the knowledge would be welcomed.
createtmp $name/ppp/tun.h
sed '/tun_fill_header.*head/{i\
\#include <net/if_tun.h>\
\#ifndef TUNMRU\
/*\
 * TUNMRU was added on 980802, whereas the byte ordering of the tun\
 * header was changed on 980626.  This leaves over a month where this\
 * code will simply not work.  If anyone has a better way of figuring this\
 * out, please let me know \!\
 */\
\#define tun_fill_header(f,proto) do { (f).head = (proto); } while (0)\
\#define tun_check_header(f,proto) ((f).head == (proto))\
\#else
n;n; i\
\#endif
}' $name/ppp/tun.h.tmp >$name/ppp/tun.h
rm $name/ppp/tun.h.tmp

# Add sys/select.h & net/if.h for FreeBSD-2.2.2's benefit
createtmp $name/ppp/tun.c
sed '/sys\/param\.h/{p; i\
\#ifdef __FreeBSD__\
\#include <sys/select.h>\
\#include <sys/socket.h>\
\#include <net/if.h>\
\#endif
d; }' $name/ppp/tun.c.tmp >$name/ppp/tun.c
rm $name/ppp/tun.c.tmp

# And finally, change %ll to %q as %ll creates cores on old versions
# of FreeBSD
for f in $(fgrep -l '%ll' $name/ppp/*.c)
do
  createtmp $f
  sed 's/%ll/%q/g' $f.tmp >$f
  rm $f.tmp
done

# Create the top level Makefile
cat >$name/Makefile <<eof
.if \${.TARGET} != install
SUBDIR += libhack
.endif
SUBDIR+=ppp pppctl
PPP_EXAMPLES?=/usr/share/examples/ppp

.include <bsd.subdir.mk>

.if defined(MANDIR)
beforeinstall:
	for dir in \${MANDIR}/man8 \${MANDIR}/cat8; do \
		if [ ! -d \$\$dir ]; then mkdir -p -m 755 \$\$dir; fi; \
	done
.endif

afterinstall:
.if defined(PPP_CONFDIR)
	if [ ! -d \${PPP_CONFDIR} ]; then \
		mkdir -p -m 755 \${PPP_CONFDIR}; \
	fi
.else
	if [ ! -d /etc/ppp ]; then mkdir -p -m 755 /etc/ppp; fi
.endif
	mkdir -p \$(PPP_EXAMPLES)
	for cfg in examples/ppp/*; \\
	do \\
	  head -1 \$\$cfg | grep -q '^#!' && mode=555 || mode=444; \\
	  install -c -o bin -g bin -m \$\$mode \$\$cfg \$(PPP_EXAMPLES); \\
	done
	@echo "Please read the README.changes file."
eof

# OpenBSD and NetBSD expect <util.h>, so make a link to our modified version
ln -sf libutil.h $name/libhack/util.h

# We don't want the original files - they take up (relatively) too
# much space.  Besides, they can always be found at
#
#   ftp://ftp.FreeBSD.org/pub/FreeBSD/FreeBSD-current/src/usr.sbin/ppp/
find $name -name \*.orig | xargs rm

# Now pack it up into our web page directory
tar cvf - $name | gzip -9c >~/public_html/$name.src.tar.gz

# Create the uuencoded version
cd ~/public_html
uuencode $name.src.tar.gz $name.src.tar.gz >src.uue

# Now build the sources for the binary archives
cd $top
mkdir $name/stage
all=$(ls)
tar cf all.tgz $all
cd $name
for mach in $machines
do

  echo Building on $mach
  
  ssh $sshargs $mach "mkdir $top 2>/dev/null && cd $top && tar xf -" \
    <$top/all.tgz &&
    cmd="ssh -o BatchMode=yes $sshargs $mach" ||
    cmd="sh -c"

  $cmd "
    cd $top/$name || exit 1

    os=\`uname\`
    ver=\`uname -r\`
    st=stage/\$os/$name

    echo \"Using account on $mach for \$os-\$ver, building in \$(pwd)\"
    make || exit 1

    # Build our hierarchy (using path names relative to root)
    mkdir -p \$st/include \$st/sbin \$st/share/man/man3 \$st/share/man/man8
    cp ppp/ppp.8 pppctl/pppctl.8 \$st/share/man/man8/.
    cp ppp/ppp pppctl/pppctl \$st/sbin/.
    cp ppp/README.changes \$st/.
    cp libhack/libalias.3 \$st/share/man/man3/.
    cp -r examples \$st/share/examples

    # And build a Makefile for installing
    cat >\$st/Makefile <<eof
PPP_EXAMPLES?=/usr/share/examples/ppp

all: install

install:
	install -c -s -o root -g network -m 4550 sbin/ppp /usr/sbin
	install -c -s -o bin -g bin -m 555 sbin/pppctl /usr/sbin
	install -c -o bin -g bin -m 444 share/man/man8/ppp.8.gz /usr/share/man/man8 
	install -c -o bin -g bin -m 444 share/man/man8/pppctl.8.gz /usr/share/man/man8
	install -c -o bin -g bin -m 444 share/man/man3/libalias.3.gz /usr/share/man/man3
	if [ ! -d /etc/ppp ]; then mkdir -p /etc/ppp; chmod 755 /etc/ppp; fi
	mkdir -p \\\$(PPP_EXAMPLES)
	for cfg in share/examples/ppp/*; \\
	do \\
	  head -1 \\\$\\\$cfg | grep -q '^#!' && mode=555 || mode=444; \\
	  install -c -o bin -g bin -m \\\$\\\$mode \\\$\\\$cfg \\\$(PPP_EXAMPLES); \\
	done
	@echo
	@echo \"Please read the README.changes file.\"
	@echo
	@echo \"Remember, this binary ppp installation was built on\"
	@echo \"\$os-\$ver.  If you wish to run an up-to-date version\"
	@echo \"on an older version of \$os, download & build\"
	@echo \"the sources rather than using this binary package.\"
eof

    # Create the binary archive
    cd $top/$name/stage/\$os || exit 1
    tar cf - $name | gzip -9c >$top/${mach#*@}-$name-\$os-\$ver.bin.tar.gz
  " || { echo "ppp failed to compile on ${mach#*@}" |
	 mail -s "ppp build failure" brian@Awfulhak.org; exit; }

  archive=$($cmd "echo $top/${mach#*@}-$name-*.bin.tar.gz")
  larchive=${archive##*/${mach#*@}-}
  os=${larchive#*-*-}
  os=${os%%.bin.tar.gz}

  scp -o BatchMode=yes $sshargs $mach:$archive ~/public_html/$larchive

  # And uuencode it
  cd ~/public_html
  uuencode $larchive $larchive >$os-bin.uue
done

cd ~/public_html

# Generate log files of all recent changes
d=/home/ncvs/CVSROOT/commitlogs
build() {
  base=$1
  shift
  >$base.log
  test ! -f $d/$base && { echo No CVS logs available; return; }
  last=
  for f in $d/${base}.*.gz $d/$base
  do
    test -n "`expr $f : $d/$base'.9[56789]\(.*\)'`" && continue
    test -n "`expr $f : $d/$base'.00\(.*\)'`" && continue
    what=`echo $* | sed 's/ /, /g'`
    [ "$what" != "$last" ] && echo "Generating logs for $what" >&2
    last="$what"
    zcat -f $f | awk '
      BEGIN {
        nlines = 0;
        ndirs = split("'"$*"'", dirs, " ");
      }
      function dump(line, nlines, lines, first) {
        if (length(line) != 0 && substr(line, 0, 1) != " ") {
          for (l = 1; l <= nlines; l++) {
            if (length(first[l]) == 0)
              continue;
            for (d = 1; d <= ndirs; d++)
              if (first[l] == dirs[d])
                break;
            if (d <= ndirs)
              break;
          }
          if (l <= nlines)
            for (l = 1; l <= nlines; l++)
              printf("%s\n", lines[l]);
          nlines = 0;
        }
        return nlines;
      }
      {
        nlines = dump($0, nlines, lines, first);
        nlines++;
        lines[nlines] = $0;
        first[nlines] = $1;
      }
      END {
        dump("x", nlines+1, lines, first);
      }'
  done >$base.log
}
build usrsbin usr.sbin/ppp usr.sbin/pppctl
build share share/examples/ppp
build lib lib/libalias

# Make sure we've got a sym-link to this script
rm -f mkppp
ln -s ../bin/mkppp mkppp

# Now tweak the web page using our template
y=$(expr $name : 'ppp-\(..\)....')
d=$(expr $name : 'ppp-....\(..\)')
sed -e "s/DAY/$d/g" -e "s/MONTH/$m/g" -e "s/YEAR/$y/g" \
    -e "s/NAME/$name/g" index.html.template >index.html
for f in $name-*.bin.tar.gz
do
  base=${f%.bin.tar.gz}
  base=${base#$name-}
  ver=${base#*-}
  os=${base%%-*}
  sed '/OPERATINGSYSTEM/{ h; s/OPERATINGSYSTEM/'"$os"'/g; s/VER/'"$ver"'/g; p; g; }' index.html >index.html.new
  mv index.html.new index.html
done
sed '/OPERATINGSYSTEM/d' index.html >index.html.new
mv index.html.new index.html
find ppp* -mtime +14 | xargs rm

# Remove any leftover crud
cd $top/..
for mach in $machines
do
  ssh -o BatchMode=yes $sshargs $mach rm -fr $top
done
rm -fr $top
