1#!/bin/sh
2#
3# Licensed to the Apache Software Foundation (ASF) under one or more
4# contributor license agreements.  See the NOTICE file distributed with
5# this work for additional information regarding copyright ownership.
6# The ASF licenses this file to You under the Apache License, Version 2.0
7# (the "License"); you may not use this file except in compliance with
8# the License.  You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18#
19# install.sh -- install a program, script or datafile
20#
21# Based on `install-sh' from the X Consortium's X11R5 distribution
22# as of 89/12/18 which is freely available.
23# Cleaned up for Apache's Autoconf-style Interface (APACI)
24# by Ralf S. Engelschall <rse apache.org>
25
26#
27#   put in absolute paths if you don't have them in your path;
28#   or use env. vars.
29#
30mvprog="${MVPROG-mv}"
31cpprog="${CPPROG-cp}"
32chmodprog="${CHMODPROG-chmod}"
33chownprog="${CHOWNPROG-chown}"
34chgrpprog="${CHGRPPROG-chgrp}"
35stripprog="${STRIPPROG-strip}"
36rmprog="${RMPROG-rm}"
37
38#
39#   parse argument line
40#
41instcmd="$mvprog"
42chmodcmd=""
43chowncmd=""
44chgrpcmd=""
45stripcmd=""
46rmcmd="$rmprog -f"
47mvcmd="$mvprog"
48ext=""
49src=""
50dst=""
51while [ "x$1" != "x" ]; do
52    case $1 in
53        -c) instcmd="$cpprog"
54            shift; continue
55            ;;
56        -m) chmodcmd="$chmodprog $2"
57            shift; shift; continue
58            ;;
59        -o) chowncmd="$chownprog $2"
60            shift; shift; continue
61            ;;
62        -g) chgrpcmd="$chgrpprog $2"
63            shift; shift; continue
64            ;;
65        -s) stripcmd="$stripprog"
66            shift; continue
67            ;;
68        -S) stripcmd="$stripprog $2"
69            shift; shift; continue
70            ;;
71        -e) ext="$2"
72            shift; shift; continue
73            ;;
74        *)  if [ "x$src" = "x" ]; then
75                src=$1
76            else
77                dst=$1
78            fi
79            shift; continue
80            ;;
81    esac
82done
83if [ "x$src" = "x" ]; then
84     echo "install.sh: no input file specified"
85     exit 1
86fi
87if [ "x$dst" = "x" ]; then
88     echo "install.sh: no destination specified"
89     exit 1
90fi
91
92#
93#  If destination is a directory, append the input filename; if
94#  your system does not like double slashes in filenames, you may
95#  need to add some logic
96#
97if [ -d $dst ]; then
98    dst="$dst/`basename $src`"
99fi
100
101#  Add a possible extension (such as ".exe") to src and dst
102src="$src$ext"
103dst="$dst$ext"
104
105#  Make a temp file name in the proper directory.
106dstdir=`dirname $dst`
107dsttmp=$dstdir/#inst.$$#
108
109#  Move or copy the file name to the temp name
110$instcmd $src $dsttmp
111
112#  And set any options; do chmod last to preserve setuid bits
113if [ "x$chowncmd" != "x" ]; then $chowncmd $dsttmp; fi
114if [ "x$chgrpcmd" != "x" ]; then $chgrpcmd $dsttmp; fi
115if [ "x$stripcmd" != "x" ]; then $stripcmd $dsttmp; fi
116if [ "x$chmodcmd" != "x" ]; then $chmodcmd $dsttmp; fi
117
118#  Now rename the file to the real destination.
119$rmcmd $dst
120$mvcmd $dsttmp $dst
121
122exit 0
123
124