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 # Don't use ":-" because 4.3BSD and earlier shells don't like it.
9 # Put in absolute paths if you don't have these commands in your PATH;
10 # or, set these upper-case variables in your environment.
14 stripprog="${STRIPPROG-strip}"
15 chmodprog="${CHMODPROG-chmod}"
25 while [ x"$1" != x ]; do
29 -m) chmodcmd="$chmodprog $2"
33 -s) stripcmd="$stripprog"
36 # The first name is the source; the last name is the destination.
45 [ x"$src" != x ] || { echo "$0: no input file was named." >&2; exit 1;}
46 [ x"$dst" != x ] || { echo "$0: no destination was named." >&2; exit 1;}
48 [ -e "$src" ] || { echo "$0: \"$src\" doesn't exist." >&2; exit 1;}
50 # Make a temporary file-name in the proper directory.
51 dsttmp="$dst/#inst.$$#"
53 # Append the input filename to the destination directory.
54 dst="$dst"/`basename "$src"`
56 # Trap to remove the temporary file if it isn't renamed.
57 trap 'status=$?; $rmcmd "$dsttmp" && exit $status' 0
58 trap '(exit $?); exit' 1 2 3 13 15
60 # Copy the source file to the temporary name.
61 $instcmd "$src" "$dsttmp" &&
63 if [ x"$stripcmd" != x ]
64 then $stripcmd "$dsttmp"
66 if [ x"$chmodcmd" != x ]
67 then $chmodcmd "$dsttmp"
70 # Remove an old file (only if the temporary file was created successfully).
72 then $rmcmd "$dst" 2>/dev/null ||
73 { echo "$0: can't remove \"$dst\"" >&2
78 # Rename the temporary file to the real name.
79 $mvcmd "$dsttmp" "$dst" &&
81 # The final little trick to pass "correctly" the exit status to exit traps.