2014-01-07 21:50:21 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-07-10 13:11:55 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2016-07-10 18:40:48 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2014-01-07 21:50:21 +01:00
|
|
|
# Retrieve arguments
|
2016-07-10 13:11:55 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
2016-07-11 09:04:42 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2016-07-10 13:11:55 +02:00
|
|
|
port=9001
|
2014-01-07 21:50:21 +01:00
|
|
|
|
|
|
|
# Check domain/path availability
|
2018-05-13 11:13:22 +02:00
|
|
|
sudo yunohost app checkurl $domain$path -a $app
|
2014-01-07 21:50:21 +01:00
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2016-07-10 13:11:55 +02:00
|
|
|
exit 1
|
2014-01-07 21:50:21 +01:00
|
|
|
fi
|
|
|
|
|
2016-07-10 13:11:55 +02:00
|
|
|
# Store config on YunoHost instance
|
2016-07-10 18:40:48 +02:00
|
|
|
ynh_app_setting_set "$app" domain "$domain"
|
|
|
|
ynh_app_setting_set "$app" path "$path"
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
2014-07-22 21:38:34 +02:00
|
|
|
|
2014-07-20 14:14:15 +02:00
|
|
|
# Remove trailing "/" for next commands
|
|
|
|
path=${path%/}
|
|
|
|
|
2014-01-07 22:15:39 +01:00
|
|
|
# Generate random key
|
2016-07-10 18:40:48 +02:00
|
|
|
# key=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
|
|
key=$(ynh_string_random 12)
|
2014-01-07 22:15:39 +01:00
|
|
|
|
2016-07-10 18:40:48 +02:00
|
|
|
# Generate MySQL password and create database
|
|
|
|
dbuser=$app
|
|
|
|
dbname=$app
|
|
|
|
dbpass=$(ynh_string_random 12)
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
2016-07-10 19:15:13 +02:00
|
|
|
ynh_app_setting_set "$app" dbpass "$dbpass"
|
|
|
|
ynh_app_setting_set "$app" dbuser "$dbuser"
|
|
|
|
ynh_app_setting_set "$app" dbname "$dbname"
|
|
|
|
|
2014-01-07 22:15:39 +01:00
|
|
|
|
2014-01-07 21:50:21 +01:00
|
|
|
# Install dependances
|
2016-07-10 13:11:55 +02:00
|
|
|
if ! ynh_package_is_installed "nodejs-legacy" ; then
|
|
|
|
sudo apt-get install nodejs-legacy npm -y
|
|
|
|
fi
|
2014-01-07 21:50:21 +01:00
|
|
|
|
2018-05-13 11:13:22 +02:00
|
|
|
# create app dir and copy sources
|
2016-07-10 13:11:55 +02:00
|
|
|
final_path=/var/www/$app
|
2014-01-07 21:50:21 +01:00
|
|
|
sudo mkdir -p $final_path
|
2014-01-10 15:14:59 +01:00
|
|
|
|
2016-07-11 00:07:26 +02:00
|
|
|
sudo cp -a ../sources/* $final_path
|
2014-01-10 14:15:01 +01:00
|
|
|
|
2016-07-11 00:07:26 +02:00
|
|
|
sudo cp ../conf/settings.json $final_path
|
2016-07-10 13:11:55 +02:00
|
|
|
# Change variables in etherpad configuration
|
2016-07-10 19:15:13 +02:00
|
|
|
sudo sed -i "s/yunouser/$dbuser/g" $final_path/settings.json
|
|
|
|
sudo sed -i "s/yunopass/$dbpass/g" $final_path/settings.json
|
|
|
|
sudo sed -i "s/yunobase/$dbname/g" $final_path/settings.json
|
2014-01-10 15:52:12 +01:00
|
|
|
sudo sed -i "s/KEY/$key/g" $final_path/settings.json
|
2014-01-07 21:50:21 +01:00
|
|
|
|
2016-07-11 00:07:26 +02:00
|
|
|
sudo npm cache clear
|
|
|
|
sudo $final_path/bin/installDeps.sh > /dev/null 2>&1
|
|
|
|
sudo npm install forever -g > /dev/null 2>&1
|
|
|
|
|
2016-07-10 13:11:55 +02:00
|
|
|
# Set permissions to etherpad directory
|
2014-01-07 21:50:21 +01:00
|
|
|
sudo chown -R www-data: $final_path
|
|
|
|
|
2016-07-11 00:07:26 +02:00
|
|
|
# service
|
|
|
|
sudo cp ../conf/etherpad-lite /etc/init.d/$app
|
|
|
|
sudo sed -i "s/APPTOCHANGE/$app/g" /etc/init.d/$app
|
|
|
|
sudo chmod +x /etc/init.d/$app
|
|
|
|
sudo update-rc.d $app defaults
|
2016-07-10 13:11:55 +02:00
|
|
|
|
2016-07-11 00:07:26 +02:00
|
|
|
# logs
|
|
|
|
sudo mkdir /var/log/$app
|
|
|
|
sudo touch /var/log/$app/$app.log
|
|
|
|
sudo chown www-data /var/log/$app/$app.log
|
|
|
|
|
|
|
|
# nginx
|
2016-07-11 00:15:42 +02:00
|
|
|
nginx_conf_path=/etc/nginx/conf.d/$domain.d/$app.conf
|
2018-05-13 11:13:22 +02:00
|
|
|
if [ "$path" = "" ]; then
|
2016-07-11 00:07:26 +02:00
|
|
|
sudo cp ../conf/nginx.conf-nosub $nginx_conf_path
|
2014-07-20 14:14:15 +02:00
|
|
|
else
|
2016-07-11 00:07:26 +02:00
|
|
|
sudo cp ../conf/nginx.conf $nginx_conf_path
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" $nginx_conf_path
|
|
|
|
sudo sed -i "s@YNH_EXAMPLE_PORT@$port@g" $nginx_conf_path
|
|
|
|
sudo sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@g" $nginx_conf_path
|
2014-01-10 15:37:13 +01:00
|
|
|
fi
|
2014-01-07 21:50:21 +01:00
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service nginx reload
|
2016-07-10 18:40:48 +02:00
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
|
|
|
if [[ $is_public -eq 1 ]]; then
|
2016-07-11 09:04:42 +02:00
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
2016-07-10 18:40:48 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2014-01-07 21:50:21 +01:00
|
|
|
fi
|
2016-07-11 00:07:26 +02:00
|
|
|
|
2014-01-07 21:50:21 +01:00
|
|
|
sudo yunohost app ssowatconf
|
2016-07-11 00:07:26 +02:00
|
|
|
|
2014-01-10 15:16:36 +01:00
|
|
|
sudo service etherpad-lite start
|