mirror of
https://github.com/YunoHost-Apps/agendav_ynh.git
synced 2024-09-03 20:36:12 +02:00
Multiple corrections + using helpers for back and restore
This commit is contained in:
parent
d27688b513
commit
aa5d2e8b98
7 changed files with 40 additions and 53 deletions
|
@ -8,7 +8,7 @@
|
|||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=1
|
||||
setup_root=1
|
||||
setup_root=0
|
||||
setup_nourl=0
|
||||
setup_private=1
|
||||
setup_public=1
|
||||
|
|
|
@ -3,7 +3,7 @@ location __PATH__/ {
|
|||
index index.php;
|
||||
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
||||
# The seemingly weird syntax is due to a long-standing bug in nginx,
|
||||
|
@ -12,10 +12,10 @@ location __PATH__/ {
|
|||
|
||||
# Another alternative to the weird try_files is to use a rewrite, like this :
|
||||
#
|
||||
# if (-f $request_filename) {
|
||||
# if (-f $request_filename) {
|
||||
# break;
|
||||
# }
|
||||
# rewrite (.*) __PATH__/index.php$request_uri;
|
||||
# rewrite (.*) {LOCATION}/index.php$request_uri;
|
||||
#
|
||||
# But remember that if-is-evil :
|
||||
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#check-if-file-exists
|
||||
|
@ -37,3 +37,6 @@ location __PATH__/ {
|
|||
# Include SSOWAT user panel.
|
||||
include conf.d/yunohost_panel.conf.inc;
|
||||
}
|
||||
|
||||
# append trailing slash in case of a subpath
|
||||
location = __PATH__ { return 302 __PATH__/; }
|
||||
|
|
|
@ -10,7 +10,7 @@ source /usr/share/yunohost/helpers
|
|||
ynh_abort_if_errors
|
||||
|
||||
# Set app specific variables
|
||||
app="$YNH_APP_INSTANCE_NAME"
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
|
@ -20,12 +20,13 @@ path=$(ynh_app_setting_get "$app" path)
|
|||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
|
||||
# Copy the app files
|
||||
DESTDIR="/var/www/$app"
|
||||
ynh_backup "$DESTDIR" "sources"
|
||||
final_path="/var/www/$app"
|
||||
ynh_backup "$final_path"
|
||||
|
||||
# Copy the conf files
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
||||
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf"
|
||||
|
||||
# Dump the database
|
||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
||||
ynh_backup ./dump.sql
|
||||
|
|
|
@ -11,7 +11,7 @@ ynh_abort_if_errors
|
|||
|
||||
# Retrieve arguments
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
language=$YNH_APP_ARG_LANGUAGE
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
|
||||
|
@ -20,19 +20,19 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
path=$(ynh_normalize_url_path "$path")
|
||||
path_url=$(ynh_normalize_url_path "$path_url")
|
||||
|
||||
# Set and store language
|
||||
language=${LANGUAGES[$language]}
|
||||
|
||||
ynh_app_setting_set "$app" language "$language"
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
ynh_app_setting_set "$app" path "$path"
|
||||
ynh_app_setting_set "$app" path "$path_url"
|
||||
|
||||
# Check web path availability
|
||||
ynh_webpath_available "$domain" "$path"
|
||||
ynh_webpath_available "$domain" "$path_url"
|
||||
# Register (book) web path
|
||||
ynh_webpath_register "$app" "$domain" "$path"
|
||||
ynh_webpath_register "$app" "$domain" "$path_url"
|
||||
|
||||
# Define LOGDIR (create it later when user is created)
|
||||
LOGDIR=/var/log/$app
|
||||
|
@ -131,9 +131,9 @@ then
|
|||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
|
||||
# ynh panel is not needed
|
||||
ynh_replace_string " include conf.d/" " #include conf.d/" "$nginx_conf"
|
||||
ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf"
|
||||
|
||||
ynh_store_file_checksum "$nginx_conf"
|
||||
ynh_store_file_checksum "$finalnginxconf"
|
||||
fi
|
||||
|
||||
# Reload services
|
||||
|
|
|
@ -19,9 +19,10 @@ ynh_mysql_drop_user "$dbuser"
|
|||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
# Delete app directory and configurations
|
||||
rm -rf "/var/www/${app}" "/var/log/${app}"
|
||||
rm -f "/etc/php5/fpm/pool.d/${app}.conf"
|
||||
[[ -n $domain ]] && rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
ynh_secure_remove "/var/www/${app}"
|
||||
ynh_secure_remove "/var/log/${app}"
|
||||
ynh_remove_fpm_config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
|
|
@ -16,30 +16,18 @@ dbuser=$app
|
|||
|
||||
# Retrieve old app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
|
||||
# Check web path availability
|
||||
ynh_webpath_available "$domain" "$path"
|
||||
ynh_webpath_available "$domain" "$path_url"
|
||||
|
||||
# Install dependencies
|
||||
ynh_install_app_dependencies "php5-cli"
|
||||
|
||||
# Check destination directory
|
||||
DESTDIR="/var/www/$app"
|
||||
[[ -d $DESTDIR ]] && ynh_die \
|
||||
"The destination directory '$DESTDIR' already exists.\
|
||||
You should safely delete it before restoring this app."
|
||||
|
||||
# Check configuration files
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
[[ -f $nginx_conf ]] && ynh_die \
|
||||
"The NGINX configuration already exists at '${nginx_conf}'.
|
||||
You should safely delete it before restoring this app."
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
||||
[[ -f $phpfpm_conf ]] && ynh_die \
|
||||
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
|
||||
You should safely delete it before restoring this app."
|
||||
final_path="/var/www/$app"
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
# Check whether Baïkal or Radicale is installed
|
||||
if yunohost app list --installed -f baikal | grep -q id ; then
|
||||
|
@ -54,29 +42,26 @@ fi
|
|||
|
||||
ynh_system_user_create "$app" "$final_path"
|
||||
|
||||
# Restore the app files and set permissions
|
||||
cp -a ./sources "$DESTDIR"
|
||||
|
||||
# Protect source code against modifications
|
||||
chown -hR root: "$DESTDIR"
|
||||
chown -hR root: "$final_path"
|
||||
|
||||
# Only agendav user should write here
|
||||
chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig}
|
||||
chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig}
|
||||
chown -hR $app: "${final_path}/web/var/cache/"{profiler,twig}
|
||||
chmod -R 750 "${final_path}/web/var/cache/"{profiler,twig}
|
||||
|
||||
# The agendav user should read here, but does not need to write
|
||||
# Other users should not be able to read as it stores passwords.
|
||||
find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \;
|
||||
find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \;
|
||||
find "${final_path}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \;
|
||||
find "${final_path}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \;
|
||||
|
||||
# Clean caches
|
||||
rm -rf "${DESTDIR}/web/var/cache/"{profiler,twig}/*
|
||||
ynh_secure_remove "${final_path}/web/var/cache/"{profiler,twig}/*
|
||||
|
||||
# CalDAV config
|
||||
caldav_domain=$(ynh_app_setting_get "$caldav_app" domain)
|
||||
caldav_path=$(ynh_app_setting_get "$caldav_app" path)
|
||||
caldav_url="https://${caldav_domain}${caldav_path%/}"
|
||||
conf_path="${DESTDIR}/web/config/settings.php"
|
||||
conf_path="${final_path}/web/config/settings.php"
|
||||
sed -i "s@^\(\$app\['caldav.baseurl'\] = \).*\
|
||||
@\1'${caldav_url}${caldav_baseurl}';@g" "$conf_path"
|
||||
sed -i "s@^\(\$app\['caldav.baseurl.public'\] = \).*\
|
||||
|
@ -90,8 +75,8 @@ ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
||||
|
||||
# Restore configuration files
|
||||
cp -a ./nginx.conf "$nginx_conf"
|
||||
cp -a ./php-fpm.conf "$phpfpm_conf"
|
||||
ynh_restore_file "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
ynh_restore_file "/etc/php5/fpm/pool.d/${app}.conf"
|
||||
|
||||
# Reload services
|
||||
service php5-fpm restart
|
||||
|
|
|
@ -16,7 +16,7 @@ dbuser=$app
|
|||
|
||||
# Retrieve arguments
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
encryptkey=$(ynh_app_setting_get "$app" encryptkey)
|
||||
language=$(ynh_app_setting_get "$app" language)
|
||||
|
@ -38,9 +38,6 @@ LOGDIR=/var/log/$app
|
|||
|
||||
# Check destination directory
|
||||
final_path=/var/www/$app
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
|
||||
mkdir -p "$final_path"
|
||||
|
||||
# Check whether Baïkal or Radicale is installed
|
||||
baikal_install=$(agendav_app_check_installation "baikal")
|
||||
|
@ -122,9 +119,9 @@ then
|
|||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
|
||||
# ynh panel is not needed
|
||||
ynh_replace_string " include conf.d/" " #include conf.d/" "$nginx_conf"
|
||||
ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf"
|
||||
|
||||
ynh_store_file_checksum "$nginx_conf"
|
||||
ynh_store_file_checksum "$finalnginxconf"
|
||||
fi
|
||||
|
||||
# Reload services
|
||||
|
|
Loading…
Add table
Reference in a new issue