Deps quickfix
[fnpdjango.git] / bin / fnpdjango_bootstrap.sh
1 #!/bin/bash
2 #
3 # Use as: 
4 #
5 #   source <(curl d.nowoczesnapolska.org.pl)
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.6,<1.7'
15 DJANGO_ROOT='src'
16
17 PYPI='http://pypi.nowoczesnapolska.org.pl/simple'
18 PROJECT_TEMPLATE='http://git.nowoczesnapolska.org.pl/?p=fnpdjango.git;a=snapshot;h=project;sf=tgz'
19
20 VIRTUALENVWRAPPER_PATHS="
21     /etc/bash_completion.d/virtualenvwrapper
22     /usr/bin/virtualenvwrapper.sh
23     /usr/local/bin/virtualenvwrapper.sh
24 "
25
26 # Colorful output.
27 strong='\e[0;32m'
28 error='\e[1;31m'
29 normal='\e[0m'
30
31 echo "Create new Django project."
32 while [ -z "$PROJECT" ]
33 do
34     echo "Name of the project:"
35     read PROJECT
36 done
37 echo -e "Project: ${strong}${PROJECT}${normal}"
38
39 for venv in $VIRTUALENVWRAPPER_PATHS
40 do
41     if [ -e "$venv" ]
42     then
43         VIRTUALENVWRAPPER="$venv"
44         break
45     fi
46 done
47 if [ "$VIRTUALENVWRAPPER" ]
48 then
49     echo "virtualenvwrapper found at $VIRTUALENVWRAPPER."
50     source "$VIRTUALENVWRAPPER"
51 else
52     echo -e "${error}ERROR: virtualenvwrapper not found. Tried locations:${normal}"
53     echo "$VIRTUALENVWRAPPER_PATHS"
54     echo -e "${error}Install virtualenvwrapper or add the correct path to this script.${normal}"
55     echo "Aborting."
56     return
57 fi
58
59 echo -e "${strong}Creating virtualenv: $PROJECT...${normal}"
60 mkvirtualenv "$PROJECT"
61 echo -e "${strong}Installing Django...${normal}"
62 pip install -i "$PYPI" "$DJANGO_REQ"
63 pip install -i "$PYPI" --pre django-startproject-plus
64
65 echo -e "${strong}Starting the project...${normal}"
66 django-startproject.py \
67     --template "$PROJECT_TEMPLATE" \
68     --name NOTICE \
69     --extra_context='{"year": "`date +%Y`"}' \
70     "$PROJECT"
71
72 cd "$PROJECT"
73
74 # GitWeb adds a top directory to the snapshot, let's remove it.
75 if [ ! -e .gitignore ]
76 then
77     WRAPPER="`ls`"
78     mv "$WRAPPER/"* "$WRAPPER/".gitignore .
79     rmdir "$WRAPPER"
80 fi
81
82 chmod +x "$DJANGO_ROOT"/manage.py
83 mv "$DJANGO_ROOT/$PROJECT/localsettings.py.dev" "$DJANGO_ROOT/$PROJECT/localsettings.py"
84
85 echo -e "${strong}Installing requirements...${normal}"
86 pip install -i "$PYPI" -r requirements.txt
87 echo -e "${strong}Installing developer requirements...${normal}"
88 pip install -i "$PYPI" -r requirements-dev.txt
89 echo -e "${strong}Running syncdb...${normal}"
90 "$DJANGO_ROOT"/manage.py syncdb --noinput
91
92 echo -e "${strong}Starting new git repository...${normal}"
93 git init
94
95 echo -e "${strong}What next?${normal}"
96 echo " * Work on your app, commit to git."
97 echo " * Review fabfile, use fab for deployment."
98
99
100 }
101 start_project
102
103 # The following is just for displaying it as a webpage:<!--
104 #--><style>body{white-space:pre;color:#ddd}</style><h1 style="color:#000;text-align:center;position:fixed;top:0;bottom:0;left:0;right:0;white-space:normal">source &lt;(curl <span id="location"></span>)</h1><script>document.getElementById('location').innerHTML=window.location;</script>
105