dtstyle: Coverity 89011
[oweals/cde.git] / cde / util / scripts / bsdinst.sh
1 #!/bin/sh
2 # $XConsortium: bsdinst.sh /main/2 1995/07/19 18:05:14 drk $
3
4 #
5 # This accepts bsd-style install arguments and makes the appropriate calls
6 # to the System V install.
7 #
8
9 flags=""
10 dst=""
11 src=""
12 dostrip=""
13 owner=""
14 mode=""
15
16 while [ x$1 != x ]; do
17     case $1 in 
18         -c) shift
19             continue;;
20
21         -m) flags="$flags $1 $2 "
22             mode="$2"
23             shift
24             shift
25             continue;;
26
27         -o) flags="$flags -u $2 "
28             owner="$2"
29             shift
30             shift
31             continue;;
32
33         -g) flags="$flags $1 $2 "
34             shift
35             shift
36             continue;;
37
38         -s) dostrip="strip"
39             shift
40             continue;;
41
42         *)  if [ x$src = x ] 
43             then
44                 src=$1
45             else
46                 dst=$1
47             fi
48             shift
49             continue;;
50     esac
51 done
52
53 case "$mode" in
54 "")
55         ;;
56 *)
57         case "$owner" in
58         "")
59                 flags="$flags -u root"
60                 ;;
61         esac
62         ;;
63 esac
64
65 if [ x$src = x ] 
66 then
67         echo "bsdinst:  no input file specified"
68         exit 1
69 fi
70
71 if [ x$dst = x ] 
72 then
73         echo "bsdinst:  no destination specified"
74         exit 1
75 fi
76
77
78 # set up some variable to be used later
79
80 rmcmd=""
81 srcdir="."
82
83 # if the destination isn't a directory we'll need to copy it first
84
85 if [ ! -d $dst ]
86 then
87         dstbase=`basename $dst`
88         cp $src /tmp/$dstbase
89         rmcmd="rm -f /tmp/$dstbase"
90         src=$dstbase
91         srcdir=/tmp
92         dst="`echo $dst | sed 's,^\(.*\)/.*$,\1,'`"
93         if [ x$dst = x ]
94         then
95                 dst="."
96         fi
97 fi
98
99
100 # If the src file has a directory, copy it to /tmp to make install happy
101
102 srcbase=`basename $src`
103
104 if [ "$src" != "$srcbase" -a "$src" != "./$srcbase" ] 
105 then
106         cp $src /tmp/$srcbase
107         src=$srcbase
108         srcdir=/tmp
109         rmcmd="rm -f /tmp/$srcbase"
110 fi
111
112 # do the actual install
113
114 if [ -f /usr/sbin/install ]
115 then
116         installcmd=/usr/sbin/install
117 elif [ -f /etc/install ]
118 then
119         installcmd=/etc/install
120 else
121         installcmd=install
122 fi
123
124 # This rm is commented out because some people want to be able to
125 # install through symbolic links.  Uncomment it if it offends you.
126 # rm -f $dst/$srcbase
127 (cd $srcdir ; $installcmd -f $dst $flags $src)
128
129 if [ x$dostrip = xstrip ]
130 then
131         strip $dst/$srcbase
132 fi
133
134 # and clean up
135
136 $rmcmd
137