File: install-sh

package info (click to toggle)
swish++ 6.1.5-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,256 kB
  • ctags: 1,759
  • sloc: ansic: 11,931; lisp: 804; sh: 629; perl: 366; makefile: 80
file content (148 lines) | stat: -rwxr-xr-x 3,158 bytes parent folder | download | duplicates (8)
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
#! /bin/sh
##
#	install-sh
#
#	Copyright (C) 2000  Paul J. Lucas
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##

CP=cp
CHOWN=chown
CHGRP=chgrp
CHMOD=chmod
MKDIR=mkdir

# uncomment the next line to test script
#ECHO=echo

########## You shouldn't have to change anything below this line. #############

ME=`basename $0`

usage() {
	echo "usage: $ME [-o owner] [-g group] [-m mode] file ... dir" >&2
	echo "       $ME [-o owner] [-g group] [-m mode] -d dir" >&2
}

###############################################################################
#
#	Process command-line options
#
#	We don't rely on getopt because it varies and/or is broken on some
#	systems.
#
###############################################################################

while [ -n "$1" ]
do
	if [ -z "$A" ]
	then
		case $1 in

		-d*)	if [ x"$1" = x-d ]
			then A=$1
			else dir=`expr $1 : '-d\(.*\)'`
			fi
			;;

		-g*)	if [ x"$1" = x-g ]
			then A=$1
			else group=`expr $1 : '-g\(.*\)'`
			fi
			;;

		-m*)	if [ x"$1" = x-m ]
			then A=$1
			else mode=`expr $1 : '-m\(.*\)'`
			fi
			;;

		-o*)	if [ x"$1" = x-o ]
			then A=$1
			else owner=`expr $1 : '-o\(.*\)'`
			fi
			;;

		-*)	echo "$ME: illegal option: $1" >&2
			usage; exit 1
			;;

		*)	if [ -z "$src" ]
			then src=$1
			else src="$src $dst"; dst=$1
			fi
			;;
		esac
	else
		##### options that have an argument
		case $1 in
		-*)	break ;;
		esac
		case $A in
		-d)	dir=$1 ;;
		-g)	group=$1 ;;
		-m)	mode=$1 ;;
		-o)	owner=$1 ;;
		esac
		unset A
	fi
	shift
done

[ -n "$A" ] && {
	echo "$ME: $A requires an argument" >&2
	usage; exit 2
}

###############################################################################
#
#	Go!
#
###############################################################################

change() {
	[ -n "$owner" ] && $ECHO $CHOWN $owner $* 2>/dev/null
	[ -n "$group" ] && $ECHO $CHGRP $group $* 2>/dev/null
	[ -n "$mode"  ] && $ECHO $CHMOD $mode  $* 2>/dev/null
}

if [ -n "$dir" ]
then
	# don't rely on mkdir -p being available
	echo $dir | tr '/' '\012' | while read subdir
	do
		[ -z "$subdir" ] && subdir=/
		if [ -z "$path" ]
		then path=$subdir
		elif [ "$path" = / ]
		then path="/$subdir"
		else path="$path/$subdir"
		fi
		[ -d "$path" ] || { $ECHO $MKDIR $path; change $path; }
	done
else
	[ -z "$src" ] && {
		echo "$ME: no source file(s) specified" >&2
		usage; exit 3
	}
	[ -z "$dst" ] && {
		echo "$ME: no destination directory specified" >&2
		usage; exit 4
	}
	$ECHO $CP $src $dst
	$ECHO cd $dst
	change `echo $src | xargs -n1 basename`
fi