2016-05-07 02:14:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
2017-04-16 17:22:30 +02:00
|
|
|
set -eu
|
2016-05-07 02:14:57 +02:00
|
|
|
|
2017-05-16 20:44:51 +02:00
|
|
|
if [ ! -e _common ]; then
|
|
|
|
# Fetch helpers file if not in current directory
|
|
|
|
sudo cp ../settings/scripts/_common ./_common
|
|
|
|
sudo chmod a+rx _common
|
|
|
|
fi
|
|
|
|
source _common
|
2017-04-16 17:22:30 +02:00
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
2016-05-07 02:14:57 +02:00
|
|
|
|
|
|
|
# This is a multi-instance app, meaning it can be installed several times independently
|
|
|
|
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
|
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
|
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
|
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
|
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
|
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
|
|
# The app instance name is probably what you are interested the most, since this is
|
|
|
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
|
|
# db names, ...
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
# Retrieve arguments
|
2017-04-16 17:22:30 +02:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path=$(ynh_app_setting_get "$app" path)
|
|
|
|
user=$(ynh_app_setting_get $app allowed_users)
|
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
2016-05-07 02:14:57 +02:00
|
|
|
|
|
|
|
# Check domain/path availability
|
2017-05-16 20:44:51 +02:00
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app"
|
2016-05-07 02:14:57 +02:00
|
|
|
|
2017-04-16 17:22:30 +02:00
|
|
|
# Check $final_path
|
|
|
|
final_path="/var/www/${app}"
|
2016-05-07 02:14:57 +02:00
|
|
|
if [ -d $final_path ]; then
|
2017-04-16 17:22:30 +02:00
|
|
|
ynh_die "There is already a directory: $final_path"
|
2016-05-07 02:14:57 +02:00
|
|
|
fi
|
|
|
|
|
2017-04-16 17:22:30 +02:00
|
|
|
# Check configuration files
|
|
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
|
|
if [ -f $nginx_conf ]; then
|
|
|
|
ynh_die "The NGINX configuration already exists at '${nginx_conf}'.
|
|
|
|
You should safely delete it before restoring this app."
|
2016-05-07 02:14:57 +02:00
|
|
|
fi
|
2017-04-16 23:57:23 +02:00
|
|
|
# Check configuration files php-fpm
|
|
|
|
phpfpm_conf="/etc/php5/fpm/pool.d/php-fpm-${app}.conf"
|
|
|
|
if [ -f $phpfpm_conf ]; then
|
|
|
|
ynh_die "The PHP FPM configuration already exists at '${phpfpm_conf}'.
|
|
|
|
You should safely delete it before restoring this app."
|
|
|
|
fi
|
|
|
|
|
|
|
|
phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini"
|
|
|
|
if [ -f $phpfpm_ini ]; then
|
|
|
|
ynh_die "The PHP FPM INI configuration already exists at '${phpfpm_ini}'.
|
|
|
|
You should safely delete it before restoring this app."
|
|
|
|
fi
|
2017-05-16 20:44:51 +02:00
|
|
|
# Create dedicated system user for this app
|
|
|
|
ynh_system_user_create $app
|
2016-05-07 02:14:57 +02:00
|
|
|
|
|
|
|
# Restore sources & data
|
|
|
|
sudo cp -a "./sources" $final_path
|
|
|
|
|
|
|
|
# Set permissions
|
2016-08-24 19:41:07 +02:00
|
|
|
sudo chown -R root:root $final_path
|
2017-05-16 20:44:51 +02:00
|
|
|
sudo chown -R $app:root $final_path/{data,tmp}
|
2016-08-24 19:41:07 +02:00
|
|
|
sudo chmod -R 700 $final_path/{data,tmp}
|
2016-05-07 02:14:57 +02:00
|
|
|
|
2017-05-20 19:40:39 +02:00
|
|
|
# Restore nginx configuration files
|
2017-04-16 17:22:30 +02:00
|
|
|
sudo cp -a ./conf/nginx.conf "${nginx_conf}"
|
2017-05-16 20:44:51 +02:00
|
|
|
sudo cp -a ./php-fpm.conf "$phpfpm_conf"
|
|
|
|
sudo cp -a ./php-fpm.ini "$phpfpm_ini"
|
2016-05-07 02:14:57 +02:00
|
|
|
|
2017-05-20 19:40:39 +02:00
|
|
|
# Restore php-fpm configuration files
|
|
|
|
sudo cp -a ./conf/php-fpm.conf "${phpfpm_conf}"
|
|
|
|
sudo cp -a ./conf/php-fpm.ini "${phpfpm_ini}"
|
|
|
|
|
2016-05-07 02:14:57 +02:00
|
|
|
# Set ssowat config
|
2017-05-16 20:44:51 +02:00
|
|
|
if [ "$is_public" = "Yes" ];
|
2016-05-07 02:14:57 +02:00
|
|
|
then
|
2017-05-16 20:44:51 +02:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2016-05-07 02:14:57 +02:00
|
|
|
fi
|
2017-04-16 17:22:30 +02:00
|
|
|
|
|
|
|
# Reload service
|
|
|
|
sudo systemctl reload nginx
|
2017-05-16 20:44:51 +02:00
|
|
|
sudo systemctl reload php5-fpm
|
|
|
|
sudo yunohost app ssowatconf
|