Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Add a way to uninstall module automatically (via start entrypoint) #6

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/odoo/scripts/module_to_uninstall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Fill the variable MODULE LIST with the module you want to uninstall
# Exemple : MODULE_LIST = ["custom_all"]
# or leave an empty list
# The modules will be uninstalled by start entrypoint script
MODULE_LIST = []
if MODULE_LIST:
print(str(MODULE_LIST).replace("[", "(").replace("]", ")"))
44 changes: 44 additions & 0 deletions src/odoo/start-entrypoint.d/005_click_odoo_uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

if [ "$( psql -tAc "SELECT 1 FROM pg_database WHERE datname='$DB_NAME'" )" != '1' ]
then
echo "Database $DB_NAME does not exist, ignoring script"
exit 0
fi

if [ "$( psql $DB_NAME -tAc "SELECT 1 FROM pg_tables WHERE tablename='ir_config_parameter'" )" != '1' ]
then
echo "Database $DB_NAME not initialized, ignoring script"
exit 0
fi

DB_INCOMPATIBLE=$(python -c "from odoo import service; print(len(service.db.list_db_incompatible(('$DB_NAME',))))")
if [ $DB_INCOMPATIBLE = 1 ]
then
echo "Database $DB_NAME has a different major odoo version than the code, ignoring script"
exit 0
fi

PATH_MODULE_LIST=/odoo/scripts/module_to_uninstall.py
if [ ! -f $PATH_MODULE_LIST ]
then
echo "$PATH_MODULE_LIST does not exists : skip module uninstallation"
exit 0
fi

TO_UNINSTALL_LIST=$(python $PATH_MODULE_LIST)
if [ -z "${TO_UNINSTALL_LIST}" ]
then
echo "No modules listed as to uninstall"
exit 0
fi

TO_UNINSTALL_REAL=$( psql $DB_NAME -tAc "SELECT string_agg(name, ',') FROM ir_module_module WHERE name in $TO_UNINSTALL_LIST AND state in ('installed', 'to upgrade', 'to remove');" )

if [ -z "${TO_UNINSTALL_REAL}" ]
then
echo "Nothing to uninstall"
exit 0
fi

click-odoo-uninstall -m $TO_UNINSTALL_REAL