1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/libreerp_ynh.git synced 2024-09-03 19:36:13 +02:00

Merge pull request #42 from moshchot/update_oca_and_gitaggregate

[ADD] config panel for managing custom code, config file
This commit is contained in:
Alexandre Aubin 2023-11-14 19:04:39 +01:00 committed by GitHub
commit f967c00c74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 147 additions and 9 deletions

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/odoo/odoo/archive/f5ffcf7feec5526a483f8ddd240648c084351008.tar.gz SOURCE_URL=https://github.com/odoo/odoo/archive/2a88076c1d1df4920bfd139c94862a894d8ef3bc.tar.gz
SOURCE_SUM=f9d257058bb7075c2f0b75022fb2ec363ddeed27e3f1a55110ed08dfbee2227b SOURCE_SUM=39d23f01d9a095d75460829acfd53b74bcfc273a074d6eae163eedcaeeeb58c7
SOURCE_FILENAME=odoo-16.tar.gz SOURCE_FILENAME=odoo-16.tar.gz
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/OCA/OCB/archive/f5ffcf7feec5526a483f8ddd240648c084351008.tar.gz SOURCE_URL=https://github.com/OCA/OCB/archive/9d5ff52da5ec65a21a00a46e21783a2c6188dd80.tar.gz
SOURCE_SUM=bf972341c69e5f720162f3d9fa8a93d08ddb9f018c8aea5c4f5d7915c4275c5c SOURCE_SUM=3c3a95ec627e3807c85b0b2fd13a484b0b990426efb4905681aaee8768386e39
SOURCE_FILENAME=oca-16.tar.gz SOURCE_FILENAME=oca-16.tar.gz
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum

36
config_panel.toml Normal file
View file

@ -0,0 +1,36 @@
version = "1.0"
[custom_code]
name = "Manage custom code"
[custom_code.components]
[custom_code.components.custom_repo]
ask = "Fill in your custom repo"
type = "url"
bind = "null"
help = """\
It is expected to contain one or more addons, and possibly a [repos.yml](https://github.com/acsone/git-aggregator#configuration-file) and/or a [requirements.txt](https://pip.pypa.io/en/stable/reference/requirements-file-format) which will be installed for this instance when you click 'Update custom code' below.\
"""
[custom_code.components.custom_branch]
ask = "Fill in the branch to use"
type = "string"
help = "You should use the repo's main branch for your production instance, and some other branch for testing that you regularly merge into the main branch. Leave empty if unsure"
bind = "null"
visible = "custom_repo"
[custom_code.components.update_code]
ask = "Update custom code"
type = "button"
help = "This will pull your custom code, run gitaggregate if there's a repos.yml file, install/update requirements.txt, and run a database update if you have the [module_auto_update](https://apps.odoo.com/apps/modules/15.0/module_auto_update) module available"
[config_file]
name = "Edit the odoo config file"
services = ["__APP__"]
[config_file.components]
[config_file.components.config_file]
type = "text"
bind = "/etc/__APP__/main.conf"

View file

