make_example_database.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/sh
  2. # GNU MediaGoblin -- federated, autonomous media hosting
  3. # Copyright (C) 2011, 2012 GNU MediaGoblin Contributors. See AUTHORS.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. USAGE="Usage: $0 -h | [-p PATH] -e ENVIRONMENT"
  18. ENVIRONMENT="migration-18"
  19. USER_DEV="user_dev_default"
  20. DEV_ENV_DIRECTORY_PATH="../mg-dev-environments"
  21. while getopts ":hp:e:" opt;
  22. do
  23. case $opt in
  24. h)
  25. echo $USAGE
  26. echo "Sets up an example mediagoblin instance for testing code."
  27. echo ""
  28. echo " -h Shows this help message."
  29. echo " -p=PATH The path to your mg-dev-environments repository"
  30. echo " -e=ENVIRONMENT The name of the environment you want to set up. Useful"
  31. echo " if you want to set up a database from a past version."
  32. echo " This defaults to a database from the most recent version"
  33. echo " of master."
  34. exit 1
  35. ;;
  36. e)
  37. ENVIRONMENT=$OPTARG
  38. ;;
  39. p)
  40. DEV_ENV_DIRECTORY_PATH=$OPTARG
  41. ;;
  42. \?)
  43. echo "Invalid Option: -$OPTARG" >&2
  44. ;;
  45. :)
  46. echo "Option -$OPTARG requires an argument" >&2
  47. ;;
  48. esac
  49. done
  50. if [ ! -d $DEV_ENV_DIRECTORY_PATH ]; then
  51. echo "$DEV_ENV_DIRECTORY_PATH not found. Have you downloaded the repo from \
  52. git@gitorious.org:mediagoblin/mg-dev-environments.git ?" >&2
  53. echo ""
  54. exit 1
  55. fi
  56. if [ ! -d "user_dev" ]; then
  57. echo "ERROR: This script should be executed from within your mediagoblin \
  58. instance directory" >&2
  59. exit 1
  60. fi
  61. if [ ! -e "$DEV_ENV_DIRECTORY_PATH/$ENVIRONMENT.tar.gz" ]; then
  62. echo "$ENVIRONMENT.tar.gz not found in directory $DEV_ENV_DIRECTORY_PATH" >&2
  63. exit 1
  64. else
  65. echo "***WARNING!***"
  66. echo "This script will WIPE YOUR FULL CURRENT ENVIRONMENT and REPLACE IT with a test database and media!"
  67. echo "Your databases and user_dev/ will all likely be wiped!"
  68. echo -n "Do you want to continue? (y/n) "
  69. read -n1 USER_CONFIRM
  70. echo ""
  71. counter=0
  72. while [ "$USER_CONFIRM"=="y" ]; do
  73. case $USER_CONFIRM in
  74. y)
  75. break
  76. ;;
  77. n)
  78. exit 1
  79. ;;
  80. *)
  81. if [ $counter -lt 5 ]; then
  82. echo "Invalid option. Please enter 'y' or 'n'"
  83. echo "Do you want to continue? (y/n)"
  84. read -n1 USER_CONFIRM
  85. echo ""
  86. counter+=1
  87. continue
  88. else
  89. exit 1
  90. fi
  91. ;;
  92. esac
  93. done
  94. tar -xzf $DEV_ENV_DIRECTORY_PATH/$ENVIRONMENT.tar.gz
  95. tar -xzf $DEV_ENV_DIRECTORY_PATH/$USER_DEV.tar.gz
  96. echo "Completed."
  97. exit 0
  98. fi