github.com/cactusblossom/fabric-ca@v0.0.0-20200611062428-0082fc643826/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 if ! "${fabric_ca}/scripts/metrics_doc.sh"; then 150 echo "Metrics doc generation failed" 151 exit 1 152 fi 153 154 temp=$docsdir/temp 155 rm -rf $temp 156 mkdir -p $temp 157 cd $temp 158 159 generateGlobalCLI 160 generateIdentityCLI 161 generateAffiliationCLI 162 generateCertificateCLI 163 164 mv servercli.rst $docsdir/servercli.rst 165 mv clientcli.rst $docsdir/clientcli.rst 166 167 rm $temp/* # Clean up artificats 168 169 ###################################################################### 170 # Configuration File Generation 171 ###################################################################### 172 173 # Start server and enroll client to generate the configuration files 174 export FABRIC_CA_HOME=$temp 175 176 echo "Starting server to generate server configuration file" 177 fabric-ca-server start -b abc:d > /dev/null 2>&1 & 178 sleep 1 # Wait for server to start before client enrolls 179 echo "Client enrolling to generate client configuration file" 180 fabric-ca-client enroll -u http://abc:d@localhost:7054 > /dev/null 2>&1 & 181 sleep 1 # Wait for client to finish enrolling 182 echo "Stopping server..." 183 pkill -9 fabric-ca-server > /dev/null 2>&1 & # Stop the server 184 185 # RST specific syntax to indicate a code a block 186 echo -e "Fabric-CA Server's Configuration File" > serverconfig.rst 187 echo -e "======================================\n" >> serverconfig.rst 188 echo -e "::\n" >> serverconfig.rst 189 190 echo -e "Fabric-CA Client's Configuration File" > clientconfig.rst 191 echo -e "======================================\n" >> clientconfig.rst 192 echo -e "::\n" >> clientconfig.rst 193 194 # Sanitize the configuration files to remove any machine specific information and provide a generic config file 195 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 196 sed -e 's/cn:.*/cn: <<<ENROLLMENT_ID>>>/' -e 's/'"$HOSTNAME"'/<<<MYHOST>>>/' -e 's/url:.*/url: <<<URL>>>/' fabric-ca-client-config.yaml > client-config.yaml 197 198 # Insert a few spaces in front of all the lines in temp files created above (RST formatting purposes) 199 sed -i -e 's/^/ /' server-config.yaml 200 sed -i -e 's/^/ /' client-config.yaml 201 202 # Append temp files to ones created earlier 203 cat server-config.yaml >> serverconfig.rst 204 cat client-config.yaml >> clientconfig.rst 205 206 mv serverconfig.rst $docsdir/serverconfig.rst 207 mv clientconfig.rst $docsdir/clientconfig.rst 208 209 rm -rf $temp # Clean up artificats 210 211 echo "Doc generation completed" 212 213 # git status by itself just returns exit code, not if there any modifications. 214 # Using the --porcelain flag returns information on what files got modified, if any. 215 # Only checking status under docs/source folder 216 cd $docsdir 217 if [[ $(git status . --porcelain --untracked-file=no) ]]; then 218 echo "ERROR: New readme files generated, commit changes before doing push" 219 exit 1 220 fi