Home | History | Annotate | Download | only in JSON
      1 #!/bin/bash
      2 # Download and build JSON.pm
      3 # Homepage:
      4 # http://search.cpan.org/~makamaka/JSON-2.58/lib/JSON.pm
      5 # SRC_URL='http://www.cpan.org/authors/id/M/MA/MAKAMAKA/JSON-2.58.tar.gz'
      6 PACKAGE='JSON'
      7 VERSION='2.59'
      8 SRC_URL="http://www.cpan.org/authors/id/M/MA/MAKAMAKA/$PACKAGE-$VERSION.tar.gz"
      9 FILENAME="$(basename $SRC_URL)"
     10 SHA1_FILENAME="$FILENAME.sha1"
     11 BUILD_DIR="$PACKAGE-$VERSION"
     12 INSTALL_DIR="$(pwd)/out"
     13 
     14 curl --remote-name "$SRC_URL"
     15 
     16 # Check hash
     17 # SHA-1 hash generated via:
     18 # shasum JSON-2.59.tar.gz > JSON-2.59.tar.gz.sha1
     19 if ! [ -f "$SHA1_FILENAME" ]
     20 then
     21   echo "SHA-1 hash file $SHA1_FILENAME not found, could not verify archive"
     22   exit 1
     23 fi
     24 
     25 # Check that hash file contains hash for archive
     26 HASHFILE_REGEX="^[0-9a-f]{40}  $FILENAME"  # 40-digit hash, followed by filename
     27 if ! grep --extended-regex --line-regex --silent \
     28   "$HASHFILE_REGEX" "$SHA1_FILENAME"
     29 then
     30   echo "SHA-1 hash file $SHA1_FILENAME does not contain hash for $FILENAME," \
     31        'could not verify archive'
     32   echo 'Hash file contents are:'
     33   cat "$SHA1_FILENAME"
     34   exit 1
     35 fi
     36 
     37 if ! shasum --check "$SHA1_FILENAME"
     38 then
     39   echo 'SHA-1 hash does not match,' \
     40        "archive file $FILENAME corrupt or compromised!"
     41   exit 1
     42 fi
     43 
     44 # Extract and build
     45 tar xvzf "$FILENAME"
     46 cd "$BUILD_DIR"
     47 perl Makefile.PL INSTALL_BASE="$INSTALL_DIR"
     48 make
     49 make test
     50 make install
     51 cd ..
     52 rm "$FILENAME"
     53 
     54 # Rename :: to __ because : is reserved in Windows filenames
     55 # (only occurs in man pages, which aren't necessary)
     56 for i in $(find . -name '*::*')
     57 do
     58   mv -f "$i" `echo "$i" | sed s/::/__/g`
     59 done
     60 
     61 # Fix permissions and shebangs
     62 # https://rt.cpan.org/Public/Bug/Display.html?id=85917
     63 # Make examples executable
     64 cd "$BUILD_DIR"
     65 chmod +x eg/*.pl
     66 cd t
     67 
     68 # Strip shebangs from test files that have them
     69 for i in *.t
     70 do
     71   if head -1 "$i" | grep --quiet '^#!'
     72   then
     73     ed -s "$i" <<END
     74 # Delete line 1
     75 1d
     76 # Write and Quit
     77 wq
     78 END
     79   fi
     80 done
     81