docker-compose-files/hyperledger_fabric/test/genMSP.sh

46 lines
1.5 KiB
Bash
Raw Normal View History

2021-03-30 04:54:46 +08:00
#!/bin/bash
# Generate a valid msp dir based on given certificates.json and admin-credential
# It will overwrite any local msp path with the same name as msp-${mspId}
# Usage: ./script mspId
if [ $# -lt 1 ]; then
echo "Please use the <msp id> as the argument" && exit 1
fi
mspId=$1
2022-02-03 09:45:54 +08:00
mspPath=msp-${mspId}
echo "msp id=${mspId}, msp path=${mspPath}"
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
certFile=${mspId}-certificates.json
adminCredentialDir=${mspId}-admin-credential
adminCredentialFile=${mspId}-admin-credential.zip
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
[ -d "${mspPath}" ] && { echo "${mspPath} already exists, will exit" && exit 0; }
mkdir -p "${mspPath}"
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
pushd "${mspPath}" && mkdir tlscacerts signcerts keystore cacerts admincerts && popd || exit 1
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
echo "Unzip ${adminCredentialFile} file to create the ${adminCredentialDir}"
unzip -d "${adminCredentialDir}" "${adminCredentialFile}"
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
echo "Get tlscacert from ${certFile}"
jq -r .certs.tlscacert "${certFile}" > "${mspPath}/tlscacerts/tlsca.cert"
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
echo "Get signcerts from ${adminCredentialDir}"
cp "${adminCredentialDir}/${mspId}-cert.pem" "${mspPath}/signcerts/"
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
echo "Get keystore from ${adminCredentialDir}"
cp "${adminCredentialDir}/${mspId}-key" "${mspPath}/keystore/"
2021-03-30 04:54:46 +08:00
2022-02-03 09:45:54 +08:00
echo "Get cacerts from ${certFile}"
jq -r .certs.cacert "${certFile}" > "${mspPath}/cacerts/ca.cert"
2021-08-19 05:19:57 +08:00
2022-02-03 09:45:54 +08:00
echo "Get admincerts from ${adminCredentialDir}"
cp "${adminCredentialDir}/${mspId}-cert.pem" "${mspPath}/admincerts/"
echo "Remove the unzipped ${adminCredentialDir}"
rm -rf ${adminCredentialDir}
echo "MSP is created at ${mspPath}, now you can run: rm -rf ${certFile} ${adminCredentialFile}"