Commit 1cdf2ab9 authored by HgO's avatar HgO
Browse files

Merge branch '15-add-script-to-move-domain-path' into 'unstable'

Create change url script

See merge request Neutrinet/neutrinet_ynh!26
parents 96620f9d fc70195e
location PATHTOCHANGE {
rewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent;
location PATHTOCHANGE/ {
return 302 PATHTOCHANGE/fr;
}
......
......@@ -26,6 +26,7 @@ path_url=$(ynh_app_setting_get $app path_url)
app_user=$(ynh_app_setting_get $app app_user)
www_path=$(ynh_app_setting_get $app www_path)
opt_path=$(ynh_app_setting_get $app opt_path)
nginx_path=/etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# STANDARD BACKUP STEPS
......@@ -36,7 +37,7 @@ opt_path=$(ynh_app_setting_get $app opt_path)
ynh_script_progression "Backing up..."
ynh_backup "$www_path"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "$nginx_path"
ynh_backup "$opt_path"
ynh_backup "/etc/cron.daily/$app-renew-cert"
......
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
source _common.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
old_domain=$YNH_APP_OLD_DOMAIN
old_path_url=$YNH_APP_OLD_PATH
www_path=$(ynh_app_setting_get $app www_path)
domain=$YNH_APP_NEW_DOMAIN
path_url=$YNH_APP_NEW_PATH
nginx_path=/etc/nginx/conf.d/$domain.d/$app.conf
#==================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#==================================================
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Trim trailing slashes
path_url=$(sed 's@*/$@@' <<< $path_url)
#=================================================
# STORE SETTINGS
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path_url $path_url
#=================================================
# CHANGE URL IN NGINX CONFIG
#=================================================
ynh_script_progression "Updating nginx configuration..."
cp ../conf/nginx.conf "$nginx_path"
if [[ $path_url == "/" ]]; then
sed -i "/^rewrite/d" "$nginx_path"
path_url=""
fi
sed -i "s@PATHTOCHANGE@$path_url@g" "$nginx_path"
sed -i "s@ALIASTOCHANGE@$www_path@g" "$nginx_path"
if [[ $old_domain != $domain ]]; then
rm -f /etc/nginx/conf.d/$old_domain.d/$app.conf
fi
ynh_script_progression "Reloading nginx web server..."
nginx -tq
ynh_systemd_action nginx reload
......@@ -23,6 +23,7 @@ domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH_URL
app=$YNH_APP_INSTANCE_NAME
app_user=$app
nginx_path=/etc/nginx/conf.d/$domain.d/$app.conf
#==================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
......@@ -92,13 +93,18 @@ ynh_script_progression "Installing static site…"
cp -a ../sources/. $www_path
chown -R $app_user: $www_path
sed -i "s@PATHTOCHANGE@$path_url@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$www_path@g" ../conf/nginx.conf
cp ../conf/nginx.conf "$nginx_path"
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
if [[ $path_url == "/" ]]; then
sed -i "/^rewrite/d" "$nginx_path"
path_url=""
fi
sed -i "s@PATHTOCHANGE@$path_url@g" "$nginx_path"
sed -i "s@ALIASTOCHANGE@$www_path@g" "$nginx_path"
nginx -tq
service nginx reload
ynh_systemd_action nginx reload
#=================================================
# INSTALL RENEW CERT
......
......@@ -20,6 +20,7 @@ path_url=$(ynh_app_setting_get $app path_url)
app_user=$(ynh_app_setting_get $app app_user)
www_path=$(ynh_app_setting_get $app www_path)
opt_path=$(ynh_app_setting_get $app opt_path)
nginx_path=/etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# STANDARD REMOVE
......@@ -28,10 +29,10 @@ opt_path=$(ynh_app_setting_get $app opt_path)
ynh_script_progression "Removing static site..."
rm -rf $www_path
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
rm -f "$nginx_path"
nginx -t > /dev/null
service nginx reload
nginx -tq
ynh_systemd_action nginx reload
ynh_script_progression "Removing automatic vpn certificate renewal..."
......
......@@ -26,6 +26,7 @@ path_url=$(ynh_app_setting_get $app path_url)
app_user=$(ynh_app_setting_get $app app_user)
www_path=$(ynh_app_setting_get $app www_path)
opt_path=$(ynh_app_setting_get $app opt_path)
nginx_path=/etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# CHECK IF THE APP CAN BE RESTORED
......@@ -66,11 +67,11 @@ ynh_system_user_create $app_user "$www_path"
ynh_script_progression "Restoring static site…"
ynh_restore_file "$www_path"
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file "$nginx_path"
chown -R $app_user: "$www_path"
nginx -tq
service nginx reload
ynh_systemd_action nginx reload
#=================================================
# RESTORE RENEW CERT
......
......@@ -30,6 +30,8 @@ opt_path=$(ynh_app_setting_get $app opt_path)
manifest=/etc/yunohost/apps/$app/manifest.json
version=$(jq '.version // empty' -r -e $manifest || ynh_app_setting_get $app version)
nginx_path=/etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
......@@ -53,6 +55,9 @@ if [[ -z $app_user ]]; then
ynh_app_setting_set $app app_user $app_user
fi
# Trim trailing slashes
path_url=$(sed 's@/*$@@' <<< $path_url)
if [[ -z $path_url ]]; then
path_url=$path
......@@ -63,12 +68,6 @@ if [[ -z $path_url ]]; then
fi
fi
if [[ $path_url == */ ]]; then
# Trim trailing slashes
path_url=$(sed 's@/*$@@' <<< $path_url)
ynh_app_setting_set $app path_url $path_url
fi
# path setting is needed by Yunohost
# when path is empty, Yunohost thinks the app is on the domain root
if [[ "$path" != "$path_url" ]]; then
......@@ -125,13 +124,18 @@ mkdir -p $www_path
cp -r ../sources/. $www_path
chown -R $app_user: $www_path
sed -i "s@PATHTOCHANGE@$path_url@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$www_path@g" ../conf/nginx.conf
cp ../conf/nginx.conf "$nginx_path"
if [[ $path_url == "/" ]]; then
sed -i "/^rewrite/d" "$nginx_path"
path_url=""
fi
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
sed -i "s@PATHTOCHANGE@$path_url@g" "$nginx_path"
sed -i "s@ALIASTOCHANGE@$www_path@g" "$nginx_path"
nginx -tq
service nginx reload
ynh_systemd_action nginx reload
#=================================================
# REINSTALL RENEW CERT
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment