Annotation of pkgsrc/pkgtools/pkgdiff/files/pkgvi, revision 1.8

1.1       hubertf     1: #!/bin/sh
1.8     ! grant       2: # $NetBSD: pkgvi,v 1.7 2001/12/03 14:30:17 seb 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: if [ "$PKGEDITOR" != "" ]; then
                     35:        editor="$PKGEDITOR"
                     36: elif [ "$EDITOR" != "" ]; then
                     37:        editor="$EDITOR"
                     38: else
                     39:        editor="vi"
                     40: fi
                     41: 
                     42: progname=`basename $0`
                     43: 
                     44: if [ $# -eq 0 ]
                     45: then
1.5       hubertf    46:        echo Usage: $progname file >&2
1.1       hubertf    47:        exit 1
                     48: fi
                     49: 
                     50: file="$1"
1.7       seb        51: cmd=""
                     52: case x"$file" in
                     53:         x+*) cmd="$1"; shift ; file="$1" ;;
                     54: esac
1.1       hubertf    55: 
                     56: if [ ! -f "$file" ]
                     57: then
                     58:        echo "$progname: $file: No such file"
                     59:        exit 2
                     60: fi
                     61: 
                     62: if [ -f $file.orig ]
                     63: then
1.7       seb        64:        $editor $cmd $file
1.3       hubertf    65:        echo "$progname: Backup already exists. For a diff type:"
1.1       hubertf    66:         echo "pkgdiff $file"
                     67:        exit 0
                     68: fi
                     69: 
                     70: tmp="$file.$$"
1.8     ! grant      71: 
        !            72: ext=`echo $file | awk -F. '{ print $NF }'`
        !            73: 
        !            74: if [ "$file" != "$ext" ]; then
        !            75:        tmp=$tmp.$ext
        !            76: fi
1.1       hubertf    77: 
1.3       hubertf    78: cp "$file" "$tmp"
                     79: 
                     80: if [ $? -ne 0 ]; then
                     81:        echo "$progname: unable to create temporary file"
                     82:        exit 1
                     83: fi
1.1       hubertf    84: 
1.7       seb        85: $editor $cmd "$tmp"
1.1       hubertf    86: 
1.6       wiz        87: if cmp "$file" "$tmp" >/dev/null 2>&1
1.1       hubertf    88: then
1.3       hubertf    89:        echo "$progname: File unchanged."
1.1       hubertf    90: else
1.3       hubertf    91:        mv "$file" "$file.orig"
                     92:        mv "$tmp" "$file"
                     93:        echo "$progname: File was modified. For a diff, type:"
                     94:        echo "pkgdiff $file"
1.1       hubertf    95: fi
                     96: 
1.3       hubertf    97: if [ -f "$tmp" ]
1.1       hubertf    98: then
1.3       hubertf    99:        rm "$tmp"
1.6       wiz       100: fi
                    101: 
                    102: if [ -f "$tmp~" ]
                    103: then
                    104:        rm "$tmp~"
1.1       hubertf   105: fi

CVSweb <webmaster@jp.NetBSD.org>