Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: next
Fetching contributors…

Cannot retrieve contributors at this time

file 174 lines (149 sloc) 4.489 kb
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
#!/bin/sh
# django-admin-aderit -- bootstrap a django project
#
# Copyright (C) 2012 Aderit srl
#
# Author: Marco Bardelli <marco.bardelli@aderit.it>, <bardelli.marco@gmail.com>
#
# This file is part of DjangoContribAderit.
#
# DjangoContribAderit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DjangoContribAderit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DjangoContribAderit. If not, see <http://www.gnu.org/licenses/>.

set -e

oldpwd="$OLDPWD"
with_git=no
group_for_share=${SHARE_FOR_GROUP:-tecnici}
prj_template_root=${DJANGO_PROJECT_TEMPLATE_ROOT:-/usr/share/python-django-contrib-aderit}

usage ()
{
    echo "$0 [--with-git] startproject|startapp <NOMEPROGETTO>|<NOMEAPP>"
    exit $1
}

check_args ()
{
    if test $# -lt 2 -o $# -gt 3 ; then
echo "Numero di argomenti sbagliato"
usage 1
    fi
    case $1 in
--with-git) which git 2>&1 1> /dev/null && with_git=yes ;;
*) ;;
    esac
}

init_git_repo ()
{
    cd $1
    git init --shared=group .
    echo '*~' >> .gitignore
    echo '*.pyc' >> .gitignore
    echo 'django.wsgi' >> .gitignore
    echo 'run.sh' >> .gitignore
    echo INSTALL_APACHE_VHOST >> .gitignore
    echo db_settings.py >> .gitignore
    echo cms_settings.py >> .gitignore
    echo local_settings.py >> .gitignore
    echo 'media/README' >> .gitignore
    git add .gitignore
    getent group $group_for_share 2>&1 1>/dev/null
    if test $? -eq 0 ; then
groups | grep -q "$group_for_share"
if test $? -eq 0 ; then
chgrp -R $group_for_share .
chmod -R g+w .
find . -type d -print0 | xargs -0 chmod g+s
fi
    fi
    cd - 2>&1 1> /dev/null
}

write_install_vh ()
{
    cd $1
    cat <<EOF > INSTALL_APACHE_VHOST
To enable this site in apache2 server web,
copy the example below in /etc/apache2/sites-available/$1 ,
edit it to fit your needs,
run "a2ensite $1 && /etc/init.d/apache2 reload" as root.

<<<<<<<<<<===== begin of apache2 virtual host example =====>>>>>>>>>>
<VirtualHost *:80>
ServerAdmin <ADMIN EMAIL>
ServerName <HTTP URL>

Alias /media/ `pwd`/media/

        <Directory `pwd`/media/ >
            Options +MultiViews -Indexes
            AllowOverride None
        </Directory>

        Alias /static/ `pwd`/static/

        <Directory `pwd`/static/ >
            Options +MultiViews -Indexes
            AllowOverride None
        </Directory>

WSGIDaemonProcess web-$1-user user=www-data group=www-data processes=1 threads=15
WSGIProcessGroup web-$1-user

WSGIScriptAlias / `pwd`/django.wsgi

ErrorLog /var/log/apache2/$1-error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/$1-access.log combined

</VirtualHost>
<<<<<<<<<<===== end of apache2 virtual host =====>>>>>>>>>>
EOF
    cd - 2>&1 1> /dev/null
}

write_run_sh_script()
{
    name="$1"
    cat <<EOF > "$name"/run.sh
#!/bin/sh

test -r \$(basename \$(pwd) | tr A-Z a-z)_settings.py
if test \$? -eq 0; then
  DJANGO_SETTINGS_MODULE=\$(basename \$(pwd)).\$(basename \$(pwd) | tr A-Z a-z)_settings ;
else
  DJANGO_SETTINGS_MODULE=\$(basename \$(pwd)).settings
fi
PYTHONPATH=\$(dirname \$(pwd)):\$(pwd)
export DJANGO_SETTINGS_MODULE PYTHONPATH

django-admin \$@

EOF

}

check_args "$@"
test xyes = x"$with_git" && shift;

CMD="$1"
NAME="$2"

case "$CMD" in
    startproject)
test -n "$NAME" || usage 1
cp -rf $prj_template_root/project_template "$NAME"
SECRET=`pwgen -s -y 54 1 | sed -e "s_[\"']_+_g"`
sed -i -e "s,@PROJECT@,$NAME,g" -e "s'@SECRET@'$SECRET'g" "$NAME"/settings.py
touch "$NAME"/__init__.py
write_run_sh_script $NAME
# echo "#!/bin/sh" > "$NAME"/run.sh
# echo "export DJANGO_SETTINGS_MODULE=\$(basename \$(pwd)).settings ; export PYTHONPATH=\$(dirname \$(pwd)):\$(pwd) ; django-admin \$@" >> "$NAME"/run.sh
# echo ""
chmod +x "$NAME"/run.sh
echo "Creato progetto in $NAME"
write_install_vh $NAME
if test xyes = x"$with_git" ; then
init_git_repo $NAME
fi
;;
    startapp)
echo "Da implementare ancora.. Wait!!!"
;;
    *)
OLDPWD="$oldpwd"
usage 1
;;
esac
OLDPWD="$oldpwd"
Something went wrong with that request. Please try again.