Ticket #329: trac_329-ref.patch

File trac_329-ref.patch, 5.1 KB (added by jhpalmieri, 8 years ago)

scripts repo

  • sage-add-integrity-check-to-spkg

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1315618599 25200
    # Node ID 201a2ed975ad22cadfb7430f38e5ee73514d19dc
    # Parent  629c2da5469466642aab89fbc5de93f5e873ed69
    
    #329: miscellaneous cleanup:
    
    * add some error checks and error messages
    
    * echo some error messages to stderr instead of stdout
    
    * automatically add a checksum in sage-pkg
    
    * replace "if DIR does not exist, mkdir DIR" by "mkdir -p DIR"
    
    * quoted some environment variables
    
    diff --git a/sage-add-integrity-check-to-spkg b/sage-add-integrity-check-to-spkg
    a b  
    11#!/usr/bin/env bash
    22
    3 # Given a spkg file as $1, this adds the necessary checksum information.
     3# Usage:
     4#
     5#    $ sage-add-integrity-check-to-spkg new.spkg
     6#
     7# adds the necessary checksum information to the spkg.
    48# See http://trac.sagemath.org/sage_trac/ticket/329.
    59
    610SPKGNAME=$(basename $1 .spkg)
    711
    812if [ "x$1" = "x$SPKGNAME" ]
    913then
    10     echo "I don't think you gave me a spkg file."
     14    echo "I don't think you gave me a spkg file." 1>&2
    1115    exit 1
    1216fi
    1317
    fi 
    2630
    2731$CAT $1 > $SPKGNAME.tar
    2832
     33if [ $? != "0" ]; then
     34    echo "Error running $CAT on $1." 1>&2
     35    exit 1
     36fi
     37
    2938{ tar xf $SPKGNAME.tar --exclude $SPKGNAME.cksum -O; \
    3039tar tf $SPKGNAME.tar --exclude $SPKGNAME.cksum; } | \
    3140cksum | awk '{print $1, $2}' > $SPKGNAME.cksum
    3241
     42# The following isn't doing everything it should, since it's picking
     43# up the exit status from 'cksum', not from 'tar'.  The 'pipestatus'
     44# script in SAGE_ROOT/spkg/ doesn't work if any of the commands
     45# involved use pipes, so we can't use it here.
     46
     47if [ $? != "0" ]; then
     48    echo "Error adding checksum file to spkg." 1>&2
     49    exit 1
     50fi
     51
    3352echo "Checksum of $1 is `cat $SPKGNAME.cksum`."
    3453
    3554tar rf $SPKGNAME.tar $SPKGNAME.cksum
    3655
    3756$UNCAT $SPKGNAME.tar > $1
     57
     58if [ $? != "0" ]; then
     59    echo "Error running $UNCAT on $SPKGNAME.tar." 1>&2
     60    exit 1
     61fi
     62
    3863rm $SPKGNAME.tar $SPKGNAME.cksum
     64
     65if [ $? != "0" ]; then
     66    echo "Error removing $PKGNAME.tar or $PKGNAME.cksum." 1>&2
     67    exit 1
     68fi
  • sage-pkg

    diff --git a/sage-pkg b/sage-pkg
    a b Proceeding anyway...""" 
    9999        hgrepo_txt = "Unchecked in changes"
    100100    else:
    101101        hgrepo_txt = "Good"
     102    p = Popen("sage-add-integrity-check-to-spkg %s" % file, shell=True,
     103              stdout=PIPE, stderr=PIPE)
     104    std_out, std_err = p.communicate()
     105    if p.returncode != 0:
     106        cksum_txt = "Error adding checksum to spkg."
     107    else:
     108        cksum_txt = "Good"
    102109
    103110    print """
    104111Created package %(file)s.
    Created package %(file)s. 
    107114 VERSION: %(version)s
    108115    SIZE: %(size)s
    109116 HG REPO: %(hgrepo)s
     117   CKSUM: %(cksum)s
    110118SPKG.txt: %(spkg)s
    111119
    112120Please test this package using
    Please test this package using 
    114122   sage -f %(file)s
    115123
    116124immediately.""" % {'file': file, 'name': name, 'version': version, 'size': size,
    117        'hgrepo': hgrepo_txt, 'spkg': spkg_txt},
     125       'hgrepo': hgrepo_txt, 'spkg': spkg_txt, 'cksum': cksum_txt},
    118126    if options.no_compress:
    119127        print ""
    120128        print ""
  • sage-spkg-integrity-check

    diff --git a/sage-spkg-integrity-check b/sage-spkg-integrity-check
    a b  
    1313
    1414if [ -z "$1" ]
    1515then
    16     echo "Error in $0: you need to specify a .spkg file."
     16    echo "Error in $0: you need to specify a .spkg file." 1>&2
    1717    exit 3
    1818fi
    1919
    2020if [ -z "$SAGE_ROOT" ]
    2121then
    22     echo "Error in $0: \$SAGE_ROOT must be set."
     22    echo "Error in $0: \$SAGE_ROOT must be set." 1>&2
    2323    exit 3
    2424fi
    2525
    else 
    3737    J="j"
    3838fi
    3939
    40 if [ ! -d $SAGE_ROOT/spkg/cksum ]
     40mkdir -p "$SAGE_ROOT"/spkg/cksum
     41if [ $? != 0 ]
    4142then
    42     mkdir $SAGE_ROOT/spkg/cksum
    43     if [ $? != 0 ]
    44     then
    45         echo Something went wrong trying to create the \$SAGE_ROOT/cksum directory.
    46         echo $0 exiting.
    47         exit 3
    48     fi
     43    echo "Something went wrong trying to create the \$SAGE_ROOT/cksum directory." 1>&2
     44    echo "$0 exiting." 1>&2
     45    exit 3
    4946fi
    5047
    5148# extract existing checksum
    52 $SAGE_ROOT/spkg/pipestatus "tar ${J}xf $1 -O $SPKGNAME.cksum" "awk 'NR==1 {print $1, $2}'" > "$SAGE_ROOT/spkg/cksum/$SPKGNAME.downloaded.cksum"
     49"$SAGE_ROOT"/spkg/pipestatus "tar ${J}xf $1 -O $SPKGNAME.cksum" "awk 'NR==1 {print $1, $2}'" > "$SAGE_ROOT/spkg/cksum/$SPKGNAME.downloaded.cksum"
    5350
    5451# the "NR==1" tells awk to only print line 1; if a checksum gets put
    5552# into the spkg twice, the -O in tar will print it out twice. We just
    fi 
    5754
    5855# use our pipestatus script to check exit code of tar (the usual $?
    5956# returns the exit code of the final process in the pipe)
    60 if [ $? != "0" ]
     57if [ $? != 0 ]
    6158then
    6259    # GNU tar gives different exit codes for "file not found" and other
    6360    # errors, but BSD tar just returns 1, so we can't quite tell the
    tar ${J}tf $1 --exclude $SPKGNAME.cksum  
    7370cksum | awk '{print $1, $2}' > "$SAGE_ROOT/spkg/cksum/$SPKGNAME.computed.cksum"
    7471
    7572cmp "$SAGE_ROOT/spkg/cksum/$SPKGNAME.downloaded.cksum" "$SAGE_ROOT/spkg/cksum/$SPKGNAME.computed.cksum" >/dev/null
    76 if [ $? = "0" ]
     73if [ $? = 0 ]
    7774then
    7875    echo Integrity check for $1 passed.
    7976else