Skip to content

Instantly share code, notes, and snippets.

@szechyjs
Last active December 15, 2015 09:49
Show Gist options
  • Save szechyjs/5240873 to your computer and use it in GitHub Desktop.
Save szechyjs/5240873 to your computer and use it in GitHub Desktop.
Dreamhost Kegbot install script
#!/bin/bash
PREFIX=$HOME
PATH=$HOME/bin:$PATH
LD_LIBRARY_PATH=$HOME/lib/
info() {
printf " [ \033[00;34m..\033[0m ] $1\n"
}
user() {
printf "\r [ \033[0;33m?\033[0m ] $1 "
}
success() {
printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n"
}
fail() {
printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n"
echo ''
exit
}
install_python() {
info "Creating tmp directory"
mkdir -p $HOME/tmp
cd $HOME/tmp
info "Downloading python source"
wget -N http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -zxf Python-2.7.3.tgz
cd Python-2.7.3
if [ ! -f Makefile ];
then
info "Configuring python"
./configure --prefix=$PREFIX
fi
info "Compiling python"
make -j4
info "Installing python"
make install
info "Adding python to path"
echo 'export PATH="$HOME/bin:$PATH"' >> $HOME/.bash_profile
echo 'export LD_LIBRARY_PATH="$HOME/lib/"'
which python
}
install_setuptools() {
cd $HOME/tmp
info "Downloading setup tools"
wget -N https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
info "Installing setup tools"
sh setuptools-0.6c11-py2.7.egg --prefix=$HOME
}
install_pip() {
info "Installing pip"
easy_install pip
}
install_deps() {
pip install pillow
pip install paste
pip install MySQL-python
}
install_s3_deps() {
pip install django-storages
pip install boto
}
clone_kegbot() {
cd $HOME
info "Cloning Kegbot source"
git clone https://github.com/Kegbot/kegbot.git
}
config_kegbot() {
info 'Configuring kegbot'
if [ -f $HOME/.kegbot/local_settings.py ];
then
user "Config already exists, create new config? [y/n]"
read -n 1 action
if [ "$action" != "y" ];
then
return
fi
fi
mkdir -p $HOME/.kegbot
cd $HOME
user ' - What is the hostname of the site?'
read -e site_host
user ' - What is your MySQL hostname?'
read -e db_host
user ' - What is your MySQL username?'
read -e db_user
user ' - What is your MySQL password?'
read -e db_pass
user ' - What is your MySQL database name?'
read -e db_name
secret_key=`tr -dc "[abcdefghijklmnopqrstuvwxyz0123456789!@#%&-_=+]" < /dev/urandom | head -c 50`
media_root="$HOME/$site_host/media/"
static_root="$HOME/$site_host/static/"
sed -e "s~DB_HOST~$db_host~g" \
-e "s~DB_NAME~$db_name~g" \
-e "s~DB_USER~$db_user~g" \
-e "s~DB_PASS~$db_pass~g" \
-e "s~NEW_SEC~$secret_key~g" \
-e "s~SITE_HOST~$site_host~g" \
-e "s~NEW_MEDIA_ROOT~$media_root~g" \
-e "s~NEW_STATIC_ROOT~$static_root~g" \
local_settings.py.example > .kegbot/local_settings.py
info "Creating media and static dirs"
mkdir -p $media_root
mkdir -p $static_root
}
info "Checking for python"
if [ ! -f $HOME/bin/python ];
then
install_python
fi
success "Python installed"
info "Checking for setup tools"
if [ ! -f $HOME/bin/easy_install ];
then
install_setuptools
fi
success "Setup tools installed"
info "Checking for pip"
if [ ! -f $HOME/bin/pip ];
then
install_pip
fi
success "Pip installed"
info "Checking dependencies"
install_deps
success "Dependencies installed"
info "Checking for Kegbot source"
if [ ! -d $HOME/kegbot ];
then
clone_kegbot
fi
success "Kegbot source cloned"
config_kegbot
echo ''
echo ' All installed!'
# Local settings for kegbot.
# Edit settings, then copy this file to /etc/kegbot/local_settings.py or
# ~/.kegbot/local_settings.py
### Database configuration
# Database settings. Edit so that one is named 'default'.
DATABASES = {
# Example MYSQL settings (rename to 'default' to use)
'default' : {
'NAME' : 'DB_NAME',
'ENGINE' : 'django.db.backends.mysql',
'USER' : 'DB_USER',
'PASSWORD': 'DB_PASS',
'HOST': 'DB_HOST',
},
}
### General
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'NEW_SEC'
# Disable DEBUG mode when serving external traffic.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS
### Timezone and language
# Local time zone for this installation. All choices can be found here:
# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
TIME_ZONE = 'America/Los_Angeles'
### Media and Static Files
# Absolute path to the directory where uploaded media (profile pictures, etc)
# should go.
MEDIA_ROOT = 'NEW_MEDIA_ROOT'
# URL of the directory above. The default is '/media/'. Note that the directory
# name given in MEDIA_ROOT does not affect this.
MEDIA_URL = 'http://SITE_HOST/media/'
# A directory where non-media static files will be stored. You should create
# this directory, and use 'kegbot-admin.py collectstatic' to fill it.
STATIC_ROOT = 'NEW_STATIC_ROOT'
STATIC_URL = 'http://SITE_HOST/static/'
### Facebook
# Want to use Facebook Connect for registration/login? You will need to set
# these values up to the correct strings.
#FACEBOOK_API_KEY = ''
#FACEBOOK_SECRET_KEY = ''
### Twitter
#TWITTER_CONSUMER_KEY = ''
#TWITTER_CONSUMER_SECRET_KEY = ''
### Foursquare
#FOURSQUARE_CLIENT_ID = ''
#FOURSQUARE_CLIENT_SECRET = ''
#FOURSQUARE_REQUEST_PERMISSION = ''
### Untappd
# You'll need an API key from Untappd to enable Untappd features.
#UNTAPPD_API_KEY = ''
#GMT_OFFSET = '-5'
### django-storages
### Uncomment to use AWS as a backend for static/media files.
#AWS_ACCESS_KEY_ID = ''
#AWS_SECRET_ACCESS_KEY = ''
#AWS_STORAGE_BUCKET_NAME = ''
#AWS_QUERYSTRING_AUTH = False
#AWS_S3_SECURE_URLS = False
#DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
#STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
# passenger_wsgi.py -- WSGI config for kegbot
import os, site, sys
HOME = os.environ.get('HOME')
INTERP = os.path.join(HOME, "bin/python")
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
### Configuration section -- modify me for your install.
# If you are using a virtualenv, set the path to its base directory here. If
# not (kegbot and all its dependencies are installed in the default Python
# path), leave it blank.
VIRTUAL_ENV = HOME
# The common_settings.py config needs to be on the PATH as well. By default,
# kegbot looks in # $HOME/.kegbot and /etc/kegbot. Only change this if you are
# doing something different.
EXTRA_PATHS = [
os.path.join(HOME, '.kegbot'),
]
### Main script -- should not need to edit past here.
_orig_sys_path = list(sys.path)
if VIRTUAL_ENV:
# If we have a VIRTUAL_ENV, add it as a site dir.
PYTHON_NAME = 'python%i.%i' % sys.version_info[:2]
PACKAGES = os.path.join(VIRTUAL_ENV, 'lib', PYTHON_NAME, 'site-packages')
site.addsitedir(PACKAGES)
# Add the kegbot common_settings.py locations to the path.
for path in EXTRA_PATHS:
sys.path.append(path)
# Adjust so any new dirs are prepended.
_sys_path_prepend = [p for p in sys.path if p not in _orig_sys_path]
for item in _sys_path_prepend:
sys.path.remove(item)
sys.path[:0] = _sys_path_prepend
# Import django (which must be done after any path adjustments), and start the
# handler.
os.environ['DJANGO_SETTINGS_MODULE'] = 'pykeg.settings'
from paste.exceptions.errormiddleware import ErrorMiddleware
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
def testapplication(environ, start_response):
status = '200 OK'
output = 'Hello World! Running Python version ' + sys.version + '\n\n'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
# to test paste's error catching prowess, uncomment the following line
# while this function is the "application"
#raise("error")
start_response(status, response_headers)
return [output]
application = ErrorMiddleware(application, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment