1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/duniter_ynh.git synced 2024-09-03 18:26:35 +02:00

[fix] little Refactoring to use ynh_helper

This commit is contained in:
frju365 2018-11-30 12:26:36 +01:00
parent f266234ee6
commit 6acb783f35
6 changed files with 185 additions and 56 deletions

View file

@ -4,21 +4,21 @@ location / {
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:YNH_EXAMPLE_PORT;
proxy_pass http://localhost:__PORT__;
proxy_redirect off;
# Socket.io support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400s;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
location ~ \.(js|css|woff|woff2|ttf|png) {
proxy_pass http://localhost:9220;
access_by_lua_file /usr/share/ssowat/access.lua;
}
location /webui {
proxy_pass http://localhost:9220/;
access_by_lua_file /usr/share/ssowat/access.lua;
@ -30,7 +30,7 @@ location / {
proxy_pass http://localhost:9220$uri;
access_by_lua_file /usr/share/ssowat/access.lua;
}
location ~ /modules {
proxy_pass http://localhost:9220;
access_by_lua_file /usr/share/ssowat/access.lua;

View file

@ -34,12 +34,12 @@
{
"name": "admin",
"type": "user",
"ask": {
"en": "Administrator. Must a YunoHost user.",
"fr": "Administrateur. Ce doit être un utilisateur YunoHost"
},
"ask": {
"en": "Administrator. Must a YunoHost user.",
"fr": "Administrateur. Ce doit être un utilisateur YunoHost"
},
"example": "jon doe"
}
}
]
}
}

View file

@ -1,6 +1,6 @@
#/bin/bash
INSTALL_DUNITER_DEBIAN_PACKAGE () {
install_duniter_debian_package() {
version="v1.6.25"
git_repo="https://git.duniter.org/nodes/typescript/duniter/"
if [ $arch == "x64" ]; then
@ -18,13 +18,13 @@ INSTALL_DUNITER_DEBIAN_PACKAGE () {
rm -f $deb_path
}
CONFIGURE_DUNITER () {
config_duniter() {
duniter config --ipv4 127.0.0.1 --port $port --remoteh $domain --remotep 80 --noupnp
duniter config --addep "BMAS $domain 443"
duniter config --ws2p-host 127.0.0.1 --ws2p-port 20901 --ws2p-remote-host $domain --ws2p-remote-port 443 --ws2p-noupnp
}
CONFIG_SSOWAT () {
config_ssowat() {
# Add admin to the allowed users
yunohost app addaccess $app -u $admin
@ -38,15 +38,7 @@ CONFIG_SSOWAT () {
ynh_app_setting_set "$app" redirected_urls "{'$domain/':'$domain/webui'}"
}
CONFIG_NGINX () {
nginx_conf="../conf/nginx.conf"
sed -i "s@YNH_EXAMPLE_PORT@$port@" $nginx_conf
sed -i "s@YNH_EXAMPLE_DOMAIN@$domain@" $nginx_conf
cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
service nginx reload
}
REMOVE_DUNITER () {
remove_duniter() {
# Stop duniter daemon if running
duniter status
if [ `echo "$?"` == 0 ]; then

View file

@ -1,33 +1,81 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path="/"
path_url="/"
port=10901
admin=$YNH_APP_ARG_ADMIN
# Source app helpers and functions
source /usr/share/yunohost/helpers
source functions.sh
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# Check domain/path availability
#=================================================
yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
#=================================================
# Check port availability
#=================================================
yunohost app checkport $port
if [[ ! $? -eq 0 ]]; then
ynh_die "Port not available: ${port}"
else
# Open port on firewall
yunohost firewall allow TCP $port > /dev/null 2>&1
fi
#=================================================
# Check the admin exists in YunoHost users
#=================================================
ynh_user_exists $admin
#=================================================
# Get CPU architecture and check it
#=================================================
arch=$(uname -m)
if [ $arch == "x86_64" ]; then
arch="x64"
@ -36,25 +84,54 @@ if [[ $arch != "x64" && $arch != "armv7l" ]]; then
ynh_die "$arch is not supported." 2
fi
# Store config on YunoHost instance
#=================================================
# STORE SETTINGS
#=================================================
ynh_app_setting_set $app port $port
ynh_app_setting_set $app arch $arch
ynh_app_setting_set "$app" admin "$admin"
# Open port on firewall
yunohost firewall allow TCP $port > /dev/null 2>&1
#=================================================
# INSTALL DEBIAN PACKAGE AND CONFIGURE APPLICATION
#=================================================
INSTALL_DUNITER_DEBIAN_PACKAGE
CONFIGURE_DUNITER
install_duniter_debian_package
config_duniter
#=================================================
# Reset Duniter node's existing data (blockchain, not conf)
#=================================================
duniter reset data > /dev/null
#=================================================
# Launch Duniter node
#=================================================
duniter webstart
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# Add Duniter service to the YunoHost monitoring
#=================================================
yunohost service add $app --log /root/.config/$app/"$app"_default/"$app".log
CONFIG_SSOWAT
CONFIG_NGINX
#=================================================
# CONFIGURATION OF SSOWAT
#=================================================
config_ssowat
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

View file

@ -1,27 +1,55 @@
#!/bin/bash
# Exit and treat unset variables as an error
set -u
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers
source _common.sh
source /usr/share/yunohost/helpers
source functions.sh
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
REMOVE_DUNITER
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE APPLICATION / DEBIAN PACKAGE
#=================================================
remove_duniter
#=================================================
# Remove data and conf
rm -rf /root/.conf/duniter
#=================================================
ynh_secure_remove /root/.conf/duniter
#=================================================
# Remove Duniter service to YunoHost monitoring
#=================================================
yunohost service remove $app
# Remove Nginx configuration
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
service nginx reload
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Close opened port
yunohost firewall disallow TCP $port
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
echo "Close port $port" >&2
yunohost firewall disallow TCP $port 2>&1
fi

View file

@ -1,25 +1,57 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers and functions
source _common.sh
source /usr/share/yunohost/helpers
source functions.sh
# Retrive arguments
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
port=$(ynh_app_setting_get "$app" port)
arch=$(ynh_app_setting_get "$app" arch)
admin=$(ynh_app_setting_get "$app" admin)
REMOVE_DUNITER
INSTALL_DUNITER_DEBIAN_PACKAGE
CONFIGURE_DUNITER
#=================================================
# REMOVE APPLICATION
#=================================================
remove_duniter
#=================================================
# REINSTALL APPLICATION
#=================================================
install_duniter_debian_package
#=================================================
# CONFIGURE APPLICATION
#=================================================
config_duniter
#=================================================
# Start duniter daemon
#=================================================
duniter webstart
CONFIG_SSOWAT
CONFIG_NGINX
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CONFIGURE SSOWAT
#=================================================
config_ssowat