github.com/adecaro/fabric-ca@v2.0.0-alpha+incompatible/scripts/regenDocs (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  ######################################################################
     9  #
    10  # This script will use the fabric-ca-server and fabric-ca-client
    11  # binaries to dynamically generate the CLI flags and the
    12  # configuration files for both server and the client and place
    13  # them in the docs/source folder. These files are referenced for
    14  # in the fabric-ca documentation when talking about CLI and the
    15  # configuration files
    16  #
    17  ######################################################################
    18  
    19  echo "Making docs..."
    20  
    21  ######################################################################
    22  # Command Line Flag Generation
    23  ######################################################################
    24  
    25  function generateGlobalCLI {
    26      echo "Generating Global CLI..."
    27  
    28      # RST specific syntax to indicate a code a block
    29      echo -e "=======================" >> servercli.rst
    30      echo -e "Fabric-CA Server's CLI" >> servercli.rst
    31      echo -e "=======================\n" >> servercli.rst
    32      echo -e "::\n" >> servercli.rst
    33  
    34      echo -e "=======================" > clientcli.rst
    35      echo -e "Fabric-CA Client's CLI" >> clientcli.rst
    36      echo -e "=======================\n" >> clientcli.rst
    37      echo -e "::\n" >> clientcli.rst
    38  
    39      # Direct the CLI help message to a temp file
    40      fabric-ca-server > servercli_temp.rst
    41      fabric-ca-client > clientcli_temp.rst
    42  
    43      # Sanitize the CLI file to remove any machine specific information and provide a generic CLI
    44      sed -i -e 's/home directory (default.*/home directory (default "$HOME\/.fabric-ca-client")/' clientcli_temp.rst
    45      sed -i -e 's/enrollment (default.*/enrollment (default "$HOSTNAME")/' clientcli_temp.rst
    46      sed -i -e 's/home directory (default.*/home directory (default "\/etc\/hyperledger\/fabric-ca")/' servercli_temp.rst
    47  
    48      # Insert a few spaces in front of all the lines in temp files created above (RST formatting purposes)
    49      sed -i -e 's/^/    /' servercli_temp.rst
    50      sed -i -e 's/^/    /' clientcli_temp.rst
    51  
    52      # Append temp files to ones created earlier
    53      cat servercli_temp.rst >> servercli.rst
    54      cat clientcli_temp.rst >> clientcli.rst
    55  }
    56  
    57  function generateIdentityCLI {
    58      echo "Generating Identity Command CLI..."
    59  
    60      echo -e "\nIdentity Command" >> clientcli.rst
    61      echo -e "==================\n" >> clientcli.rst
    62      echo -e "::\n" >> clientcli.rst
    63  
    64      fabric-ca-client identity -h >> identity_cmd.rst
    65      sed -i -e '/Global Flags:/,$d' identity_cmd.rst
    66      printf '%s\n\n' '-----------------------------' >> identity_cmd.rst
    67  
    68      fabric-ca-client identity add -h > identity_add_cmd.rst
    69      sed -i -e '/Global Flags:/,$d' identity_add_cmd.rst
    70      cat identity_add_cmd.rst >> identity_cmd.rst
    71      printf '%s\n\n' '-----------------------------' >> identity_cmd.rst
    72  
    73      fabric-ca-client identity list -h > identity_list_cmd.rst
    74      sed -i -e '/Global Flags:/,$d' identity_list_cmd.rst
    75      cat identity_list_cmd.rst >> identity_cmd.rst
    76      printf '%s\n\n' '-----------------------------' >> identity_cmd.rst
    77  
    78      fabric-ca-client identity modify -h > identity_modify_cmd.rst
    79      sed -i -e '/Global Flags:/,$d' identity_modify_cmd.rst
    80      cat identity_modify_cmd.rst >> identity_cmd.rst
    81      printf '%s\n\n' '-----------------------------' >> identity_cmd.rst
    82  
    83      fabric-ca-client identity remove -h > identity_remove_cmd.rst
    84      sed -i -e '/Global Flags:/,$d' identity_remove_cmd.rst
    85      cat identity_remove_cmd.rst >> identity_cmd.rst
    86  
    87      sed -i -e 's/^/    /' identity_cmd.rst
    88      cat identity_cmd.rst >> clientcli.rst
    89  }
    90  
    91  function generateAffiliationCLI {
    92      echo "Generating Affiliation Command CLI..."
    93  
    94      echo -e "\nAffiliation Command" >> clientcli.rst
    95      echo -e "=====================\n" >> clientcli.rst
    96      echo -e "::\n" >> clientcli.rst
    97  
    98      fabric-ca-client affiliation -h >> affiliation_cmd.rst
    99      sed -i -e '/Global Flags:/,$d' affiliation_cmd.rst
   100      printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst
   101  
   102      fabric-ca-client affiliation add -h > affiliation_add_cmd.rst
   103      sed -i -e '/Global Flags:/,$d' affiliation_add_cmd.rst
   104      cat affiliation_add_cmd.rst >> affiliation_cmd.rst
   105      printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst
   106  
   107      fabric-ca-client affiliation list -h > affiliation_list_cmd.rst
   108      sed -i -e '/Global Flags:/,$d' affiliation_list_cmd.rst
   109      cat affiliation_list_cmd.rst >> affiliation_cmd.rst
   110      printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst
   111  
   112      fabric-ca-client affiliation modify -h > affiliation_modify_cmd.rst
   113      sed -i -e '/Global Flags:/,$d' affiliation_modify_cmd.rst
   114      cat affiliation_modify_cmd.rst >> affiliation_cmd.rst
   115      printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst
   116  
   117      fabric-ca-client affiliation remove -h > affiliation_remove_cmd.rst
   118      sed -i -e '/Global Flags:/,$d' affiliation_remove_cmd.rst
   119      cat affiliation_remove_cmd.rst >> affiliation_cmd.rst
   120  
   121      sed -i -e 's/^/    /' affiliation_cmd.rst
   122      cat affiliation_cmd.rst >> clientcli.rst
   123  }
   124  
   125  function generateCertificateCLI {
   126      echo "Generating Certificate Command CLI..."
   127  
   128      echo -e "\nCertificate Command" >> clientcli.rst
   129      echo -e "=====================\n" >> clientcli.rst
   130      echo -e "::\n" >> clientcli.rst
   131  
   132      fabric-ca-client certificate -h >> certificate_cmd.rst
   133      sed -i -e '/Global Flags:/,$d' certificate_cmd.rst
   134      printf '%s\n\n' '-----------------------------' >> certificate_cmd.rst
   135  
   136      fabric-ca-client certificate list -h > certificate_list_cmd.rst
   137      sed -i -e '/Global Flags:/,$d' certificate_list_cmd.rst
   138      cat certificate_list_cmd.rst >> certificate_cmd.rst
   139  
   140      sed -i -e 's/^/    /' certificate_cmd.rst
   141      cat certificate_cmd.rst >> clientcli.rst
   142  }
   143  
   144  
   145  fabric_ca=$GOPATH/src/github.com/hyperledger/fabric-ca
   146  docsdir=$fabric_ca/docs/source
   147  export PATH=$PATH:$fabric_ca/bin
   148  
   149  temp=$docsdir/temp
   150  rm -rf $temp
   151  mkdir -p $temp
   152  cd $temp
   153  
   154  generateGlobalCLI
   155  generateIdentityCLI
   156  generateAffiliationCLI
   157  generateCertificateCLI
   158  
   159  mv servercli.rst $docsdir/servercli.rst
   160  mv clientcli.rst $docsdir/clientcli.rst
   161  
   162  rm $temp/* # Clean up artificats
   163  
   164  ######################################################################
   165  # Configuration File Generation
   166  ######################################################################
   167  
   168  # Start server and enroll client to generate the configuration files
   169  export FABRIC_CA_HOME=$temp
   170  
   171  echo "Starting server to generate server configuration file"
   172  fabric-ca-server start -b abc:d > /dev/null 2>&1 &
   173  sleep 1 # Wait for server to start before client enrolls
   174  echo "Client enrolling to generate client configuration file"
   175  fabric-ca-client enroll -u http://abc:d@localhost:7054 > /dev/null 2>&1 &
   176  sleep 1 # Wait for client to finish enrolling
   177  echo "Stopping server..."
   178  pkill -9 fabric-ca-server > /dev/null 2>&1 & # Stop the server
   179  
   180  # RST specific syntax to indicate a code a block
   181  echo -e "Fabric-CA Server's Configuration File" > serverconfig.rst
   182  echo -e "======================================\n" >> serverconfig.rst
   183  echo -e "::\n" >> serverconfig.rst
   184  
   185  echo -e "Fabric-CA Client's Configuration File" > clientconfig.rst
   186  echo -e "======================================\n" >> clientconfig.rst
   187  echo -e "::\n" >> clientconfig.rst
   188  
   189  # Sanitize the configuration files to remove any machine specific information and provide a generic config file
   190  sed -e 's/cn:.*/cn: <<<COMMONNAME>>>/' -e 's/pathlength:.*/pathlength: <<<PATHLENGTH>>>/' -e 's/abc/<<<adminUserName>>>/' -e 's/pass:.*/pass: <<<adminPassword>>>/' -e 's/'"$HOSTNAME"'/<<<MYHOST>>>/' -e 's/version:.*/version: <<<VERSION>>>/' fabric-ca-server-config.yaml > server-config.yaml
   191  sed -e 's/cn:.*/cn: <<<ENROLLMENT_ID>>>/' -e 's/'"$HOSTNAME"'/<<<MYHOST>>>/' -e 's/url:.*/url: <<<URL>>>/' fabric-ca-client-config.yaml > client-config.yaml
   192  
   193  # Insert a few spaces in front of all the lines in temp files created above (RST formatting purposes)
   194  sed -i -e 's/^/    /' server-config.yaml
   195  sed -i -e 's/^/    /' client-config.yaml
   196  
   197  # Append temp files to ones created earlier
   198  cat server-config.yaml >> serverconfig.rst
   199  cat client-config.yaml >> clientconfig.rst
   200  
   201  mv serverconfig.rst $docsdir/serverconfig.rst
   202  mv clientconfig.rst $docsdir/clientconfig.rst
   203  
   204  rm -rf $temp # Clean up artificats
   205  
   206  echo "Doc generation completed"
   207  
   208  # git status by itself just returns exit code, not if there any modifications.
   209  # Using the --porcelain flag returns information on what files got modified, if any.
   210  # Only checking status under docs/source folder
   211  cd $docsdir
   212  if [[ $(git status . --porcelain --untracked-file=no) ]]; then
   213      echo "ERROR: New readme files generated, commit changes before doing push"
   214      exit 1
   215  fi