|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path_url=$(ynh_app_setting_get "$app" path_url)
|
|
|
|
db_name=$(ynh_app_setting_get "$app" db_name)
|
|
|
|
db_pwd=$(ynh_app_setting_get "$app" db_pwd)
|
|
|
|
db_user=$app
|
|
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
|
|
secret=$(ynh_app_setting_get "$app" secret)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Check depends installation
|
|
|
|
ynh_install_app_dependencies make python-dev python-virtualenv \
|
|
|
|
uwsgi uwsgi-plugin-python
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
|
|
|
if [ "$path_url" == "/" ]
|
|
|
|
then
|
|
|
|
# $finalnginxconf comes from ynh_add_nginx_config
|
|
|
|
# uwsgi_param is only needed for non-root installation
|
|
|
|
ynh_replace_string "uwsgi_param " "#uwsgi_param " "$finalnginxconf"
|
|
|
|
ynh_replace_string "uwsgi_modifier1 " "#uwsgi_modifier1 " "$finalnginxconf"
|
|
|
|
|
|
|
|
ynh_store_file_checksum "$finalnginxconf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create "$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Copy Files
|
|
|
|
cp ../conf/syncserver.ini "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__PATH__" "$path_url" "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__NAME__" "$app" "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__SECRET__" "$secret" "$final_path/syncserver.ini"
|
|
|
|
|
|
|
|
ynh_replace_string "__DB_USER__" "$db_user" "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/syncserver.ini"
|
|
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/syncserver.ini"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
chown "$app":"$app" -R "$final_path"
|
|
|
|
find "$final_path"/ -type d -exec chmod 2755 {} \;
|
|
|
|
find "$final_path"/ -type f -exec chmod g+r,o+r {} \;
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
yunohost service add "$app" -l /var/log/$app/$app.log
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
systemctl start "$app.service"
|
|
|
|
systemctl reload nginx
|