1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/z-push_ynh.git synced 2024-09-03 18:05:58 +02:00

Apply example_ynh

This commit is contained in:
Yalh 2019-01-26 05:01:29 +01:00
parent d67843f5f5
commit c3b1e7a509
4 changed files with 330 additions and 144 deletions

View file

@ -9,25 +9,30 @@
setup_root=0
setup_nourl=0
setup_private=0
setup_public=0
setup_public=1
upgrade=1
backup_restore=1
multi_instance=0
wrong_user=0
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=0
port_already_use=0
final_path_already_use=0
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# ?
Level 4=1
# ?
Level 5=1
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4: If the app supports LDAP and SSOwat, turn level 4 to '1' and add a link to an issue or a part of your code to show it.
# If the app does not use LDAP nor SSOwat, and can't use them, turn level 4 to 'na' and explain as well.
Level 4=na
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

View file

@ -1,30 +1,83 @@
#!/bin/bash
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
final_path=$(ynh_app_setting_get $app final_path)
statedir=$(ynh_app_setting_get $app statedir)
final_logpath=$(ynh_app_setting_get $app final_logpath)
final_nginxconf=$(ynh_app_setting_get $app final_nginxconf)
final_phpconf=$(ynh_app_setting_get $app final_phpconf)
# Backup sources & data
# Note: the last argument is where to save this path, see the restore script.
ynh_backup "$final_path" "sources"
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
# Backup statedir
ynh_backup "$statedir" "statedir"
ynh_backup "$statedir"
# Backup logs
ynh_backup "$final_logpath" "logs"
ynh_backup "/etc/logrotate.d/$app" "logrotate"
ynh_backup "$final_logpath"
# Copy NGINX configuration
ynh_backup "$final_nginxconf" "nginx.conf"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
# Copy PHP-FPM configuration
ynh_backup "$final_phpconf" "php-fpm.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
#ynh_mysql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
#ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP A CRON FILE
#=================================================
#ynh_backup "/etc/cron.d/$app"

View file

@ -1,32 +1,96 @@
#!/bin/bash
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve old app settings
path=$(ynh_app_setting_get $app path)
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
statedir=$(ynh_app_setting_get $app statedir)
final_logpath=$(ynh_app_setting_get $app final_logpath)
final_nginxconf=$(ynh_app_setting_get $app final_nginxconf)
final_phpconf=$(ynh_app_setting_get $app final_phpconf)
# Prereqs
sudo apt-get update -y
sudo apt-get install php-soap php5-imap libawl-php php5-xsl -y
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
# Install dependencies using Helpers
#ynh_package_install_from_equivs ../conf/z-push-deps.control \
#|| ynh_die "Unable to install dependencies"
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Restore sources, data and permissions
sudo mkdir -p $final_path
sudo cp -a ./sources/. $final_path/
sudo chown -R www-data: $final_path
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
#db_pwd=$(ynh_app_setting_get $app mysqlpwd)
#ynh_mysql_setup_db $db_name $db_name $db_pwd
#ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
#ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R www-data: $final_path
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies php-soap php5-imap libawl-php php5-xsl
# Restore statedir
sudo mkdir -p $statedir
@ -38,25 +102,37 @@ sudo mkdir -p $final_logpath
sudo cp -a ./logs/. $final_logpath/
sudo chown -R www-data:www-data $final_logpath
# Restore logrotate
sudo cp -a ./logrotate /etc/logrotate.d/$app
sudo chmod 644 /etc/logrotate.d/$app
sudo chown root:root /etc/logrotate.d/$app
# Restore NGINX configuration
sudo cp -a ./nginx.conf $final_nginxconf
#=================================================
# RESTORE SYSTEMD
#=================================================
# Restore PHP-FPM configuration
sudo cp -a ./php-fpm.conf $final_phpconf
sudo chown root: $final_phpconf
sudo chmod 644 $final_phpconf
#ynh_restore_file "/etc/systemd/system/$app.service"
#systemctl enable $app.service
# Make app public
ynh_app_setting_set $app skipped_uris "/"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
#yunohost service add $app --log "/var/log/$app/APP.log"
# Restart webserver
sudo service nginx reload
sudo service php5-fpm reload
sudo yunohost app ssowatconf
#=================================================
# RESTORE THE CRON FILE
#=================================================
#ynh_restore_file "/etc/cron.d/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
systemctl reload php5-fpm
systemctl reload nginx

