#! /bin/sh
# AIPSSHAR
#-----------------------------------------------------------------------
#! packs the files in the current directory into a shell archive.
## Util
#-----------------------------------------------------------------------
#;  Copyright (C) 1995
#;  Associated Universities, Inc. Washington DC, USA.
#;
#;  This program is free software; you can redistribute it and/or
#;  modify it under the terms of the GNU General Public License as
#;  published by the Free Software Foundation; either version 2 of
#;  the License, or (at your option) any later version.
#;
#;  This program is distributed in the hope that it will be useful,
#;  but WITHOUT ANY WARRANTY; without even the implied warranty of
#;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#;  GNU General Public License for more details.
#;
#;  You should have received a copy of the GNU General Public
#;  License along with this program; if not, write to the Free
#;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
#;  MA 02139, USA.
#;
#;  Correspondence concerning AIPS should be addressed as follows:
#;         Internet email: aipsmail@nrao.edu.
#;         Postal address: AIPS Project Office
#;                         National Radio Astronomy Observatory
#;                         520 Edgemont Road
#;                         Charlottesville, VA 22903-2475 USA
#-----------------------------------------------------------------------
#   This Bourne shell script packs the files in the current working
#   directory that are specified in the argument list into a self-
#   unpacking archive.  On Unix systems files may be extracted by
#   executing the archive as a Bourne shell script.  Users of other
#   operating systems may use the standalone AIPS utility UNSHR.
#
#   This utility is intended for packaging source code for AIPS
#   associated programs (such as the various screen servers) that do not
#   require the AIPS libraries.  This allows them to be easily installed
#   on systems without the AIPS code management tools (COMRPL etc.).
#   It does not retain user-id or permissions on the files and therefore
#   should not be used as a substitute for true Unix shell archive
#   utilities such as newshar.
#
#   To use AIPSSHAR change to the directory containing the files to be
#   packaged and type
#
#   AIPSSHAR archive_name file1 [file2 [file3 ...]]
#
#   If the files in the file list are not in the current working
#   directory then they will not be unpacked by UNSHR.
#
#   WARNING: if there are any non-text files in the file list then the
#   resulting archive cannot be placed in the AIPS checkout system.
#-----------------------------------------------------------------------
# Check the number of arguments; there must be at least one input
# file as well as the output file:
    if   test $# -lt 2
    then echo "Usage: $0 archive_name file1 file2 ..."
         exit 1
    fi

# Save archive name:
    archive=$1; shift
    if [ -f $archive ] ; then
       echo "Sorry, $archive already exists, will NOT clobber it"
       echo "Usage: $0 archive_name file1 file2 ..."
       exit 1
    fi

# Write standard part of header to the output file:
    echo "#! /bin/sh"                                        >  $archive
    echo "#------------------------------------------------" >> $archive
    echo "# This is an AIPS self-unpacking shell archive   " >> $archive
    echo "# created on `date`."                              >> $archive
    echo "#------------------------------------------------" >> $archive

# Ask the user for a description of the archive and copy it to the
# archive:
    echo "Enter a description of the files in this archive."
    echo "Terminate the description with a CTRL-D"
    while read line
    do    echo "# " $line >> $archive
    done
    echo "#-----------------------------------------------" >> $archive


# Archive each file in the list:
    while test $# -gt 0
    do    file=$1
          echo "cat > $file << --XYZZY--" >> $archive
          cat $file                        >> $archive
          echo "--XYZZY--"                 >> $archive
          shift
    done

