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

103 lines
3.4 KiB
Text
Raw Normal View History

2023-03-22 14:28:10 +01:00
#!/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
2023-07-28 11:36:38 +02:00
ynh_exec_as $app git -C $CUSTOM_REPO fetch origin $custom_branch
2023-03-22 14:28:10 +01:00
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