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:
parent
f266234ee6
commit
6acb783f35
6 changed files with 185 additions and 56 deletions
|
@ -4,21 +4,21 @@ location / {
|
||||||
proxy_set_header Host $http_host;
|
proxy_set_header Host $http_host;
|
||||||
proxy_set_header X-NginX-Proxy true;
|
proxy_set_header X-NginX-Proxy true;
|
||||||
|
|
||||||
proxy_pass http://localhost:YNH_EXAMPLE_PORT;
|
proxy_pass http://localhost:__PORT__;
|
||||||
proxy_redirect off;
|
proxy_redirect off;
|
||||||
|
|
||||||
# Socket.io support
|
# Socket.io support
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
proxy_read_timeout 86400s;
|
proxy_read_timeout 86400s;
|
||||||
proxy_send_timeout 86400s;
|
proxy_send_timeout 86400s;
|
||||||
|
|
||||||
location ~ \.(js|css|woff|woff2|ttf|png) {
|
location ~ \.(js|css|woff|woff2|ttf|png) {
|
||||||
proxy_pass http://localhost:9220;
|
proxy_pass http://localhost:9220;
|
||||||
access_by_lua_file /usr/share/ssowat/access.lua;
|
access_by_lua_file /usr/share/ssowat/access.lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /webui {
|
location /webui {
|
||||||
proxy_pass http://localhost:9220/;
|
proxy_pass http://localhost:9220/;
|
||||||
access_by_lua_file /usr/share/ssowat/access.lua;
|
access_by_lua_file /usr/share/ssowat/access.lua;
|
||||||
|
@ -30,7 +30,7 @@ location / {
|
||||||
proxy_pass http://localhost:9220$uri;
|
proxy_pass http://localhost:9220$uri;
|
||||||
access_by_lua_file /usr/share/ssowat/access.lua;
|
access_by_lua_file /usr/share/ssowat/access.lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~ /modules {
|
location ~ /modules {
|
||||||
proxy_pass http://localhost:9220;
|
proxy_pass http://localhost:9220;
|
||||||
access_by_lua_file /usr/share/ssowat/access.lua;
|
access_by_lua_file /usr/share/ssowat/access.lua;
|
||||||
|
|
|
@ -34,12 +34,12 @@
|
||||||
{
|
{
|
||||||
"name": "admin",
|
"name": "admin",
|
||||||
"type": "user",
|
"type": "user",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Administrator. Must a YunoHost user.",
|
"en": "Administrator. Must a YunoHost user.",
|
||||||
"fr": "Administrateur. Ce doit être un utilisateur YunoHost"
|
"fr": "Administrateur. Ce doit être un utilisateur YunoHost"
|
||||||
},
|
},
|
||||||
"example": "jon doe"
|
"example": "jon doe"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#/bin/bash
|
#/bin/bash
|
||||||
|
|
||||||
INSTALL_DUNITER_DEBIAN_PACKAGE () {
|
install_duniter_debian_package() {
|
||||||
version="v1.6.25"
|
version="v1.6.25"
|
||||||
git_repo="https://git.duniter.org/nodes/typescript/duniter/"
|
git_repo="https://git.duniter.org/nodes/typescript/duniter/"
|
||||||
if [ $arch == "x64" ]; then
|
if [ $arch == "x64" ]; then
|
||||||
|
@ -18,13 +18,13 @@ INSTALL_DUNITER_DEBIAN_PACKAGE () {
|
||||||
rm -f $deb_path
|
rm -f $deb_path
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIGURE_DUNITER () {
|
config_duniter() {
|
||||||
duniter config --ipv4 127.0.0.1 --port $port --remoteh $domain --remotep 80 --noupnp
|
duniter config --ipv4 127.0.0.1 --port $port --remoteh $domain --remotep 80 --noupnp
|
||||||
duniter config --addep "BMAS $domain 443"
|
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
|
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
|
# Add admin to the allowed users
|
||||||
yunohost app addaccess $app -u $admin
|
yunohost app addaccess $app -u $admin
|
||||||
|
|
||||||
|
@ -38,15 +38,7 @@ CONFIG_SSOWAT () {
|
||||||
ynh_app_setting_set "$app" redirected_urls "{'$domain/':'$domain/webui'}"
|
ynh_app_setting_set "$app" redirected_urls "{'$domain/':'$domain/webui'}"
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_NGINX () {
|
remove_duniter() {
|
||||||
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 () {
|
|
||||||
# Stop duniter daemon if running
|
# Stop duniter daemon if running
|
||||||
duniter status
|
duniter status
|
||||||
if [ `echo "$?"` == 0 ]; then
|
if [ `echo "$?"` == 0 ]; then
|
105
scripts/install
105
scripts/install
|
@ -1,33 +1,81 @@
|
||||||
#!/bin/bash
|
#!/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
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path="/"
|
path_url="/"
|
||||||
port=10901
|
port=10901
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
admin=$YNH_APP_ARG_ADMIN
|
||||||
|
|
||||||
# Source app helpers and functions
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
source functions.sh
|
#=================================================
|
||||||
|
|
||||||
|
### 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
|
# Check domain/path availability
|
||||||
|
#=================================================
|
||||||
|
|
||||||
yunohost app checkurl "${domain}${path}" -a "$app" \
|
yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
|| ynh_die "Path not available: ${domain}${path}"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Check port availability
|
# Check port availability
|
||||||
|
#=================================================
|
||||||
|
|
||||||
yunohost app checkport $port
|
yunohost app checkport $port
|
||||||
if [[ ! $? -eq 0 ]]; then
|
if [[ ! $? -eq 0 ]]; then
|
||||||
ynh_die "Port not available: ${port}"
|
ynh_die "Port not available: ${port}"
|
||||||
|
else
|
||||||
|
# Open port on firewall
|
||||||
|
yunohost firewall allow TCP $port > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Check the admin exists in YunoHost users
|
# Check the admin exists in YunoHost users
|
||||||
|
#=================================================
|
||||||
|
|
||||||
ynh_user_exists $admin
|
ynh_user_exists $admin
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Get CPU architecture and check it
|
# Get CPU architecture and check it
|
||||||
|
#=================================================
|
||||||
|
|
||||||
arch=$(uname -m)
|
arch=$(uname -m)
|
||||||
if [ $arch == "x86_64" ]; then
|
if [ $arch == "x86_64" ]; then
|
||||||
arch="x64"
|
arch="x64"
|
||||||
|
@ -36,25 +84,54 @@ if [[ $arch != "x64" && $arch != "armv7l" ]]; then
|
||||||
ynh_die "$arch is not supported." 2
|
ynh_die "$arch is not supported." 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Store config on YunoHost instance
|
#=================================================
|
||||||
|
# STORE SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
ynh_app_setting_set $app port $port
|
ynh_app_setting_set $app port $port
|
||||||
ynh_app_setting_set $app arch $arch
|
ynh_app_setting_set $app arch $arch
|
||||||
ynh_app_setting_set "$app" admin "$admin"
|
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
|
install_duniter_debian_package
|
||||||
CONFIGURE_DUNITER
|
config_duniter
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Reset Duniter node's existing data (blockchain, not conf)
|
# Reset Duniter node's existing data (blockchain, not conf)
|
||||||
|
#=================================================
|
||||||
|
|
||||||
duniter reset data > /dev/null
|
duniter reset data > /dev/null
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Launch Duniter node
|
# Launch Duniter node
|
||||||
|
#=================================================
|
||||||
|
|
||||||
duniter webstart
|
duniter webstart
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Add Duniter service to the YunoHost monitoring
|
# Add Duniter service to the YunoHost monitoring
|
||||||
|
#=================================================
|
||||||
|
|
||||||
yunohost service add $app --log /root/.config/$app/"$app"_default/"$app".log
|
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
|
||||||
|
|
|
@ -1,27 +1,55 @@
|
||||||
#!/bin/bash
|
#!/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 /usr/share/yunohost/helpers
|
||||||
source functions.sh
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
port=$(ynh_app_setting_get $app port)
|
port=$(ynh_app_setting_get $app port)
|
||||||
|
|
||||||
REMOVE_DUNITER
|
#=================================================
|
||||||
|
# STANDARD REMOVE
|
||||||
|
#=================================================
|
||||||
|
# STOP AND REMOVE APPLICATION / DEBIAN PACKAGE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
remove_duniter
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Remove data and conf
|
# Remove data and conf
|
||||||
rm -rf /root/.conf/duniter
|
#=================================================
|
||||||
|
|
||||||
|
ynh_secure_remove /root/.conf/duniter
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Remove Duniter service to YunoHost monitoring
|
# Remove Duniter service to YunoHost monitoring
|
||||||
|
#=================================================
|
||||||
|
|
||||||
yunohost service remove $app
|
yunohost service remove $app
|
||||||
|
|
||||||
# Remove Nginx configuration
|
#=================================================
|
||||||
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
# REMOVE NGINX CONFIGURATION
|
||||||
service nginx reload
|
#=================================================
|
||||||
|
|
||||||
# Close opened port
|
# Remove the dedicated nginx config
|
||||||
yunohost firewall disallow TCP $port
|
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
|
||||||
|
|
|
@ -1,25 +1,57 @@
|
||||||
#!/bin/bash
|
#!/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 /usr/share/yunohost/helpers
|
||||||
source functions.sh
|
|
||||||
|
|
||||||
# Retrive arguments
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
port=$(ynh_app_setting_get "$app" port)
|
port=$(ynh_app_setting_get "$app" port)
|
||||||
arch=$(ynh_app_setting_get "$app" arch)
|
arch=$(ynh_app_setting_get "$app" arch)
|
||||||
admin=$(ynh_app_setting_get "$app" admin)
|
admin=$(ynh_app_setting_get "$app" admin)
|
||||||
|
|
||||||
REMOVE_DUNITER
|
#=================================================
|
||||||
INSTALL_DUNITER_DEBIAN_PACKAGE
|
# REMOVE APPLICATION
|
||||||
CONFIGURE_DUNITER
|
#=================================================
|
||||||
|
|
||||||
|
remove_duniter
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REINSTALL APPLICATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
install_duniter_debian_package
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CONFIGURE APPLICATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
config_duniter
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Start duniter daemon
|
# Start duniter daemon
|
||||||
|
#=================================================
|
||||||
|
|
||||||
duniter webstart
|
duniter webstart
|
||||||
|
|
||||||
CONFIG_SSOWAT
|
#=================================================
|
||||||
CONFIG_NGINX
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CONFIGURE SSOWAT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
config_ssowat
|
||||||
|
|
Loading…
Add table
Reference in a new issue