diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..bf4b748 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,39 @@ +version = "1.0" + +[custom_code] +name = "Manage custom code" + + [custom_code.components] + name = "Custom code" + + [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] + name = "Config file" + + [config_file.components.config_file] + help = "When you change this, you need to restart your app" + type = "text" + bind = "/etc/__APP__/main.conf" diff --git a/scripts/config b/scripts/config new file mode 100755 index 0000000..a81b932 --- /dev/null +++ b/scripts/config @@ -0,0 +1,101 @@ +#!/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 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 <