mirror of
https://github.com/YunoHost-Apps/cesium_ynh.git
synced 2024-09-03 18:06:25 +02:00
refactoring with the new example_ynh
This commit is contained in:
parent
640fa2770a
commit
60e61f955b
8 changed files with 539 additions and 99 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Retrieve sources, get sha256sum, parse package version and update these strings in manifest, README and /conf/app.src
|
# Retrieve sources, get sha256sum, parse package version and update these strings in manifest, README and /conf/app.src
|
||||||
|
|
||||||
# URL=$(curl -s https://api.github.com/repos/duniter/cesium/releases/ | grep "browser_" | grep "web" | head -1 | cut -d\" -f4)
|
# URL=$(curl -s https://api.github.com/repos/duniter/cesium/releases/latest | grep "browser_" | grep "web" | head -1 | cut -d\" -f4)
|
||||||
# wget -nc --quiet $URL -P ./tmp
|
# wget -nc --quiet $URL -P ./tmp
|
||||||
# CHECKSUM=$(sha256sum ./tmp/cesium-*-web.zip | head -c 64)
|
# CHECKSUM=$(sha256sum ./tmp/cesium-*-web.zip | head -c 64)
|
||||||
# sed -i "s/SOURCE_SUM=.*/SOURCE_SUM=${CHECKSUM}/" ./conf/app.src
|
# sed -i "s/SOURCE_SUM=.*/SOURCE_SUM=${CHECKSUM}/" ./conf/app.src
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"url": "https://moul.re"
|
"url": "https://moul.re"
|
||||||
},
|
},
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">> 2.4.0"
|
"yunohost": ">> 3.5.0"
|
||||||
},
|
},
|
||||||
"multi_instance": false,
|
"multi_instance": false,
|
||||||
"services": [
|
"services": [
|
||||||
|
|
|
@ -1,18 +1,58 @@
|
||||||
#!/bin/bash
|
#!/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 /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Backup sources & data
|
#=================================================
|
||||||
# Note: the last argument is where to save this path, see the restore script.
|
# MANAGE SCRIPT FAILURE
|
||||||
ynh_backup "/var/www/${app}" "sources"
|
#=================================================
|
||||||
|
|
||||||
|
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
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Loading installation settings..."
|
||||||
|
|
||||||
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Declaring files to be backed up..."
|
||||||
|
|
||||||
|
### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs
|
||||||
|
### to be backuped and not an actual copy of any file. The actual backup that
|
||||||
|
### creates and fill the archive with the files happens in the core after this
|
||||||
|
### script is called. Hence ynh_backups calls takes basically 0 seconds to run.
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup --src_path="$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
||||||
|
|
||||||
|
|
||||||
# Copy NGINX configuration
|
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
|
||||||
|
|
118
scripts/change_url
Normal file
118
scripts/change_url
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
old_domain=$YNH_APP_OLD_DOMAIN
|
||||||
|
old_path=$YNH_APP_OLD_PATH
|
||||||
|
|
||||||
|
new_domain=$YNH_APP_NEW_DOMAIN
|
||||||
|
new_path=$YNH_APP_NEW_PATH
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||||
|
|
||||||
|
# Needed for helper "ynh_add_nginx_config"
|
||||||
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1
|
||||||
|
|
||||||
|
# Backup the current version of the app
|
||||||
|
ynh_backup_before_upgrade
|
||||||
|
ynh_clean_setup () {
|
||||||
|
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
|
||||||
|
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||||
|
|
||||||
|
# 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 WHICH PARTS SHOULD BE CHANGED
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
change_domain=0
|
||||||
|
if [ "$old_domain" != "$new_domain" ]
|
||||||
|
then
|
||||||
|
change_domain=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
change_path=0
|
||||||
|
if [ "$old_path" != "$new_path" ]
|
||||||
|
then
|
||||||
|
change_path=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MODIFY URL IN NGINX CONF
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1
|
||||||
|
|
||||||
|
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||||
|
|
||||||
|
## Move from sub path to root
|
||||||
|
#if [ "$new_path" == "/" ]
|
||||||
|
#then
|
||||||
|
# ynh_replace_string "\(^.*rewrite.*\^$old_path.* permanent;\)" "#sub_path_only\1" "$nginx_conf_path"
|
||||||
|
# ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path" "$nginx_conf_path"
|
||||||
|
|
||||||
|
# Move to a sub path
|
||||||
|
#else
|
||||||
|
# ynh_replace_string "^#sub_path_only" "" "$nginx_conf_path"
|
||||||
|
# ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path/" "$nginx_conf_path"
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# Change the path in the nginx config file
|
||||||
|
if [ $change_path -eq 1 ]
|
||||||
|
then
|
||||||
|
# Make a backup of the original nginx config file if modified
|
||||||
|
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||||
|
# Set global variables for nginx helper
|
||||||
|
domain="$old_domain"
|
||||||
|
path_url="$new_path"
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Change the domain for nginx
|
||||||
|
if [ $change_domain -eq 1 ]
|
||||||
|
then
|
||||||
|
# Delete file checksum for the old conf file location
|
||||||
|
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||||
|
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||||
|
# Store file checksum for the new config file location
|
||||||
|
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Change of URL completed for $app" --time --last
|
||||||
|
|
125
scripts/install
125
scripts/install
|
@ -1,45 +1,118 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
source /usr/share/yunohost/helpers
|
||||||
set -eu
|
|
||||||
|
#=================================================
|
||||||
|
# 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
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
|
||||||
# Source YunoHost helpers
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# 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 --message="This path already contains a folder"
|
||||||
|
# Normalize the url path syntax
|
||||||
|
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=$app --domain=$domain --path_url=$path_url
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STORE SETTINGS FROM MANIFEST
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Storing installation settings..." --time --weight=1
|
||||||
|
|
||||||
# Save app settings
|
# Save app settings
|
||||||
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
|
||||||
|
|
||||||
# Check domain/path availability
|
#=================================================
|
||||||
yunohost app checkurl "${domain}${path}" -a "$app" \
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setting up source files..." --time --weight=1
|
||||||
|
|
||||||
# Retrieve sources and install them
|
# Retrieve sources and install them
|
||||||
src_path=/var/www/$app
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||||
mkdir -p $src_path
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_script_progression --message="Setting up source files..." --time --weight=1
|
|
||||||
ynh_setup_source --dest_dir=$src_path
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Permissions files
|
||||||
|
#=================================================
|
||||||
|
|
||||||
chown -R www-data: $src_path
|
chown -R www-data: $src_path
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Remove the public access
|
||||||
nginx_conf=../conf/nginx.conf
|
ynh_app_setting_delete --app=$app --key=skipped_uris
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
|
||||||
sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf
|
|
||||||
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
|
# NGINX CONFIGURATION
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
#=================================================
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
|
||||||
# activate read-only
|
|
||||||
ynh_replace_string --match_string='"readonly": false,' --replace_string='"readonly": true,' --target_file="$src_path/config.js"
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
|
ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$path_url" --target_file="$final_path/nginx_conf"
|
||||||
|
ynh_replace_string --match_string='YNH_WWW_ALIAS' --replace_string='$final_path' --target_file="$final_path/nginx_conf"
|
||||||
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
if [ "$path_url" != "/" ]
|
||||||
|
then
|
||||||
|
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload nginx service
|
#=================================================
|
||||||
systemctl reload nginx
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
|
||||||
|
|
||||||
|
|
||||||
|
# If app is public, add url to SSOWat conf as skipped_uris and read-only mode
|
||||||
|
if [[ $is_public -eq 1 ]]; then
|
||||||
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
||||||
|
# activate read-only
|
||||||
|
ynh_replace_string --match_string='"readonly": false,' --replace_string='"readonly": true,' --target_file="$final_path/config.js"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Installation of $app completed" --time --last
|
|
@ -1,17 +1,63 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Source YunoHost helpers
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Retrieve app settings
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
|
|
||||||
# Remove sources
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
ynh_secure_remove /var/www/$app
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing app main directory..." --time --weight=1
|
||||||
|
|
||||||
|
# Remove the app directory securely
|
||||||
|
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
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1
|
||||||
|
|
||||||
|
# Delete a system user
|
||||||
|
ynh_system_user_delete --username=$app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Removal of $app completed" --time --last
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Remove configuration files
|
|
||||||
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
|
|
||||||
# Reload nginx service
|
|
||||||
systemctl reload nginx
|
|
||||||
|
|
102
scripts/restore
102
scripts/restore
|
@ -1,35 +1,87 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Note: each files and directories you've saved using the ynh_backup helper
|
#=================================================
|
||||||
# will be located in the current directory, regarding the last argument.
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
set -eu
|
|
||||||
|
|
||||||
# See comments in install script
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
|
|
||||||
# Source YunoHost helpers
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Retrieve old app settings
|
#=================================================
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
# MANAGE SCRIPT FAILURE
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
#=================================================
|
||||||
|
|
||||||
# Check domain/path availability
|
ynh_clean_setup () {
|
||||||
yunohost app checkurl "${domain}${path}" -a "$app" \
|
#### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
true
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
# Restore sources & data
|
#=================================================
|
||||||
src_path="/var/www/${app}"
|
# LOAD SETTINGS
|
||||||
cp -a ./sources "$src_path"
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||||
|
|
||||||
# Restore permissions to app files
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
|
||||||
chown -R www-data: "$src_path"
|
|
||||||
|
|
||||||
# Restore NGINX configuration
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
# Restart webserver
|
#=================================================
|
||||||
systemctl reload nginx
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
|
||||||
|
|
||||||
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
||||||
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
||||||
|
test ! -d $final_path \
|
||||||
|
|| ynh_die --message="There is already a directory: $final_path "
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD RESTORATION STEPS
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring the app main directory..." --time --weight=1
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="$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 --username=$app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE USER RIGHTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Restore permissions on app files
|
||||||
|
chown -R www-data: $final_path
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Restoration completed for $app" --time --last
|
161
scripts/upgrade
161
scripts/upgrade
|
@ -1,16 +1,37 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
# Exit on command errors and treat unset variables as an error
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Source YunoHost helpers
|
# Source YunoHost helpers
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve app settings
|
# Retrieve app settings
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
||||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||||
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK VERSION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
### This helper will compare the version of the currently installed app and the version of the upstream package.
|
### This helper will compare the version of the currently installed app and the version of the upstream package.
|
||||||
### $upgrade_type can have 2 different values
|
### $upgrade_type can have 2 different values
|
||||||
|
@ -20,35 +41,125 @@ is_public=$(ynh_app_setting_get "$app" is_public)
|
||||||
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
|
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
|
||||||
upgrade_type=$(ynh_check_app_version_changed)
|
upgrade_type=$(ynh_check_app_version_changed)
|
||||||
|
|
||||||
# Remove trailing "/" for next commands
|
|
||||||
path=${path%/}
|
|
||||||
|
|
||||||
# Retreive sources and install them
|
#=================================================
|
||||||
src_path=/var/www/$app
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
|
||||||
|
|
||||||
|
# Fix is_public as a boolean value
|
||||||
|
if [ "$is_public" = "Yes" ]; then
|
||||||
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
||||||
|
is_public=1
|
||||||
|
elif [ "$is_public" = "No" ]; then
|
||||||
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
||||||
|
is_public=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If final_path doesn't exist, create it
|
||||||
|
if [ -z "$final_path" ]; then
|
||||||
|
final_path=/var/www/$app
|
||||||
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# N.B. : this is for app installations before YunoHost 2.7
|
||||||
|
# where this value might be something like /foo/ or foo/
|
||||||
|
# instead of /foo ....
|
||||||
|
# If nobody installed your app before 2.7, then you may
|
||||||
|
# safely remove this line
|
||||||
|
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
then
|
then
|
||||||
ynh_secure_remove $src_path
|
ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
||||||
mkdir -p $src_path
|
|
||||||
ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
|
||||||
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_setup_source --dest_dir=$src_path
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
chown -R www-data: $src_path
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# # Retreive sources and install them
|
||||||
|
# src_path=/var/www/$app
|
||||||
|
# if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
# then
|
||||||
|
# ynh_secure_remove $src_path
|
||||||
|
# mkdir -p $src_path
|
||||||
|
# ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
||||||
|
|
||||||
|
# # Download, check integrity, uncompress and patch the source from app.src
|
||||||
|
# ynh_setup_source --dest_dir=$src_path
|
||||||
|
# chown -R www-data: $src_path
|
||||||
|
# fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
nginx_conf=../conf/nginx.conf
|
ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$path_url/" --target_file="$final_path/nginx_conf"
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
ynh_replace_string --match_string='YNH_WWW_ALIAS' --replace_string='$final_path/' --target_file="$final_path/nginx_conf"
|
||||||
sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
||||||
cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
# If app is public, add url to SSOWat conf as skipped_uris
|
if [ "$path_url" != "/" ]
|
||||||
if [[ $is_public -eq 1 ]]; then
|
then
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
# activate read-only
|
|
||||||
ynh_replace_string --match_string='"readonly": false,' --replace_string='"readonly": true,' --target_file="$src_path/config.js"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload nginx service
|
#=================================================
|
||||||
systemctl reload nginx
|
# SECURE FILES AND DIRECTORIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Set permissions on app files
|
||||||
|
chown -R root: $final_path
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
|
||||||
|
|
||||||
|
|
||||||
|
# If app is public, add url to SSOWat conf as skipped_uris and read-only mode
|
||||||
|
if [[ $is_public -eq 1 ]]; then
|
||||||
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
||||||
|
# activate read-only
|
||||||
|
ynh_replace_string --match_string='"readonly": false,' --replace_string='"readonly": true,' --target_file="$final_path/config.js"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Upgrade of $app completed" --time --last
|
Loading…
Reference in a new issue