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

[enh] close #19: use functions for duplicate code on scripts

This commit is contained in:
Moul 2016-08-20 02:31:08 +02:00
parent 6f96db42ac
commit aeef0080cd
3 changed files with 45 additions and 52 deletions

33
scripts/functions.sh Normal file
View file

@ -0,0 +1,33 @@
#/bin/bash
INSTALL_DUNITER_DEBIAN_PACKAGE () {
# Retrieve url of last version and version number
url=$(curl -s https://api.github.com/repos/duniter/duniter/releases | grep "browser_" | grep $arch | head -1 | cut -d\" -f4)
version=$(curl -s https://api.github.com/repos/duniter/duniter/releases | grep "browser_" | grep $arch | head -1 | cut -d/ -f8)
# Retrieve debian package and install it
wget -nc --quiet $url -P /tmp
sudo dpkg -i /tmp/duniter-$version-linux-$arch.deb
sudo rm -f /tmp/duniter-$version-linux-$arch.deb
}
CONFIG_SSOWAT_FOR_RESTRICTED_ACCESS () {
# Add admin to the allowed users
sudo yunohost app addaccess $app -u $admin
# Allow only allowed users to access admin panel
ynh_app_setting_set "$app" protected_uris "/"
# SSOwat Configuration
#ynh_app_setting_set "$app" unprotected_uris "/api/"
}
CONFIG_NGINX_FOR_WEB_ADMIN () {
# Configure Nginx
nginx_conf="../conf/nginx.conf"
#sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" $nginx_conf
sudo sed -i "s@YNH_EXAMPLE_PORT@$port@" $nginx_conf
sudo sed -i "s@YNH_EXAMPLE_DOMAIN@$domain@" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
sudo nginx -t && sudo service nginx reload
}

View file

@ -14,8 +14,9 @@ salt=$YNH_APP_ARG_SALT
password=$YNH_APP_ARG_PASSWORD password=$YNH_APP_ARG_PASSWORD
admin=$YNH_APP_ARG_ADMIN admin=$YNH_APP_ARG_ADMIN
# Source app helpers # Source app helpers and functions
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source functions.sh
# Check domain/path availability # Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \ sudo yunohost app checkurl "${domain}${path}" -a "$app" \
@ -48,7 +49,7 @@ if [ $arch == "x86_64" ]; then
arch="x64" arch="x64"
fi fi
if [[ $arch != "x64" && $arch != "armv7l" ]]; then if [[ $arch != "x64" && $arch != "armv7l" ]]; then
ynh_die "$arch is not currently supported." 2 ynh_die "$arch is not supported." 2
fi fi
# Open port on firewall # Open port on firewall
@ -59,14 +60,7 @@ 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"
# Retrieve url of last version and version number INSTALL_DUNITER_DEBIAN_PACKAGE
url=$(curl -s https://api.github.com/repos/duniter/duniter/releases | grep "browser_" | grep $arch | head -1 | cut -d\" -f4)
version=$(curl -s https://api.github.com/repos/duniter/duniter/releases | grep "browser_" | grep $arch | head -1 | cut -d/ -f8)
# Retrieve debian package and install it
wget -nc --quiet $url -P /tmp
sudo dpkg -i /tmp/duniter-$version-linux-$arch.deb
#sudo rm -f /tmp/duniter-$version-linux-$arch.deb
# Configure Duniter node # Configure Duniter node
sudo $app init --autoconf sudo $app init --autoconf
@ -82,19 +76,5 @@ sudo $app webstart
# Add Duniter service to the YunoHost monitoring # Add Duniter service to the YunoHost monitoring
sudo yunohost service add $app --log /home/admin/.config/$app/"$app"_default/"$app".log sudo yunohost service add $app --log /home/admin/.config/$app/"$app"_default/"$app".log
# Add admin to the allowed users CONFIG_SSOWAT_FOR_RESTRICTED_ACCESS
sudo yunohost app addaccess $app -u $admin CONFIG_NGINX_FOR_WEB_ADMIN
# Allow only allowed users to access admin panel
ynh_app_setting_set "$app" protected_uris "/"
# SSOwat Configuration
#ynh_app_setting_set "$app" unprotected_uris "/api/"
# Configure Nginx
nginx_conf="../conf/nginx.conf"
#sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" $nginx_conf
sudo sed -i "s@YNH_EXAMPLE_PORT@$port@" $nginx_conf
sudo sed -i "s@YNH_EXAMPLE_DOMAIN@$domain@" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
sudo nginx -t && sudo service nginx reload

View file

@ -3,8 +3,9 @@
# Exit on command errors and treat unset variables as an error # Exit on command errors and treat unset variables as an error
set -eu set -eu
# Source app helpers # Source app helpers and functions
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source functions.sh
# Retrive arguments # Retrive arguments
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -16,7 +17,7 @@ admin=$(ynh_app_setting_get "$app" admin)
# Check CPU arch # Check CPU arch
if [[ $arch != "x64" && $arch != "armv7l" ]]; then if [[ $arch != "x64" && $arch != "armv7l" ]]; then
ynh_die "$arch is not currently supported." 2 ynh_die "$arch is not supported." 2
fi fi
# Stop duniter daemon # Stop duniter daemon
@ -25,14 +26,7 @@ sudo $app stop
# Remove Duniter package # Remove Duniter package
sudo dpkg -r duniter sudo dpkg -r duniter
# Retrieve url of latest version and number INSTALL_DUNITER_DEBIAN_PACKAGE
url=$(curl -s https://api.github.com/repos/duniter/duniter/releases | grep "browser_" | grep $arch | head -1 | cut -d\" -f4)
version=$(curl -s https://api.github.com/repos/duniter/duniter/releases | grep "browser_" | grep $arch | head -1 | cut -d/ -f8)
# Retrieve Debian package and install it
wget -nc --quiet $url -P /tmp
sudo dpkg -i /tmp/duniter-$version-linux-$arch.deb
sudo rm -f /tmp/duniter-$version-linux-$arch.deb
# Start duniter daemon # Start duniter daemon
sudo $app webstart sudo $app webstart
@ -40,19 +34,5 @@ sudo $app webstart
# Remove trailing "/" for next command # Remove trailing "/" for next command
path=${path%/} path=${path%/}
# Add admin to the allowed users CONFIG_SSOWAT_FOR_RESTRICTED_ACCESS
sudo yunohost app addaccess $app -u $admin CONFIG_NGINX_FOR_WEB_ADMIN
# Allow only allowed users to access admin panel
ynh_app_setting_set "$app" protected_uris "/"
# SSOwat Configuration
#ynh_app_setting_set "$app" unprotected_uris "/api/"
# Upgrade Nginx configuration
nginx_conf="../conf/nginx.conf"
#sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" $nginx_conf
sudo sed -i "s@YNH_EXAMPLE_PORT@$port@" $nginx_conf
sudo sed -i "s@YNH_EXAMPLE_DOMAIN@$domain@" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
sudo nginx -t && sudo service nginx reload