View file

@ -1,89 +1,116 @@
#!/bin/bash
set -eu
# Source app helpers
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve arguments
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
statedir=$(ynh_app_setting_get $app statedir)
final_logpath=$(ynh_app_setting_get $app final_logpath)
final_nginxconf=$(ynh_app_setting_get $app final_nginxconf)
final_phpconf=$(ynh_app_setting_get $app final_phpconf)
# We make the app retro-compatible with previous versions
if [ -z "$final_path" ];
then
final_path="/var/www/$app"
ynh_app_setting_set "$app" final_path "$final_path"
else
echo "${final_path} exists, we don't create it."
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
if [ -z "$statedir" ];
then
statedir="/home/yunohost.app/$app"
ynh_app_setting_set "$app" statedir "$statedir"
else
echo "${statedir} exists, we don't create it."
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
if [ -z "$final_logpath" ];
then
final_logpath="/var/log/$app"
ynh_app_setting_set "$app" final_logpath "$final_logpath"
else
echo "${final_logpath} exists, we don't create it."
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
if [ -z "$final_nginxconf" ];
then
final_nginxconf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
ynh_app_setting_set "$app" final_nginxconf "$final_nginxconf"
else
echo "${final_nginxconf} exists, we don't create it."
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
if [ -z "$final_phpconf" ];
then
final_phpconf=/etc/php5/fpm/pool.d/$app.conf
ynh_app_setting_set "$app" final_phpconf "$final_phpconf"
else
echo "${final_phpconf} exists, we don't create it."
fi
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Prereqs
#sudo apt-get install php-soap php5-imap libawl-php php5-xsl
# Install dependencies using Helpers
ynh_package_install_from_equivs ../conf/z-push-deps.control \
|| ynh_die "Unable to install dependencies"
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Cleaning
sudo rm -rf $final_path
sudo rm -rf $final_logpath
sudo rm -f $final_nginxconf
sudo rm -f $final_phpconf
sudo rm -f /etc/logrotate.d/$app
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
# Copy files to the right place
sudo mkdir -p $final_path
#=================================================
# NGINX CONFIGURATION
#=================================================
# We download the sources and check the md5sum
SFILE=`sudo cat ../sources/source_file`;
sudo wget -nv -i ../sources/source_url -O ${SFILE}.tar.gz
sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
sudo tar xvf ${SFILE}.tar.gz -C ../sources/
sudo cp -a ../sources/$SFILE/. $final_path/
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_install_app_dependencies php-soap php5-imap libawl-php php5-xsl
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
# Configuration
sed -i "s^define('TIMEZONE', .*^define('TIMEZONE', '$(cat /etc/timezone)');^" ../conf/config.php
sed -i "s@LOGTOCHANGE@$final_logpath@g" ../conf/config.php
sed -i "s@LOGTOCHANGE@$final_logpath@g" ../conf/logrotate
# Storage of state_dir in /home/yunohost.app
# This contains the sync status in between device and z-push
@ -134,32 +161,57 @@ sudo mkdir -p $final_logpath
sudo chmod 750 $final_logpath
sudo chown www-data:www-data $final_logpath
# Activate logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/$app
sudo chmod 644 /etc/logrotate.d/$app
sudo chown root:root /etc/logrotate.d/$app
#Copy XMLElement.php
sudo ln -s /usr/share/awl/inc/XML* /var/www/z-push/include/
# Modify Nginx configuration file and copy it to Nginx conf directory
sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
sudo sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf $final_nginxconf
# Dedicated php-fpm processes
sudo sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
sudo cp ../conf/php-fpm.conf $final_phpconf
sudo chown root: $final_phpconf
sudo chmod 644 $final_phpconf
# Fixstates to avoid full resync of devices after version upgrades
sudo $final_path/z-push-admin.php -a fixstates
# Enable api for client and make the app public
ynh_app_setting_set $app skipped_uris "/"
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/config.php"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/config.php"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx
# Restart of services
sudo service php5-fpm reload
sudo service nginx reload
sudo yunohost app ssowatconf