github.com/silveraid/fabric-ca@v1.1.0-preview.0.20180127000700-71974f53ab08/scripts/regenDocs (about)

     1  #!/bin/bash
     2  
     3  ######################################################################
     4  #
     5  # This script will use the fabric-ca-server and fabric-ca-client
     6  # binaries to dynamically generate the CLI flags and the
     7  # configuration files for both server and the client and place
     8  # them in the docs/source folder. These files are referenced for
     9  # in the fabric-ca documentation when talking about CLI and the
    10  # configuration files
    11  #
    12  ######################################################################
    13  
    14  echo "Making docs..."
    15  
    16  ######################################################################
    17  # Command Line Flag Generation
    18  ######################################################################
    19  
    20  fabric_ca=$GOPATH/src/github.com/hyperledger/fabric-ca
    21  docsdir=$fabric_ca/docs/source
    22  export PATH=$PATH:$fabric_ca/bin
    23  
    24  temp=$docsdir/temp
    25  mkdir -p $temp
    26  cd $temp
    27  
    28  # RST specific syntax to indicate a code a block
    29  echo -e "Fabric-CA Server's CLI" > servercli.rst
    30  echo -e "=======================\n" >> servercli.rst
    31  echo -e "::\n" >> servercli.rst
    32  
    33  echo -e "Fabric-CA Client's CLI" > clientcli.rst
    34  echo -e "======================\n" >> clientcli.rst
    35  echo -e "::\n" >> clientcli.rst
    36  
    37  # Direct the CLI help message to a temp file
    38  fabric-ca-server > servercli_temp.rst
    39  fabric-ca-client > clientcli_temp.rst
    40  
    41  # Sanitize the CLI file to remove any machine specific information and provide a generic CLI
    42  sed -i -e 's/home directory (default.*/home directory (default "$HOME\/.fabric-ca-client")/' clientcli_temp.rst
    43  sed -i -e 's/enrollment (default.*/enrollment (default "$HOSTNAME")/' clientcli_temp.rst
    44  sed -i -e 's/home directory (default.*/home directory (default "\/etc\/hyperledger\/fabric-ca")/' servercli_temp.rst
    45  
    46  # Insert a few spaces in front of all the lines in temp files created above (RST formatting purposes)
    47  sed -i -e 's/^/    /' servercli_temp.rst
    48  sed -i -e 's/^/    /' clientcli_temp.rst
    49  
    50  # Append temp files to ones created earlier
    51  cat servercli_temp.rst >> servercli.rst
    52  cat clientcli_temp.rst >> clientcli.rst
    53  
    54  mv servercli.rst $docsdir/servercli.rst
    55  mv clientcli.rst $docsdir/clientcli.rst
    56  
    57  rm $temp/* # Clean up artificats
    58  
    59  ######################################################################
    60  # Configuration File Generation
    61  ######################################################################
    62  
    63  # Start server and enroll client to generate the configuration files
    64  export FABRIC_CA_HOME=$temp
    65  
    66  echo "Starting server to generate server configuration file"
    67  fabric-ca-server start -b abc:d > /dev/null 2>&1 &
    68  sleep 1 # Wait for server to start before client enrolls
    69  echo "Client enrolling to generate client configuration file"
    70  fabric-ca-client enroll -u http://abc:d@localhost:7054 > /dev/null 2>&1 &
    71  sleep 1 # Wait for client to finish enrolling
    72  echo "Stopping server..."
    73  pkill -9 fabric-ca-server > /dev/null 2>&1 & # Stop the server
    74  
    75  # RST specific syntax to indicate a code a block
    76  echo -e "Fabric-CA Server's Configuration File" > serverconfig.rst
    77  echo -e "======================================\n" >> serverconfig.rst
    78  echo -e "::\n" >> serverconfig.rst
    79  
    80  echo -e "Fabric-CA Client's Configuration File" > clientconfig.rst
    81  echo -e "======================================\n" >> clientconfig.rst
    82  echo -e "::\n" >> clientconfig.rst
    83  
    84  # Sanitize the configuration files to remove any machine specific information and provide a generic config file
    85  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
    86  sed -e 's/cn:.*/cn: <<<ENROLLMENT_ID>>>/' -e 's/'"$HOSTNAME"'/<<<MYHOST>>>/' -e 's/url:.*/url: <<<URL>>>/' fabric-ca-client-config.yaml > client-config.yaml
    87  
    88  # Insert a few spaces in front of all the lines in temp files created above (RST formatting purposes)
    89  sed -i -e 's/^/    /' server-config.yaml
    90  sed -i -e 's/^/    /' client-config.yaml
    91  
    92  # Append temp files to ones created earlier
    93  cat server-config.yaml >> serverconfig.rst
    94  cat client-config.yaml >> clientconfig.rst
    95  
    96  mv serverconfig.rst $docsdir/serverconfig.rst
    97  mv clientconfig.rst $docsdir/clientconfig.rst
    98  
    99  rm -rf $temp # Clean up artificats
   100  
   101  echo "Doc generation completed"
   102  
   103  # git status by itself just returns exit code, not if there any modifications.
   104  # Using the --porcelain flag returns information on what files got modified, if any.
   105  # Only checking status under docs/source folder
   106  cd $docsdir
   107  if [[ $(git status . --porcelain --untracked-file=no) ]]; then
   108      echo "ERROR: New readme files generated, commit changes before doing push"
   109      exit 1
   110  fi