3 # install-sh -- install a program, script, or data-file.
5 # This isn't a full install-script; it does only what is needed by the cc65
6 # package. It can install only one file at a time.
8 # If the system has an "install" command, then use it; otherwise, emulate it.
9 if type install >/dev/null 2>&1
10 then exec install "$@"
13 # Don't use ":-" because 4.3BSD and earlier shells don't like it.
14 # Put in absolute paths if you don't have these commands in your PATH;
15 # or, set these upper-case variables in your environment.
19 stripprog="${STRIPPROG-strip}"
20 chmodprog="${CHMODPROG-chmod}"
30 while [ x"$1" != x ]; do
34 -m) chmodcmd="$chmodprog $2"
38 -s) stripcmd="$stripprog"
41 # The first name is the source; the last name is the destination.
50 [ x"$src" != x ] || { echo "$0: no input file was named." >&2; exit 1;}
51 [ x"$dst" != x ] || { echo "$0: no destination was named." >&2; exit 1;}
53 [ -e "$src" ] || { echo "$0: \"$src\" doesn't exist." >&2; exit 1;}
55 # Make a temporary file-name in the proper directory.
56 dsttmp="$dst/#inst.$$#"
58 # Append the input filename to the destination directory.
59 dst="$dst"/`basename "$src"`
61 # Trap to remove the temporary file if it isn't renamed.
62 trap 'status=$?; $rmcmd "$dsttmp" && exit $status' 0
63 trap '(exit $?); exit' 1 2 3 13 15
65 # Copy the source file to the temporary name.
66 $instcmd "$src" "$dsttmp" &&
68 if [ x"$stripcmd" != x ]
69 then $stripcmd "$dsttmp"
71 if [ x"$chmodcmd" != x ]
72 then $chmodcmd "$dsttmp"
75 # Remove an old file (only if the temporary file was created successfully).
77 then $rmcmd "$dst" 2>/dev/null ||
78 { echo "$0: can't remove \"$dst\"" >&2
83 # Rename the temporary file to the real name.
84 $mvcmd "$dsttmp" "$dst" &&
86 # The final little trick to pass "correctly" the exit status to exit traps.