Guest User

Untitled

a guest
Feb 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Copyright 2017 Théo Chamley
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. # this software and associated documentation files (the "Software"), to deal in the Software
  6. # without restriction, including without limitation the rights to use, copy, modify, merge,
  7. # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  8. # to whom the Software is furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in all copies or
  11. # substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  14. # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  16. # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17.  
  18. IMAGES=$@
  19.  
  20. echo "This will remove all your current containers and images except for:"
  21. echo ${IMAGES}
  22. read -p "Are you sure? [yes/NO] " -n 1 -r
  23. echo # (optional) move to a new line
  24. if [[ ! $REPLY =~ ^[Yy]$ ]]
  25. then
  26. exit 1
  27. fi
  28.  
  29.  
  30. TMP_DIR=$(mktemp -d)
  31.  
  32. pushd $TMP_DIR >/dev/null
  33.  
  34. open -a Docker
  35. echo "=> Saving the specified images"
  36. for image in ${IMAGES}; do
  37. echo "==> Saving ${image}"
  38. tar=$(echo -n ${image} | base64)
  39. docker save -o ${tar}.tar ${image}
  40. echo "==> Done."
  41. done
  42.  
  43. echo "=> Cleaning up"
  44. echo -n "==> Quiting Docker"
  45. osascript -e 'quit app "Docker"'
  46. while docker info >/dev/null 2>&1; do
  47. echo -n "."
  48. sleep 1
  49. done;
  50. echo ""
  51.  
  52. echo "==> Removing Docker.qcow2 file"
  53. rm ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
  54.  
  55. echo "==> Launching Docker"
  56. open -a Docker
  57. echo -n "==> Waiting for Docker to start"
  58. until docker info >/dev/null 2>&1; do
  59. echo -n "."
  60. sleep 1
  61. done;
  62. echo ""
  63.  
  64. echo "=> Done."
  65.  
  66. echo "=> Loading saved images"
  67. for image in ${IMAGES}; do
  68. echo "==> Loading ${image}"
  69. tar=$(echo -n ${image} | base64)
  70. docker load -q -i ${tar}.tar || exit 1
  71. echo "==> Done."
  72. done
  73.  
  74. popd >/dev/null
  75. rm -r ${TMP_DIR}
Add Comment
Please, Sign In to add comment