Last active
June 13, 2018 12:20
-
-
Save katyukha/f37b5cfedbbb88953b30 to your computer and use it in GitHub Desktop.
Odoo v8 Dev Install (WARNING: this is old unmaintained version. look at https://katyukha.gitlab.io/odoo-helper-scripts/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# WARNING: This is old and unmaintained version. | |
# for better quality install script look at: https://katyukha.gitlab.io/odoo-helper-scripts/ | |
# | |
# Bash script to instal dev version of OpenERP version 8 in local environment | |
# | |
# Usage: | |
# bash install.bash [dest-dir] | |
# | |
# Environment variables: | |
# ODOO_BRANCH - allow to clone specified branch. Default is 8.0 | |
# ODOO_DOWNLOAD_ARCHIVE - (on|off) if on then only archive will be downloaded | |
# not clonned. Default 'on' | |
# ODOO_SHALLOW_CLONE - (on|off) allow or disallow shallow clone. | |
# signifianly increases performance, but have some limitations. | |
# If ODOO_DOWNLOAD_ARCHIVE option is on, then this option | |
# has no effect | |
# Default is: off | |
# ODOO_DBHOST - allow to specify Postgresql's server host. | |
# Default: localhost | |
# ODOO_DBUSER - allow to specify user to connect to DB as. | |
# Default: odoo | |
# ODOO_DBPASSWORD - allow to specify db password to connect to DB as. | |
# Default: odoo | |
# | |
# installs Odoo 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 | |
# - git | |
# | |
# After instalation configs will be generated in 'conf' dir | |
# Also 'log' directory will contain Odoo logs | |
# Two more scripts will be generated: | |
# run_server.bash - will run openerp server. It is able to be executed outside virtual env | |
# test_module.bash - will run tests for specified module. Should have specific config | |
# ('conf/openerp-server-test.conf') | |
# | |
echo "WARNING: this is old and unmaintained version of script. | |
Now it is moved to separate repository: https://github.com/katyukha/odoo-helper-scripts | |
Look there for maintained version. There are a lot of new features)"; | |
set -e; | |
# Utility functions | |
function create_dirs { | |
# Simple function to create directories passed as arguments | |
while [[ $# > 1 ]]; do | |
if [ ! -d $1 ]; then | |
mkdir -p "$1"; | |
fi | |
shift; | |
done | |
} | |
# Check environment | |
BRANCH=${ODOO_BRANCH:-8.0}; | |
SHALLOW_CLONE=${ODOO_SHALLOW_CLONE:-off}; | |
DOWNLOAD_ARCHIVE=${ODOO_DOWNLOAD_ARCHIVE:-on}; | |
INSTALL_DIR=${1:-"`pwd`/odoo-$BRANCH"}; | |
DB_USER=${ODOO_DBUSER:-odoo}; | |
DB_PASSWORD=${ODOO_DBPASSWORD:-odoo}; | |
DB_HOST=${ODOO_DBHOST:-localhost}; | |
create_dirs $INSTALL_DIR; | |
cd "$INSTALL_DIR"; | |
# Directory and file paths | |
BASE_DIR=$INSTALL_DIR; | |
CONF_DIR=$BASE_DIR/conf; | |
LOG_DIR=$BASE_DIR/logs; | |
LIBS_DIR=$BASE_DIR/libs; | |
DOWNLOADS_DIR=$BASE_DIR/downloads; | |
CUSTOM_ADDONS_DIR=$BASE_DIR/custom_addons; | |
DATA_DIR=$BASE_DIR/data_dir; | |
BIN_DIR=$BASE_DIR/bin; | |
VENV_DIR=$BASE_DIR/venv; | |
PID_FILE=$BASE_DIR/openerp.pid; | |
ODOO_PATH=$BASE_DIR/odoo; | |
ADDONS_PATH="$ODOO_PATH/openerp/addons,$ODOO_PATH/addons,$CUSTOM_ADDONS_DIR"; | |
# Create dirs | |
create_dirs $CUSTOM_ADDONS_DIR \ | |
$CONF_DIR \ | |
$LOG_DIR \ | |
$LIBS_DIR \ | |
$DOWNLOADS_DIR \ | |
$BIN_DIR; | |
# Create virtual env, if it is not created yet | |
if [ ! -d $VENV_DIR ]; then | |
virtualenv $VENV_DIR; | |
fi | |
function download_odoo { | |
ODOO_ARCHIVE=$DOWNLOADS_DIR/odoo.$BRANCH.tar.gz | |
if [ ! -f $ODOO_ARCHIVE ]; then | |
wget -q -O $ODOO_ARCHIVE https://github.com/odoo/odoo/archive/$BRANCH.tar.gz; | |
fi | |
tar -zxf $ODOO_ARCHIVE; | |
mv odoo-$BRANCH $ODOO_PATH; | |
} | |
function clone_odoo { | |
if [ "$SHALLOW_CLONE" == "on" ]; then | |
DEPTH="--depth=1"; | |
else | |
DEPTH=""; | |
fi | |
git clone --branch $BRANCH --single-branch $DEPTH https://github.com/odoo/odoo.git $ODOO_PATH; | |
} | |
# if not installed odoo, install it via git (takes a long, very long time) | |
if [ ! -d $BASE_DIR/odoo ]; then | |
if [ "$DOWNLOAD_ARCHIVE" == "on" ]; then | |
download_odoo; | |
else | |
clone_odoo; | |
fi | |
fi | |
# install into virtualenv odoo and its dependencies | |
source $VENV_DIR/bin/activate; | |
pip install --upgrade pip setuptools; # required to make odoo.py work correctly | |
if ! python -c "import pychart"; then | |
pip install http://download.gna.org/pychart/PyChart-1.39.tar.gz; | |
fi | |
pip install --allow-external=PIL \ | |
--allow-unverified=PIL \ | |
-e $ODOO_PATH; | |
deactivate; | |
# Generate configuration | |
cat > $CONF_DIR/openerp-server.conf << EOF | |
[options] | |
addons_path = $ADDONS_PATH | |
admin_passwd = admin | |
auto_reload = False | |
csv_internal_sep = , | |
data_dir = $DATA_DIR | |
db_host = $DB_HOST | |
db_maxconn = 64 | |
;db_name = odoo | |
db_user = $DB_USER | |
db_password = $DB_PASSWORD | |
db_port = False | |
db_template = template1 | |
dbfilter = .* | |
debug_mode = False | |
demo = {} | |
email_from = False | |
import_partial = | |
limit_memory_hard = 2684354560 | |
limit_memory_soft = 2147483648 | |
limit_request = 8192 | |
limit_time_cpu = 60 | |
limit_time_real = 120 | |
list_db = True | |
log_db = False | |
log_handler = [':INFO'] | |
log_level = info | |
logfile = $LOG_DIR/openerp.log | |
logrotate = False | |
longpolling_port = 8072 | |
max_cron_threads = 2 | |
osv_memory_age_limit = 1.0 | |
osv_memory_count_limit = False | |
pg_path = None | |
pidfile = $PID_FILE | |
proxy_mode = False | |
reportgz = False | |
secure_cert_file = server.cert | |
secure_pkey_file = server.pkey | |
server_wide_modules = None | |
smtp_password = False | |
smtp_port = 25 | |
smtp_server = localhost | |
smtp_ssl = False | |
smtp_user = False | |
syslog = False | |
test_commit = False | |
test_enable = False | |
test_file = False | |
test_report_directory = False | |
timezone = False | |
translate_modules = ['all'] | |
unaccent = False | |
without_demo = False | |
workers = 1 | |
xmlrpc = True | |
xmlrpc_interface = | |
xmlrpc_port = 8069 | |
xmlrpcs = True | |
xmlrpcs_interface = | |
xmlrpcs_port = 8071 | |
EOF | |
#--------------------------------------------- | |
# Generate test configuration configuration | |
cat > $CONF_DIR/openerp-server-test.conf << EOF | |
[options] | |
addons_path = $ADDONS_PATH | |
admin_passwd = admin | |
auto_reload = False | |
csv_internal_sep = , | |
data_dir = $BASE_DIR/data_dir | |
db_host = $DB_HOST | |
db_maxconn = 64 | |
db_name = $DB_USER-odoo-test | |
db_user = $DB_USER | |
db_password = $DB_PASSWORD | |
db_port = False | |
db_template = template1 | |
dbfilter = $DB_USER-odoo-test | |
debug_mode = False | |
demo = {} | |
email_from = False | |
import_partial = | |
limit_memory_hard = 2684354560 | |
limit_memory_soft = 2147483648 | |
limit_request = 8192 | |
limit_time_cpu = 60 | |
limit_time_real = 120 | |
list_db = True | |
log_db = False | |
log_handler = [':INFO'] | |
log_level = test | |
logfile = False | |
logrotate = False | |
longpolling_port = 8072 | |
max_cron_threads = 2 | |
osv_memory_age_limit = 1.0 | |
osv_memory_count_limit = False | |
pg_path = None | |
pidfile = $BASE_DIR/openerp-test.pid | |
proxy_mode = False | |
reportgz = False | |
;secure_cert_file = server.cert | |
;secure_pkey_file = server.pkey | |
server_wide_modules = None | |
smtp_password = False | |
smtp_port = 25 | |
smtp_server = localhost | |
smtp_ssl = False | |
smtp_user = False | |
syslog = False | |
test_commit = False | |
test_enable = False | |
test_file = False | |
test_report_directory = False | |
timezone = False | |
translate_modules = ['all'] | |
unaccent = False | |
without_demo = False | |
workers = 1 | |
xmlrpc = False | |
xmlrpc_interface = | |
xmlrpc_port = 8269 | |
xmlrpcs = False | |
xmlrpcs_interface = | |
xmlrpcs_port = 8271 | |
EOF | |
#--------------------------------------------- | |
# Generate start server script | |
cat > $BIN_DIR/run_erp.bash <<EOF | |
#!/bin/bash | |
# This is openERP run script | |
# Available envoronment variables can be used: | |
# 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.pid | |
SCRIPTPATH=openerp-server | |
# If config file not set from environment set default one. | |
if [ -z \$OE_CONFIG ]; then | |
OE_CONFIG=$CONF_DIR/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 \$@ &); | |
else | |
(cd \$BASEDIR && \ | |
source ./venv/bin/activate && \ | |
exec \$SCRIPTPATH -c \$OE_CONFIG \$@); | |
fi | |
EOF | |
chmod a+x $BIN_DIR/run_erp.bash; | |
#--------------------------------------------------------------- | |
# Generate test module script | |
cat > $BIN_DIR/test_module.bash <<EOF | |
#!/bin/bash | |
# This is openERP test script | |
# | |
# Usage: | |
# ./test_erp.bash <module_name> | |
# | |
# Available environment 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 | |
# Guess directory script is placed in | |
F=\`readlink -f \$0\` | |
BASEDIR=\`dirname \$F\`/.. | |
# Check if log level set in environment and if not set default 'test' level | |
if [ -z \$OE_LOG_LEVEL ]; then | |
OE_LOG_LEVEL=test; | |
fi | |
# If config file not set from environment set default one. | |
if [ -z \$OE_CONFIG ]; then | |
OE_CONFIG=\$BASEDIR/conf/openerp-server-test.conf; | |
fi | |
echo "Start testing OpenERP server module \$1" | |
(cd \$BASEDIR && source ./venv/bin/activate && openerp-server -c \$OE_CONFIG --init=\$1 --log-level=\$OE_LOG_LEVEL --test-enable --stop-after-init --no-xmlrpc --no-xmlrpcs && deactivate) | |
EOF | |
chmod a+x $BIN_DIR/test_module.bash; | |
#--------------------------------------------------------------- | |
# Generate new module script | |
cat > $BIN_DIR/new_module.bash <<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\`/.. | |
CUSTOM_ADDONS_DIR=\$BASEDIR/custom_addons | |
set -e; | |
function usage { | |
echo "Usage:"; | |
echo " new_module.bash <module_name> [root]"; | |
echo "Where 'root' arg is root directory to place module in. By default it is 'custom_addons'"; | |
} | |
function generate_oerp_py { | |
MOD_PATH=\$1 | |
cat > \$MOD_PATH/__openerp__.py << EOFI | |
# -*- coding: utf-8 -*- | |
{ | |
'name': 'New OpenERP Module', | |
'version': '0.0.1', | |
'author': '`whoami`', | |
'category': 'Added functionality', | |
'description': """ | |
--- | |
""", | |
'website': '', | |
'images': [], | |
'depends' : [], | |
'data': [], # Place xml views here | |
'demo': [], | |
'installable': True, | |
'auto_install': False, | |
} | |
EOFI | |
} | |
function generate_gitignore { | |
MOD_PATH=\$1 | |
cat > \$MOD_PATH/.gitignore << EOFI | |
*.pyc | |
*.swp | |
*.idea/ | |
*~ | |
*.swo | |
*.pyo | |
EOFI | |
} | |
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"; | |
} | |
if [ -z \$1 ]; then | |
usage; | |
exit 0; | |
fi | |
create_module \$1 \$2; | |
EOF | |
chmod a+x $BIN_DIR/new_module.bash; | |
#--------------------------------------------- | |
# Generate odoo script | |
cat > $BIN_DIR/odoo <<EOF | |
#!/bin/bash | |
# This script runs odoo.py inside virtual env, and should be used to | |
# run odoo.py outside virtualenv | |
# Guess directory script is placed in | |
F=\`readlink -f \$0\` | |
BASEDIR=\`dirname \$F/\`/.. | |
SCRIPTPATH=\$BASEDIR/venv/bin/odoo.py; | |
ADDONS_PATH=$ADDONS_PATH; | |
(cd \$BASEDIR && \ | |
source ./venv/bin/activate && \ | |
exec \$SCRIPTPATH \$@ && \ | |
deactivate); | |
EOF | |
chmod a+x $BIN_DIR/odoo; | |
#--------------------------------------------------------------- | |
cat > $BIN_DIR/fetch_module.bash <<EOF | |
#!/bin/bash | |
# Environment variaable could be passed | |
# - ODOO_DOWNLOADS_DIR - Folder to store cloned addons repositories | |
# - ODOO_CUSTOM_ADDONS_DIR - Folder to link addons to | |
# - ODOO_REQUIREMENTS_FILE_NAME - default requirements file name to search for in fetched modules. | |
# Default name is: odoo_requirements.txt | |
# | |
# Requirements file is a text file where each line is just set of options | |
# to this script | |
# -r repository -n repository_name -m module_name | |
# or | |
# -p python_module | |
# | |
# For example: | |
# -r https://github.com/katyukha/base_tags -n base_tags -m base_tags | |
# -p requests | |
SCRIPT=\$0; | |
F=\`readlink -f \$SCRIPT\` | |
BASEDIR=\`dirname \$F\`/.. | |
VENV_DIR=\$BASEDIR/venv; | |
# Configura variables from environment | |
DOWNLOADS_DIR=\${ODOO_DOWNLOADS_DIR:-\$BASEDIR/downloads}; | |
CUSTOM_ADDONS_DIR=\${ODOO_CUSTOM_ADDONS_DIR:-\$BASEDIR/custom_addons}; | |
REQUIREMENTS_FILE_NAME=\${ODOO_REQUIREMENTS_FILE_NAME:-odoo_requirements.txt}; | |
set -e; | |
function print_usage { | |
echo "Usage:"; | |
echo " fetch_module.bash -r|--repo <git repository> [-m|--module <odoo module name>] [-n|--name <repo name>] [-b|--branch <git branch>] [--requirements <requirements file>]"; | |
echo ""; | |
echo " fetch_module.bash -p|--python <python module>"; | |
echo ""; | |
} | |
function fetch_requirements { | |
REQUIREMENTS_FILE=\$1; | |
echo "Processing requirements file \$1"; | |
while read -r line; do | |
if [ ! -z "\$line" ] && [[ ! "\$line" == "#"* ]]; then | |
if bash \$SCRIPT \$line; then | |
echo "Line OK: \$line"; | |
else | |
echo "Line FAIL: \$line"; | |
fi | |
fi | |
done < \$1; | |
} | |
if [[ \$# < 2 ]]; then | |
print_usage; | |
exit 0; | |
fi | |
while [[ \$# > 1 ]] | |
do | |
key="\$1"; | |
case \$key in | |
-r|--repo) | |
REPOSITORY="\$2"; | |
shift; | |
;; | |
-m|--module) | |
MODULE="\$2"; | |
shift; | |
;; | |
-n|--name) | |
REPO_NAME="\$2"; | |
shift; | |
;; | |
-b|--branch) | |
REPO_BRANCH="\$2"; | |
REPO_BRANCH_OPT="-b \$REPO_BRANCH"; | |
shift; | |
;; | |
-p|--python) | |
PYTHON_INSTALL=1; | |
source \$VENV_DIR/bin/activate && pip install \$2 && deactivate; | |
shift; | |
;; | |
-h|--help) | |
print_usage; | |
exit 0; | |
;; | |
--downloads_dir) | |
DOWNLOADS_DIR=\$2; | |
shift; | |
;; | |
--addons_dir) | |
CUSTOM_ADDONS_DIR=\$2; | |
shift; | |
;; | |
--requirements) | |
fetch_requirements \$2; | |
exit 0; | |
;; | |
*) | |
echo "Unknown option \$key"; | |
exit 1; | |
;; | |
esac | |
shift | |
done | |
if [ -z \$REPOSITORY ]; then | |
if [ ! -z \$PYTHON_INSTALL ]; then | |
exit 0; | |
fi | |
echo "No git repository supplied to fetch module from!"; | |
echo ""; | |
print_usage; | |
exit 2; | |
fi | |
REPO_NAME=\${REPO_NAME:-\`echo \$REPOSITORY | sha256sum\`}; | |
REPO_PATH=\$DOWNLOADS_DIR/\$REPO_NAME; | |
# Clone or pull repository | |
if [ ! -d \$REPO_PATH ]; then | |
git clone -q \$REPO_BRANCH_OPT \$REPOSITORY \$REPO_PATH; | |
else | |
(cd \$REPO_PATH && git pull -q); | |
fi | |
# Guess repository type | |
if [ -f "\$REPO_PATH/__openerp__.py" ]; then | |
REPO_TYPE="single_module"; | |
else | |
REPO_TYPE="multi_module"; | |
fi | |
function link_module { | |
MODULE_NAME=\$1; | |
MODULE_DEST=\$CUSTOM_ADDONS_DIR/\$MODULE_NAME; | |
if [ -d "\$MODULE_DEST" ]; then | |
#echo "\$MODULE_NAME already linked"; | |
exit 0; | |
fi | |
echo "Linking module \$MODULE_NAME to \$MODULE_DEST"; | |
if [ "\$REPO_TYPE" == "single_module" ]; then | |
MODULE_PATH=\$REPO_PATH; | |
else | |
MODULE_PATH=\$REPO_PATH/\$MODULE_NAME; | |
fi | |
ln -s \$MODULE_PATH \$MODULE_DEST; | |
if [ -f "\$MODULE_PATH/\$REQUIREMENTS_FILE_NAME" ]; then | |
fetch_requirements "\$MODULE_PATH/\$REQUIREMENTS_FILE_NAME"; | |
fi | |
} | |
# Link modules | |
if [ -z \$MODULE ]; then | |
# No module specified, then link all modules | |
for file in "\$REPO_PATH"/*; do | |
if [[ -d "\$file" ]] && [[ -f "\$file/__openerp__.py" ]]; then | |
echo "Module found: \`basename \$file\`"; | |
link_module \`basename \$file\`; | |
fi | |
done | |
else | |
# module specified, then link jus one module | |
link_module \$MODULE; | |
fi | |
EOF | |
chmod a+x $BIN_DIR/fetch_module.bash; | |
#--------------------------------------------------------------- | |
echo "Edit configuration at $CONF_DIR/openerp-server.conf and run via $BIN_DIR/run_erp.bash"; | |
echo "To create skeleton for new module use $BIN_DIR/new_module.bash script"; | |
echo "To test module use $BIN_DIR/test_module.bash script"; | |
echo "$BIN_DIR/odoo script could be used to run odoo.py outside virtual environment"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment