mirror of
https://github.com/YunoHost-Apps/libreerp_ynh.git
synced 2024-09-03 19:36:13 +02:00
Apply last example_ynh
This commit is contained in:
parent
8af8c9e096
commit
d854c545f7
10 changed files with 764 additions and 409 deletions
|
@ -1,10 +1,18 @@
|
||||||
#
|
#!/bin/bash
|
||||||
# Common variables
|
|
||||||
#
|
#=================================================
|
||||||
|
# COMMON VARIABLES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
export appname="libreerp"
|
export appname="libreerp"
|
||||||
export FORKNAME="odoo"
|
export FORKNAME="odoo"
|
||||||
DEPENDENCIES="curl postgresql xfonts-75dpi xfonts-base wkhtmltopdf node-less python3-dev gcc libldap2-dev libssl-dev libsasl2-dev python3-pip python3-dev python3-venv python3-wheel libxslt-dev libzip-dev python3-setuptools python-virtualenv python-wheel python-setuptools libjpeg-dev zlib1g-dev virtualenv libfreetype6-dev"
|
|
||||||
|
# dependencies used by the app
|
||||||
|
pkg_dependencies="curl postgresql xfonts-75dpi xfonts-base wkhtmltopdf node-less python3-dev gcc libldap2-dev libssl-dev libsasl2-dev python3-pip python3-dev python3-venv python3-wheel libxslt-dev libzip-dev python3-setuptools python-virtualenv python-wheel python-setuptools libjpeg-dev zlib1g-dev virtualenv libfreetype6-dev"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PERSONAL HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
function debranding() {
|
function debranding() {
|
||||||
# Remove Odoo references to avoid trademark issue
|
# Remove Odoo references to avoid trademark issue
|
||||||
|
@ -24,6 +32,7 @@ function debranding() {
|
||||||
cp ../conf/favicon.ico $final_path/$appname/addons/web/static/src/img/favicon.ico
|
cp ../conf/favicon.ico $final_path/$appname/addons/web/static/src/img/favicon.ico
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_files() {
|
function setup_files() {
|
||||||
|
|
||||||
if [[ $oca -eq 0 ]]; then
|
if [[ $oca -eq 0 ]]; then
|
||||||
|
@ -43,64 +52,162 @@ function setup_files() {
|
||||||
|
|
||||||
# Autoinstall the LDAP auth module
|
# Autoinstall the LDAP auth module
|
||||||
if ls $final_path/$appname/$FORKNAME-bin > /dev/null ; then
|
if ls $final_path/$appname/$FORKNAME-bin > /dev/null ; then
|
||||||
ynh_replace_string "^{$" "{'auto_install': True," ${final_path}/$appname/addons/auth_ldap/__manifest__.py
|
ynh_replace_string "^{$" "{'auto_install': True," $final_path/$appname/addons/auth_ldap/__manifest__.py
|
||||||
else
|
else
|
||||||
ynh_replace_string "'auto_install': False" "'auto_install': True" ${final_path}/$appname/addons/auth_ldap/__openerp__.py
|
ynh_replace_string "'auto_install': False" "'auto_install': True" $final_path/$appname/addons/auth_ldap/__openerp__.py
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
# Install dependencies
|
|
||||||
function install_dependencies() {
|
|
||||||
ynh_add_swap 1024
|
|
||||||
ynh_install_app_dependencies $DEPENDENCIES
|
|
||||||
|
|
||||||
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
|
function setup_database() {
|
||||||
# The debian package has a bug so we deploy a more recent version
|
export preinstall=1
|
||||||
if [ -f '../manifest.json' ] ; then
|
ynh_configure server.conf $conf_file
|
||||||
ynh_setup_source /usr/
|
chown $app:$app $conf_file
|
||||||
else
|
# Load translation
|
||||||
OLD_YNH_CWD=$YNH_CWD
|
#param=" --without-demo True --addons-path $final_path/$appname/addons --db_user $app --db_password $db_pass --db_host 127.0.0.1 --db_port 5432 --db-filter '^$app\$' -d $app "
|
||||||
YNH_CWD=$YNH_CWD/../settings/conf
|
param=" -c $conf_file -d $app "
|
||||||
ynh_setup_source /usr/
|
sudo -u $app $bin_file -c $conf_file --stop-after-init -i base -d $app
|
||||||
YNH_CWD=$OLD_YNH_CWD
|
sudo -u $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app
|
||||||
fi
|
sudo -u $app $bin_file -c $conf_file --stop-after-init --load-language $lang -d $app
|
||||||
|
# Configure language, timezone and ldap
|
||||||
|
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
|
||||||
|
"
|
||||||
|
self.env['res.users'].search([['login', '=', 'admin']])[0].write({'password': '$admin_password'})
|
||||||
|
self.env.cr.commit()
|
||||||
|
"
|
||||||
|
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
|
||||||
|
"
|
||||||
|
self.write({'tz':'$tz','lang':'$lang'})
|
||||||
|
self.env.cr.commit()
|
||||||
|
"
|
||||||
|
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
|
||||||
|
"
|
||||||
|
template=env['res.users'].create({
|
||||||
|
'login':'template',
|
||||||
|
'password':'',
|
||||||
|
'name':'template',
|
||||||
|
'email':'template',
|
||||||
|
'sel_groups_9_10':9,
|
||||||
|
'tz':'$tz',
|
||||||
|
'lang':'$lang'
|
||||||
|
})
|
||||||
|
self.env.cr.commit()
|
||||||
|
self.company_id.ldaps.create({
|
||||||
|
'ldap_server':'localhost',
|
||||||
|
'ldap_server_port':389,
|
||||||
|
'ldap_base':'ou=users, dc=yunohost,dc=org',
|
||||||
|
'ldap_filter':'uid=%s',
|
||||||
|
'user':template.id,
|
||||||
|
'company':self.company_id.id
|
||||||
|
})
|
||||||
|
self.env.cr.commit()
|
||||||
|
"
|
||||||
|
export preinstall=0
|
||||||
|
ynh_configure server.conf $conf_file
|
||||||
|
chown $app:$app $conf_file
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_sso_access () {
|
||||||
|
ynh_app_setting_set $app unprotected_uris "/"
|
||||||
|
|
||||||
|
if [[ $is_public -eq 0 ]]; then
|
||||||
|
ynh_app_setting_set $app protected_uris "$1"
|
||||||
fi
|
fi
|
||||||
pushd $final_path
|
sudo yunohost app ssowatconf
|
||||||
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
|
}
|
||||||
python3 -m venv venv
|
|
||||||
venv/bin/pip3 install wheel
|
ynh_configure () {
|
||||||
venv/bin/pip3 install -r $appname/requirements.txt
|
local TEMPLATE=$1
|
||||||
|
local DEST=$2
|
||||||
|
content=""
|
||||||
|
content2=""
|
||||||
|
content3=""
|
||||||
|
if [[ $preinstall == '1' ]]
|
||||||
|
then
|
||||||
|
content="dbfilter = $db_name"
|
||||||
|
else
|
||||||
|
content="db_name = $db_name"
|
||||||
|
if [[ $app_version > 9 ]]
|
||||||
|
then
|
||||||
|
content2="dbfilter = False"
|
||||||
|
fi
|
||||||
|
content3="list_db = False"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$(dirname $DEST)"
|
||||||
|
if [ -f '../manifest.json' ] ; then
|
||||||
|
ynh_add_config "${YNH_CWD}/../conf/$TEMPLATE" "$DEST"
|
||||||
else
|
else
|
||||||
virtualenv venv
|
ynh_add_config "${YNH_CWD}/../settings/conf/$TEMPLATE" "$DEST"
|
||||||
venv/bin/pip install wheel
|
|
||||||
venv/bin/pip install -r $appname/requirements.txt
|
|
||||||
fi
|
fi
|
||||||
popd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Argument $1 is the size of the swap in MiB
|
||||||
|
ynh_add_swap () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
declare -Ar args_array=( [s]=size= )
|
||||||
|
local size
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
# Add services
|
local swap_max_size=$(( $size * 1024 ))
|
||||||
function add_services() {
|
|
||||||
if ! grep "^postgresql:$" /etc/yunohost/services.yml; then
|
|
||||||
yunohost service add postgresql
|
|
||||||
fi
|
|
||||||
ynh_configure app.service /etc/systemd/system/$app.service
|
|
||||||
systemctl daemon-reload
|
|
||||||
|
|
||||||
yunohost service add $app --log /var/log/$app.log
|
local free_space=$(df --output=avail / | sed 1d)
|
||||||
yunohost service stop $app
|
# Because we don't want to fill the disk with a swap file, divide by 2 the available space.
|
||||||
yunohost service start $app
|
local usable_space=$(( $free_space / 2 ))
|
||||||
yunohost service enable $app
|
|
||||||
|
# Compare the available space with the size of the swap.
|
||||||
|
# And set a acceptable size from the request
|
||||||
|
if [ $usable_space -ge $swap_max_size ]
|
||||||
|
then
|
||||||
|
local swap_size=$swap_max_size
|
||||||
|
elif [ $usable_space -ge $(( $swap_max_size / 2 )) ]
|
||||||
|
then
|
||||||
|
local swap_size=$(( $swap_max_size / 2 ))
|
||||||
|
elif [ $usable_space -ge $(( $swap_max_size / 3 )) ]
|
||||||
|
then
|
||||||
|
local swap_size=$(( $swap_max_size / 3 ))
|
||||||
|
elif [ $usable_space -ge $(( $swap_max_size / 4 )) ]
|
||||||
|
then
|
||||||
|
local swap_size=$(( $swap_max_size / 4 ))
|
||||||
|
else
|
||||||
|
echo "Not enough space left for a swap file" >&2
|
||||||
|
local swap_size=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If there's enough space for a swap, and no existing swap here
|
||||||
|
if [ $swap_size -ne 0 ] && [ ! -e /swap ]
|
||||||
|
then
|
||||||
|
# Preallocate space for the swap file
|
||||||
|
fallocate -l ${swap_size}K /swap
|
||||||
|
chmod 0600 /swap
|
||||||
|
# Create the swap
|
||||||
|
mkswap /swap
|
||||||
|
# And activate it
|
||||||
|
swapon /swap
|
||||||
|
# Then add an entry in fstab to load this swap at each boot.
|
||||||
|
echo -e "/swap swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function ssowat_and_restart() {
|
ynh_del_swap () {
|
||||||
# Restart odoo service
|
# If there a swap at this place
|
||||||
service $app restart
|
if [ -e /swap ]
|
||||||
|
then
|
||||||
# Configure SSOWat
|
# Clean the fstab
|
||||||
ynh_sso_access "/web/database/manager"
|
sed -i "/#Swap added by $app/d" /etc/fstab
|
||||||
|
# Desactive the swap file
|
||||||
# Reload services
|
swapoff /swap
|
||||||
service nginx reload
|
# And remove it
|
||||||
|
rm /swap
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# EXPERIMENTAL HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# FUTURE OFFICIAL HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
|
@ -1,199 +0,0 @@
|
||||||
ynh_check_var () {
|
|
||||||
test -n "$1" || ynh_die "$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_export () {
|
|
||||||
local ynh_arg=""
|
|
||||||
for var in $@;
|
|
||||||
do
|
|
||||||
ynh_arg=$(echo $var | awk '{print toupper($0)}')
|
|
||||||
ynh_arg="YNH_APP_ARG_$ynh_arg"
|
|
||||||
export $var=${!ynh_arg}
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Save listed var in YunoHost app settings
|
|
||||||
# usage: ynh_save_args VARNAME1 [VARNAME2 [...]]
|
|
||||||
ynh_save_args () {
|
|
||||||
for var in $@;
|
|
||||||
do
|
|
||||||
ynh_app_setting_set $app $var ${!var}
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_sso_access () {
|
|
||||||
ynh_app_setting_set $app unprotected_uris "/"
|
|
||||||
|
|
||||||
if [[ $is_public -eq 0 ]]; then
|
|
||||||
ynh_app_setting_set $app protected_uris "$1"
|
|
||||||
fi
|
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
}
|
|
||||||
ynh_configure () {
|
|
||||||
local TEMPLATE=$1
|
|
||||||
local DEST=$2
|
|
||||||
content=""
|
|
||||||
content2=""
|
|
||||||
content3=""
|
|
||||||
if [[ $preinstall == '1' ]]
|
|
||||||
then
|
|
||||||
content="dbfilter = $db_name"
|
|
||||||
else
|
|
||||||
content="db_name = $db_name"
|
|
||||||
if [[ $app_version > 9 ]]
|
|
||||||
then
|
|
||||||
content2="dbfilter = False"
|
|
||||||
fi
|
|
||||||
content3="list_db = False"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "$(dirname $DEST)"
|
|
||||||
if [ -f '../manifest.json' ] ; then
|
|
||||||
ynh_add_config "${YNH_CWD}/../conf/$TEMPLATE.j2" "$DEST"
|
|
||||||
else
|
|
||||||
ynh_add_config "${YNH_CWD}/../settings/conf/$TEMPLATE.j2" "$DEST"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_configure_nginx () {
|
|
||||||
ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
sudo service nginx reload
|
|
||||||
}
|
|
||||||
|
|
||||||
# Upgrade
|
|
||||||
ynh_read_json () {
|
|
||||||
python3 -c "import sys, json;print(json.load(open('$1'))['$2'])"
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_read_manifest () {
|
|
||||||
if [ -f '../manifest.json' ] ; then
|
|
||||||
ynh_read_json '../manifest.json' "$1"
|
|
||||||
else
|
|
||||||
ynh_read_json '../settings/manifest.json' "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
is_stretch () {
|
|
||||||
if [ "$(ynh_get_debian_release)" == "stretch" ]
|
|
||||||
then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
is_jessie () {
|
|
||||||
if [ "$(ynh_get_debian_release)" == "jessie" ]
|
|
||||||
then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Argument $1 is the size of the swap in MiB
|
|
||||||
ynh_add_swap () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
declare -Ar args_array=( [s]=size= )
|
|
||||||
local size
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
local swap_max_size=$(( $size * 1024 ))
|
|
||||||
|
|
||||||
local free_space=$(df --output=avail / | sed 1d)
|
|
||||||
# Because we don't want to fill the disk with a swap file, divide by 2 the available space.
|
|
||||||
local usable_space=$(( $free_space / 2 ))
|
|
||||||
|
|
||||||
# Compare the available space with the size of the swap.
|
|
||||||
# And set a acceptable size from the request
|
|
||||||
if [ $usable_space -ge $swap_max_size ]
|
|
||||||
then
|
|
||||||
local swap_size=$swap_max_size
|
|
||||||
elif [ $usable_space -ge $(( $swap_max_size / 2 )) ]
|
|
||||||
then
|
|
||||||
local swap_size=$(( $swap_max_size / 2 ))
|
|
||||||
elif [ $usable_space -ge $(( $swap_max_size / 3 )) ]
|
|
||||||
then
|
|
||||||
local swap_size=$(( $swap_max_size / 3 ))
|
|
||||||
elif [ $usable_space -ge $(( $swap_max_size / 4 )) ]
|
|
||||||
then
|
|
||||||
local swap_size=$(( $swap_max_size / 4 ))
|
|
||||||
else
|
|
||||||
echo "Not enough space left for a swap file" >&2
|
|
||||||
local swap_size=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If there's enough space for a swap, and no existing swap here
|
|
||||||
if [ $swap_size -ne 0 ] && [ ! -e /swap ]
|
|
||||||
then
|
|
||||||
# Preallocate space for the swap file
|
|
||||||
fallocate -l ${swap_size}K /swap
|
|
||||||
chmod 0600 /swap
|
|
||||||
# Create the swap
|
|
||||||
mkswap /swap
|
|
||||||
# And activate it
|
|
||||||
swapon /swap
|
|
||||||
# Then add an entry in fstab to load this swap at each boot.
|
|
||||||
echo -e "/swap swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_del_swap () {
|
|
||||||
# If there a swap at this place
|
|
||||||
if [ -e /swap ]
|
|
||||||
then
|
|
||||||
# Clean the fstab
|
|
||||||
sed -i "/#Swap added by $app/d" /etc/fstab
|
|
||||||
# Desactive the swap file
|
|
||||||
swapoff /swap
|
|
||||||
# And remove it
|
|
||||||
rm /swap
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Checks the app version to upgrade with the existing app version and returns:
|
|
||||||
# - UPGRADE_APP if the upstream app version has changed
|
|
||||||
# - UPGRADE_PACKAGE if only the YunoHost package has changed
|
|
||||||
#
|
|
||||||
## It stops the current script without error if the package is up-to-date
|
|
||||||
#
|
|
||||||
# This helper should be used to avoid an upgrade of an app, or the upstream part
|
|
||||||
# of it, when it's not needed
|
|
||||||
#
|
|
||||||
# To force an upgrade, even if the package is up to date,
|
|
||||||
# you have to set the variable YNH_FORCE_UPGRADE before.
|
|
||||||
# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
|
|
||||||
|
|
||||||
# usage: ynh_check_app_version_changed
|
|
||||||
ynh_check_app_version_changed () {
|
|
||||||
local force_upgrade=${YNH_FORCE_UPGRADE:-0}
|
|
||||||
local package_check=${PACKAGE_CHECK_EXEC:-0}
|
|
||||||
|
|
||||||
# By default, upstream app version has changed
|
|
||||||
local return_value="UPGRADE_APP"
|
|
||||||
|
|
||||||
local current_version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0)
|
|
||||||
local current_upstream_version="${current_version/~ynh*/}"
|
|
||||||
local update_version=$(ynh_read_manifest "version" || echo 1.0)
|
|
||||||
local update_upstream_version="${update_version/~ynh*/}"
|
|
||||||
|
|
||||||
if [ "$current_version" == "$update_version" ] ; then
|
|
||||||
# Complete versions are the same
|
|
||||||
if [ "$force_upgrade" != "0" ]
|
|
||||||
then
|
|
||||||
echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2
|
|
||||||
unset YNH_FORCE_UPGRADE
|
|
||||||
elif [ "$package_check" != "0" ]
|
|
||||||
then
|
|
||||||
echo "Upgrade forced for package check." >&2
|
|
||||||
else
|
|
||||||
ynh_die "Up-to-date, nothing to do" 0
|
|
||||||
fi
|
|
||||||
elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then
|
|
||||||
# Upstream versions are the same, only YunoHost package versions differ
|
|
||||||
return_value="UPGRADE_PACKAGE"
|
|
||||||
fi
|
|
||||||
echo $return_value
|
|
||||||
}
|
|
|
@ -1,31 +1,79 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
source /usr/share/yunohost/helpers
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
#source _future.sh
|
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
||||||
conf_file=$(ynh_app_setting_get "$app" conf_file)
|
|
||||||
|
|
||||||
# Backup sources & data
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
ynh_backup "${final_path}/$appname"
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
ynh_backup "${final_path}/custom-addons"
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
ynh_backup "${final_path}/.local"
|
conf_file=$(ynh_app_setting_get --app=$app --key=conf_file)
|
||||||
|
|
||||||
# Backup configuration
|
#=================================================
|
||||||
ynh_backup "$conf_file"
|
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Declaring files to be backed up..."
|
||||||
|
|
||||||
# Copy NGINX configuration
|
#=================================================
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Backup services
|
ynh_backup --src_path="$final_path/$appname"
|
||||||
ynh_backup "/etc/systemd/system/${app}.service"
|
ynh_backup --src_path="$final_path/custom-addons"
|
||||||
|
ynh_backup --src_path="$final_path/.local"
|
||||||
|
|
||||||
# Copy database
|
#=================================================
|
||||||
sudo su -c "pg_dump $app" postgres > ./dump.sql
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC BACKUP
|
||||||
|
#=================================================
|
||||||
|
# BACKUP SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup --src_path="/etc/systemd/system/$app.service"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP VARIOUS FILES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup --src_path="$conf_file"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE POSTGRESQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Backing up the PostgreSQL database..."
|
||||||
|
|
||||||
|
ynh_psql_dump_db --database="$db_name" > db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
||||||
|
|
261
scripts/install
261
scripts/install
|
@ -1,20 +1,41 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -eu
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
source _future.sh
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
# Arguments from manifest
|
#=================================================
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
ynh_export domain oca admin_password lang tz
|
#=================================================
|
||||||
export app_version=$YNH_APP_ARG_VERSION
|
|
||||||
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
|
path_url="/"
|
||||||
export is_public=0
|
export is_public=0
|
||||||
export final_path="/var/www/$app"
|
export app_version=$YNH_APP_ARG_VERSION
|
||||||
|
oca=$YNH_APP_ARG_OCA
|
||||||
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
||||||
|
lang=$YNH_APP_ARG_LANG
|
||||||
|
tz=$YNH_APP_ARG_TZ
|
||||||
|
|
||||||
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
export conf_file=/etc/$app/main.conf
|
export conf_file=/etc/$app/main.conf
|
||||||
|
export final_path=/var/www/$app
|
||||||
export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin"
|
export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin"
|
||||||
if [ "$app_version" = "9" ]; then
|
if [ "$app_version" = "9" ]; then
|
||||||
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
||||||
|
@ -22,79 +43,173 @@ fi
|
||||||
if [ "$app_version" = "8" ]; then
|
if [ "$app_version" = "8" ]; then
|
||||||
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
|
||||||
fi
|
fi
|
||||||
export db_name=$(ynh_sanitize_dbid $app)
|
|
||||||
export port=$(ynh_find_port 8069)
|
|
||||||
export port_chat=$(ynh_find_port 8072)
|
|
||||||
export preinstall=0
|
export preinstall=0
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
#=================================================
|
#=================================================
|
||||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
ynh_script_progression --message="Validating installation parameters..."
|
||||||
ynh_webpath_register $app $domain "/"
|
|
||||||
|
|
||||||
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||||
|
|
||||||
|
# Register (book) web path
|
||||||
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP THE APP BY MODIFYING THE SYSTEM
|
# STORE SETTINGS FROM MANIFEST
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Storing installation settings..."
|
||||||
|
|
||||||
function setup_database() {
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||||
export preinstall=1
|
ynh_app_setting_set --app=$app --key=app_version --value=$app_version
|
||||||
ynh_configure server.conf $conf_file
|
ynh_app_setting_set --app=$app --key=oca --value=$oca
|
||||||
chown $app:$app $conf_file
|
ynh_app_setting_set --app=$app --key=lang --value=$lang
|
||||||
# Load translation
|
ynh_app_setting_set --app=$app --key=tz --value=$tz
|
||||||
#param=" --without-demo True --addons-path $final_path/$appname/addons --db_user $app --db_password $db_pass --db_host 127.0.0.1 --db_port 5432 --db-filter '^$app\$' -d $app "
|
ynh_app_setting_set --app=$app --key=conf_file --value=$conf_file
|
||||||
param=" -c $conf_file -d $app "
|
|
||||||
sudo -u $app $bin_file -c $conf_file --stop-after-init -i base -d $app
|
#=================================================
|
||||||
sudo -u $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app
|
# STANDARD MODIFICATIONS
|
||||||
sudo -u $app $bin_file -c $conf_file --stop-after-init --load-language $lang -d $app
|
#=================================================
|
||||||
# Configure language, timezone and ldap
|
# FIND AND OPEN A PORT
|
||||||
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
|
#=================================================
|
||||||
"
|
ynh_script_progression --message="Finding an available port..."
|
||||||
self.env['res.users'].search([['login', '=', 'admin']])[0].write({'password': '$admin_password'})
|
|
||||||
self.env.cr.commit()
|
# Find an available port
|
||||||
"
|
port=$(ynh_find_port --port=8069)
|
||||||
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
||||||
"
|
|
||||||
self.write({'tz':'$tz','lang':'$lang'})
|
# Find an available port
|
||||||
self.env.cr.commit()
|
port_chat=$(ynh_find_port --port=8072)
|
||||||
"
|
ynh_app_setting_set --app=$app --key=port_chat --value=$port_chat
|
||||||
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
|
|
||||||
"
|
#=================================================
|
||||||
template=env['res.users'].create({
|
# INSTALL DEPENDENCIES
|
||||||
'login':'template',
|
#=================================================
|
||||||
'password':'',
|
ynh_script_progression --message="Installing dependencies..."
|
||||||
'name':'template',
|
|
||||||
'email':'template',
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
'sel_groups_9_10':9,
|
|
||||||
'tz':'$tz',
|
#=================================================
|
||||||
'lang':'$lang'
|
# CREATE DEDICATED USER
|
||||||
})
|
#=================================================
|
||||||
self.env.cr.commit()
|
ynh_script_progression --message="Configuring system user..."
|
||||||
self.company_id.ldaps.create({
|
|
||||||
'ldap_server':'localhost',
|
# Create a system user
|
||||||
'ldap_server_port':389,
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||||
'ldap_base':'ou=users, dc=yunohost,dc=org',
|
|
||||||
'ldap_filter':'uid=%s',
|
#=================================================
|
||||||
'user':template.id,
|
# CREATE A POSTGRESQL DATABASE
|
||||||
'company':self.company_id.id
|
#=================================================
|
||||||
})
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
||||||
self.env.cr.commit()
|
|
||||||
"
|
export db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||||
export preinstall=0
|
db_user=$db_name
|
||||||
ynh_configure server.conf $conf_file
|
|
||||||
chown $app:$app $conf_file
|
|
||||||
}
|
|
||||||
ynh_save_args domain app_version oca lang tz final_path conf_file db_name port port_chat
|
|
||||||
ynh_system_user_create -u $app -h $final_path
|
|
||||||
export db_pass=$(ynh_string_random)
|
export db_pass=$(ynh_string_random)
|
||||||
setup_files
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||||
install_dependencies
|
|
||||||
ynh_psql_test_if_first_run
|
|
||||||
ynh_psql_setup_db $db_name $db_name $db_pass
|
|
||||||
export db_pass=$(ynh_app_setting_get $app psqlpwd)
|
|
||||||
ynh_configure_nginx
|
|
||||||
add_services
|
|
||||||
setup_database
|
|
||||||
ssowat_and_restart
|
|
||||||
|
|
||||||
|
# Make sure that postgresql is installed and running
|
||||||
|
ynh_psql_test_if_first_run
|
||||||
|
|
||||||
|
# Create the database
|
||||||
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass
|
||||||
|
export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setting up source files..."
|
||||||
|
|
||||||
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||||
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
|
setup_files
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring NGINX web server..."
|
||||||
|
|
||||||
|
# Create a dedicated NGINX config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC SETUP
|
||||||
|
#=================================================
|
||||||
|
# BUILD APP
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Building $app..."
|
||||||
|
|
||||||
|
ynh_add_swap 1024
|
||||||
|
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
|
||||||
|
# The debian package has a bug so we deploy a more recent version
|
||||||
|
if [ -f '../manifest.json' ] ; then
|
||||||
|
ynh_setup_source /usr/
|
||||||
|
else
|
||||||
|
OLD_YNH_CWD=$YNH_CWD
|
||||||
|
YNH_CWD=$YNH_CWD/../settings/conf
|
||||||
|
ynh_setup_source /usr/
|
||||||
|
YNH_CWD=$OLD_YNH_CWD
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
pushd $final_path
|
||||||
|
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
|
||||||
|
python3 -m venv venv
|
||||||
|
venv/bin/pip3 install wheel
|
||||||
|
venv/bin/pip3 install -r $appname/requirements.txt
|
||||||
|
else
|
||||||
|
virtualenv venv
|
||||||
|
venv/bin/pip install wheel
|
||||||
|
venv/bin/pip install -r $appname/requirements.txt
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring a systemd service..."
|
||||||
|
|
||||||
|
# Create a dedicated systemd config
|
||||||
|
ynh_add_systemd_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setuping the database..."
|
||||||
|
|
||||||
|
setup_database
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||||
|
|
||||||
|
yunohost service add $app --log="/var/log/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Starting a systemd service..."
|
||||||
|
|
||||||
|
# Start a systemd service
|
||||||
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring permissions..."
|
||||||
|
|
||||||
|
ynh_sso_access "/web/database/manager"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading NGINX web server..."
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Installation of $app completed"
|
||||||
|
|
|
@ -1,29 +1,95 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -u
|
|
||||||
|
|
||||||
source /usr/share/yunohost/helpers
|
#=================================================
|
||||||
source _future.sh
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
|
db_user=$db_name
|
||||||
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
conf_file=$(ynh_app_setting_get --app=$app --key=conf_file)
|
||||||
|
|
||||||
# Retrieve app settings
|
#=================================================
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
# STANDARD REMOVE
|
||||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
#=================================================
|
||||||
conf_file=$(ynh_app_setting_get "$app" conf_file)
|
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
yunohost service stop $app
|
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
|
||||||
yunohost service remove $app
|
if ynh_exec_warn_less yunohost service status $app >/dev/null
|
||||||
ynh_psql_remove_db $app $app
|
then
|
||||||
|
ynh_script_progression --message="Removing $app service integration..."
|
||||||
|
yunohost service remove $app
|
||||||
|
fi
|
||||||
|
|
||||||
ynh_secure_remove "$final_path"
|
#=================================================
|
||||||
ynh_secure_remove "$conf_file"
|
# REMOVE THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing the MySQL database..."
|
||||||
|
|
||||||
ynh_remove_app_dependencies
|
# Remove a database if it exists, along with the associated user
|
||||||
|
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
|
||||||
|
|
||||||
ynh_system_user_delete $app
|
#=================================================
|
||||||
|
# REMOVE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing app main directory..."
|
||||||
|
|
||||||
|
# Remove the app directory securely
|
||||||
|
ynh_secure_remove --file="$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing NGINX web server configuration..."
|
||||||
|
|
||||||
|
# Remove the dedicated NGINX config
|
||||||
ynh_remove_nginx_config
|
ynh_remove_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing dependencies..."
|
||||||
|
|
||||||
|
# Remove metapackage and its dependencies
|
||||||
|
ynh_remove_app_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC REMOVE
|
||||||
|
#=================================================
|
||||||
|
# REMOVE VARIOUS FILES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing various files..."
|
||||||
|
|
||||||
|
ynh_secure_remove --file="$conf_file"
|
||||||
|
|
||||||
ynh_del_swap
|
ynh_del_swap
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing the dedicated system user..."
|
||||||
|
|
||||||
|
# Delete a system user
|
||||||
|
ynh_system_user_delete --username=$app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Removal of $app completed"
|
||||||
|
|
188
scripts/restore
188
scripts/restore
|
@ -1,23 +1,43 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eu
|
|
||||||
|
|
||||||
# Import helpers
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# GENERIC START
|
||||||
source ../settings/scripts/_future.sh
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
export domain=$(ynh_app_setting_get $app domain)
|
|
||||||
export app_version=$(ynh_app_setting_get $app app_version)
|
export domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
export oca=$(ynh_app_setting_get $app oca)
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
export port=$(ynh_app_setting_get $app port)
|
export app_version=$(ynh_app_setting_get --app=$app --key=app_version)
|
||||||
export port_chat=$(ynh_app_setting_get $app port_chat)
|
export oca=$(ynh_app_setting_get --app=$app --key=oca)
|
||||||
export db_name=$(ynh_app_setting_get $app db_name)
|
export port=$(ynh_app_setting_get --app=$app --key=port)
|
||||||
export db_pass=$(ynh_app_setting_get $app psqlpwd)
|
export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat)
|
||||||
export final_path=$(ynh_app_setting_get $app final_path)
|
export db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
export conf_file=$(ynh_app_setting_get $app conf_file)
|
db_user=$db_name
|
||||||
|
export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||||
|
export final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file)
|
||||||
export is_public=0
|
export is_public=0
|
||||||
export bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin"
|
export bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin"
|
||||||
if [ "$app_version" = "9" ]; then
|
if [ "$app_version" = "9" ]; then
|
||||||
|
@ -30,33 +50,133 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK IF THE APP CAN BE RESTORED
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_webpath_available "$domain" "/"
|
ynh_script_progression --message="Validating restoration parameters..."
|
||||||
|
|
||||||
|
test ! -d $final_path \
|
||||||
|
|| ynh_die --message="There is already a directory: $final_path "
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE APP BY MODIFYING THE SYSTEM
|
# STANDARD RESTORATION STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
# Restore files
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
function restore_files () {
|
#=================================================
|
||||||
ynh_restore
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
||||||
chown -R $app:$app $final_path
|
|
||||||
chown $app:$app $conf_file
|
|
||||||
touch /var/log/$app.log
|
|
||||||
chown $app:$app /var/log/$app.log
|
|
||||||
}
|
|
||||||
|
|
||||||
# Restore database
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
function restore_database () {
|
|
||||||
su -c "psql $app" postgres < ./dump.sql
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_system_user_create $app $final_path
|
#=================================================
|
||||||
restore_files
|
# RECREATE THE DEDICATED USER
|
||||||
install_dependencies
|
#=================================================
|
||||||
|
ynh_script_progression --message="Recreating the dedicated system user..."
|
||||||
|
|
||||||
|
# Create the dedicated user (if not existing)
|
||||||
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring the app main directory..."
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="$final_path/$appname"
|
||||||
|
ynh_restore_file --origin_path="$final_path/custom-addons"
|
||||||
|
ynh_restore_file --origin_path="$final_path/.local"
|
||||||
|
|
||||||
|
chown -R $app:$app "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC RESTORATION
|
||||||
|
#=================================================
|
||||||
|
# REINSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reinstalling dependencies..."
|
||||||
|
|
||||||
|
# Define and install dependencies
|
||||||
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BUILD APP
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Building $app..."
|
||||||
|
|
||||||
|
ynh_add_swap 1024
|
||||||
|
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
|
||||||
|
# The debian package has a bug so we deploy a more recent version
|
||||||
|
if [ -f '../manifest.json' ] ; then
|
||||||
|
ynh_setup_source /usr/
|
||||||
|
else
|
||||||
|
OLD_YNH_CWD=$YNH_CWD
|
||||||
|
YNH_CWD=$YNH_CWD/../settings/conf
|
||||||
|
ynh_setup_source /usr/
|
||||||
|
YNH_CWD=$OLD_YNH_CWD
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
pushd $final_path
|
||||||
|
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
|
||||||
|
python3 -m venv venv
|
||||||
|
venv/bin/pip3 install wheel
|
||||||
|
venv/bin/pip3 install -r $appname/requirements.txt
|
||||||
|
else
|
||||||
|
virtualenv venv
|
||||||
|
venv/bin/pip install wheel
|
||||||
|
venv/bin/pip install -r $appname/requirements.txt
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE POSTGRESQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring the PostgreSQL database..."
|
||||||
|
|
||||||
|
# Make sure that postgresql is installed and running
|
||||||
ynh_psql_test_if_first_run
|
ynh_psql_test_if_first_run
|
||||||
ynh_psql_setup_db $db_name $db_name $db_pass
|
|
||||||
add_services
|
|
||||||
restore_database
|
|
||||||
ssowat_and_restart
|
|
||||||
|
|
||||||
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass
|
||||||
|
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE VARIOUS FILES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring various files..."
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="$conf_file"
|
||||||
|
chown $app:$app $conf_file
|
||||||
|
|
||||||
|
touch /var/log/$app.log
|
||||||
|
chown $app:$app /var/log/$app.log
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring the systemd configuration..."
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
||||||
|
systemctl enable $app.service --quiet
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||||
|
|
||||||
|
yunohost service add $app --log="/var/log/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Starting a systemd service..."
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading NGINX web server..."
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Restoration completed for $app"
|
||||||
|
|
140
scripts/upgrade
140
scripts/upgrade
|
@ -1,58 +1,156 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC STARTING
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Source YunoHost helpers
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
source _future.sh
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
# Retrieve arguments
|
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
export domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
export app_version=$(ynh_app_setting_get "$app" app_version)
|
export domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
export oca=$(ynh_app_setting_get "$app" oca)
|
export app_version=$(ynh_app_setting_get --app=$app --key=app_version)
|
||||||
export port=$(ynh_app_setting_get $app port)
|
export oca=$(ynh_app_setting_get --app=$app --key=oca)
|
||||||
export port_chat=$(ynh_app_setting_get $app port_chat)
|
export port=$(ynh_app_setting_get --app=$app --key=port)
|
||||||
|
export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat)
|
||||||
export is_public=0
|
export is_public=0
|
||||||
export final_path=$(ynh_app_setting_get $app final_path)
|
export final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
export conf_file=$(ynh_app_setting_get $app conf_file)
|
export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file)
|
||||||
export preinstall=0
|
export preinstall=0
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK VERSION
|
# CHECK VERSION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Checking version..."
|
||||||
|
|
||||||
ynh_check_app_version_changed
|
upgrade_type=$(ynh_check_app_version_changed)
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STANDARD UPGRADE STEPS
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
||||||
|
|
||||||
# Backup the current version of the app
|
# Backup the current version of the app
|
||||||
ynh_backup_before_upgrade
|
ynh_backup_before_upgrade
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
# restore it if the upgrade fails
|
# Restore it if the upgrade fails
|
||||||
ynh_restore_upgradebackup
|
ynh_restore_upgradebackup
|
||||||
}
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD UPGRADE STEPS
|
||||||
|
#=================================================
|
||||||
|
# STOP SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Stopping a systemd service..."
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STEP Migrations
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_system_user_create $app
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
||||||
setup_files
|
|
||||||
install_dependencies
|
# Cleaning legacy permissions
|
||||||
service $app restart
|
if ynh_legacy_permissions_exists; then
|
||||||
|
ynh_legacy_permissions_delete_all
|
||||||
|
|
||||||
|
ynh_app_setting_delete --app=$app --key=is_public
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
||||||
|
|
||||||
|
# Create a dedicated user (if not existing)
|
||||||
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
|
ynh_script_progression --message="Upgrading source files..."
|
||||||
|
|
||||||
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
|
setup_files
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# UPGRADE DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading dependencies..."
|
||||||
|
|
||||||
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC UPGRADE
|
||||||
|
#=================================================
|
||||||
|
# BUILD APP
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Building $app..."
|
||||||
|
|
||||||
|
ynh_add_swap 1024
|
||||||
|
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
|
||||||
|
# The debian package has a bug so we deploy a more recent version
|
||||||
|
if [ -f '../manifest.json' ] ; then
|
||||||
|
ynh_setup_source /usr/
|
||||||
|
else
|
||||||
|
OLD_YNH_CWD=$YNH_CWD
|
||||||
|
YNH_CWD=$YNH_CWD/../settings/conf
|
||||||
|
ynh_setup_source /usr/
|
||||||
|
YNH_CWD=$OLD_YNH_CWD
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
pushd $final_path
|
||||||
|
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
|
||||||
|
python3 -m venv venv
|
||||||
|
venv/bin/pip3 install wheel
|
||||||
|
venv/bin/pip3 install -r $appname/requirements.txt
|
||||||
|
else
|
||||||
|
virtualenv venv
|
||||||
|
venv/bin/pip install wheel
|
||||||
|
venv/bin/pip install -r $appname/requirements.txt
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||||
|
|
||||||
|
yunohost service add $app --log="/var/log/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Starting a systemd service..."
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading NGINX web server..."
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Upgrade of $app completed"
|
||||||
|
|
Loading…
Reference in a new issue