mute warning about shadow declaration of bind_addr
[rofl0r-microsocks.git] / install.sh
blob0410883866824467110dc307d2809637454e8fac
1 #!/bin/sh
3 # Written by Rich Felker, originally as part of musl libc.
4 # Multi-licensed under MIT, 0BSD, and CC0.
6 # This is an actually-safe install command which installs the new
7 # file atomically in the new location, rather than overwriting
8 # existing files.
11 usage() {
12 printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
13 exit 1
16 mkdirp=
17 symlink=
18 mode=755
20 while getopts Dlm: name ; do
21 case "$name" in
22 D) mkdirp=yes ;;
23 l) symlink=yes ;;
24 m) mode=$OPTARG ;;
25 ?) usage ;;
26 esac
27 done
28 shift $(($OPTIND - 1))
30 test "$#" -eq 2 || usage
31 src=$1
32 dst=$2
33 tmp="$dst.tmp.$$"
35 case "$dst" in
36 */) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
37 esac
39 set -C
40 set -e
42 if test "$mkdirp" ; then
43 umask 022
44 case "$2" in
45 */*) mkdir -p "${dst%/*}" ;;
46 esac
49 trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
51 umask 077
53 if test "$symlink" ; then
54 ln -s "$1" "$tmp"
55 else
56 cat < "$1" > "$tmp"
57 chmod "$mode" "$tmp"
60 mv -f "$tmp" "$2"
61 test -d "$2" && {
62 rm -f "$2/$tmp"
63 printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
64 exit 1
67 exit 0