in performing dns lookups, check result from res_mkquery
[musl.git] / tools / install.sh
blobd913b60bf24fc0589a211bc4f83dd0ce9d3c983a
1 #!/bin/sh
3 # This is an actually-safe install command which installs the new
4 # file atomically in the new location, rather than overwriting
5 # existing files.
8 usage() {
9 printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
10 exit 1
13 mkdirp=
14 symlink=
15 mode=755
17 while getopts Dlm: name ; do
18 case "$name" in
19 D) mkdirp=yes ;;
20 l) symlink=yes ;;
21 m) mode=$OPTARG ;;
22 ?) usage ;;
23 esac
24 done
25 shift $(($OPTIND - 1))
27 test "$#" -eq 2 || usage
28 src=$1
29 dst=$2
30 tmp="$dst.tmp.$$"
32 case "$dst" in
33 */) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
34 esac
36 set -C
37 set -e
39 if test "$mkdirp" ; then
40 umask 022
41 case "$2" in
42 */*) mkdir -p "${dst%/*}" ;;
43 esac
46 trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
48 umask 077
50 if test "$symlink" ; then
51 ln -s "$1" "$tmp"
52 else
53 cat < "$1" > "$tmp"
54 chmod "$mode" "$tmp"
57 mv -f "$tmp" "$2"
58 test -d "$2" && {
59 rm -f "$2/$tmp"
60 printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
61 exit 1
64 exit 0