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