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