@ -6,14 +6,14 @@
"en": "Suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...)", "en": "Suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...)",
"fr": "Une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats...)" "fr": "Une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats...)"
}, },
"version": "16.0~ynh1", "version": "16.0~ynh2",
"url": "https://odoo.com", "url": "https://odoo.com",
"upstream": { "upstream": {
"license": "LGPL-3.0-only", "license": "LGPL-3.0-only",
"website": "https://odoo.com", "website": "https://odoo.com",
"demo": "https://www.odoo.com/trial", "demo": "https://www.odoo.com/trial",
"admindoc": "https://www.odoo.com/documentation/15.0/administration.html", "admindoc": "https://www.odoo.com/documentation/16.0/administration.html",
"userdoc": "https://www.odoo.com/documentation/15.0/applications.html", "userdoc": "https://www.odoo.com/documentation/16.0/applications.html",
"code": "https://github.com/odoo/odoo" "code": "https://github.com/odoo/odoo"
}, },
"license": "LGPL-3.0-only", "license": "LGPL-3.0-only",
@ -52,8 +52,8 @@
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"ask": { "ask": {
"en": "Do you want to setup OCA instead of LibreERP? (not yet implemented)", "en": "Do you want to setup OCA instead of LibreERP?",
"fr": "Désirez vous installer OCA à la place des sources de LibreERP (pas encore implémenté)" "fr": "Désirez vous installer OCA à la place des sources de LibreERP"
} }
}, },
{ {

102
scripts/config Executable file
View file

@ -0,0 +1,102 @@
#!/bin/bash
source /usr/share/yunohost/helpers
ynh_abort_if_errors
CUSTOM_ADDONS=$final_path/custom-addons
VENV=$final_path/venv
CUSTOM_REPO=$CUSTOM_ADDONS/custom-repo
REPOS_YML=$CUSTOM_REPO/repos.yml
REQUIREMENTS_TXT=$CUSTOM_REPO/requirements.txt
_setup_git() {
pushd $CUSTOM_ADDONS>/dev/null
ynh_exec_as $app git config --global user.email $app@$(hostname)
ynh_exec_as $app git config --global user.name $app
ynh_exec_as $app git config --global init.defaultBranch main
ynh_exec_as $app git config --global pull.rebase false
popd>/dev/null
}
get__custom_repo() {
_setup_git
if [ -d $CUSTOM_REPO ]; then
echo '"'$(ynh_exec_as $app git -C $CUSTOM_REPO remote get-url origin)'"'
fi
}
get__custom_branch() {
_setup_git
if [ -d $CUSTOM_REPO ]; then
echo '"'$(ynh_exec_as $app git -C $CUSTOM_REPO rev-parse --abbrev-ref HEAD)'"'
fi
}
run__update_code() {
_setup_git
if [ -d $CUSTOM_REPO ]; then
ynh_script_progression --message="Updating custom code"
if [ -z "$custom_repo" ]; then
rm -rf $CUSTOM_REPO
else
pushd $CUSTOM_REPO
if [ ! -z "$custom_branch" ]; then
ynh_exec_as $app git -C $CUSTOM_REPO fetch origin $custom_branch
ynh_exec_as $app git -C $CUSTOM_REPO checkout $custom_branch
fi
ynh_exec_as $app git -C $CUSTOM_REPO reset --hard
ynh_exec_as $app git -C $CUSTOM_REPO pull -X theirs
popd
fi
else
ynh_script_progression --message="Installing custom code from $custom_repo"
pushd $CUSTOM_ADDONS
if [ ! -z "$custom_repo" ]; then
if [ ! -z "$custom_branch" ]; then
CUSTOM_BRANCH="-b $custom_branch"
else
CUSTOM_BRANCH=""
fi
ynh_exec_as $app git clone $custom_repo $CUSTOM_REPO $CUSTOM_BRANCH
fi
popd
fi
if [ ! -f "$REPOS_YML" ]; then
ynh_print_warn --message="Could not find a repos.yml file in $CUSTOM_REPO"
else
ynh_script_progression --message="Resetting repos and running gitaggregate"
pushd $CUSTOM_ADDONS
for GITDIR in $(find $CUSTOM_ADDONS -name .git); do
ynh_exec_as $app git -C $(dirname $GITDIR) reset --hard
done
ynh_exec_as $app $VENV/bin/pip3 install -U git-aggregator
ynh_exec_as $app $VENV/bin/gitaggregate --force --no-color -c $REPOS_YML
popd
fi
pushd $CUSTOM_ADDONS
# link addons to custom-addons
for MANIFEST in $(find $CUSTOM_ADDONS -name __manifest__.py); do
ynh_exec_as $app ln -rsnf $(dirname $MANIFEST)
done
find $CUSTOM_ADDONS -maxdepth 1 -xtype l -delete
popd
if [ -f $REQUIREMENTS_TXT ]; then
ynh_exec_as $app $VENV/bin/pip3 install -Ur $CUSTOM_REPO/requirements.txt
fi
ynh_script_progression --message="Updating odoo addons and restarting the service"
sudo -u $app $VENV/bin/python $final_path/libreerp/odoo-bin shell -d $app -c /etc/$app/main.conf --logfile /proc/self/fd/1 <<ODOODOC
if hasattr(self.env['ir.module.module'], 'upgrade_changed_checksum_shell'):
self.env['ir.module.module'].upgrade_changed_checksum_shell()
else:
self.env['ir.module.module'].update_list()
auto_update = self.env['ir.module.module'].search([('name', '=', 'module_auto_update')])
if not auto_update:
print('Unable to install module_auto_update')
else:
if auto_update.state != 'installed':
auto_update.button_immediate_install()
self.env['ir.module.module'].upgrade_changed_checksum()
ODOODOC
sudo systemctl restart $app
}
ynh_app_config_run $1