2015-08-11 12:26:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-07-10 16:24:09 +02:00
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
app="movim"
|
|
|
|
|
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Retrieve app settings
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path=$(ynh_app_setting_get "$app" path)
|
|
|
|
port=$(ynh_app_setting_get "$app" port)
|
|
|
|
ssoenabled=$(ynh_app_setting_get "$app" ssoenabled)
|
|
|
|
public_site=$(ynh_app_setting_get "$app" public_site)
|
2015-08-31 16:30:44 +02:00
|
|
|
timezone=`cat /etc/timezone`
|
2015-08-11 12:26:57 +02:00
|
|
|
|
2015-08-31 16:39:08 +02:00
|
|
|
# Check timezone
|
2016-07-10 16:24:09 +02:00
|
|
|
[[ -n "$timezone" ]] \
|
|
|
|
|| ynh_die "Could not detect timezone, please check /etc/timezone." \
|
|
|
|
&& echo "Detected timezone: $timezone"
|
2015-08-31 16:39:08 +02:00
|
|
|
|
2016-07-10 16:24:09 +02:00
|
|
|
# Copy Movim source files
|
2015-08-11 12:26:57 +02:00
|
|
|
final_path=/var/www/movim
|
2016-07-10 16:24:09 +02:00
|
|
|
sudo cp -a ../sources "$final_path"
|
2015-08-21 18:12:22 +02:00
|
|
|
|
|
|
|
# Create movim user if not exists and set permissions
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_system_user_exists movim \
|
|
|
|
|| sudo useradd -d /var/www/movim -s /bin/sh movim
|
|
|
|
sudo chown -R movim:www-data "$final_path"
|
|
|
|
sudo find "${final_path}/" -type f -print0 | sudo xargs -0 chmod 0640
|
|
|
|
sudo find "${final_path}/" -type d -print0 | sudo xargs -0 chmod 0750
|
2015-08-11 12:26:57 +02:00
|
|
|
|
2015-08-19 11:25:29 +02:00
|
|
|
# Update PHP dependencies
|
2016-03-15 16:28:38 +01:00
|
|
|
sudo su -c "cd $final_path && php composer.phar config --global discard-changes true" movim
|
|
|
|
sudo su -c "cd $final_path && php composer.phar install -n" movim
|
2015-08-11 12:26:57 +02:00
|
|
|
|
|
|
|
# Movim configuration
|
|
|
|
sudo sed -i "s@/ws/@$path/ws/@g" $final_path/app/assets/js/movim_websocket.js
|
|
|
|
|
2015-11-13 15:44:16 +01:00
|
|
|
# Upgrade db if necessary
|
2016-04-12 10:30:03 +02:00
|
|
|
sudo su -c "cd $final_path && php mud.php db --set" movim
|
2015-11-13 15:44:16 +01:00
|
|
|
|
2015-12-16 13:53:46 +01:00
|
|
|
# Reset SSO parameters
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_app_setting_delete "$app" protected_uris
|
|
|
|
ynh_app_setting_delete "$app" skipped_uris
|
2015-12-16 13:58:03 +01:00
|
|
|
sudo yunohost app clearaccess movim
|
2015-12-16 13:53:46 +01:00
|
|
|
|
2015-12-16 17:24:02 +01:00
|
|
|
# Replace old public_site variable (if exists) by ssoenabled
|
|
|
|
if [ ! -z "$public_site" ] && [ $public_site = "Yes" ];
|
|
|
|
then
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_app_setting_delete "$app" public_site
|
|
|
|
ynh_app_setting_set "$app" ssoenabled "No"
|
2015-12-16 17:24:02 +01:00
|
|
|
elif [ ! -z "$public_site" ] && [ $public_site = "No" ];
|
|
|
|
then
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_app_setting_delete "$app" public_site
|
|
|
|
ynh_app_setting_set "$app" ssoenabled "Yes"
|
2015-12-16 17:24:02 +01:00
|
|
|
fi
|
|
|
|
|
2015-12-16 13:53:46 +01:00
|
|
|
# SSOwat Configuration
|
2015-12-16 17:24:02 +01:00
|
|
|
if [ $ssoenabled = "No" ];
|
2015-08-21 18:12:22 +02:00
|
|
|
then
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
2016-04-15 10:08:22 +02:00
|
|
|
sudo su -c "cd $final_path && php mud.php config --xmppwhitelist=$domain" movim
|
2015-12-16 13:53:46 +01:00
|
|
|
else
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2016-01-07 10:46:40 +01:00
|
|
|
# Next line is to avoid SSO to auto-connect just after disconnect
|
|
|
|
sudo sed -i "s@redirect('login')@redirect('')@g" $final_path/app/controllers/DisconnectController.php
|
2015-08-21 18:12:22 +02:00
|
|
|
fi
|
|
|
|
|
2015-08-19 11:25:29 +02:00
|
|
|
# Update init scripts
|
2015-08-19 14:08:24 +02:00
|
|
|
sudo sed -i "s@YHURL@$domain$path@g" ../conf/movim.{service,init}
|
|
|
|
sudo sed -i "s@YHDIR@$final_path@g" ../conf/movim.{service,init}
|
|
|
|
sudo sed -i "s@YHPORT@$port@g" ../conf/movim.{service,init}
|
2015-08-19 11:25:29 +02:00
|
|
|
initcheck=`pgrep -ox systemd`
|
|
|
|
if [ "$initcheck" = "1" ];
|
|
|
|
then
|
2015-09-10 16:37:25 +02:00
|
|
|
sudo rm -f /lib/systemd/system/movim.service
|
|
|
|
sudo cp ../conf/movim.service /etc/systemd/system/
|
2015-08-31 14:52:30 +02:00
|
|
|
sudo systemctl daemon-reload
|
2015-08-19 11:25:29 +02:00
|
|
|
else
|
|
|
|
sudo /etc/init.d/movim stop
|
|
|
|
sudo cp ../conf/movim.init /etc/init.d/movim
|
|
|
|
sudo chmod 755 /etc/init.d/movim
|
2015-09-10 16:19:54 +02:00
|
|
|
sudo update-rc.d movim defaults
|
2015-08-19 11:25:29 +02:00
|
|
|
sudo /etc/init.d/movim start
|
|
|
|
fi
|
|
|
|
|
2015-08-21 18:12:22 +02:00
|
|
|
# Update php-fpm configuration
|
2015-08-31 16:30:44 +02:00
|
|
|
sed -i "s@YHTZ@$timezone@g" ../conf/php-fpm.conf
|
2015-08-21 18:12:22 +02:00
|
|
|
sudo cp ../conf/php-fpm.conf /etc/php5/fpm/pool.d/movim.conf
|
|
|
|
|
|
|
|
# Nginx configuration
|
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@YHPORT@$port@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@//ws/@/ws/@g" ../conf/nginx.conf # Avoid duplicate /
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/movim.conf
|
|
|
|
|
2015-08-11 12:26:57 +02:00
|
|
|
# Reload
|
2015-08-19 14:00:16 +02:00
|
|
|
sudo service movim restart
|
2015-08-21 18:12:22 +02:00
|
|
|
sudo service php5-fpm restart
|
|
|
|
sudo service nginx reload
|