1#!/bin/bash 2 3### This code basically just generates the license PMs on-the-fly ### 4 5PMDIR='lib/Software/License' 6LYNX='lynx -dump -width 83 -display_charset US-ASCII -nolist -nonumbers' 7 8for VER in 1.0 2.0 3.0 4.0; do 9 for CODE in BY BY-SA BY-NC BY-ND BY-NC-SA BY-NC-ND; do 10 PACKAGE=CC_`echo $CODE"_"$VER | tr '.-' '__'` 11 12 # V1.0 has this flipped 13 if [ $PACKAGE == "CC_BY_NC_ND_1_0" ]; then 14 CODE="BY-ND-NC" 15 PACKAGE="CC_BY_ND_NC_1_0" 16 fi 17 18 URL=http://creativecommons.org/licenses/${CODE,,}/$VER/ 19 LNAME=`$LYNX $URL'legalcode' | head -20 | perl -pe 's/^\s+|\s+$//g; $_ = "" unless /'$VER'/'` 20 META_NAME=restricted 21 [ $CODE == "BY-SA" -o $CODE == "BY" ] && META_NAME=unrestricted 22 23 echo "$PACKAGE.pm - $LNAME" 24 25 echo "package Software::License::$PACKAGE; 26 27use strict; 28use warnings; 29 30use base 'Software::License'; 31 32# AUTHORITY 33# VERSION 34# ABSTRACT: Creative Commons $LNAME License (CC $CODE $VER) 35 36### NOTE: This file was auto-generated using cc-license.sh. Do not edit this file! 37 38sub name { 'Creative Commons $LNAME License (CC $CODE $VER)' } 39sub url { '$URL' } 40 41sub version { '$VER' } 42sub meta_name { '$META_NAME' } 43 441; 45__DATA__ 46__NOTICE__ 47This work, created by {{\$self->holder}}, is licensed under a 48Creative Commons $LNAME License. 49" > $PMDIR/$PACKAGE.pm 50 $LYNX $URL | perl -e ' 51 $_ = join("", <>); 52 s/.+(?=You are free to:)//s; # garbage above 53 s/\s*(?:A new version of this license is available|The applicable mediation rules will be designated).+/\n/s; # garbage below 54 s/^[ ]+\*[ ]*\n[ ]*\n//m; # weird blank bullet point 55 s/^\s+Attribute this work:.+?\n\n(?=^\s+\*)//ms; # more garbage 56 s/^[ ]{5}(?=\*)/ /gm; # reduce to 3 spaces per bullet point 57 s/^[ ]{7}(?=\w)/ /gm; # adjust bullet word indents 58 s/\S+\n\K(?=[ ]+\*)/\n/g; # add blank lines before each bullet point 59 print $_; 60 ' >> $PMDIR/$PACKAGE.pm 61 echo "__LICENSE__" >> $PMDIR/$PACKAGE.pm 62 63 $LYNX $URL'legalcode' | perl -e ' 64 $_ = join("", <>); 65 s/^\s+(Creative Commons)\n\n\s+CC/$1/; # garbage header on 4.0 licenses 66 s/\s*(?:Creative Commons Notice|Creative Commons is not a party to (?:this License,|its public licenses\.)).+/\n/s; # garbage below 67 s/\S+\n\K(?=[ ]+(?:\w{1,2}|[ivx]{1,5})\. )/\n/g; # add blank lines before each numbered point 68 s/^[ ]+\Q'"$LNAME"'\E\n\K(?=[ ]*\w)/\n/m; # add blank line after titles 69 print $_; 70 ' >> $PMDIR/$PACKAGE.pm 71 done 72done 73