Skip to content

Instantly share code, notes, and snippets.

@georgelima
Last active January 15, 2020 14:42
Show Gist options
  • Save georgelima/ca819081b99b46b0d0eda7458c255ec8 to your computer and use it in GitHub Desktop.
Save georgelima/ca819081b99b46b0d0eda7458c255ec8 to your computer and use it in GitHub Desktop.
#! /bin/bash
set -e
if [ -z "$1" ]; then
echo "Usage: docker-machine-import.sh MACHINE_NAME.zip"
echo ""
echo "Imports an exported machine from a MACHINE_NAME.zip file"
echo "Note: This script requires you to have the same \$MACHINE_STORAGE_PATH/certs available on all host systems"
exit 0
fi
machine_archive="$1"
machine_name="${machine_archive}"
MACHINE_STORAGE_PATH="${MACHINE_STORAGE_PATH:-"$HOME/.docker/machine"}"
machine_path="$MACHINE_STORAGE_PATH/machines/$machine_name"
if [ -d "$machine_path" ]; then
echo "$machine_name already exists"
exit 1
fi
rm -rf "$machine_name"
unzip "$machine_archive" -d "$machine_name" > /dev/null
perl -pi -e "s|__MACHINE__STORAGE_PATH__|$MACHINE_STORAGE_PATH|g" $machine_name/config.json
mkdir -p "$MACHINE_STORAGE_PATH/machines"
mv "$machine_name" "$MACHINE_STORAGE_PATH/machines"
echo "Imported $machine_name to docker-machine ($machine_path)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment