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

redo scripts 'backup', 'restore' and 'upgrade' + upgrade 'manifest'

This commit is contained in:
Gofannon 2018-05-10 16:44:32 +02:00
parent ef27b91d50
commit ea5e4bcc0f
7 changed files with 364 additions and 90 deletions

43
check_process Normal file
View file

@ -0,0 +1,43 @@
# See here for more informations
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
admin="john" (USER)
#language="fr"
is_public=1 (PUBLIC|public=1|private=0)
password="pass"
#port="666" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
incorrect_path=1
port_already_use=0
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4:
Level 4=0
# Level 5:
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

View file

@ -35,7 +35,7 @@ location __PATH__ {
# Very important security restriction
# See https://forum.cheky.net/information-sur-message-avertissement-securite-t553-p1.html#p2127
location /var {
location __PATH__/var {
deny all;
#return 403 # Cannot pass 'install' with 'package_check' if this line is present
}

10
conf/php-fpm.ini Normal file
View file

@ -0,0 +1,10 @@
; Common values to change to increase file upload limit
; upload_max_filesize = 50M
; post_max_size = 50M
; mail.add_x_header = Off
; Other common parameters
; max_execution_time = 600
; max_input_time = 300
; memory_limit = 256M
; short_open_tag = On

View file

@ -10,12 +10,12 @@
"url": "https://www.cheky.net",
"license": "free",
"maintainer": {
"name": "JimboJoe",
"email": "jimmy@monin.net",
"name": "Gofannon",
"email": "gofanon@riseup.net",
"url": ""
},
"requirements": {
"yunohost": ">> 2.4.0"
"yunohost": ">> 2.6.4"
},
"multi_instance": true,
"services": [

View file

@ -1,24 +1,73 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost 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
source /usr/share/yunohost/helpers
# Backup sources & data
ynh_backup "/var/www/${app}" "sources"
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Dump the database
dbname=$app
dbuser=$app
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Copy NGINX and cron configuration
domain=$(ynh_app_setting_get "$app" domain)
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
ynh_backup "/etc/cron.d/${app}" "conf/cron"
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP THE CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app"

View file

@ -1,40 +1,115 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost 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
source /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Restore sources & data
src_path="/var/www/${app}"
sudo cp -a ./sources "$src_path"
#=================================================
# LOAD SETTINGS
#=================================================
# Restore permissions to app files
sudo chown -R root: "$src_path"
sudo chown -R www-data: "$src_path/var"
app=$YNH_APP_INSTANCE_NAME
# Create and restore the database
dbname=$app
dbuser=$app
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
# Restore NGINX and cron configuration
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
sudo cp -a ./conf/cron "/etc/cron.d/${app}"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
# Restart webserver
sudo service nginx reload
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 "
#=================================================
# 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 root: $final_path
# Only path that needs to be writable by cheky
chown -R $app: $final_path/var
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/APP.log"
#=================================================
# 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,51 +1,148 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
admin=$(ynh_app_setting_get "$app" admin)
is_public=$(ynh_app_setting_get "$app" is_public)
language=$(ynh_app_setting_get "$app" language)
#=================================================
# LOAD SETTINGS
#=================================================
# Remove trailing "/" for next commands
path=${path%/}
app=$YNH_APP_INSTANCE_NAME
# Download sources
sudo wget -q https://github.com/Blount/Cheky/archive/3.3.zip -O Cheky.zip
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
# Uncompress
sudo unzip -qq Cheky.zip -d ..
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Copy source files
src_path=/var/www/$app
sudo mkdir -p $src_path
sudo cp -a ../Cheky*/. $src_path
# Set permissions to app files
# you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R www-data: $src_path
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# See install script
ynh_app_setting_set "$app" unprotected_uris "/"
# 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
# Reload nginx service
sudo service nginx reload
# 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 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
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# 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
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
#todo: part needed ?
# Verify the checksum and backup the file if it's different
#ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
# Recalculate and store the config file checksum into the app settings
#ynh_store_file_checksum "$final_path/CONFIG_FILE"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $final_path
# Only path that needs to be writable by cheky
chown -R $app: $final_path/var
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
fi
# 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