diff --git a/conf/db.inc.php b/conf/db.inc.php new file mode 100644 index 0000000..e876147 --- /dev/null +++ b/conf/db.inc.php @@ -0,0 +1,17 @@ + 'mysql', + # The database username + 'username' => '__DB_USER__', + # The password + 'password' => '__DB_PWD__', + # Where can we find the database ? + 'host' => 'localhost', + # The port number, 3306 for MySQL and 5432 for PostGreSQL + 'port' => 3306, + # The database name + 'database' => '__DB_NAME__' +]; diff --git a/scripts/_common.sh b/scripts/_common.sh index b4c690b..b7a2c22 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,14 +10,7 @@ PKGDIR=$(cd ../; pwd) # Common helpers # -# Execute a command as movim user in the destination directory -# usage: exec_cmd COMMAND [ARG ...] -exec_cmd() { - (cd "$final_path" \ - && sudo sudo -u movim "$@") -} - -# Undo the SSO patch to Movim source code (applied by default with ynh_setup_source) +# Undo the SSO patch to source code (applied by default with ynh_setup_source) # usage: undo_sso_patch undo_sso_patch() { ( diff --git a/scripts/install b/scripts/install index 3e3eac1..5dc2a07 100644 --- a/scripts/install +++ b/scripts/install @@ -131,46 +131,26 @@ ynh_add_fpm_config #================================================= # TODO: add checksum -# Set database configuration -cp "$final_path/config/"{db.example.inc.php,db.inc.php} -ynh_replace_string "'username' => 'username'" "'username' => '$db_user'" \ - "$final_path/config/db.inc.php" -ynh_replace_string "'password' => 'password'" "'password' => '$db_pwd'" \ - "$final_path/config/db.inc.php" +cp ../conf/db.inc.php "$final_path/config/db.inc.php" + +ynh_replace_string "__DB_USER__" "$db_user" "$final_path/config/db.inc.php" +ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/config/db.inc.php" +ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/config/db.inc.php" + ## TODO: consider installation in a subpath ynh_replace_string "'/ws/'" "'${path_url%/}/ws/'" \ "$final_path/app/assets/js/movim_websocket.js" -#================================================= -# 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 using composer #================================================= -# Install PHP dependencies using composer -(curl -sS https://getcomposer.org/installer \ - | exec_cmd php -- --install-dir="$final_path" \ - && exec_cmd php composer.phar config --global discard-changes true \ - && exec_cmd php composer.phar install --no-interaction) \ - || ynh_die "Unable to install Movim dependencies." - - -#================================================= -# Set Movim database and configuration -#================================================= - -# Set Movim database and configuration -exec_cmd php mud.php db --set -exec_cmd php mud.php config --loglevel=1 \ - --locale="$language" --timezone="$timezone" \ - --username="$admin" --password="$password" +( + cd "$final_path" + curl -sS https://getcomposer.org/installer | php -- --install-dir="$final_path" \ + && php composer.phar config --global discard-changes true --quiet \ + && php composer.phar install --no-interaction --quiet +) #================================================= # SETUP SYSTEMD @@ -181,9 +161,29 @@ ynh_replace_string "__URL__" "${domain}${path_url}" ../conf/systemd.service ynh_replace_string "__PORT__" "${port}" ../conf/systemd.service ynh_add_systemd_config +#================================================= +# Set-up database and configuration +#================================================= + +( + cd "$final_path" + php mud.php db --set + php mud.php config --loglevel=1 \ + --locale="$language" --timezone="$timezone" \ + --username="$admin" --password="$password" +) + #================================================= # GENERIC FINALIZATION #================================================= +# SET PERMISSIONS +#================================================= + +# TODO: use more strict permissions +chown -R "$app":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" #================================================= # SETUP SSOWAT @@ -192,7 +192,7 @@ ynh_add_systemd_config # SSOwat configuration if [[ "$ssoenabled" = "No" ]]; then ynh_app_setting_set "$app" skipped_uris "/" - exec_cmd php mud.php config --xmppwhitelist="$domain" + (cd "$final_path" && php mud.php config --xmppwhitelist="$domain") undo_sso_patch else ynh_app_setting_set "$app" unprotected_uris "/" diff --git a/scripts/remove b/scripts/remove index f9d7661..8017332 100644 --- a/scripts/remove +++ b/scripts/remove @@ -69,7 +69,7 @@ ynh_secure_remove "$final_path" if yunohost firewall list | grep -q "\- $port$" then echo "Close port $port" >&2 - yunohost firewall disallow TCP $port 2>&1 + yunohost firewall disallow TCP "$port" 2>&1 fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 0b626a5..939f1f0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -72,7 +72,6 @@ path_url=$(ynh_normalize_url_path $path_url) # UPGRADE DEPENDENCIES #================================================= -# Since Movim 0.13, zmq is required ynh_install_app_dependencies php-gd php-curl php-imagick php-cli php-zmq #================================================= @@ -81,6 +80,10 @@ ynh_install_app_dependencies php-gd php-curl php-imagick php-cli php-zmq ynh_setup_source "$final_path" +## TODO: consider installation in a subpath +ynh_replace_string "'/ws/'" "'${path_url%/}/ws/'" \ + "${final_path}/app/assets/js/movim_websocket.js" + #================================================= # NGINX CONFIGURATION #================================================= @@ -102,40 +105,34 @@ ynh_system_user_create "$app" # Create a dedicated php-fpm config ynh_add_fpm_config - -chown -R movim:www-data "$final_path" - -## TODO: consider installation in a subpath -ynh_replace_string "'/ws/'" "'${path_url%/}/ws/'" \ - "${final_path}/app/assets/js/movim_websocket.js" - #================================================= # SET PERMISSIONS #================================================= -chown -R movim:www-data "$final_path" +chown -R "$app":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 +# Install PHP dependencies using composer #================================================= -curl -sS https://getcomposer.org/installer \ -| exec_cmd php -- --install-dir="$final_path" - -# 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." +( + cd "$final_path" + curl -sS https://getcomposer.org/installer | php -- --install-dir="$final_path" \ + && php composer.phar config --global discard-changes true --quiet \ + && php composer.phar install --no-interaction --quiet +) #================================================= -# Upgrade Movim Databas +# Set-up database #================================================= -# Upgrade Movim database as needed -exec_cmd php mud.php db --set +( + cd "$final_path" + php mud.php db --set +) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -144,7 +141,7 @@ exec_cmd php mud.php db --set # Reset SSO parameters ynh_app_setting_delete "$app" protected_uris ynh_app_setting_delete "$app" skipped_uris -yunohost app clearaccess movim +yunohost app clearaccess "$app" # Replace old public_site variable (if exists) by ssoenabled # TODO: add clean support for old/new setting public_site/ssoenabled @@ -163,7 +160,7 @@ fi # SSOwat configuration if [[ "$ssoenabled" = "No" ]]; then ynh_app_setting_set "$app" skipped_uris "/" - exec_cmd php mud.php config --xmppwhitelist=$domain + (cd "$final_path" && php mud.php config --xmppwhitelist="$domain") yunohost app ssowatconf undo_sso_patch else @@ -185,6 +182,4 @@ ynh_add_systemd_config #================================================= # Reload services -service movim restart -service php5-fpm restart service nginx reload