]>
Dogcows Code - chaz/yoink/blob - tools/install.sh
3 # INSTALL (C) 2002 Emile van Bergen. Distribution of this file is allowed under
4 # the conditions detailed in the GNU General Public License (GPL). See the file
5 # COPYING for more information.
7 # This script installs zero or more files into a specified directory. If one or
8 # more components of the destination path do not exist, they are created. The
9 # permissions of the destination file and the destination directory(s), if any
10 # need to be created, can be specified separately. The user can also specify
11 # that the operation must be skipped if the destination file or the destination
12 # directory already exists. Source files are stripped of their directory
13 # components before determining the destination name.
15 # It is intended to replace the /usr/bin/install command, which has no portable
16 # subset of features that offers anything above /bin/cp. Each version is broken
17 # in its own ways, the most annoying examples being that some can only install
18 # a single file at a time and that some do not create destination directories
19 # recursively. Hence this shell script, that is intended to be portable across
20 # all POSIX-compliant /bin/sh shells. It does not assume a working 'mkdir -p'
25 # install arguments...
27 # Each argument is either an option, as specified below, a source file, or
28 # a destination directory, with -d prepended. Each time a destination
29 # directory is encountered, the source files leading up to it are installed,
30 # and then all options are reset, allowing you to perform multiple install
31 # operations with one command.
35 # -h Show a brief usage message
36 # -v Show what's being done
37 # -m specify mode of destination files
38 # -md specify mode of destination directories, if any are created
39 # -n skip operation if destination file exists
40 # -nd skip operation if destination directory exists
44 # 0 Successful completion
49 # * Source files cannot start with a '-' or contain spaces
50 # * Destination directories cannot start with a '-' or contain spaces
51 # * If multiple different modes are desired for files in a single destination
52 # directory, you must specify multiple installation sets (-d options), one
53 # for each mode (eg. install -m 644 file1 file2 -d dir file3 -m 600 -d dir).
54 # * The /bin/sh shell used to run this script must support user-defined
56 # * The system must have mkdir, chmod, basename, tr, sed and cp available.
57 # If needed, basename and tr could be provided by sed, but I don't think
58 # that should be done by default as they are very common.
60 # Notes (not bugs, features. Really!):
62 # * If the destination directory already exists, its mode is not changed
63 # even if -md is specified; that mode is only used when creating new ones.
64 # * If the destination file already exists but is overwritten because no -n
65 # was specified, the new mode, if specified, is applied as well.
66 # * QNX-style paths starting with // are honored, as are .. path components.
67 # An initial .. works as expected, and a destination path a/b/../c creates
68 # a, a/b, a/c and installs the files in a/c.
72 # 2002/09/13 - EvB - Created
78 [ -n "$verbose" ] && echo "Creating directory $dir"
80 mkdir "$dir" || exit 1
84 chmod "$mode_dir" "$dir" || exit 2
93 root
=`echo $1 | sed -e 's/[^/].*$//g'`
94 components
=`echo $1 | tr / " "`
97 for comp
in $components
105 [ "$comp" = "." ] || [ "$comp" = ".." ] ||
106 [ -d "$root$cumul" ] || make_dir
"$root$cumul"
119 make_dir_tree
"$dest"
123 echo "$me: Directory $dest already exists -- skipping"
130 file=`basename $src_file`
131 dest_file
="$dest/$file"
133 if [ -n "$new" ] && [ -f $dest_file ]
135 echo "$me: File $dest_file already exists -- skipping"
139 [ -n "$verbose" ] && echo "Copying $src_file to $dest_file"
140 cp "$src_file" "$dest_file" || exit 3
144 chmod "$mode" "$dest_file" || exit 4
172 -m) mode
="$2" ; shift ;;
173 -md) mode_dir
="$2" ; shift ;;
178 -d) do_install
"$2" ; init_opts
; shift ;;
181 echo Usage
: $me [options
] [file...
] -d directory
This page took 0.042784 seconds and 4 git commands to generate.