5d2dc18e8209e643990552efd07e1470f4de4a3d
[fnpdjango.git] / bin / fnpdjango_bootstrap.sh
1 #!/bin/bash
2
3 PROJECT="$1"
4
5 # Make it a function, so that it works with `source`
6 start_project() {
7
8 DJANGO_REQ='Django>=1.5,<1.6'
9 DJANGO_ROOT='src'
10 PROJECT_TEMPLATE='http://git.nowoczesnapolska.org.pl/?p=fnpdjango.git;a=snapshot;h=64c636d1e3ff35a7a1d3394fd1d3ff0093f44aa2;sf=tgz'
11 VIRTUALENVWRAPPER_PATHS="
12     /etc/bash_completion.d/virtualenvwrapper
13     /usr/bin/virtualenvwrapper.sh
14     /usr/local/bin/virtualenvwrapper.sh
15 "
16
17 # Colorful output.
18 strong='\e[0;32m'
19 error='\e[1;31m'
20 normal='\e[0m'
21
22 echo "Create new Django project."
23 while [ -z "$PROJECT" ]
24 do
25     echo "Name of the project:"
26     read PROJECT
27 done
28 echo -e "Project: ${strong}${PROJECT}${normal}"
29
30 for venv in $VIRTUALENVWRAPPER_PATHS
31 do
32     if [ -e "$venv" ]
33     then
34         VIRTUALENVWRAPPER="$venv"
35         break
36     fi
37 done
38 if [ "$VIRTUALENVWRAPPER" ]
39 then
40     echo "virtualenvwrapper found at $VIRTUALENVWRAPPER."
41     source "$VIRTUALENVWRAPPER"
42 else
43     echo -e "${error}ERROR: virtualenvwrapper not found. Tried locations:${normal}"
44     echo "$VIRTUALENVWRAPPER_PATHS"
45     echo -e "${error}Install virtualenvwrapper or add the correct path to this script.${normal}"
46     echo "Aborting."
47     return
48 fi
49
50 echo -e "${strong}Creating virtualenv: $PROJECT...${normal}"
51 mkvirtualenv "$PROJECT"
52 echo -e "${strong}Installing Django...${normal}"
53 pip install "$DJANGO_REQ"
54
55 echo -e "${strong}Starting the project...${normal}"
56 django-admin.py startproject \
57     --template "$PROJECT_TEMPLATE" \
58     "$PROJECT"
59
60 cd "$PROJECT"
61
62 WRAPPER="`ls`"
63 mv "$WRAPPER/"* "$WRAPPER/".gitignore .
64 rmdir "$WRAPPER"
65
66 chmod +x "$DJANGO_ROOT"/manage.py
67 mv "$DJANGO_ROOT/$PROJECT/localsettings.py.dev" "$DJANGO_ROOT/$PROJECT/localsettings.py"
68
69 echo -e "${strong}Installing requirements...${normal}"
70 pip install -r requirements.txt
71 echo -e "${strong}Installing developer requirements...${normal}"
72 pip install -r requirements-dev.txt
73 echo -e "${strong}Running syncdb...${normal}"
74 "$DJANGO_ROOT"/manage.py syncdb --noinput
75
76 echo -e "${strong}Starting new git repository...${normal}"
77 git init
78
79 echo -e "${strong}What next?${normal}"
80 echo " * Work on your app, commit to git."
81 echo " * Review fabfile, use fab for deployment."
82
83
84 }
85 start_project