From ed68227b97ca7aa0f4e0d0f9450df936e867585f Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Tue, 16 May 2017 20:44:51 +0200 Subject: [PATCH] Various fixes --- check_process | 8 +++----- conf/nginx.conf | 2 +- scripts/_common | 26 +++++++++++++++++++++++++- scripts/install | 18 +++++++----------- scripts/restore | 22 ++++++++++++++++------ scripts/upgrade | 1 + 6 files changed, 53 insertions(+), 24 deletions(-) diff --git a/check_process b/check_process index 9956847..5f2b2cd 100644 --- a/check_process +++ b/check_process @@ -14,13 +14,8 @@ upgrade=1 backup_restore=1 multi_instance=1 - wrong_user=1 - wrong_path=1 incorrect_path=1 - corrupt_source=0 - fail_download_source=0 port_already_use=0 - final_path_already_use=0 ;;; Levels Level 1=auto Level 2=auto @@ -32,3 +27,6 @@ Level 8=0 Level 9=0 Level 10=0 +;;; Options +Email= +Notification=none \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index 71a8b38..36f2f05 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -7,7 +7,7 @@ location YNH_WWW_PATH { try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_pass unix:/var/run/php5-fpm-YNH_NAME.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; diff --git a/scripts/_common b/scripts/_common index 5753486..e80c476 100644 --- a/scripts/_common +++ b/scripts/_common @@ -144,4 +144,28 @@ ynh_compare_checksum_config () { echo "$backup_config_file" # Return the name of the backup file fi fi -} \ No newline at end of file +} + +# Normalize the url path syntax +# Handle the slash at the beginning of path and its absence at ending +# Return a normalized url path +# +# example: url_path=$(ynh_normalize_url_path $url_path) +# ynh_normalize_url_path example -> /example +# ynh_normalize_url_path /example -> /example +# ynh_normalize_url_path /example/ -> /example +# ynh_normalize_url_path / -> / +# +# usage: ynh_normalize_url_path path_to_normalize +# | arg: url_path_to_normalize - URL path to normalize before using it +ynh_normalize_url_path () { + path_url=$1 + test -n "$path_url" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing." + if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a / + path_url="/$path_url" # Add / at begin of path variable + fi + if [ "${path_url:${#path_url}-1}" == "/" ] && [ ${#path_url} -gt 1 ]; then # If the last character is a / and that not the only character. + path_url="${path_url:0:${#path_url}-1}" # Delete the last character + fi + echo $path_url +} diff --git a/scripts/install b/scripts/install index 86dd0ad..8887354 100644 --- a/scripts/install +++ b/scripts/install @@ -9,19 +9,13 @@ source /usr/share/yunohost/helpers # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH +path=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME # Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" - -# Remove trailing "/" for next commands -if [[ ! "$path" == "/" ]]; then - path=${path%/} -fi +sudo yunohost app checkurl "${domain}${path}" -a "$app" # Copy files to the right place final_path=/var/www/$app @@ -44,6 +38,7 @@ sudo chmod 700 $final_path/{data,tmp} # Modify Nginx configuration file and copy it to Nginx conf directory sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf +sed -i "s@YNH_NAME@$app@g" ../conf/nginx.conf nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf sudo cp ../conf/nginx.conf $nginxconf sudo chown root: $nginxconf @@ -53,10 +48,11 @@ sudo chmod 600 $nginxconf ynh_fpm_config # Set ssowat config -if [ "$is_public" = "No" ]; +ynh_app_setting_set $app is_public "$is_public" +if [ "$is_public" = "Yes" ]; then - ynh_app_setting_delete $app skipped_uris + ynh_app_setting_set $app unprotected_uris "/" fi sudo systemctl reload nginx -sudo yunohost app ssowatconf \ No newline at end of file +sudo yunohost app ssowatconf diff --git a/scripts/restore b/scripts/restore index 6a981a9..55b37a3 100644 --- a/scripts/restore +++ b/scripts/restore @@ -3,6 +3,12 @@ # causes the shell to exit if any subcommand or pipeline returns a non-zero status set -eu +if [ ! -e _common ]; then + # Fetch helpers file if not in current directory + sudo cp ../settings/scripts/_common ./_common + sudo chmod a+rx _common +fi +source _common # Source app helpers source /usr/share/yunohost/helpers @@ -25,8 +31,7 @@ user=$(ynh_app_setting_get $app allowed_users) is_public=$(ynh_app_setting_get $app is_public) # Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +sudo yunohost app checkurl "${domain}${path}" -a "$app" # Check $final_path final_path="/var/www/${app}" @@ -52,24 +57,29 @@ if [ -f $phpfpm_ini ]; then ynh_die "The PHP FPM INI configuration already exists at '${phpfpm_ini}'. You should safely delete it before restoring this app." fi +# Create dedicated system user for this app +ynh_system_user_create $app # Restore sources & data sudo cp -a "./sources" $final_path # Set permissions sudo chown -R root:root $final_path -sudo chown -R www-data:root $final_path/{data,tmp} +sudo chown -R $app:root $final_path/{data,tmp} sudo chmod -R 700 $final_path/{data,tmp} # Restore configuration files sudo cp -a ./conf/nginx.conf "${nginx_conf}" +sudo cp -a ./php-fpm.conf "$phpfpm_conf" +sudo cp -a ./php-fpm.ini "$phpfpm_ini" # Set ssowat config -if [ "$is_public" = "No" ]; +if [ "$is_public" = "Yes" ]; then - ynh_app_setting_delete $app skipped_uris + ynh_app_setting_set $app unprotected_uris "/" fi # Reload service sudo systemctl reload nginx -sudo yunohost app ssowatconf \ No newline at end of file +sudo systemctl reload php5-fpm +sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index 6d146b7..327c565 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -59,6 +59,7 @@ sudo chmod 700 $final_path/{data,tmp} # Modify Nginx configuration file and copy it to Nginx conf directory sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf +sed -i "s@YNH_NAME@$app@g" ../conf/nginx.conf nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf sudo cp ../conf/nginx.conf $nginxconf sudo chown root: $nginxconf