1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/garradin_ynh.git synced 2024-09-03 18:36:17 +02:00

add hooks to copy file config.dist.php in config.local.php with good options

This commit is contained in:
Rodolphe Robles 2020-04-04 03:34:57 +02:00
parent 9fa22de996
commit 5245009c35
8 changed files with 158 additions and 58 deletions

20
hooks/post_app_change_url Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# Change options in config.local.php
#=================================================
ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php"
sudo cp -a $final_path/config.dist.php $final_path/local.dist.php

22
hooks/post_app_install Normal file
View file

@ -0,0 +1,22 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# Change options in file config.dist.php
# and copy in local.dist.php
#=================================================
ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = 'uqn8jvlmVZLn988lOZiHd1z97hD36V40AnE0LLqLY1801LG3caO';" --target_file="$final_path/config.dist.php"
sudo cp -a $final_path/config.dist.php $final_path/local.dist.php

20
hooks/post_app_upgrade Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# Change options in config.local.php
#=================================================
ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php"
sudo cp -a $final_path/config.dist.php $final_path/local.dist.php

View file

@ -1,5 +1,12 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="php7.0-sqlite3"
# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#

View file

@ -24,40 +24,45 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
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)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Backing up the main app directory..." --time --weight=1
ynh_backup "$final_path"
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
--time --weight=1ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_backup "/etc/php/7.0/fpm/conf.d/20-$app.ini"
ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_backup --src_path="/etc/php/7.0/fpm/conf.d/20-$app.ini"
# Backup directory location for the app from where the script is executed and
# which will be compressed afterward
backup_dir=$YNH_APP_BACKUP_DIR
# # Backup directory location for the app from where the script is executed and
# # which will be compressed afterward
# backup_dir=$YNH_APP_BACKUP_DIR
# Backup sources & data
ynh_backup "/var/www/$app" "sources"
# # Backup sources & data
# ynh_backup "/var/www/$app" "sources"
# Copy Nginx conf
sudo mkdir -p ./conf
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"
# # Copy Nginx conf
# sudo mkdir -p ./conf
# ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"

View file

@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
@ -39,41 +40,44 @@ path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --time --weight=1
ynh_app_setting_set $app path_url $path_url
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
# Install dependency to convert tracks to a readable format for the browser
#=================================================
ynh_script_progression --message="Installing dependencies..." --time --weight=1
if [ "$(lsb_release --codename --short)" != "jessie" ]
then
ynh_install_app_dependencies php7.0-sqlite3
ynh_install_app_dependencies $pkg_dependencies
else
ynh_install_app_dependencies php5-sqlite
ynh_die --message="Votre version de Debian n'est pas compatible..." --time --weight=1
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --time --weight=1
# Create a system user
ynh_system_user_create $app
ynh_system_user_create --username=$app
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --time --weight=1
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
ynh_setup_source --dest_dir="$final_path"
#=================================================
# Files owned by user app
@ -85,13 +89,14 @@ sudo chmod 755 $final_path -R
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring php-fpm..." --time --weight=1
# Create a dedicated php-fpm config
ynh_add_fpm_config
@ -99,6 +104,9 @@ ynh_add_fpm_config
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
if [ $is_public -eq 0 ]
then # Remove the public access
@ -108,11 +116,18 @@ fi
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
systemctl reload nginx
systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --time --last

View file

@ -12,15 +12,17 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --time --weight=1
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
@ -28,13 +30,15 @@ ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --time --weight=1
# Remove the app directory securely
ynh_secure_remove "$final_path"
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1
# Remove the dedicated nginx config
ynh_remove_nginx_config
@ -42,6 +46,7 @@ ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
@ -51,6 +56,13 @@ ynh_remove_fpm_config
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1
# Delete a system user
ynh_system_user_delete $app
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --time --last

View file

@ -6,12 +6,8 @@
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.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
#=================================================
@ -24,16 +20,18 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
@ -57,9 +55,10 @@ ynh_restore_file "$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create $app
ynh_system_user_create --username=$app
#=================================================
# RESTORE USER RIGHTS
@ -73,11 +72,10 @@ chown -R $app:$app $final_path
#=================================================
if [ "$(lsb_release --codename --short)" != "jessie" ]
then
ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php/7.0/fpm/conf.d/20-$app.ini"
ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_restore_file --origin_path="/etc/php/7.0/fpm/conf.d/20-$app.ini"
else
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
ynh_die --message="Votre version de Debian n'est pas compatible..."
fi
#=================================================
@ -85,23 +83,24 @@ fi
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1
# Define and install dependencies
ynh_install_app_dependencies php7.0-sqlite3
if [ "$(lsb_release --codename --short)" != "jessie" ]
then
ynh_install_app_dependencies php7.0-sqlite3
else
ynh_install_app_dependencies php5-sqlite
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
if [ "$(lsb_release --codename --short)" != "jessie" ]
then
systemctl reload php7.0-fpm
else
systemctl reload php5-fpm
fi
systemctl reload nginx
ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1
ynh_systemd_action --service_name=php7.0-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --time --last