2015-05-24 23:01:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-05-31 23:22:59 +02:00
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
2015-12-02 21:41:55 +01:00
|
|
|
|
2015-05-24 23:01:16 +02:00
|
|
|
# Retrieve arguments
|
2016-06-23 13:27:00 +02:00
|
|
|
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
|
2016-06-24 11:57:31 +02:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2016-06-23 13:27:00 +02:00
|
|
|
cpu=`bc -l <<< "scale=2; $YNH_APP_ARG_CPU/100"`
|
2016-06-22 20:31:03 +02:00
|
|
|
version=$(cat ../conf/upstream_version)
|
2015-12-25 21:33:56 +01:00
|
|
|
|
2016-05-31 15:26:06 +02:00
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2015-12-25 21:33:56 +01:00
|
|
|
# Check domain/path availability
|
2016-06-23 13:12:33 +02:00
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
2015-12-25 21:33:56 +01:00
|
|
|
|
2016-08-09 18:35:09 +02:00
|
|
|
# Check path is root
|
|
|
|
if [[ $path != '/' ]]; then
|
|
|
|
ynh_die "Web admin can only be installed on root path for now"
|
|
|
|
fi
|
|
|
|
|
2015-12-25 21:33:56 +01:00
|
|
|
# Check port availability
|
|
|
|
sudo yunohost app checkport $port
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-12-29 14:03:44 +01:00
|
|
|
# Check node availability
|
|
|
|
if curl --output /dev/null --silent --head --fail "$sync_node:$sync_port/node/summary"; then
|
2015-12-29 20:15:33 +01:00
|
|
|
echo "Node $sync_node:$sync_port is available"
|
2015-12-29 14:03:44 +01:00
|
|
|
else
|
2016-05-31 15:26:06 +02:00
|
|
|
ynh_die "Node $sync_node:$sync_port is not available" 2
|
2015-12-29 14:03:44 +01:00
|
|
|
fi
|
|
|
|
|
2016-06-24 11:57:31 +02:00
|
|
|
# Check the admin exists in YunoHost users
|
|
|
|
ynh_user_exists $admin
|
|
|
|
|
2016-06-24 11:49:05 +02:00
|
|
|
# Get CPU architecture and check it
|
2016-06-23 12:05:02 +02:00
|
|
|
arch=$(uname -m)
|
|
|
|
if [ $arch == "x86_64" ]; then
|
|
|
|
arch="x64"
|
|
|
|
fi
|
2016-07-03 11:47:35 +02:00
|
|
|
if [[ $arch != "x64" && $arch != "armv7l" ]]; then
|
2016-06-24 11:49:05 +02:00
|
|
|
ynh_die "$arch is not currently supported." 2
|
|
|
|
fi
|
2016-06-23 12:05:02 +02:00
|
|
|
|
2015-12-25 21:33:56 +01:00
|
|
|
# Open port on firewall
|
|
|
|
sudo yunohost firewall allow TCP $port > /dev/null 2>&1
|
|
|
|
|
|
|
|
# Store config on YunoHost instance
|
2016-05-31 15:26:06 +02:00
|
|
|
ynh_app_setting_set $app port $port
|
2016-06-23 12:05:02 +02:00
|
|
|
ynh_app_setting_set $app arch $arch
|
2016-06-24 11:57:31 +02:00
|
|
|
ynh_app_setting_set "$app" admin "$admin"
|
2015-05-24 23:01:16 +02:00
|
|
|
|
2016-06-24 11:49:05 +02:00
|
|
|
# Retrieve debian package and install it
|
|
|
|
wget -nc --quiet https://github.com/duniter/duniter/releases/download/$version/duniter-$version-linux-$arch.deb -P /tmp
|
2016-05-31 23:22:59 +02:00
|
|
|
sudo dpkg -i /tmp/duniter-$version-linux-$arch.deb
|
2016-05-31 19:38:57 +02:00
|
|
|
#sudo rm -f /tmp/duniter-$version-linux-$arch.deb
|
2015-05-24 23:01:16 +02:00
|
|
|
|
2016-05-02 14:54:52 +02:00
|
|
|
# Configure Duniter node
|
2016-05-31 19:57:12 +02:00
|
|
|
sudo $app init --autoconf
|
|
|
|
sudo $app config --remoteh $domain --port $port --remotep $port --salt $salt --passwd $password --cpu $cpu
|
2015-12-25 21:33:56 +01:00
|
|
|
|
2016-05-02 14:54:52 +02:00
|
|
|
# Synchronize Duniter node
|
2015-12-29 20:15:33 +01:00
|
|
|
echo "Synchronizing with $sync_node:$sync_port. It may take a while."
|
2016-05-31 19:57:12 +02:00
|
|
|
sudo $app sync $sync_node $sync_port --nointeractive
|
2015-12-27 13:07:02 +01:00
|
|
|
|
2016-05-02 14:54:52 +02:00
|
|
|
# Launch Duniter node
|
2016-06-23 14:47:19 +02:00
|
|
|
sudo $app webstart
|
2015-12-31 15:24:30 +01:00
|
|
|
|
2016-05-02 14:54:52 +02:00
|
|
|
# Add Duniter service to the YunoHost monitoring
|
|
|
|
sudo yunohost service add $app --log /home/admin/.config/$app/"$app"_default/"$app".log
|
2015-12-25 21:33:56 +01:00
|
|
|
|
2016-06-24 12:19:02 +02:00
|
|
|
# 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 "/"
|
|
|
|
|
2015-12-25 21:33:56 +01:00
|
|
|
# SSOwat Configuration
|
2016-06-24 12:19:02 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/" # "api/"
|
2015-12-25 21:33:56 +01:00
|
|
|
|
2016-06-23 12:11:46 +02:00
|
|
|
# Configure Nginx
|
|
|
|
nginx_conf="../conf/nginx.conf"
|
2016-08-09 18:35:09 +02:00
|
|
|
#sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" $nginx_conf
|
2016-06-23 12:11:46 +02:00
|
|
|
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
|
2015-12-25 21:33:56 +01:00
|
|
|
sudo service nginx reload
|