xref: /netbsd-src/external/gpl3/gdb/dist/move-if-change (revision 9d2109275e137f9027abb05e859af639830e18f5)
1597410b8Schristos#!/bin/sh
2597410b8Schristos# Like mv $1 $2, but if the files are the same, just delete $1.
3597410b8Schristos# Status is zero if successful, nonzero otherwise.
4597410b8Schristos
5*9d210927SchristosVERSION='2012-01-06 07:23'; # UTC
6597410b8Schristos# The definition above must lie within the first 8 lines in order
7597410b8Schristos# for the Emacs time-stamp write hook (at end) to update it.
8597410b8Schristos# If you change this file with Emacs, please let the write hook
9597410b8Schristos# do its job.  Otherwise, update this string manually.
10597410b8Schristos
11*9d210927Schristos# Copyright (C) 2002-2014 Free Software Foundation, Inc.
12597410b8Schristos
13597410b8Schristos# This program is free software: you can redistribute it and/or modify
14597410b8Schristos# it under the terms of the GNU General Public License as published by
15597410b8Schristos# the Free Software Foundation, either version 3 of the License, or
16597410b8Schristos# (at your option) any later version.
17597410b8Schristos
18597410b8Schristos# This program is distributed in the hope that it will be useful,
19597410b8Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
20597410b8Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21597410b8Schristos# GNU General Public License for more details.
22597410b8Schristos
23597410b8Schristos# You should have received a copy of the GNU General Public License
24597410b8Schristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
25597410b8Schristos
26597410b8Schristosusage="usage: $0 SOURCE DEST"
27597410b8Schristos
28597410b8Schristoshelp="$usage
29597410b8Schristos  or:  $0 OPTION
30597410b8SchristosIf SOURCE is different than DEST, then move it to DEST; else remove SOURCE.
31597410b8Schristos
32597410b8Schristos  --help     display this help and exit
33597410b8Schristos  --version  output version information and exit
34597410b8Schristos
35*9d210927SchristosThe variable CMPPROG can be used to specify an alternative to 'cmp'.
36597410b8Schristos
37597410b8SchristosReport bugs to <bug-gnulib@gnu.org>."
38597410b8Schristos
39597410b8Schristosversion=`expr "$VERSION" : '\([^ ]*\)'`
40597410b8Schristosversion="move-if-change (gnulib) $version
41597410b8SchristosCopyright (C) 2011 Free Software Foundation, Inc.
42597410b8SchristosLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
43597410b8SchristosThis is free software: you are free to change and redistribute it.
44597410b8SchristosThere is NO WARRANTY, to the extent permitted by law."
45597410b8Schristos
46597410b8Schristoscmpprog=${CMPPROG-cmp}
47597410b8Schristos
48597410b8Schristosfor arg
49597410b8Schristosdo
50597410b8Schristos  case $arg in
51597410b8Schristos    --help | --hel | --he | --h)
52597410b8Schristos      exec echo "$help" ;;
53597410b8Schristos    --version | --versio | --versi | --vers | --ver | --ve | --v)
54597410b8Schristos      exec echo "$version" ;;
55597410b8Schristos    --)
56597410b8Schristos      shift
57597410b8Schristos      break ;;
58597410b8Schristos    -*)
59597410b8Schristos      echo "$0: invalid option: $arg" >&2
60597410b8Schristos      exit 1 ;;
61597410b8Schristos    *)
62597410b8Schristos      break ;;
63597410b8Schristos  esac
64597410b8Schristosdone
65597410b8Schristos
66597410b8Schristostest $# -eq 2 || { echo "$0: $usage" >&2; exit 1; }
67597410b8Schristos
68597410b8Schristosif test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null; then
69597410b8Schristos  rm -f -- "$1"
70597410b8Schristoselse
71597410b8Schristos  if mv -f -- "$1" "$2"; then :; else
72597410b8Schristos    # Ignore failure due to a concurrent move-if-change.
73597410b8Schristos    test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null && rm -f -- "$1"
74597410b8Schristos  fi
75597410b8Schristosfi
76597410b8Schristos
77597410b8Schristos## Local Variables:
78597410b8Schristos## eval: (add-hook 'write-file-hooks 'time-stamp)
79597410b8Schristos## time-stamp-start: "VERSION='"
80597410b8Schristos## time-stamp-format: "%:y-%02m-%02d %02H:%02M"
81597410b8Schristos## time-stamp-time-zone: "UTC"
82597410b8Schristos## time-stamp-end: "'; # UTC"
83597410b8Schristos## End:
84