blob: 6272a6708e685c0349b7d19f98dc7e2201f8a404 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
:
# NAME:
# install.sh - portable version of install(1)
#
# SYNOPSIS:
# install [-CNcs] [-f flags] [-i errs] [-o owner] [-g group] [-m mode] file1 file2 ...
# install -d [-i errs] [-o owner] [-g group] [-m mode] directory ...
#
# DESCRIPTION:
# Compatible with BSD install(1). Except that '-c' is always
# true and we always move an already installed target aside as
# this is important on many systems. Recent BSD install(1)
# versions have a '-b' option for this.
#
#
# OPTIONS:
# -b move previous target file aside (always true).
#
# -B "suffix"
# use "suffix" instead of .old for saving existing target.
#
# -c copy rather than move the file into place (always true).
#
# -C compare. Only install if target is missing or
# different.
#
# -N newer. Only install if target is missing or older.
#
# -s strip target
#
# -o "owner"
# make target owned by "owner"
#
# -g "group"
# make target group owned by "group"
#
# -m "mode"
# set permissions to "mode"
#
# -f "flags"
# Pass "flags" onto chflags(1)
#
# -i "errs"
# Ignore errors from steps indicated by "errs" (``s,o,g,m'').
#
# BUGS:
# The '-i' option is to save your sanity when 'bsd.prog.mk'
# insists on haveing a '-o' "owner" option which is doomed to
# fail on many systems. We ignore '-b', '-B' and '-c' options.
#
# AUTHOR:
# Simon J. Gerraty <sjg@quick.com.au>
#
# RCSid:
# $Id: install-sh,v 1.1.1.1 2005/12/02 00:03:00 sjg Exp $
#
# @(#) Copyright (c) 1993 Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@quick.com.au
#
set -- `getopt B:bpxCNcsdo:g:m:i:f: $*`
Mydir=`dirname $0`
[ -s $Mydir/.installrc ] && . $Mydir/.installrc
owner=:
group=:
mode=:
strip=:
mkdirs=
compare=:
newer=:
chflags=:
LS1=
CP_P=
while [ $# -gt 1 ]
do
case $1 in
--) shift; break;;
-p) CP_P=-p;;
-x) set -x;;
-B) OLD_EXT=$2; shift;;
-C) compare=Different;;
-N) newer=Newer;
# check if /bin/ls supports -1
/bin/ls -1 $0 >/dev/null 2>&1 && LS1=1
;;
-o) owner="${CHOWN:-chown} $2 "; shift;;
-g) group="${CHGRP:-chgrp} $2 "; shift;;
-m) mode="${CHMOD:-chmod} $2 "; shift;;
-s) strip=${STRIP:-strip};;
-d) mkdirs="mkdir -p";;
-i) ignore_err="$ignore_err$2"; shift;;
-f) chflags="${CHFLAGS:-chflags} $2 "; shift;;
esac
shift
done
Newer() {
n=`/bin/ls -t$LS1 $* 2>/dev/null | head -1`
[ $1 = $n ]
}
Different() {
cmp -s $*
[ $? != 0 ]
}
Err() {
case "$ignore_err" in
*$1*) ;;
*) exit 1;;
esac
}
Setem() {
# the order is important
if [ ! -d $1 ]; then
$strip $1 || Err s
fi
$group $1 || Err g
$owner $1 || Err o
$mode $1 || Err m
$chflags $1 || Err f
return 0
}
# a bug in HP-UX's /bin/sh, means we need to re-set $*
# after any calls to add_path()
args="$*"
# all this just for chown!
add_path () { [ -d $1 ] && eval ${2:-PATH}="\$${2:-PATH}:$1"; }
add_path /etc
add_path /usr/etc
add_path /sbin
add_path /usr/sbin
# restore saved $*
set -- $args
# make directories if needed
# and ensure mode etc are as desired
if [ "$mkdirs" ]; then
for d in $*
do
[ ! -d $d ] && $mkdirs $d
Setem $d
done
exit 0 # that's all we do
fi
# install files
if [ $# -gt 2 ]; then
dest_dir=yes
elif [ $# -eq 1 ]; then
echo "what should I do with $*?" >&2
exit 1
fi
# get list of files
while [ $# -gt 1 ]
do
files="$files $1"
shift
done
# last one is dest
dest=$1
shift
if [ "$dest_dir" = yes -a ! -d $dest ]; then
echo "no directory $dest" >&2
exit 1
fi
for f in $files
do
b=`basename $f`
if [ -d $dest ]; then
t=$dest/$b
else
t=$dest
fi
$newer $f $t || continue
$compare $f $t || continue
[ -f $t ] && { mv -f $t $t.old || exit 1; }
{ cp $CP_P $f $t && Setem $t; } || exit 1
done
exit 0
|