-
Notifications
You must be signed in to change notification settings - Fork 0
/
initproject.bash
executable file
·51 lines (36 loc) · 1.07 KB
/
initproject.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Load environment variables for postactivate
. ./env.config
PROJECT_NAME="iwg_blog"
if [ -z "$DATABASE_URL" ]; then
echo "declare environment variables in env.config"
exit 0
fi
# Initialize virtualenvwrapper
source "/usr/local/bin/virtualenvwrapper.sh"
WORKON_HOME=$HOME/.virtualenvs
# Create virtualenv
if [ -d "$WORKON_HOME/$PROJECT_NAME" ]; then
echo "$PROJECT_NAME virtualenv already exists."
workon $PROJECT_NAME
else
mkvirtualenv $PROJECT_NAME
fi
# Write variables to postactivate
postactivate_file_path="$WORKON_HOME/$PROJECT_NAME/bin/postactivate"
printf 'export DATABASE_URL="%s"\n\ncd "%s"' "$DATABASE_URL$PROJECT_NAME" "$(pwd)" > "$postactivate_file_path"
# Install requirements
pip install -r requirements/dev.txt
# Create database
psql "$DATABASE_URL" -c "CREATE DATABASE $PROJECT_NAME;"
# We need to reload virtualenv
deactivate
workon $PROJECT_NAME
# Make manage.py executable
chmod 755 manage.py
echo "RUNNING INITIAL MIGRATIONS"
python manage.py migrate
echo "CREATE SUPERUSER"
python manage.py createsuperuser
deactivate
exit 0