Files
Odoo-Build/task
T
2021-06-17 13:25:24 +02:00

410 lines
10 KiB
Bash
Executable File

#!/bin/bash
set -e
function help() {
echo
echo "$1 <command> [options]"
echo
echo "commands:"
echo
column -t -s"|" ./task.md | tail -n +3
echo
}
# load lib functions and env vars
. ./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 install-odoo-scripts() {
curl -L https://raw.githubusercontent.com/mint-system/ansible-playbooks/master/roles/odoo-scripts/files/install | sh
}
function install-src() {
init-venv
activate-venv
pip install --upgrade --pre pylint-odoo
pip install setuptools wheel watchdog phonenumbers
pip install -r odoo/requirements.txt
}
function start() {
if test -z "$1"; then
echo "Open http://localhost:8069 url in your browser."
docker-compose up -d
fi
if [ "$1" = "db" ]; then
docker-compose up -d db pgadmin
echo "Open http://localhost:8000 url in your browser."
fi
if [ "$1" = "mail" ]; then
docker-compose up -d mail
echo "Open http://localhost url in your browser."
fi
if [ "$1" = "src" ]; then
locale
activate-venv
echo "Open http://localhost:8069 url in your browser."
odoo-bin --config 'config/odoo-src.conf' --dev=reload
fi
}
function restart() {
if test -z "$1"; then
docker-compose restart
fi
if [ "$1" = "db" ]; then
docker-compose restart db pgadmin
fi
if [ "$1" = "mail" ]; then
docker-compose restart mail
fi
}
function start-shell() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
locale
activate-venv
odoo-bin shell -d $1 --config 'config/odoo-src.conf' --no-http
}
function init-db() {
DATABSE=$1
DATABASE=${DATABSE:="odoo"}
locale
activate-venv
odoo-bin --init base -d $DATABASE --config 'config/odoo-src.conf' --stop-after-init --no-http
}
function odoo-cloc() {
DATABSE=$1
DATABASE=${DATABSE:="odoo"}
locale
activate-venv
odoo-bin cloc -d $DATABASE --config 'config/odoo-src.conf' --stop-after-init --no-http
}
function lint-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
activate-venv
pylint --load-plugins=pylint_odoo -d all -e odoolint $1
}
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
locale
activate-venv
odoo-bin -d $1 -u $2 --config 'config/odoo-src.conf' --stop-after-init --no-http
}
function install-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
if test -z "$2"; then echo "\$2 is empty"; exit; fi
locale
activate-venv
odoo-bin -d $1 -i $2 --config 'config/odoo-src.conf' --stop-after-init --no-http
}
function remove-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
if test -z "$2"; then echo "\$2 is empty"; exit; fi
locale
activate-venv
echo "self.env['ir.module.module'].search([('name', '=', '$2')]).button_immediate_uninstall()" |
odoo-bin shell -d $1 --config 'config/odoo-src.conf' --no-http
}
function create-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
MODULE_NAME=$(basename "$1")
PARENT_DIR=$(dirname "$1")
locale
activate-venv
echo "Scaffolding module $MODULE_NAME in $PARENT_DIR ..."
odoo-bin scaffold "$MODULE_NAME" "$PARENT_DIR" -t template/ms_custom_module
}
function drop-db() {
DATABSE=$1
DATABASE=${DATABSE:="odoo"}
psql postgres://odoo:odoo@localhost:5432/postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$DATABASE';"
psql postgres://odoo:odoo@localhost:5432/postgres -c "DROP DATABASE $DATABASE;"
}
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 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
# Reset enterprise
cd enterprise
git checkout .
cd ..
# Checkout branch
git checkout $1
# Reset submodules
git submodule update --init
git submodule foreach git checkout $1
# Sync files from last branch
git checkout $GIT_BRANCH README.md task task.md scripts snippets template data .vuepress package.json package-lock.json .gitignore .vercelignore config
}
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 $VERSION to tmp folder"
MODULE_NAME="$MODULE-$VERSION"
MODULE_PATH="tmp/$MODULE_NAME"
mkdir -p "$MODULE_PATH"
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"
cd tmp
zip -q -r $MODULE_NAME.zip $MODULE_NAME
cd ..
}
function clear-filestore() {
echo "Remove directory ~/.local/share/Odoo/filestore/$1"
rm -rf ~/.local/share/Odoo/filestore/$1
}
function init-odoo-env() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
echo "Init env file: .env.$1"
echo "#ODOO_URL=" > .env.$1
echo "ODOO_DATABASE=" >> .env.$1
echo "ODOO_USERNAME=" >> .env.$1
echo "ODOO_PASSWORD=" >> .env.$1
cat .env.$1
}
function disable-mailserver() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
activate-venv
load-env $1
scripts/odooctl --model 'ir.mail_server' --field 'active' --value False
scripts/odooctl --model 'fetchmail.server' --field 'active' --value False
}
function update-odoo-view() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
if test -z "$2"; then echo "\$2 is empty"; exit; fi
# Generate view name from filename
FILE=$(basename $2)
NAME="mint_system.${FILE%.xml}"
activate-venv
load-env $1
scripts/odooctl --model 'ir.ui.view' --domain "['name', '=', '$NAME']" --field 'arch_base' --value "'''$(cat $2)'''"
}
function update-app-list() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
locale
activate-venv
echo "env['ir.module.module'].update_list()" | odoo-bin shell -d $1 --config 'config/odoo-src.conf' --no-http
}
function init-next-env() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
echo "Init env file: .env.$1"
echo "NEXTCLOUD_URL=" > .env.$1
echo "NEXTCLOUD_USERNAME=" >> .env.$1
echo "NEXTCLOUD_PASSWORD=" >> .env.$1
cat .env.$1
}
function upload-module() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
if test -z "$2"; then echo "\$1 is empty"; exit; fi
zip-module $2
# Get path to zip file and upload url
FILE_PATH="tmp/$MODULE_NAME.zip"
pwd
load-env $1
NEXTCLOUD_UPLOAD_URL="$NEXTCLOUD_URL/remote.php/dav/files/$NEXTCLOUD_USERNAME/Odoo-Apps/"
# Upload zip file
curl -u "$NEXTCLOUD_USERNAME:$NEXTCLOUD_PASSWORD" -T "$FILE_PATH" "$NEXTCLOUD_UPLOAD_URL"
echo "File $FILE_PATH uploaded to $NEXTCLOUD_UPLOAD_URL."
}
function save-config() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
locale
activate-venv
odoo-bin -s -d $1 --config 'config/odoo-src.conf' --stop-after-init --no-http
}
case "$1" in
disable-auto-install)
disable-auto-install
;;
save-config)
save-config $2
;;
checkout)
checkout $2
;;
start)
start $2
;;
restart)
restart $2
;;
stop)
docker-compose stop
;;
kill)
docker-compose down -v
;;
logs)
docker logs odoo -f
;;
init-venv)
init-venv
;;
install-odoo-scripts)
install-odoo-scripts
;;
install-src)
install-src
;;
init-db)
init-db $2
;;
start-shell)
start-shell $2
;;
update-module)
update-module $2 $3
;;
create-module)
create-module $2
;;
drop-db)
drop-db $2
;;
send-support-mail)
send-support-mail
;;
clear-assets)
clear-assets $2
;;
odoo-cloc)
odoo-cloc $2
;;
convert-database)
convert-database $2
;;
install-module)
install-module $2 $3
;;
remove-module)
remove-module $2 $3
;;
release-module)
release-module $2
;;
lint-module)
lint-module $2
;;
zip-module)
zip-module $2
;;
clear-filestore)
clear-filestore $2
;;
init-odoo-env)
init-odoo-env $2
;;
disable-mailserver)
disable-mailserver $2 $3
;;
update-odoo-view)
update-odoo-view $2 $3
;;
update-app-list)
update-app-list $2
;;
init-next-env)
init-next-env $2
;;
upload-module)
upload-module $2 $3
;;
*)
help task
exit 1
;;
esac