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"
|
|
|
|
|
2016-07-11 18:41:22 +02:00
|
|
|
# Source local helpers
|
2016-07-10 17:34:37 +02:00
|
|
|
source ./_common.sh
|
2016-07-10 16:24:09 +02:00
|
|
|
|
2016-07-11 18:41:22 +02:00
|
|
|
# Source YunoHost helpers if exists.
|
|
|
|
# If not, source backported helpers from file.
|
2016-07-11 20:18:24 +02:00
|
|
|
if [ -a "/usr/share/yunohost/helpers" ]; then
|
2016-07-11 18:41:22 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
else
|
|
|
|
source ./_helpers.sh
|
|
|
|
fi
|
|
|
|
|
2016-07-10 16:24:09 +02:00
|
|
|
# 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 20:36:22 +02:00
|
|
|
# Init git repository as needed
|
|
|
|
if [ ! -d "${DESTDIR}/.git" ]; then
|
|
|
|
tmp_path=/tmp/movim-git
|
|
|
|
sudo rm -rf "$tmp_path"
|
|
|
|
|
|
|
|
# Download Movim source code
|
2016-07-11 18:41:22 +02:00
|
|
|
(git clone "$GIT_REPO" "$tmp_path" \
|
|
|
|
&& cd "$tmp_path" && git checkout "$HEAD_COMMIT") \
|
2016-07-10 20:36:22 +02:00
|
|
|
|| ynh_die "Unable to download Movim source code."
|
|
|
|
sudo cp "${DESTDIR}/config/db.inc.php" "${tmp_path}/config/db.inc.php"
|
|
|
|
|
|
|
|
# Replace current source code
|
|
|
|
sudo rm -rf "$DESTDIR"
|
|
|
|
sudo mv "$tmp_path" "$DESTDIR"
|
|
|
|
sudo chown -R movim:www-data "$DESTDIR"
|
|
|
|
|
|
|
|
# Install composer for PHP dependencies
|
|
|
|
curl -sS https://getcomposer.org/installer \
|
2016-07-11 18:41:22 +02:00
|
|
|
| exec_cmd php -- --install-dir="$DESTDIR"
|
2016-07-10 20:36:22 +02:00
|
|
|
fi
|
|
|
|
|
2016-07-10 17:34:37 +02:00
|
|
|
# Update Movim source code
|
2016-07-11 18:41:22 +02:00
|
|
|
(exec_cmd git fetch origin \
|
|
|
|
&& exec_cmd git reset --hard "$HEAD_COMMIT") \
|
2016-07-10 17:34:37 +02:00
|
|
|
|| 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"
|
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
|
2016-07-10 17:34:37 +02:00
|
|
|
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"
|
2015-08-11 12:26:57 +02:00
|
|
|
|
2016-07-10 17:34:37 +02:00
|
|
|
# Update PHP dependencies using composer
|
|
|
|
(exec_cmd php composer.phar config --global discard-changes true \
|
2016-07-11 18:41:22 +02:00
|
|
|
&& exec_cmd php composer.phar install --no-interaction) \
|
2016-07-10 17:34:37 +02:00
|
|
|
|| ynh_die "Unable to update Movim dependencies."
|
2015-08-11 12:26:57 +02:00
|
|
|
|
2016-07-10 17:34:37 +02:00
|
|
|
# Upgrade Movim database as needed
|
|
|
|
exec_cmd php mud.php db --set
|
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
|
2016-07-10 17:56:37 +02:00
|
|
|
if [ ! -z "$public_site" ]; then
|
|
|
|
[[ $public_site = "Yes" ]] \
|
2016-07-11 18:41:22 +02:00
|
|
|
&& ssoenabled="No" \
|
|
|
|
|| ssoenabled="Yes"
|
2016-07-10 17:56:37 +02:00
|
|
|
ynh_app_setting_delete "$app" public_site
|
|
|
|
ynh_app_setting_set "$app" ssoenabled "$ssoenabled"
|
2015-12-16 17:24:02 +01:00
|
|
|
fi
|
|
|
|
|
2016-07-10 17:56:37 +02:00
|
|
|
# SSOwat configuration
|
2016-07-11 18:41:22 +02:00
|
|
|
if [[ "$ssoenabled" = "No" ]]; then
|
2016-07-10 17:56:37 +02:00
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
|
|
|
exec_cmd php mud.php config --xmppwhitelist=$domain
|
2016-07-11 18:41:22 +02:00
|
|
|
sudo yunohost app ssowatconf
|
2015-12-16 13:53:46 +01:00
|
|
|
else
|
2016-07-10 17:56:37 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2016-07-10 18:19:18 +02:00
|
|
|
apply_sso_patch
|
2015-08-21 18:12:22 +02:00
|
|
|
fi
|
|
|
|
|
2015-08-19 11:25:29 +02:00
|
|
|
# Update init scripts
|
2016-07-10 18:31:45 +02:00
|
|
|
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}
|
|
|
|
if [ -d /run/systemd/system ]; then
|
|
|
|
sudo rm -f /lib/systemd/system/movim.service
|
|
|
|
sudo cp ../conf/movim.service /etc/systemd/system/
|
2016-07-11 18:41:22 +02:00
|
|
|
sudo systemctl daemon-reload
|
2015-08-19 11:25:29 +02:00
|
|
|
else
|
2016-07-10 18:31:45 +02:00
|
|
|
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
|
2015-08-19 11:25:29 +02:00
|
|
|
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
|
2016-07-10 17:34:37 +02:00
|
|
|
sed -i "s@ALIASTOCHANGE@$DESTDIR/@g" ../conf/nginx.conf
|
2015-08-21 18:12:22 +02:00
|
|
|
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
|
|
|
|
|
2016-07-10 18:31:45 +02:00
|
|
|
# Reload services
|
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
|