#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) 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) timezone=$(cat /etc/timezone) 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 #================================================= # 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) #================================================= # STANDARD UPGRADE STEPS #================================================= #================================================= # UPGRADE DEPENDENCIES #================================================= # Since Movim 0.13, zmq is required ynh_install_app_dependencies php5-zmq #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= # Init git repository as needed if [ ! -d "${final_path}/.git" ]; then tmp_path=/tmp/movim-git ynh_secure_remove "$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." cp "${final_path}/config/db.inc.php" "${tmp_path}/config/db.inc.php" # Replace current source code ynh_secure_remove "$final_path" mv "$tmp_path" "$final_path" chown -R movim:www-data "$final_path" # Install composer for PHP dependencies curl -sS https://getcomposer.org/installer \ | 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." ## TODO: consider installation in a subpath exec_cmd ynh_replace_string "'/ws/'" "'${path_url%/}/ws/'" \ "${final_path}/app/assets/js/movim_websocket.js" #================================================= # CREATE DEDICATED USER #================================================= # Create movim user if not exists and set permissions ynh_system_user_exists movim \ || useradd -d /var/www/movim -s /bin/sh movim #================================================= # SET PERMISSIONS #================================================= chown -R movim:www-data "$final_path" find "${final_path}/" -type f -print0 | xargs -0 chmod 0644 find "${final_path}/" -type d -print0 | xargs -0 chmod 0755 chmod 400 "${final_path}/config/db.inc.php" #================================================= # 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." #================================================= # Upgrade Movim Databas #================================================= # Upgrade Movim database as needed exec_cmd php mud.php db --set #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= # Reset SSO parameters ynh_app_setting_delete "$app" protected_uris ynh_app_setting_delete "$app" skipped_uris yunohost app clearaccess movim # 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" fi #================================================= # SETUP SSOWAT #================================================= # SSOwat configuration if [[ "$ssoenabled" = "No" ]]; then ynh_app_setting_set "$app" skipped_uris "/" exec_cmd php mud.php config --xmppwhitelist=$domain yunohost app ssowatconf else ynh_app_setting_set "$app" unprotected_uris "/" apply_sso_patch fi #================================================= # SETUP SYSTEMD #================================================= ynh_replace_string "YHURL" "${domain}${path_url}" ../conf/movim.service ynh_replace_string "YHDIR" "${final_path}" ../conf/movim.service ynh_replace_string "YHPORT" "${port}" ../conf/movim.service ynh_secure_remove /lib/systemd/system/movim.service cp ../conf/movim.service /etc/systemd/system/ systemctl daemon-reload #================================================= # PHP-FPM CONFIGURATION #================================================= # Update php-fpm configuration ynh_replace_string "YHTZ" "$timezone" ../conf/php-fpm.conf cp ../conf/php-fpm.conf /etc/php5/fpm/pool.d/movim.conf #================================================= # NGINX CONFIGURATION #================================================= # Nginx configuration ynh_replace_string "PATHTOCHANGE" "$path_url" ../conf/nginx.conf ynh_replace_string "ALIASTOCHANGE" "$final_path/" ../conf/nginx.conf ynh_replace_string "YHPORT" "$port" ../conf/nginx.conf ynh_replace_string "//ws/" "/ws/" ../conf/nginx.conf # Avoid duplicate / cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/movim.conf #================================================= # RELOAD SERVICES #================================================= # Reload services service movim restart service php5-fpm restart service nginx reload