1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/duniter_ynh.git synced 2024-09-03 18:26:35 +02:00
duniter_ynh/scripts/install
Moul 6f96db42ac [enh] #14: automatically retrieve last version
- retrive last version available for x64 or for armel architectures
- upgrade enable set -u
2016-08-20 01:35:46 +02:00

100 lines
3 KiB
Bash
Executable file

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
port=$YNH_APP_ARG_PORT
sync_node=$YNH_APP_ARG_SYNC_NODE
sync_port=$YNH_APP_ARG_SYNC_PORT
salt=$YNH_APP_ARG_SALT
password=$YNH_APP_ARG_PASSWORD
admin=$YNH_APP_ARG_ADMIN
# Source app helpers
source /usr/share/yunohost/helpers
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
# Check path is root
if [[ $path != '/' ]]; then
ynh_die "Web admin can only be installed on root path for now"
fi
# Check port availability
sudo yunohost app checkport $port
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Check node availability
if curl --output /dev/null --silent --head --fail "$sync_node:$sync_port/node/summary"; then
echo "Node $sync_node:$sync_port is available"
else
ynh_die "Node $sync_node:$sync_port is not available" 2
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"
fi
if [[ $arch != "x64" && $arch != "armv7l" ]]; then
ynh_die "$arch is not currently supported." 2
fi
# Open port on firewall
sudo yunohost firewall allow TCP $port > /dev/null 2>&1
# Store config on YunoHost instance
ynh_app_setting_set $app port $port
ynh_app_setting_set $app arch $arch
ynh_app_setting_set "$app" admin "$admin"
# 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
# Configure Duniter node
sudo $app init --autoconf
sudo $app config --remoteh $domain --port $port --remotep $port --salt $salt --passwd $password
# Synchronize Duniter node
echo "Synchronizing with $sync_node:$sync_port. It may take a while."
sudo $app sync $sync_node $sync_port --nointeractive
# Launch Duniter node
sudo $app webstart
# Add Duniter service to the YunoHost monitoring
sudo yunohost service add $app --log /home/admin/.config/$app/"$app"_default/"$app".log
# 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/"
# 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