Skip to content

Instantly share code, notes, and snippets.

@thynctank thynctank/sh
Created Sep 16, 2019

Embed
What would you like to do?
Yip Docker Machine configs
#!/bin/bash
#AWS stuff expected from your env...
#export AWS_ACCESS_KEY="AWS_ACCESS_KEY"
#export AWS_SECRET_KEY="AWS_SECRET_KEY"
#path all directories should be copied to
copy_path=$HOME/.docker/machine/machines
#copy from override location? Override next line
usb_key_docker_path=/Volumes/Samsung\ USB/.docker
#usb_key_docker_path="/Users/nickcarter/Desktop/juan-key-docker"
source_docker_machines_path="$usb_key_docker_path/machine/machines"
if [ -d "$source_docker_machines_path" ] && [ -d "$copy_path" ]; then
for machine_directory in $source_docker_machines_path/*; do
echo "Copying Directory -> $machine_directory"
cp -r -f $machine_directory $copy_path && echo "Done Copying Directory -> $machine_directory"
done
for machine_directory in $copy_path/*; do
#location of newly-copied directory's config.json
config_path="$machine_directory/config.json"
#update config.json for each dir
#TODO copy AccessKey and SecretKey (grab from AWS CLI)
#replace Juan with Me, and swap AccessKey and SecretKey values
sed -i -e -E "s,jt044c,$(whoami),g" $config_path && echo "Replaced Juan with Myself for $machine_directory"
sed -i -e -E "s,(AccessKey\": \").+\",\1$AWS_ACCESS_KEY\",g" $config_path && echo "Replaced AccessKey for $machine_directory"
sed -i -e -E "s,(SecretKey\": \").+\",\1$AWS_SECRET_KEY\",g" $config_path && echo "Replaced SecretKey for $machine_directory"
chmod 400 "$machine_directory/id_rsa" && echo "Set permissions to 400 for $machine_directory/id_rsa"
done
echo "Yipped!"
else
echo "Hooyip, we have a problem. $source_docker_machines_path or $copy_path is bogus!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.