]>
zdv2.bktei.com Git - BK-2020-03.git/blob - user/bkcc 
   3  # Date: 2020-02-08T22:21Z    5  # Author: Steven Baltakatei Sandoval    7  # License: This bash script, 'bkcc', is licensed under GPLv3 or    8  # later by Steven Baltakatei Sandoval:   10  #    'bkcc', a Creative Commons HTML tag generator.   11  #    Copyright (C) 2020  Steven Baltakatei Sandoval (baltakatei.com)   13  #    This program is free software: you can redistribute it and/or modify   14  #    it under the terms of the GNU General Public License as published by   15  #    the Free Software Foundation, either version 3 of the License, or   18  #    This program is distributed in the hope that it will be useful,   19  #    but WITHOUT ANY WARRANTY; without even the implied warranty of   20  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   21  #    GNU General Public License for more details.   23  #    A copy of the GNU General Public License may be found at   24  #    <https://www.gnu.org/licenses/>.   26  #   The structure of this script was modeled after the following   27  #   Creative Commons license choosers:   29  #     https://creativecommons.org/choose/   30  #     https://chooser-beta.creativecommons.org/   32  # Description: bkcc - A tool that creates a machine-readable (RDFa   33  # XML) Creative Commons license tag. The tag is generated using   34  # information prompted from the user and exported to stdout.   36  # Usage: bkcc [ OPTIONS ]   41  # regular expression for identifying valid URLs (source: http://regexlib.com/REDetails.aspx?regexp_id=1051 )   42  regexURL
