1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/scripts/upgrade
Jérôme Lebleu 9ae09c9f4e [enh] Download Movim source code with git with local helpers
Instead of using a git submodule attached to this app, the Movim source
code is downloaded using git - as suggested in the Movim Wiki. It fixes by
the way the upgrade which was broken before that.
It also adds `scripts/_common.sh` which defines common variables and
functions.
2016-07-10 17:39:51 +02:00

108 lines
3.5 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
app="movim"
# Source YunoHost and local helpers
source /usr/share/yunohost/helpers
source ./_common.sh
# 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)
timezone=`cat /etc/timezone`
# Check timezone
[[ -n "$timezone" ]] \
|| ynh_die "Could not detect timezone, please check /etc/timezone." \
&& echo "Detected timezone: $timezone"
# Update Movim source code
(exec_cmd git fetch --quiet origin \
&& exec_cmd git reset --quiet --hard "$HEAD_COMMIT") \
|| ynh_die "Unable to download Movim source code."
## FIXME: consider installation in a subpath
exec_cmd sed -i "s@'/ws/'@'${path%/}/ws/'@g" \
"${DESTDIR}/app/assets/js/movim_websocket.js"
# Create movim user if not exists and set permissions
ynh_system_user_exists movim \
|| sudo useradd -d /var/www/movim -s /bin/sh movim
sudo chown -R movim:www-data "$DESTDIR"
sudo find "${DESTDIR}/" -type f -print0 | sudo xargs -0 chmod 0644
sudo find "${DESTDIR}/" -type d -print0 | sudo xargs -0 chmod 0755
sudo chmod 400 "${DESTDIR}/config/db.inc.php"
# Update PHP dependencies using composer
(exec_cmd php composer.phar config --global discard-changes true \
&& exec_cmd php composer.phar install -n) \
|| ynh_die "Unable to update Movim dependencies."
# Upgrade Movim database as needed
exec_cmd php mud.php db --set
# Reset SSO parameters
ynh_app_setting_delete "$app" protected_uris
ynh_app_setting_delete "$app" skipped_uris
sudo yunohost app clearaccess movim
# Replace old public_site variable (if exists) by ssoenabled
if [ ! -z "$public_site" ] && [ $public_site = "Yes" ];
then
ynh_app_setting_delete "$app" public_site
ynh_app_setting_set "$app" ssoenabled "No"
elif [ ! -z "$public_site" ] && [ $public_site = "No" ];
then
ynh_app_setting_delete "$app" public_site
ynh_app_setting_set "$app" ssoenabled "Yes"
fi
# SSOwat Configuration
if [ $ssoenabled = "No" ];
then
ynh_app_setting_set "$app" skipped_uris "/"
exec_cmd php mud.php config --xmppwhitelist=$domain
else
ynh_app_setting_set "$app" unprotected_uris "/"
# Next line is to avoid SSO to auto-connect just after disconnect
sudo sed -i "s@redirect('login')@redirect('')@g" $DESTDIR/app/controllers/DisconnectController.php
fi
# Update init scripts
sudo sed -i "s@YHURL@$domain$path@g" ../conf/movim.{service,init}
sudo sed -i "s@YHDIR@$DESTDIR@g" ../conf/movim.{service,init}
sudo sed -i "s@YHPORT@$port@g" ../conf/movim.{service,init}
initcheck=`pgrep -ox systemd`
if [ "$initcheck" = "1" ];
then
sudo rm -f /lib/systemd/system/movim.service
sudo cp ../conf/movim.service /etc/systemd/system/
sudo systemctl daemon-reload
else
sudo /etc/init.d/movim stop
sudo cp ../conf/movim.init /etc/init.d/movim
sudo chmod 755 /etc/init.d/movim
sudo update-rc.d movim defaults
sudo /etc/init.d/movim start
fi
# Update php-fpm configuration
sed -i "s@YHTZ@$timezone@g" ../conf/php-fpm.conf
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@$DESTDIR/@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
# Reload
sudo service movim restart
sudo service php5-fpm restart
sudo service nginx reload