diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..4112d7d --- /dev/null +++ b/conf/app.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://release.larsjung.de/h5ai/h5ai-0.29.0.zip +SOURCE_SUM=508324f14df32bfa79096b8c272dd644cbd8ff97d0dbc7dde2eec6ce7d95104e +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=false +SOURCE_FILENAME=h5ai-0.29.0.zip diff --git a/conf/nginx.conf b/conf/nginx.conf index 624ee61..fea5f1e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,23 +1,28 @@ -location YNH_WWW_PATH { +location __PATH__ { - # Path to source - alias YNH_WWW_ALIAS ; + # Path to source + alias __FINALPATH__; - # Example PHP configuration - index index.php /YNH_WWW_PATH/public/index.php; - - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm.sock; + index index.php __PATH__/_h5ai/public/index.php; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } + try_files $uri.html $uri $uri/ =404; - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + client_max_body_size 10G; + + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/manifest.json b/manifest.json index 58cc930..4b4528e 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,7 @@ "name": "H5AI", "id": "h5ai", "packaging_format": 1, + "version": "0.29.0~ynh1", "description": { "en": "A modern HTTP web server index for Nginx.", "fr": "Un serveur moderne d'index pour Nginx." @@ -9,11 +10,11 @@ "url": "https://larsjung.de/h5ai/", "license": "free", "maintainer": { - "name": "inrepublica", - "email": "duvalmickael@gmail.com" + "name": "alexAubin", + "email": "alex.aubin@mailoo.org" }, "requirements": { - "yunohost": ">= 2.4.0.6" + "yunohost": ">= 3.0.0" }, "multi_instance": false, "services": [ @@ -38,8 +39,17 @@ "en": "Choose a path for H5AI", "fr": "Choisissez un chemin pour H5AI" }, - "example": "/_h5ai", - "default": "/_h5ai" + "example": "/documents", + "default": "/documents" + }, + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public application?", + "fr": "Est-ce une application publique ?" + }, + "default": true } ] } diff --git a/scripts/install b/scripts/install index fe68410..3f91a63 100644 --- a/scripts/install +++ b/scripts/install @@ -1,54 +1,80 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Define app -app=h5ai -version=0.29.0 -md5_source=dd44880a4353bec140ded7fdec0ac3ce +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 +#================================================= -# Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH +path_url=$YNH_APP_ARG_PATH +is_public=$YNH_APP_ARG_IS_PUBLIC -# Source YunoHost helpers -. /usr/share/yunohost/helpers +app=$YNH_APP_INSTANCE_NAME -# Save app settings -ynh_app_setting_set "$app" domain "$domain" -ynh_app_setting_set "$app" path "$path" +final_path=/var/www/$path_url # so e.g. if path_url is /docs, we put stuff in /var/www/docs -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= -# Download source, check md5, untar, copy it -sudo wget -q https://release.larsjung.de/h5ai/h5ai-$version.zip -O /tmp/h5ai.zip +# Register (book) web path +ynh_webpath_register $app $domain $path_url -# Check md5 -md5_check=($(md5sum /tmp/h5ai.zip)) -if [ $md5_source != $md5_check ] -then - ynh_die "the download is corrupted (md5 different)" -fi +# Check final_path availability +test ! -e "$final_path" || ynh_die "This path already contains a folder" -# unzip and copy it -sudo unzip -o /tmp/h5ai.zip -d /tmp/ -final_path=/var/www/$path -sudo mkdir -p $final_path -sudo cp -a /tmp/_h5ai/. $final_path +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app is_public $is_public +ynh_app_setting_set $app final_path $final_path + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# Download, check integrity, uncompress and patch the source from app.src +# For this app sources are in app subdirectory +ynh_setup_source "$final_path" # Set permissions to phpsysinfo directory -sudo chown -R www-data: $final_path +sudo chown -R www-data: "$final_path" -# 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 -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +#================================================= +# NGINX CONFIGURATION +#================================================= -# unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" +# Create a dedicated nginx config +ynh_add_nginx_config -# Restart services -sudo service nginx reload +#================================================= +# SETUP SSOWAT +#================================================= + +# Make app public if necessary or protect it +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove index 82cf716..8579c79 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,20 +1,31 @@ #!/bin/bash -# Define app -app=h5ai +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source YunoHost helpers -. /usr/share/yunohost/helpers +source /usr/share/yunohost/helpers -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) +#================================================= +# LOAD SETTINGS +#================================================= + +readonly app=$YNH_APP_INSTANCE_NAME +readonly domain=$(ynh_app_setting_get "$app" domain) +readonly final_path=$(ynh_app_setting_get "$app" final_path) + +#================================================= +# REMOVE THE MAIN DIR OF THE APP +#================================================= # Remove sources -sudo rm -rf /var/www/$path +ynh_secure_remove "$final_path" -# Remove configuration files -sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +#================================================= +# REMOVE THE NGINX CONFIGURATION +#================================================= -# Restart services -sudo service nginx reload \ No newline at end of file +ynh_remove_nginx_config +systemctl reload nginx