1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/h5ai_ynh.git synced 2024-09-03 20:36:25 +02:00

Refactor / clean app

This commit is contained in:
Alexandre Aubin 2018-08-05 02:02:55 +02:00
parent 0598ba9ffe
commit 14a5db3e00
5 changed files with 131 additions and 73 deletions

6
conf/app.src Normal file
View file

@ -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

View file

@ -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;
}

View file

@ -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
}
]
}

View file

@ -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

View file

@ -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
ynh_remove_nginx_config
systemctl reload nginx