mirror of
https://github.com/YunoHost-Apps/movim_ynh.git
synced 2024-09-03 19:46:19 +02:00
[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.
This commit is contained in:
parent
3f86f21273
commit
9ae09c9f4e
5 changed files with 86 additions and 49 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "sources"]
|
||||
path = sources
|
||||
url = git@github.com:movim/movim.git
|
23
scripts/_common.sh
Normal file
23
scripts/_common.sh
Normal file
|
@ -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 "$@")
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
1
sources
1
sources
|
@ -1 +0,0 @@
|
|||
Subproject commit 512523576b03c2c8952305e70681ed31172b9fd2
|
Loading…
Add table
Reference in a new issue