Annotation of pkgsrc/pkgtools/pkgdiff/files/pkgvi, revision 1.2
1.1 hubertf 1: #!/bin/sh
1.2 ! jlam 2: # $NetBSD: pkgvi,v 1.1 2001/01/17 23:16:46 hubertf Exp $
1.1 hubertf 3: #
4: # Copyright (c) 2001 Tomasz Luchowski. All rights reserved.
5: #
6: # Redistribution and use in source and binary forms, with or without
7: # modification, are permitted provided that the following conditions
8: # are met:
9: # 1. Redistributions of source code must retain the above copyright
10: # notice, this list of conditions and the following disclaimer.
11: # 2. Redistributions in binary form must reproduce the above copyright
12: # notice, this list of conditions and the following disclaimer in the
13: # documentation and/or other materials provided with the distribution.
14: # 3. All advertising materials mentioning features or use of this software
15: # must display the following acknowledgement:
16: # This product includes software developed by Tomasz Luchowski for
17: # the NetBSD Project
18: # 4. The name of the author may not be used to endorse or promote products
19: # derived from this software without specific prior written permission.
20: #
21: # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: # SUCH DAMAGE.
32: #
33:
34: #
35: # Usage: pkgvi file
36: #
37: # The pkgvi utility runs user's favourite editor (it uses $PKG_EDITOR if
38: # defined, then it looks for $EDITOR, if none is defined, it uses vi) on
39: # copy of specified file. If no changes are made in the editor, nothing
40: # happens, else original file is stored as $filename.orig, and modified
41: # file is saved as $filename. If it founds $filename.orig, it behaves as
42: # normal editor.
43: #
44: # - Tomasz Luchowski <zuntum@eik.pl>
45: #
46:
47: if [ "$PKGEDITOR" != "" ]; then
48: editor="$PKGEDITOR"
49: elif [ "$EDITOR" != "" ]; then
50: editor="$EDITOR"
51: else
52: editor="vi"
53: fi
54:
55: progname=`basename $0`
56:
57: if [ $# -eq 0 ]
58: then
59: echo echo Usage: $progname file >&2
60: exit 1
61: fi
62:
63: file="$1"
64: tmp="$file.tmp"
65:
66: if [ ! -f "$file" ]
67: then
68: echo "$progname: $file: No such file"
69: exit 2
70: fi
71:
72: if [ -f $file.orig ]
73: then
1.2 ! jlam 74: $editor $file
1.1 hubertf 75: echo "$progname: Backup already exists, for a diff type:"
76: echo "pkgdiff $file"
77: exit 0
78: fi
79:
80: tmp="$file.$$"
81:
82: cp $file $tmp
83:
1.2 ! jlam 84: $editor $tmp
1.1 hubertf 85:
86: if cmp $file $tmp 2>&1 >/dev/null
87: then
88: echo File unchanged.
89: else
90: mv $file $file.orig
91: mv $tmp $file
92: echo $progname: File was modified. For a diff, type:
93: echo pkgdiff $file
94: fi
95:
96: if [ -f $tmp ]
97: then
98: rm $tmp
99: fi
CVSweb <webmaster@jp.NetBSD.org>