Last active
June 7, 2016 01:18
-
-
Save fud/de18a7e66d77c6f39e39d0f0204fca0d to your computer and use it in GitHub Desktop.
Script to update docker-machine config paths which are hardcoded. Needs jq installed which can be installed with home brew.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| for config in ~/.docker/machine/machines/*/config.json; do | |
| echo Fixing $config to refer to your user. | |
| echo Backup at $config.orig | |
| cp $config $config.orig | |
| jq --arg user $USER -f users.jq $config > $config.fixed | |
| mv $config.fixed $config | |
| echo "Done" | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # We share docker-machine config amoungst users but the paths are | |
| # hardcoded for a particular user. This script will update the user | |
| # to your user on a unix system if $USER environment variable is set | |
| # as your user. | |
| # | |
| # There is probably are more succinct method using jq. | |
| # | |
| # jq --arg user $USER -f users.jq config.json | |
| # If your version of jq doesn't have walk defined in builtin.jq | |
| # which mine didn't (https://github.com/stedolan/jq/blob/master/src/builtin.jq) | |
| def walk(f): | |
| . as $in | |
| | if type == "object" then | |
| reduce keys[] as $key | |
| ( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f | |
| elif type == "array" then map( walk(f) ) | f | |
| else f | |
| end; | |
| def replaceUser(obj): | |
| with_entries(if .value|type == "string" then .value |= sub("/Users/([^/])*/"; "/Users/" + $user + "/") else . end); | |
| walk(if type == "object" then replaceUser(.) else . end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment