#! /bin/csh -f
#
# Title      :  make_cvs_tutorial
# Author     :  Kris Monsen
# Date       :  01/08/2001
# Description:  See usage message below.

set required_cmds = ( uudecode gunzip tar )

# --------------------------------------------------------------------------
# Check command line

if ($#argv > 0) then
  cat << EOH
Usage: make_cvs_tutorial

    To set up your directory for the CVS tutorial, simply run this
    script without any arguments (none are necessary).  It sets up
    and populates a directory called "db" in the current directory.
    
    This script requires that the following commands are available
    on your system:  $required_cmds

EOH
  exit 1
endif

# --------------------------------------------------------------------------
# Check whether target directory already exists
if (-e "db") then
  echo "Error: a file or directory with the name 'db' already exists."
  echo "Cannot continue."
  exit 1
endif

# --------------------------------------------------------------------------
# Check this system for necessary commands
foreach cmd ( $required_cmds )

  # Seems to be no other clever way to figure out whether a command exists.
  # 'which' on Linux and Solaris (/bin/csh and /bin/sh), at least, do not
  # have consistent status values (Solaris 'which' always returns 0--ugh!)
  # Not sure how portable this is...
  set resp="`which $cmd |& egrep '^no | not '`"

  if ("$resp" != "") then
    echo "Error: could not find the command '""$cmd""' on your system."
    echo "Cannot continue."
    exit 1
  endif

end

# --------------------------------------------------------------------------
# Try to figure out which version of uudecode exists on this system.
# On Linux, need to use 'uudecode -o /dev/stdout'
# On Solaris, need to use 'uudecode -p'.
# Others?  You'll need to add them yourself.  Very annoying.

set uudec_option=""

# First, try to get help message
set a="`uudecode -h |& cat`"

# Then check help message for each type of option.
echo "$a" | grep '\-p' >& /dev/null
if ($status == 0) then
  set uudec_option="-p"
  goto main
endif

echo "$a" | grep '\-o' >& /dev/null
if ($status == 0) then
  set uudec_option="-o /dev/stdout"
  goto main
endif

# else...
echo "Error: Unable to determine how to use 'uudecode' command."
echo "It doesn't seem to support -p or -o options for outputting on stdout."
exit 1

# --------------------------------------------------------------------------
main:
# Note: need quotes around the EOF token to tell /bin/csh that
# it should NOT perform variable & history substituion on the
# text between the EOF's.
cat << "EOF" | uudecode $uudec_option | gunzip -c | tar xf -
begin 664 cvs_tutorial.tar.gz
M'XL(`#39/3P``^V776O;,!2&<VO]BC.W@Z0MCI3XHZL7,(S!=E78RFZV41Q+
MKL4<*TA*FC'ZWW><IJQC=%_866%Z;B39TM''*^FU^7P\Z!M*0YHD$::4)G&\
M2V_+.P8T85/&HFD430:4T8A.!A#U/C)D96RN`08+U1C1/%Q/-%=Z'^/9,WP^
M?O'N[9OS\XO^]L&?Z!\FF&<L#JG3?Q^@_J52_=X!OZ=_R))I%$["K?Z3A#G]
M]\%.?Z.+?WW^[^L_H;$[_WOAGOZ8!L7)NOL^T,]I&(8/Z<_B*/JF/\5Z;#J)
M\/S3[H?R(_^Y_I7(N<<"EI*\*(0Q*3&?%W-58Z96Q2>3@K%:%C8EA5HL1&.]
M#(X@2PDAV(KPW`IO@B(&-`EH'+!G;28,4R]?V4II;"W*O$D]7&4KX.5FF9*Y
MSINB$MA#(S;6:T-Q80J29;N@M;HB62FUL;`6VDC5@"JAE+4@&;'8!I/Q4;<0
MG%0V/!C!X6M^2#H./B:DG;\LO*+*M5=<ZL)<2O[^HS<#O^W0!UR%[J=$.HXX
M)@>R*>H5%X#XQG*I@LHG9)'+9C@B7TC[7#86),ZGS9>X!8829D!3D/`<\";8
MYHZ/1W!;NV6IL4TY]%^)NE9PK73-G\"P5FH)3_GH0^.?@!REV^HWMW'%1MHA
MQ6<W?:P;K.49&&'!5+*TUY+;:A:"S>?&JN7L%(PJ[5TIQ+$L\X9C&1IE%KEN
M7YV1C@>%6R@C/9S_W?W/U2/S_VGL_'\?W-._]7^[L=U_`?S"_^DT2N[^_R(6
M;?T_9K'S_WWP%_Y_\%/[9],@/.W!_G&'?O\)<%%)@UZQJCG,!>30!M%R:7?U
M;2705]25SA?@X];V@YYN4(?#X7`X'`Z'P^%P.!P.A\/A>)Q\!2'T'ML`*```
`
end
"EOF"
#tar xf /tools/local/etc/cvs_tutorial.tar

echo "CVS tutorial setup done.  Now you can run through the tutorial."

exit 0

