1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wallabag2_ynh.git synced 2024-10-01 13:35:06 +02:00
wallabag2_ynh/scripts/upgrade
JimboJoe 689e47f4c5 Testing (#42)
* Keep optional configuration lines in nginx.conf to allow changing URL from/to "/path" locations
Rename comment prefixes fore more readability

* Add change_url script

* Require YNH 2.7.2, remove helpers and sudo prefixes

* Use ynh_replace_string

* Handle nginx conf file checksums

* Fix indentation

* Update source to 2.3

* Update version to 2.3

* Update readme version to 2.3

* Fix 20-app.ini in restore

* Replace app checkurl by webpath_available

* Adapt existing patches to 2.3

* Remove need to manage parameters.yml file; adapt to version 2.3

* Fix php5-redis dependency (redis-server is installed by YunoHost)

* Manage new domain_name parameter in change_url

* Upgrade to upstream version 2.3.1

* Upgrade to upstream version 2.3.2

* Remove obsolete calls to checkurl

* Fix check_process for upgrade from previous commit

* Fix Version number
2018-02-12 22:09:26 +01:00

142 lines
No EOL
4.9 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
# Set app specific variables
app=$YNH_APP_INSTANCE_NAME
# Check destination directory
DESTDIR="/var/www/$app"
[[ ! -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' does not exist.\
The app is not correctly installed, you should remove it first."
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path_url)
# Compatibility with previous version
if [ -z "$path_url" ] ; then
path_url=$(ynh_app_setting_get "$app" path)
ynh_app_setting_set $app path_url "$path_url"
fi
path_url=$(ynh_normalize_url_path $path_url)
db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
deskey=$(ynh_app_setting_get "$app" deskey)
final_path=$(ynh_app_setting_get "$app" final_path)
# Compatibility with previous version
if [ -z "$final_path" ] ; then
final_path="/var/www/$app"
ynh_app_setting_set $app final_path "$final_path"
fi
db_name=$(ynh_app_setting_get "$app" db_name)
# Compatibility with previous version
if [ -z "$db_name" ] ; then
db_name=$app
ynh_app_setting_set "$app" db_name "$db_name"
fi
db_user="$db_name"
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Use prior backup and restore on error only if backup feature
# exists on installed instance
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
ynh_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () {
ynh_backup_after_failed_upgrade
}
ynh_abort_if_errors # Stop script if an error is detected
fi
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Create tmp directory and fetch app inside
TMPDIR=$(ynh_mkdir_tmp)
ynh_setup_source "$TMPDIR"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app # Create dedicated user if not existing
#=================================================
# SPECIFIC SETUP
#=================================================
# Copy and set Wallabag dist configuration
wb_conf="${TMPDIR}/app/config/parameters.yml"
cp ${TMPDIR}/app/config/parameters.yml.dist $wb_conf
ynh_replace_string "fosuser_registration: true" "fosuser_registration: false" "$wb_conf"
ynh_replace_string "database_name: wallabag" "database_name: ${db_name}" "$wb_conf"
ynh_replace_string "database_user: root" "database_user: ${db_user}" "$wb_conf"
ynh_replace_string "database_password: ~" "database_password: ${db_pwd}" "$wb_conf"
ynh_replace_string "database_table_prefix: wallabag_" "database_table_prefix: null" "$wb_conf"
ynh_replace_string "secret: ovmpmAWXRCabNlMgzlzFXDYmCFfzGv" "secret: ${deskey}" "$wb_conf"
ynh_replace_string "domain_name: https://your-wallabag-url-instance.com" "domain_name: https://$domain$path_url" "$wb_conf"
# Replace files and set permissions
ynh_secure_remove "${final_path}/var/cache"
mkdir "${final_path}/var/cache"
cp -a $TMPDIR/. "${final_path}"
chown -R $app: "${final_path}"
chmod 755 $final_path
# Upgrade database and clear the cache
exec_console $app "${final_path}" doctrine:migrations:migrate
exec_console $app "${final_path}" cache:clear
# Configure Wallabag instance URL
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_user" <<< "UPDATE craue_config_setting SET value = 'https://$domain$path_url' WHERE name = 'wallabag_url'"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_add_nginx_config
if [ "$path_url" = "/" ]
then
# Replace "//" location (due to nginx template)
# Prevent from replacing in "http://" expressions by excluding ":" as preceding character
sed --in-place "s@\([^:]\)//@\1/@g" /etc/nginx/conf.d/$domain.d/$app.conf
else
# Move prefix comment #for-subdir at end of lines
sed --in-place "s/#for-subdir\(.*\)/\1 #for-subdir/g" /etc/nginx/conf.d/$domain.d/$app.conf
fi
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
# Copy and set php-fpm configuration
ynh_add_fpm_config
# Set SSOwat rules
ynh_app_setting_set "$app" unprotected_uris "/"
#=================================================
# RELOAD NGINX
#=================================================
systemctl restart php5-fpm
systemctl reload nginx