Skip to content

Instantly share code, notes, and snippets.

@katyukha
Last active August 29, 2015 14:00
Show Gist options
  • Save katyukha/3ea61a8bb3a2071aa045 to your computer and use it in GitHub Desktop.
Save katyukha/3ea61a8bb3a2071aa045 to your computer and use it in GitHub Desktop.
OpenERP Dev Install
#!/usr/bin/bash
#
# Bash script to instal dev version of OpenERP version 7 in local environment
#
# Ussage:
# bash install.bash [dest-dir]
#
# installs OpenERP into specified directory. automatically creates base config,
# run_server script, and script to create skeletons of new modules
#
# Prerequirements:
# Next packages must be installed system-wide:
# - virtualenv
# - postgres
# - python-dev
# - g++
# - libpq-dev
# - bazaar client (bzr)
#
set -e;
# Choose install dir
INSTALL_DIR="`pwd`/OpenERP-7";
if [[ ! -z $1 ]]; then
INSTALL_DIR=$1;
fi;
if [ ! -d $INSTALL_DIR ]; then
mkdir "$INSTALL_DIR";
fi
cd "$INSTALL_DIR";
BASE_DIR=`pwd`;
CONF_DIR=$BASE_DIR/conf;
LOG_DIR=$BASE_DIR/logs;
LIBS_DIR=$BASE_DIR/libs;
CUSTOM_ADDONS_DIR=$BASE_DIR/custom_addons;
WEBADDONS_DIR=$BASE_DIR/webaddons;
ADDONS_DIR=$BASE_DIR/addons;
# Download sources
if [ ! -f $BASE_DIR/server/xx_downloaded ]; then
echo "Downloading sources for Server package...";
bzr branch lp:openobject-server/7.0 $BASE_DIR/server;
touch $BASE_DIR/server/xx_downloaded;
fi
if [ ! -f $WEBADDONS_DIR/xx_downloaded ]; then
echo "Downloading sources for Web addons package...";
bzr branch lp:openerp-web/7.0 $WEBADDONS_DIR;
touch $WEBADDONS_DIR/xx_downloaded;
fi
if [ ! -f $ADDONS_DIR/xx_downloaded ]; then
echo "Dowloading sources for standard OpenERP addons...";
bzr branch lp:openobject-addons/7.0 $ADDONS_DIR;
touch $ADDONS_DIR/xx_downloaded;
fi
# Create dirs
if [ ! -d $CUSTOM_ADDONS_DIR ]; then
mkdir $CUSTOM_ADDONS_DIR;
fi
if [ ! -d $CONF_DIR ]; then
mkdir $CONF_DIR;
fi
if [ ! -d $LOG_DIR ]; then
mkdir $LOG_DIR;
fi
if [ ! -d $LIBS_DIR ]; then
mkdir $LIBS_DIR;
fi
# Generate configuration
cat > $CONF_DIR/openerp-server.conf << EOF
[options]
db_host = localhost
db_port = 5432
db_user = openerp
db_password = openerp
without_demo = True
; This is the password that allows database operations:
admin_passwd = admin
translate_modules = ['all']
xmlrpc = True
; xmlrpc_interface =
xmlrpc_port = 8069
xmlrpc_host = 0.0.0.0
addons_path = $BASE_DIR/server/openerp/addons/,$ADDONS_DIR,$WEBADDONS_DIR/addons,$CUSTOM_ADDONS_DIR
EOF
#---------------------------------------------
# Create virtual environment
virtualenv venv;
# Install dependencies in created environment
source venv/bin/activate;
bzr branch http://download.gna.org/pychart/bzr-archive libs/pychart;
(cd libs/pychart && python setup.py install);
pip install babel docutils feedparser gdata Jinja2 lxml mako mock PIL psutil "psycopg2>=2.2" pydot "python-dateutil<2" python-openid pytz pywebdav pyyaml reportlab simplejson unittest2 vatnumber vobject werkzeug xlwt;
deactivate; # deactivate virtual environment
# Generate start server script
cat > $BASE_DIR/run_erp.bash <<'EOF'
#!/bin/bash
# This is openERP run script
# Available envoronment variables can be used:
# OE_LOG_LEVEL - log level to be used for openerp server
# OE_CONFIG - config file to be used by openerp server
# OE_FOREGROUND - if set and not null then server will run in foreground
# Guess directory script is placed in
F=`readlink -f $0`
BASEDIR=`dirname $F`
LOGDIR=$BASEDIR/logs
PIDFILE=$BASEDIR/openerp-server.pid
LOGFILE=$LOGDIR/openerp-server.log
SCRIPTPATH=$BASEDIR/server/openerp-server
# Check if log level set in environment and if not set default 'debug' level
if [ -z $OE_LOG_LEVEL ]; then
OE_LOG_LEVEL=debug;
fi
# If config file not set from environment set default one.
if [ -z $OE_CONFIG ]; then
OE_CONFIG=$BASEDIR/conf/openerp-server.conf;
fi
if [ -f $PIDFILE ]; then
PROCESS_ID=`cat $PIDFILE`
echo "killing OpenERP process $PROCESS_ID"
kill $PROCESS_ID
rm -f $PIDFILE
sleep 2
fi
echo "Starting OpenERP server"
if [ -z "$OE_FOREGROUND" ] && [ -z "$OE_FG" ]; then
(cd $BASEDIR && \
source ./venv/bin/activate && \
exec $SCRIPTPATH -c $OE_CONFIG --log-level=$OE_LOG_LEVEL --logfile=$LOGFILE --pidfile=$PIDFILE $@ &);
else
(cd $BASEDIR && \
source ./venv/bin/activate && \
exec $SCRIPTPATH -c $OE_CONFIG --log-level=$OE_LOG_LEVEL --logfile=$LOGFILE --pidfile=$PIDFILE $@);
fi
EOF
chmod a+x $BASE_DIR/run_erp.bash;
# Generate new_module script
cat > $BASE_DIR/new_module.bash << 'SCRIPT_EOF'
#!/bin/bash
#
# Usage:
# new_module.bash <module_name> [root]
# Where 'root' arg is root directory to place module in. By default it is 'custom_addons'
#
# Guess directory script is placed in
F=`readlink -f $0`
BASEDIR=`dirname $F`
LOGDIR=$BASEDIR/logs
PIDFILE=$BASEDIR/openerp-server.pid
LOGFILE=$LOGDIR/openerp-server.log
CUSTOM_ADDONS_DIR=$BASEDIR/custom_addons
set -e;
function generate_oerp_py {
MOD_PATH=$1
cat > $MOD_PATH/__openerp__.py << EOF
# -*- coding: utf-8 -*-
'author': '`whoami`',
'category': 'Added functionality',
'description': """
---
""",
'website': '',
'images': [],
'depends' : [],
'data': [], # Place xml views here
'demo': [],
'installable': True,
'auto_install': False,
}
EOF
}
function generate_gitignore {
MOD_PATH=$1
cat > $MOD_PATH/.gitignore << EOF
*.pyc
*.swp
*.idea/
*~
*.swo
*.pyo
EOF
}
function create_module {
NEW_MODULE_NAME=$1
NEW_MODULE_DIR=$2
if [ -z $NEW_MODULE_DIR ]; then
NEW_MODULE_DIR=$CUSTOM_ADDONS_DIR;
fi
NEW_MODULE_PATH=$NEW_MODULE_DIR/$NEW_MODULE_NAME
if [ -d "$NEW_MODULE_PATH" ]; then
echo "Module $NEW_MODULE_NAME already exists in module path $NEW_MODULE_PATH";
exit -1;
fi;
mkdir $NEW_MODULE_PATH;
generate_oerp_py $NEW_MODULE_PATH;
generate_gitignore $NEW_MODULE_PATH;
mkdir $NEW_MODULE_PATH/models;
mkdir $NEW_MODULE_PATH/views;
mkdir $NEW_MODULE_PATH/security;
mkdir $NEW_MODULE_PATH/reports;
echo "import models" > $NEW_MODULE_PATH/__init__.py;
touch "$NEW_MODULE_PATH/models/__init__.py";
}
create_module $1 $2;
SCRIPT_EOF
chmod a+x $BASE_DIR/new_module.bash;
echo "Edit configuration at $CONF_DIR/openerp-server.conf and run via $BASE_DIR/run_erp.bash ";
echo "To create new module, use $BASE_DIR/new_module.bash script";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment