1#! @SCRIPT_SH@
2#	$Header$
3#
4# @WARNING@
5#
6# HylaFAX Facsimile Software
7#
8# Copyright (c) 1990-1997 Sam Leffler
9# Copyright (c) 1991-1997 Silicon Graphics, Inc.
10# HylaFAX is a trademark of Silicon Graphics
11# 
12# Permission to use, copy, modify, distribute, and sell this software and 
13# its documentation for any purpose is hereby granted without fee, provided
14# that (i) the above copyright notices and this permission notice appear in
15# all copies of the software and related documentation, and (ii) the names of
16# Sam Leffler and Silicon Graphics may not be used in any advertising or
17# publicity relating to the software without the specific, prior written
18# permission of Sam Leffler and Silicon Graphics.
19# 
20# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
21# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
22# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
23# 
24# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
25# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
26# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
28# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
29# OF THIS SOFTWARE.
30#
31
32#
33# Warning, this file was automatically created by the HylaFAX configure script
34#
35# VERSION:	@VERSION@
36# DATE:		@DATE@
37# TARGET:	@TARGET@
38#
39
40#
41# Shell script to emulate Silicon Graphics install program.
42# We emulate the non-standard interface used by install so
43# that we can build SGI inst packages on SGI systems.  Note
44# that we cannot emulate everything because we don't maintain
45# a history of installed software; thus we cannot tell when
46# configuration files have been modified and save old copies.
47#
48# NB: we don't do chown/chmod/chgrp by default; it must be
49#     explicitly set on the command line.
50#
51
52#
53# install [options] files ...
54# 
55# Options are:
56#
57# -o		save existing target foo as OLDfoo
58# -O		remove existing target foo, if it fails save as OLDfoo
59# -m mode	set mode of installed target
60# -u uid	set uid of installed target
61# -g gid	set gid of installed target
62# -root path	set ROOT directory for target pathnames
63# -dir		create directories
64# -fifo		create FIFO special files
65# -ln path	create hard link
66# -lns path	create symbolic link
67# -src path	source pathname different from target
68# -f dir	install files in the target directory ROOT/dir
69# -F dir	like -f, but create directories that do not exist
70# -v		echo actions
71# -idb stuff	specify package and, optionally, do special work
72#
73preopts=
74postopts=
75SaveFirst=no
76HasSource=yes
77RemoveFirst=no
78NoUpdate=no
79Suggested=no
80Updated=no
81
82CMD=cp
83SRC=
84FILES=
85DESTDIR=
86CHMOD=":"
87CHOWN=":"
88CHGRP=":"
89RM="rm -f"
90MV="mv @MV_F@"
91ECHO=echo
92VERBOSE=":"
93STRIP="@STRIP@"
94CMP=cmp
95
96TARGETS=
97while [ x"$1" != x ]
98do
99    arg=$1
100    case $arg in
101    -m)		shift; CHMOD="@CHMOD@ $1";;
102    -u)		shift; CHOWN="@CHOWN@ $1";;
103    -g)		shift; CHGRP="@CHGRP@ $1";;
104    -o)		SaveFirst=yes;;
105    -O)		RemoveFirst=yes; SaveFirst=yes;;
106    -root)	shift; ROOT=$1;;
107    -dir)	CMD="mkdir -p"; HasSource=no;
108		RM=":"; STRIP=":"
109		;;
110    -fifo)	CMD=@MKFIFO@; HasSource=no;
111		x=`echo $CMD | @SED@ 's;.*/;;'`;
112		test $x = mknod && postopts="p";
113		STRIP=":"
114		;;
115    -ln)	shift; CMD=@LN@; SRC="$1"
116		STRIP=":"
117		;;
118    -lns)	shift; CMD=@LN@; preopts="@LN_S@"; SRC="$1"
119		STRIP=":"
120		;;
121    -src)	shift; SRC="$1";;
122    -[fF])	shift; DESTDIR="$1";;
123    -idb)	shift; opt="$1"
124		case "$opt" in
125		*config\(update\)*)	Updated=yes;;
126		*config\(suggest\)*)	Suggested=yes;;
127		*config\(noupdate\)*)	NoUpdate=yes;;
128		*nostrip*)		STRIP=":";;
129		esac
130		;;
131    # these are skipped/not handled
132    -new|-rawidb|-blk|-chr) shift;;
133    -v)		VERBOSE=$ECHO;;
134    -*) 	;;
135    *)		TARGETS="$TARGETS $arg";;
136    esac
137    shift
138done
139
140
141if [ "$ROOT" != "" ] ; then
142  ROOT_PREFIX=${ROOT}/
143else
144  ROOT_PREFIX=
145fi
146if [ "$DESTDIR" != "" ] ; then
147  DESTDIR_PREFIX=${DESTDIR}/
148else
149  DESTDIR_PREFIX=
150fi
151
152#
153# Install the specified target.
154#
155install()
156{
157    src=$1 target=$2
158    if [ $RemoveFirst = yes -a -f $target ]; then
159	$VERBOSE "$RM $target"
160	$RM $target
161    fi
162    if [ $SaveFirst = yes -a -f $target ]; then
163	bf=`echo $src | @SED@ 's;.*/;;'`
164	$VERBOSE "$MV $target ${ROOT_PREFIX}${DESTDIR_PREFIX}OLD$bf"
165	$MV $target ${ROOT_PREFIX}${DESTDIR_PREFIX}OLD$bf
166    fi
167    if [ -z "$SRC" -a $HasSource = yes ]; then
168	$VERBOSE "$CMD $preopts $src $target $postopts"
169	$CMD $preopts $f $target $postopts
170    else
171	$VERBOSE "$CMD $preopts $SRC $target $postopts"
172	$CMD $preopts $SRC $target $postopts
173    fi
174    if [ $? -eq 0 ]; then
175	$VERBOSE "$CHOWN $target"
176	$CHOWN $target
177	$VERBOSE "$CHGRP $target"
178	$CHGRP $target
179	$VERBOSE "$CHMOD $target"
180	$CHMOD $target
181	if [ $STRIP != ":" -a -x ${ROOT_PREFIX}${DESTDIR_PREFIX}$f ]; then
182	    $STRIP $target >/dev/null 2>&1 || true
183	    $VERBOSE "$STRIP $target"
184	fi
185    fi
186}
187
188if [ $Suggested = yes ]; then
189    #
190    # A suggested file.  If an existing target does
191    # not exist, then install it.  Otherwise, install
192    # it as target.N if it's different from the current
193    # installed target.
194    #
195    # NB: cannot be used with a special file 'cuz we
196    #     use test -f to see if the file exists.
197    #
198    for f in $TARGETS; do
199	t=${ROOT_PREFIX}${DESTDIR_PREFIX}$f
200	if [ -f $t ]; then
201	    if [ -z "$SRC" -a $HasSource = yes ]; then
202		$CMP -s $f $t || {
203		    $ECHO "*** Warning, target has local changes, installing $f as $t.N"
204		    install $f $t.N;
205		}
206	    else
207		$CMP -s $SRC $t || {
208		    $ECHO "*** Warning, target has local changes, installing $f as $t.N"
209		    install $f $t.N
210		}
211	    fi
212	else
213	    install $f $t
214	fi
215    done
216elif [ $Updated = yes ]; then
217    #
218    # A file to be updated.  If an existing target does
219    # not exist, then install it.  Otherwise, install
220    # it as target and save the old version as target.O
221    # if the old version is different from the current
222    # installed target.
223    #
224    # NB: cannot be used with a special file 'cuz we
225    #     use test -f to see if the file exists.
226    #
227    for f in $TARGETS; do
228	t=${ROOT_PREFIX}${DESTDIR_PREFIX}$f
229	if [ -f $t ]; then
230	    if [ -z "$SRC" -a $HasSource = yes ]; then
231		$CMP -s $f $t || $MV $t $t.O
232	    else
233		$CMP -s $SRC $t || $MV $t $t.O
234	    fi
235	fi
236	install $f $t
237    done
238elif [ $NoUpdate = yes ]; then
239    #
240    # A file that is never to be updated; the target
241    # is created only if it does not exist.
242    #
243    # NB: cannot be used with a special file 'cuz we
244    #     use test -f to see if the file exists.
245    #
246    for f in $TARGETS; do
247	t=${ROOT_PREFIX}${DESTDIR_PREFIX}$f
248	test -f $t || install $f $t
249    done
250else
251    #
252    # Normal case, a target that should be installed
253    # with the existing copy, optionally, saved first.
254    #
255    for f in $TARGETS; do
256	install $f ${ROOT_PREFIX}${DESTDIR_PREFIX}$f
257    done
258fi
259