1#!/bin/sh
2if [ $# -lt 1 ] || [ $# -gt 3 ]; then
3  echo 'usage: make-sea.sh <archive.tar> [<filename>.sh] [<install-script>.sh]'
4  exit
5fi
6
7# parse optional arguments
8if [ -z "$2" ]; then
9  filename="`uname`_sea.sh"
10else
11  filename="$2"
12fi
13if [ -z "$3" ]; then
14  install=install.sh
15else
16  install="$3"
17fi
18
19# peek into archive for the install script
20if tar tf "$1" | grep "$install" >/dev/null; then
21  :
22else
23  echo "the archive \"$1\" doesn't contain the specified install script \"$install\""
24  exit
25fi
26
27# find out about compression to use
28# Linux usually doesn't even have compress, otherwise its standard
29if [ `uname` = "Linux" ]; then
30  compress=gzip
31  expand=gunzip
32else
33  compress=compress
34  expand=uncompress
35fi
36
37echo '#!/bin/sh
38( read l; read l; read l; exec cat ) < "$0" | '$expand' | tar xf - && /bin/sh '"$install $*"'
39exit' > "$filename" &&
40$compress < "$1" >> "$filename" &&
41chmod +x "$filename"
42