summaryrefslogtreecommitdiffstats
path: root/usr.sbin/xntpd/scripts/install.sh
blob: 5dd98315d82cc2c8a0340d56e428104118b84918 (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
#!/bin/sh
#
# Emulate the BSD install command with cpset for System V
# Tom Moore - NCR Corporation
#
PATH=/bin:/etc:/usr/bin:/usr/ucb
export PATH

# Default values
mode=0755
owner=bin
group=bin
strip=FALSE
remove=TRUE

USAGE="install [-s] [-c] [-m mode] [-o owner] [-g group] source file|directory"
set -- `getopt scm:o:g: $*` || {
	echo $USAGE >&2
	exit 2
}
for option in $*
do
	case $option in
	-s)	# Strip the installed file
		strip=TRUE
		shift
		;;
	-c)	# Copy the source file rather than move it
		remove=FALSE
		shift
		;;
	-m)	# File mode
		mode=$2
		shift 2
		;;
	-o)	# File owner
		owner=$2
		shift 2
		;;
	-g)	# File group
		group=$2
		shift 2
		;;
	--)	# End of options
		shift
		break
		;;
	esac
done

case $# in
0)	echo "install: no file or destination specified" >&2
	exit 2
	;;
1)	echo "install: no destination specified" >&2
	exit 2
	;;
2)	source=$1
	destination=$2
	;;
*)	echo "install: too many files specified" >&2
	exit 2
	;;
esac

[ $source = $destination -o $destination = . ] && {
	echo "install: can't move $source onto itself" >&2
	exit 1
}

[ -f $source ] || {
	echo "install: can't open $source" >&2
	exit 1
}

if [ -d $destination ]
then
	file=`basename $source`
	OLDdestination=$destination/OLD$file
	destination=$destination/$file
else
	dir=`dirname $destination`
	file=`basename $destination`
	OLDdestination=$dir/OLD$file
fi

(cp $source $destination &&
  chmod $mode $destination &&
  chown $owner $destination &&
  chgrp $group $destination) || exit 1

# /bin/rm -f $OLDdestination

[ $strip = TRUE ] &&
	strip $destination

[ $remove = TRUE ] &&
	rm -f $source

exit 0
OpenPOWER on IntegriCloud