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

1.1       hubertf     1: #!/bin/sh
1.12    ! schmonz     2: # $NetBSD: pkgvi,v 1.11 2011/08/23 21:47:18 abs 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: 
1.12    ! schmonz    34: set -e
        !            35: 
        !            36: progname=`basename $0`
        !            37: editor="vi"
1.1       hubertf    38: if [ "$PKGEDITOR" != "" ]; then
                     39:        editor="$PKGEDITOR"
                     40: elif [ "$EDITOR" != "" ]; then
                     41:        editor="$EDITOR"
                     42: fi
                     43: 
1.12    ! schmonz    44: die() {
        !            45:        _exitcode=$1; shift
        !            46:        warn "$@"
        !            47:        exit ${_exitcode}
        !            48: }
        !            49: 
        !            50: warn() {
        !            51:        echo >&2 "$@"
        !            52: }
        !            53: 
        !            54: usage() {
        !            55:        die 1 "Usage: $progname [+cmd] file [...]"
        !            56: }
        !            57: 
        !            58: prepare_backup_files() {
        !            59:        for file in $@; do
        !            60:                [ -f "$file" ] || die 2 "$progname: $file: No such file"
        !            61:                chmod u+w "$file"
        !            62:                if [ -f "$file.orig" ]; then
        !            63:                        echo "$progname: Backup already exists."
        !            64:                else
        !            65:                        cp "$file" "$file.orig"
        !            66:                fi
        !            67:        done
        !            68: }
        !            69: 
        !            70: remove_unneeded_backup_files() {
        !            71:        for file in $@; do
        !            72:                if cmp "$file" "$file.orig" >/dev/null 2>&1; then
        !            73:                        echo "$progname: File unchanged."
        !            74:                        rm -f "$file.orig"
        !            75:                else
        !            76:                        echo "$progname: File was modified. For a diff, type:"
        !            77:                        echo "pkgdiff \"$file\""
        !            78:                fi
        !            79:        done
        !            80: }
        !            81: 
        !            82: main() {
        !            83:        [ $# -eq 0 ] && usage
        !            84: 
        !            85:        cmd=""
        !            86:        case "$1" in
        !            87:                +*)     cmd="$1"; shift ;;
        !            88:        esac
        !            89: 
        !            90:        prepare_backup_files "$@"
1.8       grant      91: 
1.12    ! schmonz    92:        $editor $cmd $@
1.8       grant      93: 
1.12    ! schmonz    94:        remove_unneeded_backup_files "$@"
        !            95: }
1.1       hubertf    96: 
1.12    ! schmonz    97: main "$@"
        !            98: exit $?

CVSweb <webmaster@jp.NetBSD.org>