Python/Django/Django installer

From Site5Wiki

Jump to: navigation, search
Provided below is a Bash Shell script that can be used to install Django on your Site5 hosting account. This script was created by a Site5 customer and is in no way supported or endorsed by Site5. As with any script or application installed or executed, please make sure that you review and understand the functions executed. You should ensure that any 3rd party software that you install to your account is kept up to date. Subscribe to the software vendors' mailing list or other notification services to keep as up to date as possible.



The following was obtained from the following Forum post: http://forums.site5.com/showpost.php?p=106220&postcount=64 Actual Thread: http://forums.site5.com/showthread.php?t=10236



Quick use instructions:

1. Copy the contents of the box below and paste the contents within a regular text file on your computer. Save this file as django-installer.txt.
2. You should then upload the file and rename the file removing the .txt file extension and replace it with .sh instead.
3. Using your SSH shell client of choice, issue the following command on the file to remove any DOS line formatting that may have been introduced:

dos2unix -k django-installer.sh

4. Execute the installer:

bash django-installer.sh


#!/bin/bash
#
# Updated from http://forums.site5.com/showthread.php?t=10236
# Thanks to Topdeck for the howto
#
# This assumes that Python 2.4 is available on your Site5 server
# if not, you'll also need to "easy_install python-eunuchs"
#
# This installs Django's trunk. You'll need to modify the script
# if you want a specific release.
#

#
# Settings that need configuration
#
# The name of your django site - used in the django.fcgi script
DJANGO_SITE_NAME=mysite

#
# Create our personal python
#

# install virtual python
curl http://peak.telecommunity.com/dist/virtual-python.py | python

# correct bash profile to use your bin directory first
# done in two simple steps to maintain readability
cp .bash_profile .bash_profile.bak
sed 's#PATH=$PATH:$HOME/bin#PATH=$HOME/bin:$PATH#' < .bash_profile.bak > .bash_profile
cp .bash_profile .bash_profile.bak
sed 's|PATH=.*|&\nexport PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects\n|' < .bash_profile.bak > .bash_profile

# use the new path settings - picking up the personal python
source .bash_profile

#
# Customise our personal python
#

# add easy_python
curl http://peak.telecommunity.com/dist/ez_setup.py | python

# add mysql-python
easy_install MySQL-python

# add flup for FCGI
easy_install flup

#
# Install Django
#
svn co http://code.djangoproject.com/svn/django/trunk/ django-src
ln -s ~/django-src/django/ ~/lib/python2.4/site-packages/django
ln -s ~/django-src/django/bin/django-admin.py bin/

#
# Create django-projects
#
mkdir django-projects

#
# Symbolically link the django admin media folder
#
ln -s ~/django-src/django/contrib/admin/media/ ~/public_html/media

#
# Output the FCGI handler
#
cat << EOF > ~/public_html/django.fcgi
#!/home/$USER/bin/python
import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home/$USER/django-projects")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "$DJANGO_SITE_NAME.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
EOF

#
# Output the .htaccess file
# Note that this creates a default file that assumes you want django running the root of your site
#
cat << EOF > ~/public_html/.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(django.fcgi)
RewriteRule ^(.*)$ django.fcgi/$1 [L]
EOF

#
# Django installed
#
echo -
echo Django Installed!\n
Personal tools