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

216 lines
6.7 KiB
Text
Raw Normal View History

2015-08-11 12:26:57 +02:00
#!/bin/bash
2018-08-10 15:55:41 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2018-08-10 15:55:41 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2018-08-10 15:55:41 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2018-08-10 15:55:41 +02:00
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
2018-08-10 15:55:41 +02:00
path_url=$(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)
2018-08-10 15:55:41 +02:00
timezone=$(cat /etc/timezone)
2018-08-10 16:36:04 +02:00
final_path=$(ynh_app_setting_get "$app" final_path)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path="/var/www/$app"
ynh_app_setting_set "$app" final_path "$final_path"
fi
2018-08-10 15:55:41 +02:00
#=================================================
# ACTIVE TRAP
#=================================================
# TODO: activate backup
# Backup the current version of the app
# ynh_backup_before_upgrade
# ynh_clean_setup () {
# restore it if the upgrade fails
# ynh_restore_upgradebackup
# }
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
2015-08-11 12:26:57 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2015-08-31 16:39:08 +02:00
2017-12-29 14:33:28 +01:00
# Since Movim 0.13, zmq is required
2018-08-10 15:00:05 +02:00
ynh_install_app_dependencies php5-zmq
2017-12-29 14:33:28 +01:00
2018-08-10 15:55:41 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Init git repository as needed
2018-08-10 16:36:04 +02:00
if [ ! -d "${final_path}/.git" ]; then
tmp_path=/tmp/movim-git
sudo rm -rf "$tmp_path"
# Download Movim source code
(git clone "$GIT_REPO" "$tmp_path" \
&& cd "$tmp_path" && git checkout "$HEAD_COMMIT") \
|| ynh_die "Unable to download Movim source code."
2018-08-10 16:36:04 +02:00
sudo cp "${final_path}/config/db.inc.php" "${tmp_path}/config/db.inc.php"
# Replace current source code
2018-08-10 16:36:04 +02:00
sudo rm -rf "$final_path"
sudo mv "$tmp_path" "$final_path"
sudo chown -R movim:www-data "$final_path"
# Install composer for PHP dependencies
curl -sS https://getcomposer.org/installer \
2018-08-10 16:36:04 +02:00
| exec_cmd php -- --install-dir="$final_path"
fi
# Update Movim source code
(exec_cmd git fetch origin \
&& exec_cmd git reset --hard "$HEAD_COMMIT") \
|| ynh_die "Unable to download Movim source code."
2018-08-10 15:55:41 +02:00
## TODO: consider installation in a subpath
exec_cmd sed -i "s@'/ws/'@'${path_url%/}/ws/'@g" \
2018-08-10 16:36:04 +02:00
"${final_path}/app/assets/js/movim_websocket.js"
2015-08-21 18:12:22 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2015-08-21 18:12:22 +02:00
# Create movim user if not exists and set permissions
ynh_system_user_exists movim \
|| sudo useradd -d /var/www/movim -s /bin/sh movim
2018-08-10 15:55:41 +02:00
#=================================================
# SET PERMISSIONS
#=================================================
2018-08-10 16:36:04 +02:00
sudo chown -R movim:www-data "$final_path"
sudo find "${final_path}/" -type f -print0 | sudo xargs -0 chmod 0644
sudo find "${final_path}/" -type d -print0 | sudo xargs -0 chmod 0755
sudo chmod 400 "${final_path}/config/db.inc.php"
2015-08-11 12:26:57 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# install PHP dependencies
#=================================================
# Update PHP dependencies using composer
(exec_cmd php composer.phar config --global discard-changes true \
&& exec_cmd php composer.phar install --no-interaction) \
|| ynh_die "Unable to update Movim dependencies."
2015-08-11 12:26:57 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# Upgrade Movim Databas
#=================================================
# Upgrade Movim database as needed
exec_cmd php mud.php db --set
2018-08-10 15:55:41 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2015-12-16 13:53:46 +01:00
# Reset SSO parameters
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" ]; then
[[ $public_site = "Yes" ]] \
&& ssoenabled="No" \
|| ssoenabled="Yes"
ynh_app_setting_delete "$app" public_site
ynh_app_setting_set "$app" ssoenabled "$ssoenabled"
2015-12-16 17:24:02 +01:00
fi
2018-08-10 15:55:41 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
# SSOwat configuration
if [[ "$ssoenabled" = "No" ]]; then
ynh_app_setting_set "$app" skipped_uris "/"
exec_cmd php mud.php config --xmppwhitelist=$domain
sudo yunohost app ssowatconf
2015-12-16 13:53:46 +01:00
else
ynh_app_setting_set "$app" unprotected_uris "/"
apply_sso_patch
2015-08-21 18:12:22 +02:00
fi
2018-08-10 15:55:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
# Update init scripts
2018-08-10 15:55:41 +02:00
sudo sed -i "s@YHURL@${domain}${path_url}@g" ../conf/movim.{service,init}
2018-08-10 16:36:04 +02:00
sudo sed -i "s@YHDIR@${final_path}@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/
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
2018-08-10 15:55:41 +02:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2015-08-21 18:12:22 +02:00
# Update php-fpm configuration
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
2018-08-10 15:55:41 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2015-08-21 18:12:22 +02:00
# Nginx configuration
2018-08-10 15:55:41 +02:00
sed -i "s@PATHTOCHANGE@$path_url@g" ../conf/nginx.conf
2018-08-10 16:36:04 +02:00
sed -i "s@ALIASTOCHANGE@$final_path/@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
2018-08-10 15:55:41 +02:00
#=================================================
# RELOAD SERVICES
#=================================================
# 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