Skip to content

Instantly share code, notes, and snippets.

@ianblenke
Created Aug 2, 2016
Embed
What would you like to do?
Fix docker-machine configs
#!/bin/bash
INCONFIG=config.json
OUTCONFIG=config.json.$$
if [ ! -f $INCONFIG ]; then
echo "Cannot find $INCONFIG file"
exit 1
fi
SSHKeyPath="$(jq -r .Driver.SSHKeyPath $INCONFIG)"
if ! diff "${SSHKeyPath}" id_rsa > /dev/null 2>&1 ; then
if [ -f id_rsa ]; then
set -x
cp id_rsa id_rsa.$$
set +x
fi
set -x
cp -f "${SSHKeyPath}" id_rsa
set +x
fi
CertDir="$(jq -r .HostOptions.AuthOptions.CertDir $INCONFIG)"
CaCertPath="$(jq -r .HostOptions.AuthOptions.CaCertPath $INCONFIG)"
if ! diff "${CaCertPath}" ca.pem > /dev/null 2>&1 ; then
if [ -f ca.pem ]; then
set -x
cp ca.pem ca.pem.$$
set +x
fi
set -x
cp -f "${CaCertPath}" ca.pem
set +x
fi
CaPrivateKeyPath="$(jq -r .HostOptions.AuthOptions.CaPrivateKeyPath $INCONFIG)"
if ! diff "${CaPrivateKeyPath}" ca-key.pem > /dev/null 2>&1 ; then
if [ -f ca-key.pem ]; then
set -x
cp ca-key.pem ca-key.pem.$$
set +x
fi
set -x
cp -f "${CaPrivateKeyPath}" ca-key.pem
set +x
fi
ServerCertPath="$(jq -r .HostOptions.AuthOptions.ServerCertPath $INCONFIG)"
if ! diff "${ServerCertPath}" server.pem > /dev/null 2>&1 ; then
if [ -f server.pem ] ; then
set -x
cp server.pem server.pem.$$
set +x
fi
set -x
cp -f "${ServerCertPath}" server.pem
set +x
fi
ServerKeyPath="$(jq -r .HostOptions.AuthOptions.ServerKeyPath $INCONFIG)"
if ! diff "${ServerKeyPath}" server-key.pem > /dev/null 2>&1 ; then
if [ -f server-key.pem ]; then
set -x
cp server-key.pem server-key.pem.$$
set +x
fi
set -x
cp -f "${ServerKeyPath}" server-key.pem
set +x
fi
ClientKeyPath="$(jq -r .HostOptions.AuthOptions.ClientKeyPath $INCONFIG)"
if ! diff "${ClientKeyPath}" key.pem > /dev/null 2>&1 ; then
if [ -f key.pem ]; then
set -x
cp key.pem key.pem.$$
set +x
fi
set -x
cp -f "${ClientKeyPath}" key.pem
set +x
fi
ClientCertPath="$(jq -r .HostOptions.AuthOptions.ClientCertPath $INCONFIG)"
if ! diff "${ClientCertPath}" cert.pem > /dev/null 2>&1 ; then
if [ -f cert.pem ]; then
set -x
cp cert.pem cert.pem.$$
set +x
fi
set -x
cp -f "${ClientCertPath}" cert.pem
set +x
fi
StorePath="$(jq -r .HostOptions.AuthOptions.StorePath $INCONFIG)"
cat $INCONFIG | \
jq ".Driver.SSHKeyPath = \"$PWD/id_rsa\"" | \
jq ".HostOptions.AuthOptions.CertDir = \"$PWD\"" | \
jq ".HostOptions.AuthOptions.CaCertPath = \"$PWD/ca.pem\"" | \
jq ".HostOptions.AuthOptions.CaPrivateKeyPath = \"$PWD/ca-key.pem\"" | \
jq ".HostOptions.AuthOptions.ServerCertPath = \"$PWD/server.pem\"" | \
jq ".HostOptions.AuthOptions.ServerKeyPath = \"$PWD/server-key.pem\"" | \
jq ".HostOptions.AuthOptions.ClientKeyPath = \"$PWD/key.pem\"" | \
jq ".HostOptions.AuthOptions.ClientCertPath = \"$PWD/cert.pem\"" | \
jq ".HostOptions.AuthOptions.StorePath = \"$PWD\"" > $OUTCONFIG
if ! diff $INCONFIG $OUTCONFIG > /dev/null 2>&1 ; then
set -x
cp $INCONFIG ${INCONFIG}.$$.backup
mv -f $OUTCONFIG $INCONFIG
set +x
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment