Skip to content

Instantly share code, notes, and snippets.

@sjug
Created February 18, 2020 16:26
Show Gist options
  • Save sjug/19cb5035cebb0a84a22d86d94413592f to your computer and use it in GitHub Desktop.
Save sjug/19cb5035cebb0a84a22d86d94413592f to your computer and use it in GitHub Desktop.
Shell script to create machineconfig entitlements
#!/bin/bash
sed "s/BASE64_RHSM_CONF_FILE/$(base64 -w 0 rhsm.conf)/" 0000-cluster-wide-machineconfigs.yaml.template > 0000-cluster-wide-machineconfigs.yaml
CERTS=$(find . -maxdepth 1 -name "*.pem" ! -name "*-key.pem")
VALID_CERTS=
ED_FILE=ed_replace
for c in ${CERTS}; do
CERT_KEY=${c%.pem}-key.pem
if [[ -f "${CERT_KEY}" ]]; then
echo "${CERT_KEY} exists"
VALID_CERTS+=$c
break
fi
done
echo ${VALID_CERTS}
BASE64_PEM_FILE=$(base64 -w 0 ${VALID_CERTS})
cat >${ED_FILE} <<EOL
%s/BASE64_PEM_FILE/${BASE64_PEM_FILE}/g
w
q
EOL
< ${ED_FILE} ed 0000-cluster-wide-machineconfigs.yaml
rm ${ED_FILE}
BASE64_KEY_PEM_FILE=$(base64 -w 0 ${VALID_CERTS%.pem}-key.pem)
cat >${ED_FILE} <<EOL
%s/BASE64_KEY_PEM_FILE/${BASE64_KEY_PEM_FILE}/g
w
q
EOL
< ${ED_FILE} ed 0000-cluster-wide-machineconfigs.yaml
rm ${ED_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment