Apply last example_ynh

This commit is contained in:
yalh76 2022-02-13 22:09:18 +01:00
parent 8af8c9e096
commit d854c545f7
10 changed files with 764 additions and 409 deletions

View file

@ -1,10 +1,18 @@
#
# Common variables
#
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
export appname="libreerp"
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() {
# 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
}
function setup_files() {
if [[ $oca -eq 0 ]]; then
@ -43,64 +52,162 @@ function setup_files() {
# Autoinstall the LDAP auth module
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
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
}
# 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
# 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
function setup_database() {
export preinstall=1
ynh_configure server.conf $conf_file
chown $app:$app $conf_file
# Load translation
#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 "
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
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
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
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" "$DEST"
else
virtualenv venv
venv/bin/pip install wheel
venv/bin/pip install -r $appname/requirements.txt
ynh_add_config "${YNH_CWD}/../settings/conf/$TEMPLATE" "$DEST"
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
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
local swap_max_size=$(( $size * 1024 ))
yunohost service add $app --log /var/log/$app.log
yunohost service stop $app
yunohost service start $app
yunohost service enable $app
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
}
function ssowat_and_restart() {
# Restart odoo service
service $app restart
# Configure SSOWat
ynh_sso_access "/web/database/manager"
# Reload services
service nginx reload
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
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -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
}

View file

@ -1,31 +1,79 @@
#!/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
#source _future.sh
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
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
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
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
ynh_backup "${final_path}/$appname"
ynh_backup "${final_path}/custom-addons"
ynh_backup "${final_path}/.local"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
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 "/etc/systemd/system/${app}.service"
ynh_backup --src_path="$final_path/$appname"
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)."

View file

@ -1,20 +1,41 @@
#!/bin/bash
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
source _future.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
# Arguments from manifest
export app=$YNH_APP_INSTANCE_NAME
ynh_export domain oca admin_password lang tz
export app_version=$YNH_APP_ARG_VERSION
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url="/"
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 final_path=/var/www/$app
export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin"
if [ "$app_version" = "9" ]; then
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
@ -22,79 +43,173 @@ fi
if [ "$app_version" = "8" ]; then
bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py"
fi
export db_name=$(ynh_sanitize_dbid $app)
export port=$(ynh_find_port 8069)
export port_chat=$(ynh_find_port 8072)
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_webpath_register $app $domain "/"
ynh_script_progression --message="Validating installation parameters..."
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() {
export preinstall=1
ynh_configure server.conf $conf_file
chown $app:$app $conf_file
# Load translation
#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 "
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
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_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
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=app_version --value=$app_version
ynh_app_setting_set --app=$app --key=oca --value=$oca
ynh_app_setting_set --app=$app --key=lang --value=$lang
ynh_app_setting_set --app=$app --key=tz --value=$tz
ynh_app_setting_set --app=$app --key=conf_file --value=$conf_file
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
# Find an available port
port=$(ynh_find_port --port=8069)
ynh_app_setting_set --app=$app --key=port --value=$port
# Find an available port
port_chat=$(ynh_find_port --port=8072)
ynh_app_setting_set --app=$app --key=port_chat --value=$port_chat
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..."
export db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
export db_pass=$(ynh_string_random)
setup_files
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
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
# 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"

View file

@ -1,29 +1,95 @@
#!/bin/bash
set -u
source /usr/share/yunohost/helpers
source _future.sh
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
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)
final_path=$(ynh_app_setting_get "$app" final_path)
conf_file=$(ynh_app_setting_get "$app" conf_file)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
yunohost service stop $app
yunohost service remove $app
ynh_psql_remove_db $app $app
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
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
#=================================================
# 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
#=================================================
# 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"

View file

@ -1,23 +1,43 @@
#!/bin/bash
set -eu
# Import helpers
source /usr/share/yunohost/helpers
source ../settings/scripts/_future.sh
#=================================================
# GENERIC START
#=================================================
# 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 /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
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
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 oca=$(ynh_app_setting_get $app oca)
export port=$(ynh_app_setting_get $app port)
export port_chat=$(ynh_app_setting_get $app port_chat)
export db_name=$(ynh_app_setting_get $app db_name)
export db_pass=$(ynh_app_setting_get $app psqlpwd)
export final_path=$(ynh_app_setting_get $app final_path)
export conf_file=$(ynh_app_setting_get $app conf_file)
export domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
export app_version=$(ynh_app_setting_get --app=$app --key=app_version)
export oca=$(ynh_app_setting_get --app=$app --key=oca)
export port=$(ynh_app_setting_get --app=$app --key=port)
export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat)
export db_name=$(ynh_app_setting_get --app=$app --key=db_name)
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 bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin"
if [ "$app_version" = "9" ]; then
@ -30,33 +50,133 @@ fi
#=================================================
# 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
function restore_files () {
ynh_restore
chown -R $app:$app $final_path
chown $app:$app $conf_file
touch /var/log/$app.log
chown $app:$app /var/log/$app.log
}
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
# Restore database
function restore_database () {
su -c "psql $app" postgres < ./dump.sql
}
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_system_user_create $app $final_path
restore_files
install_dependencies
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
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_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"

View file

@ -1,58 +1,156 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source YunoHost helpers
source /usr/share/yunohost/helpers
source _future.sh
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
# Retrieve arguments
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 oca=$(ynh_app_setting_get "$app" oca)
export port=$(ynh_app_setting_get $app port)
export port_chat=$(ynh_app_setting_get $app port_chat)
export domain=$(ynh_app_setting_get --app=$app --key=domain)
export app_version=$(ynh_app_setting_get --app=$app --key=app_version)
export oca=$(ynh_app_setting_get --app=$app --key=oca)
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 final_path=$(ynh_app_setting_get $app final_path)
export conf_file=$(ynh_app_setting_get $app conf_file)
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 preinstall=0
#=================================================
# 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
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
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
setup_files
install_dependencies
service $app restart
ynh_script_progression --message="Ensuring downward compatibility..."
# Cleaning legacy permissions
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"