From 9ae09c9f4e87c904b5347f8305fd12a23ed8e4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 10 Jul 2016 17:34:37 +0200 Subject: [PATCH] [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. --- .gitmodules | 3 --- scripts/_common.sh | 23 ++++++++++++++++ scripts/install | 66 ++++++++++++++++++++++++++++------------------ scripts/upgrade | 42 ++++++++++++++++------------- sources | 1 - 5 files changed, 86 insertions(+), 49 deletions(-) delete mode 100644 .gitmodules create mode 100644 scripts/_common.sh delete mode 160000 sources diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index c13c381..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "sources"] - path = sources - url = git@github.com:movim/movim.git diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..de97d1c --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,23 @@ +# +# Common variables +# + +# Git repository of Movim +GIT_REPO="https://github.com/movim/movim" + +# Commit to checkout +HEAD_COMMIT="512523576b03c2c8952305e70681ed31172b9fd2" + +# Source code destination directory +DESTDIR="/var/www/movim" + +# +# Common helpers +# + +# Execute a command as movim user in the destination directory +# usage: exec_cmd COMMAND [ARG ...] +exec_cmd() { + (cd "$DESTDIR" \ + && sudo sudo -u movim "$@") +} diff --git a/scripts/install b/scripts/install index cdd7739..867d701 100644 --- a/scripts/install +++ b/scripts/install @@ -15,8 +15,9 @@ ssoenabled=$6 port=$7 timezone=`cat /etc/timezone` -# Source YunoHost helpers +# Source YunoHost and local helpers source /usr/share/yunohost/helpers +source ./_common.sh # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ @@ -59,36 +60,49 @@ ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" # Install packages ynh_package_install php5-gd php5-curl php5-imagick php5-cli -# Copy Movim source files -final_path=/var/www/movim -sudo cp -a ../sources "$final_path" -sudo cp "${final_path}/config/"{db.example.inc.php,db.inc.php} +# Download Movim source code +tmp_path=/tmp/movim-git +sudo rm -rf "$tmp_path" +(git clone --quiet "$GIT_REPO" "$tmp_path" \ + && cd "$tmp_path" && git checkout --quiet "$HEAD_COMMIT") \ + || ynh_die "Unable to download Movim source code." + +# Set database configuration +cp "${tmp_path}/config/"{db.example.inc.php,db.inc.php} +sed -i "s@'username' => 'username'@'username' => '$db_user'@g" \ + "${tmp_path}/config/db.inc.php" +sed -i "s@'password' => 'password'@'password' => '$db_pwd'@g" \ + "${tmp_path}/config/db.inc.php" +## FIXME: consider installation in a subpath +sed -i "s@'/ws/'@'${path%/}/ws/'@g" \ + "${tmp_path}/app/assets/js/movim_websocket.js" + +# Move Movim source code +sudo mv "$tmp_path" "$DESTDIR" # Create movim system user and set permissions sudo useradd -d /var/www/movim -s /bin/sh movim -sudo chown -R movim:www-data "$final_path" -sudo find "${final_path}/" -type f -print0 | sudo xargs -0 chmod 0640 -sudo find "${final_path}/" -type d -print0 | sudo xargs -0 chmod 0750 +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" -# Install PHP dependencies -sudo su -c "curl -sS https://getcomposer.org/installer | php -- --install-dir=$final_path" movim -sudo su -c "cd $final_path && php composer.phar config --global discard-changes true" movim # auto yes -sudo su -c "cd $final_path && php composer.phar install -n" movim # install + quiet mode +# Install PHP dependencies using composer +(curl -sS https://getcomposer.org/installer \ + | exec_cmd php -- --quiet --install-dir="$DESTDIR" \ + && exec_cmd php composer.phar config --global discard-changes true \ + && exec_cmd php composer.phar install -n) \ + || ynh_die "Unable to install Movim dependencies." -# Movim configuration -sudo sed -i "s@'username' => 'username'@'username' => '$db_user'@g" $final_path/config/db.inc.php -sudo sed -i "s@'password' => 'password'@'password' => '$db_pwd'@g" $final_path/config/db.inc.php -sudo sed -i "s@/ws/@$path/ws/@g" $final_path/app/assets/js/movim_websocket.js -sudo su -c "cd $final_path && php mud.php db --set" movim -sudo su -c "cd $final_path && php mud.php config --locale=$language" movim -sudo su -c "cd $final_path && php mud.php config --loglevel=1" movim -sudo su -c "cd $final_path && php mud.php config --timezone=$timezone" movim -sudo su -c "cd $final_path && php mud.php config --username=$admin" movim -sudo su -c "cd $final_path && php mud.php config --password=$password" movim +# 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" # Copy init script or systemd service sudo sed -i "s@YHURL@$domain$path@g" ../conf/movim.{service,init} -sudo sed -i "s@YHDIR@$final_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" ]; @@ -109,7 +123,7 @@ 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@$final_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 @@ -118,11 +132,11 @@ sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/movim.conf if [ $ssoenabled = "No" ]; then ynh_app_setting_set "$app" skipped_uris "/" - sudo su -c "cd $final_path && php mud.php config --xmppwhitelist=$domain" movim + 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" $final_path/app/controllers/DisconnectController.php + sudo sed -i "s@redirect('login')@redirect('')@g" $DESTDIR/app/controllers/DisconnectController.php fi # Start Movim diff --git a/scripts/upgrade b/scripts/upgrade index 9bf5168..eb5fee1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -5,8 +5,9 @@ set -eu app="movim" -# Source YunoHost helpers +# Source YunoHost and local helpers source /usr/share/yunohost/helpers +source ./_common.sh # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) @@ -21,26 +22,29 @@ timezone=`cat /etc/timezone` || ynh_die "Could not detect timezone, please check /etc/timezone." \ && echo "Detected timezone: $timezone" -# Copy Movim source files -final_path=/var/www/movim -sudo cp -a ../sources "$final_path" +# 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 "$final_path" -sudo find "${final_path}/" -type f -print0 | sudo xargs -0 chmod 0640 -sudo find "${final_path}/" -type d -print0 | sudo xargs -0 chmod 0750 +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 -sudo su -c "cd $final_path && php composer.phar config --global discard-changes true" movim -sudo su -c "cd $final_path && php composer.phar install -n" movim +# 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." -# Movim configuration -sudo sed -i "s@/ws/@$path/ws/@g" $final_path/app/assets/js/movim_websocket.js - -# Upgrade db if necessary -sudo su -c "cd $final_path && php mud.php db --set" movim +# Upgrade Movim database as needed +exec_cmd php mud.php db --set # Reset SSO parameters ynh_app_setting_delete "$app" protected_uris @@ -62,16 +66,16 @@ fi if [ $ssoenabled = "No" ]; then ynh_app_setting_set "$app" skipped_uris "/" - sudo su -c "cd $final_path && php mud.php config --xmppwhitelist=$domain" movim + 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" $final_path/app/controllers/DisconnectController.php + 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@$final_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" ]; @@ -93,7 +97,7 @@ 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@$final_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 diff --git a/sources b/sources deleted file mode 160000 index 5125235..0000000 --- a/sources +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 512523576b03c2c8952305e70681ed31172b9fd2