= "((http\://|https\://|ftp\://)|(www.))+(([a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9%:/-_ \? \.'~]*)?"   44  # Define 'echoerr' function which outputs text to stderr   45      # Note: function copied from https://stackoverflow.com/a/2990533   51      ###echoerr "Note: RECOMMENDED options promote \"Free Cultural Works\" as defined by creativecommons.org"   52      echoerr 
"======================================================="   53      echoerr 
"Do you want to require attribution for your work? (y/n)"   54      echoerr 
"  y) Yes, anyone using my work must give me appropriate credit (RECOMMENDED)."   55      echoerr 
"  n) No, anyone can use my work even without attribution."   58          y | Y | 
yes  | 
1 )  OPTION_BY
= "true" ;;   60              echoerr 
"======================================================="   61              echoerr 
"I hereby waive all copyright and related or neighboring rights together with all"   62              echoerr 
"associated claims and causes of action with respect to this work to the extent"   63              echoerr 
"possible under law according to"   64              echoerr 
"https://creativecommons.org/publicdomain/zero/1.0/ ."   66              echoerr 
"I have read and understood the terms and intended legal effect of CC0, and"   67              echoerr 
"hereby voluntarily elect to apply it to this work (y/n):"   70                  y | Y | 
yes  | 
1 )  OPTION_BY
= "false" ;   71                                   echoerr 
"DEBUG: OPTION_BY set to  $OPTION_BY "   74                  n | N | no | 
2 )  echoerr 
"No license selected. Exiting." ;  exit  1 ;;   75                  *)  echoerr 
"Invalid CC0 release option. Exiting." ;  exit  1 ;;   77          *)  echoerr 
"Invalid attribution requirement option. Exiting." ;  exit  1 ;;   82      echoerr 
"======================================================="   83      echoerr 
"Do you want to prohibit others commercial use of your work? (y/n)"   84      echoerr 
"  y) Yes, others cannot use my work for commercial purposes."   85      echoerr 
"  n) No, others can use my work for commercial purposes (RECOMMENDED)."   88          y | Y | 
yes  | 
1 )  OPTION_NC
= "true" ;  echoerr 
"DEBUG: OPTION_NC set to  $OPTION_NC " ;;   89          n | N | no | 
2 )  OPTION_NC
= "false" ;  echoerr 
"DEBUG: OPTION_NC set to  $OPTION_NC " ;;   90          *)  echoerr 
"Invalid commercial use permission option. Exiting." ;  exit  1 ;;   95      echoerr 
"======================================================="   96      echoerr 
"Do you want to prohibit others from distributing your work if they remix, transform, or build upon it?"   97      echoerr 
"  y) Yes, others can use and share my work only as is, without modifications."   98      echoerr 
"  n) No, others may share modified versions of my work (RECOMMENDED)."  101          y | Y | 
yes  | 
1 )  OPTION_ND
= "true" ;  echoerr 
"DEBUG: OPTION_ND set to  $OPTION_ND " ;;  102          n | N | no | 
2 )  OPTION_ND
= "false" ;  echoerr 
"DEBUG: OPTION_ND set to  $OPTION_ND " ;;  103          *)  echoerr 
"Invalid derivative use permission option. Exiting." ;  exit  1 ;;  108      echoerr 
"======================================================="  109      echoerr 
"Do you want to prohibit your work under other terms?"  110      echoerr 
"  y) Yes, anyone who changes your work must share their contributions under the same license as the original. (RECOMMENDED)"  111      echoerr 
"  n) No, anyone who changes your work can distribute their contributions under a different license."  114          y | Y | 
yes  | 
1 )  OPTION_SA
= "true" ;  echoerr 
"DEBUG: OPTION_SA set to  $OPTION_SA " ;;  115          n | N | no | 
2 )  OPTION_SA
= "false" ;  echoerr 
"DEBUG: OPTION_SA set to  $OPTION_SA " ;;  116          *)  echoerr 
"Invalid sharealike requirement option. Exiting." ;  exit  1 ;;  120  promptLicenseDetails
() {  121      # Usage: promptLicenseDetails  122      # Description: Sets LICENSE_TYPE by questioning user.  124      echoerr 
"DEBUG: Beginning promptLicenseDetails function."  126      # Evaluate BY option.  127      # Ask if author wishes to be attributed.  128      promptAttribute 
# set OPTION_BY to true or false.  129      if  [[  $OPTION_BY  ==  "false"  ]];  then  130          LICENSE_TYPE
= "CC 1.0"  131          echoerr 
"DEBUG: LICENSE_TYPE set to  $LICENSE_TYPE "  135      # Evaluate NC option.  136      # Ask if author permits commercial use of work.  137      promptCommercial 
# set OPTION_NC to true or false.  139      # Evaluate ND option.  140      # Ask if author permits derivative use of work.  141      promptDerivatives 
# set OPTION_ND to true or false.  143      # Evaluate SA option.  144      # Ask if author requires derivative works to also carry same license as work.  145      if  [[  $OPTION_ND  =  "true"  ]];  then   146          OPTION_SA
= "false"  # An SA work cannot be made from an ND work.  148          promptShareAlike 
# set OPTION_SA to true or false.  152      if  [[  $OPTION_BY  ==  "true"  ]] &&  \
 153         [[  $OPTION_NC  ==  "false"  ]] &&  \
 154         [[  $OPTION_ND  ==  "false"  ]] &&  \
 155         [[  $OPTION_SA  ==  "false"  ]]  157          LICENSE_TYPE
= "CC BY 4.0"  162      if  [[  $OPTION_BY  ==  "true"  ]] &&  \
 163         [[  $OPTION_NC  ==  "false"  ]] &&  \
 164         [[  $OPTION_ND  ==  "false"  ]] &&  \
 165         [[  $OPTION_SA  ==  "true"  ]]  167          LICENSE_TYPE
= "CC BY-SA 4.0"  172      if  [[  $OPTION_BY  ==  "true"  ]] &&  \
 173         [[  $OPTION_NC  ==  "false"  ]] &&  \
 174         [[  $OPTION_ND  ==  "true"  ]] &&  \
 175         [[  $OPTION_SA  ==  "false"  ]]  177          LICENSE_TYPE
= "CC BY-ND 4.0"  182      if  [[  $OPTION_BY  ==  "true"  ]] &&  \
 183         [[  $OPTION_NC  ==  "true"  ]] &&  \
 184         [[  $OPTION_ND  ==  "false"  ]] &&  \
 185         [[  $OPTION_SA  ==  "false"  ]]  187          LICENSE_TYPE
= "CC BY-NC 4.0"  191      # Check for CC BY-NC-SA  192      if  [[  $OPTION_BY  ==  "true"  ]] &&  \
 193         [[  $OPTION_NC  ==  "true"  ]] &&  \
 194         [[  $OPTION_ND  ==  "false"  ]] &&  \
 195         [[  $OPTION_SA  ==  "true"  ]]  197          LICENSE_TYPE
= "CC BY-NC-SA 4.0"  201      # Check for CC BY-NC-ND  202      if  [[  $OPTION_BY  ==  "true"  ]] &&  \
 203         [[  $OPTION_NC  ==  "true"  ]] &&  \
 204         [[  $OPTION_ND  ==  "true"  ]] &&  \
 205         [[  $OPTION_SA  ==  "false"  ]]  207          LICENSE_TYPE
= "CC BY-NC-ND 4.0"  211      # Error message if none of the above if statements returned out of function.  212      echoerr 
"ERROR: Invalid license specified or LICENSE_TYPE not set." ;  exit  1 ;  217      # Usage: selectLicense  218      # Description: Sets LICENSE_TYPE variable according to a set of user prompts.  220      # Prompt license type  221      echoerr 
"Select license type:"  222      echoerr 
"  0) I don't know. Guide me."  223      echoerr 
"  1) CC0 1.0  \" CC0 1.0 Universal \" "  224      echoerr 
"  2) CC BY 4.0  \" Attribution 4.0 International \" "  225      echoerr 
"  3) CC BY-SA 4.0  \" Attribution-ShareAlike 4.0 International \" "  226      echoerr 
"  4) CC BY-ND 4.0  \" Attribution-NoDerivatives 4.0 International \" "  227      echoerr 
"  5) CC BY-NC 4.0  \" Attribution-NonCommercial 4.0 International \" "  228      echoerr 
"  6) CC BY-NC-SA 4.0  \" Attribution-NonCommercial-ShareAlike 4.0 International \" "  229      echoerr 
"  7) CC BY-NC-ND 4.0  \" Attribution-NonCommercial-NoDerivatives 4.0 International \" "  232          0 )  promptLicenseDetails
;  return ;;  # Sets LICENSE_TYPE via many questions to user.  233          1 )  LICENSE_TYPE
= "CC 1.0" ;;  234          2 )  LICENSE_TYPE
= "CC BY 4.0" ;;  235          3 )  LICENSE_TYPE
= "CC BY-SA 4.0" ;;  236          4 )  LICENSE_TYPE
= "CC BY-ND 4.0" ;;  237          5 )  LICENSE_TYPE
= "CC BY-NC 4.0" ;;  238          6 )  LICENSE_TYPE
= "CC BY-NC-SA 4.0" ;;  239          7 )  LICENSE_TYPE
= "CC BY-NC-ND 4.0" ;;  240          *)  echoerr 
"Invalid option selected. Exiting." ;  exit  1 ;;  246  selectLicense 
# Sets LICENSE_TYPE via simple prompt.  248  # Display value of $LICENSE_TYPE  249  echoerr 
"======================================================="  250  echoerr 
" $LICENSE_TYPE " " license selected."  253  echoerr 
"======================================================="  254  echoerr 
"Specify metadata (leave blank if not needed):"  255  read -p  "  Title of work [title]:"  workTitle
 256  read -p  "  Attribute work to [author]:"  workAuthor
 258  read -p  "  Attribute work to (ex: author's website) [URL]:"  workAuthorURL
 259  if  [[  -n  $workAuthorURL  ]];  then  260      while  [[ !  $workAuthorURL  = ~ 
$regexURL  ]];  do  261          echoerr 
"WARNING: URL may contain error (ex: does not begin with  \" https:// \" ."  262          echoerr 
"  Preappend  \" http:// \"  to URL? (y/n)"  265              y | Y | 
yes  | 
1 )  workAuthorURL
= "http://" " $workAuthorURL "  ;;  266              n | N | no | 
2 )  read -p  "  Attribute work to (ex: author's website) [URL]:"  workAuthorURL 
;;  272  read -p  "  Source work from which work was derived (leave blank if original work) [URL]:"  workSourceURL
 273  if  [[  -n  $workSourceURL  ]];  then  274      while  [[ !  $workSourceURL  = ~ 
$regexURL  ]];  do  275          echoerr 
"WARNING: URL may contain error (ex: does not begin with  \" https://\."  276          echoerr 
"  Preappend  \" http:// \"  to URL? (y/n)"  279              y | Y | 
yes  | 
1 )  workSourceURL
= "http://" " $workSourceURL "  ;;  280              n | N | no | 
2 )  read -p  "  Source work from which work was derived (leave blank if original work) [URL]:"  workSourceURL 
;;  286  read -p  "  Webpage where more additional permissions may be requested (OPTIONAL) [URL]:"  morePermissionsURL
 287  if  [[  -n  $morePermissionsURL  ]];  then  288      while  [[ !  $morePermissionsURL  = ~ 
$regexURL  ]];  do  289          echoerr 
"WARNING: URL may contain error (ex: does not begin with  \" https://\."  290          echoerr 
"  Preappend  \" http:// \"  to URL? (y/n)"  293              y | Y | 
yes  | 
1 )  morePermissionsURL
= "http://" " $morePermissionsURL " ;;  294              n | N | no | 
2 )  read -p  "  Webpage where more additional permissions may be requested (OPTIONAL) [URL]:"  morePermissionsURL 
;;  299  #===CONSTRUCT RDFA TAG===  300  #====RDFA:Handle workTitle, workAuthor, workAuthorURL====  301  ###echoerr "DEBUG: workTitle is --$workTitle--"  302  ###echoerr "DEBUG: workAuthor is --$workAuthor--"  303  ###echoerr "DEBUG: workAuthorURL is --$workAuthorURL--"  304  ###echoerr "DEBUG: workSourceURL is --$workSourceURL--"  305  ###echoerr "DEBUG: morePermissionsURL is --$morePermissionsURL--"  306  ###echoerr "DEBUG: LICENSE_TYPE is --$LICENSE_TYPE--"  308  # Exit early if critical parameters not provided  309  if      [[  -z  " $workTitle "  ]]  || \
 310         [[ !  -v  LICENSE_TYPE 
]];  312      echoerr 
"ERROR: Problem with workTitle or LICENSE_TYPE."  316  # Add workTitle to OUTPUT variable  317  OUTPUT
= $OUTPUT "<span xmlns:dct= \" http://purl.org/dc/terms/ \"  property= \" dct:title \" > $workTitle </span>"  319  # Add workAuthor and/or workAuthorURL to OUTPUT variable (if applicable)  320  if  [[  -v  workAuthor 
]];  then  321      if  [[  -v  workAuthorURL 
]];  then  322          # workAuthor set, workAuthorURL set  323          OUTPUT
= $OUTPUT " by <a xmlns:cc= \" http://creativecommons.org/ns# \"  href= \" $workAuthorURL \"  property= \" cc:attributionName \"  rel= \" cc:attributionURL \" > $workAuthor </a>"  325          #workAuthor set, workAuthorURL not set  326          OUTPUT
= $OUTPUT " by <span xmlns:cc= \" http://creativecommons.org/ns# \"  property= \" cc:attributionName \" > $workAuthor </span>"  330  #====RDFA:Handle LICENSE_TYPE====  331  # Add selected license to OUTPUT variable  334  OUTPUT
= $OUTPUT " is licensed under "  337  case  $LICENSE_TYPE  in  339          OUTPUT
= $OUTPUT "<a href= \" https://creativecommons.org/publicdomain/zero/1.0/ \"  target= \" _blank \"  rel= \" license noopener noreferrer \"  style= \" display: inline-block; \" >CC0 1.0</a><a href= \" https://creativecommons.org/publicdomain/zero/1.0/ \" ><img style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-cc0_icon.svg \"  /></a>"  342          OUTPUT
= $OUTPUT "<a href= \" https://creativecommons.org/licenses/by/4.0/ \"  target= \" _blank \"  rel= \" license noopener noreferrer \"  style= \" display: inline-block; \" >CC BY 4.0</a><a href= \" https://creativecommons.org/licenses/by/4.0/ \" ><img style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-by_icon.svg \"  /></a>"  345          OUTPUT
= $OUTPUT "<a href= \" https://creativecommons.org/licenses/by-sa/4.0/ \"  target= \" _blank \"  rel= \" license noopener noreferrer \"  style= \" display: inline-block; \" >CC BY-SA 4.0</a><a href= \" https://creativecommons.org/licenses/by-sa/4.0/ \" ><img style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-by_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-sa_icon.svg \"  /></a>"  348          OUTPUT
= $OUTPUT "<a href= \" https://creativecommons.org/licenses/by-nd/4.0/ \"  target= \" _blank \"  rel= \" license noopener noreferrer \"  style= \" display: inline-block; \" >CC BY-ND 4.0</a><a href= \" https://creativecommons.org/licenses/by-nd/4.0/ \" ><img style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-by_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-nd_icon.svg \"  /></a>"  351          OUTPUT
= $OUTPUT "<a href= \" https://creativecommons.org/licenses/by-nc/4.0/ \"  target= \" _blank \"  rel= \" license noopener noreferrer \"  style= \" display: inline-block; \" >CC BY-NC 4.0</a><a href= \" https://creativecommons.org/licenses/by-nc/4.0/ \" ><img style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-by_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-nc_icon.svg \"  /></a>"  354          OUTPUT
= $OUTPUT "<a href= \" https://creativecommons.org/licenses/by-nc-sa/4.0/ \"  target= \" _blank \"  rel= \" license noopener noreferrer \"  style= \" display: inline-block; \" >CC BY-NC-SA 4.0</a><a href= \" https://creativecommons.org/licenses/by-nc-sa/4.0/ \" ><img style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-by_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-nc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-sa_icon.svg \"  /></a>"  357          OUTPUT
= $OUTPUT "<a href= \" https://creativecommons.org/licenses/by-nc-nd/4.0/ \"  target= \" _blank \"  rel= \" license noopener noreferrer \"  style= \" display: inline-block; \" >CC BY-NC-ND 4.0</a><a href= \" https://creativecommons.org/licenses/by-nc-nd/4.0/ \" ><img style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-by_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-nc_icon.svg \"  /><img  style= \" height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7; \"  src= \" https://search.creativecommons.org/static/img/cc-nd_icon.svg \"  /></a>"  359      *)  echoerr 
"Error." ;  exit  1 ;;  365  #====RDFA:Handle workSourceURL, morePermissionsURL (if applicable)====  366  # Add workSourceURL to OUTPUT (if applicable)  367  if  [[  -n  " $workSourceURL "  ]];  then  368      OUTPUT
= $OUTPUT "<br /> $workTitle  is based on a work at <a xmlns:dct= \" http://purl.org/dc/terms/ \"  href= \" $workSourceURL \"  rel= \" dct:source \" > $workSourceURL </a>"  373  # Add morePermissionsURL to OUTPUT (if applicable)  374  if  [[  -n  " $morePermissionsURL "  ]];  then  375      OUTPUT
= $OUTPUT "<br />Permissions beyond the scope of this license may be available at <a xmlns:cc= \" http://creativecommons.org/ns# \"  href= \" $morePermissionsURL \"  rel= \" cc:morePermissions \" > $morePermissionsURL </a>"  382  #====Deliver output====  383  # Send OUTPUT to stdout.