Files
Odoo-Build/task
T
2021-03-09 14:29:26 +01:00

230 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
function help() {
echo
echo "$1 <command> [options]"
echo
echo "commands:"
echo
column -t -s"|" ./task.md | tail -n +3
echo
}
# load lib functions
. ./scripts/lib
function disable-auto-install() {
echo "Disable auto install for all enterprise modules."
find ./enterprise -type f -name '__manifest__.py' -exec sed -i'' $'s/\'auto_install\': True,/\'auto_install\': False,/g' {} +
}
function venv-init() {
python3 -m venv venv
source venv/bin/activate
}
function install-src() {
cd odoo
activate-venv
pip install setuptools wheel watchdog phonenumbers
pip install -r requirements.txt
}
function start-shell() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
cd odoo
locale
activate-venv
./odoo-bin shell -d $1 --config '../config/odoo-src.conf' --no-http
}
function init-db() {
cd odoo
locale
activate-venv
./odoo-bin --init base -d odoo --config '../config/odoo-src.conf' --stop-after-init --no-http
}
function start-src() {
cd odoo
locale
activate-venv
./odoo-bin --config '../config/odoo-src.conf' --dev=reload
}
function update-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
if test -z "$2"; then echo "\$2 is empty"; exit; fi
cd odoo
locale
activate-venv
./odoo-bin -d $1 -u $2 --config '../config/odoo-src.conf' --stop-after-init --no-http
}
function install-module() {
cd odoo
locale
activate-venv
./odoo-bin -d $1 -i $2 --config '../config/odoo-src.conf' --stop-after-init --no-http
}
function create-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
cd odoo
locale
activate-venv
./odoo-bin scaffold $1 ../addons -t ../template/ms_custom_module
}
function drop-db() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
psql postgres://odoo:odoo@localhost:5432/postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$1';"
psql postgres://odoo:odoo@localhost:5432/postgres -c "DROP DATABASE $1;"
}
function send-support-mail() {
curl smtp://localhost --mail-from admin@yourcompany.example.com --mail-rcpt support@localhost --upload-file ./data/email.txt
}
function clear-assets() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
echo "Delete these assets:"
psql postgres://odoo:odoo@localhost/$1 -c "select id,name from ir_attachment where res_model='ir.ui.view' and name like '%assets_%';"
psql postgres://odoo:odoo@localhost/$1 -c "delete from ir_attachment where res_model='ir.ui.view' and name like '%assets_%';"
}
function upload-module() {
if [ "$1" = "certificate_planer" ]; then
rsync -av -e ssh --exclude='.git' addons/certificate_planer hermes.mint-system.com:/usr/share/odoo05/addons/
fi
}
function convert-database() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
unzip "tmp/$1.zip" -d "./tmp/$1"
sed -i '' 's/AS integer//g' "./tmp/$1/dump.sql"
grep -i 'as integer' "./tmp/$1/dump.sql"
cd "tmp/$1" ; zip -r "../${1}2.zip" . ; cd ../..
rm -r "tmp/$1"
echo "Converted database file $1 to ${1}2"
}
function checkout() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
cd enterprise
git checkout .
cd ..
git checkout $1 && git submodule update --init
git submodule foreach git checkout $1
}
function release-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
VERSION=$(get-module-version $1)
echo "Create release $VERSION ..."
cd $1
gh release create "v$VERSION" -t "Release $VERSION"
}
function zip-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
# Get version and module name
VERSION=$(get-module-version $1)
MODULE=$(basename "$1")
# copy module to tmp folder
echo "Copy module $MODULE $VERSION to tmp folder"
MODULE_PATH="tmp/$MODULE-$VERSION"
cp -r "$1" "$MODULE_PATH"
# configure and zip module
echo "Remove auto install option"
sed -i'' -e "s/'auto_install': True,/'auto_install': False,/" $MODULE_PATH/__manifest__.py
echo "Zip module $MODULE"
zip -q -r $MODULE_PATH.zip $MODULE_PATH
}
case "$1" in
disable-auto-install)
disable-auto-install
;;
checkout)
checkout $2
;;
start)
docker-compose up -d
;;
stop)
docker-compose stop
;;
kill)
docker-compose down -v
;;
logs)
docker logs odoo -f
;;
start-db)
docker-compose up -d db pgadmin
;;
venv-init)
venv-init
;;
install-src)
install-src
;;
init-db)
init-db
;;
start-src)
start-src
;;
start-shell)
start-shell $2
;;
update-module)
update-module $2 $3
;;
upload-module)
upload-module $2
;;
create-module)
create-module $2
;;
drop-db)
drop-db $2
;;
send-support-mail)
send-support-mail
;;
clear-assets)
clear-assets $2
;;
convert-database)
convert-database $2
;;
install-module)
install-module $2 $3
;;
release-module)
release-module $2
;;
zip-module)
zip-module $2
;;
clear-filestore)
rm -rf ~/.local/share/Odoo/filestore/
;;
*)
help task
exit 1
esac