2015-08-03 11:35:01 +02:00
|
|
|
#!/bin/bash
|
2016-07-10 16:24:09 +02:00
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
app="movim"
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
2016-07-10 16:24:09 +02:00
|
|
|
path=${2:-/}
|
2015-08-03 15:37:44 +02:00
|
|
|
admin=$3
|
2015-08-10 16:45:03 +02:00
|
|
|
password=$4
|
2015-08-10 15:52:45 +02:00
|
|
|
language=$5
|
2015-12-16 13:53:46 +01:00
|
|
|
ssoenabled=$6
|
2015-08-10 17:28:11 +02:00
|
|
|
port=$7
|
2015-08-31 16:30:44 +02:00
|
|
|
timezone=`cat /etc/timezone`
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2016-07-10 17:34:37 +02:00
|
|
|
# Source YunoHost and local helpers
|
2016-07-10 16:24:09 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-07-10 17:34:37 +02:00
|
|
|
source ./_common.sh
|
2016-07-10 16:24:09 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
# Check domain/path availability
|
2016-07-10 16:24:09 +02:00
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| exit 1
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-08-10 17:34:50 +02:00
|
|
|
# Check port availability
|
2016-07-10 16:24:09 +02:00
|
|
|
sudo yunohost app checkport "$port" \
|
|
|
|
|| exit 1
|
2015-08-10 17:34:50 +02:00
|
|
|
|
2015-08-12 14:35:47 +02:00
|
|
|
# Check user availability
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_user_exists "$admin" \
|
|
|
|
|| ynh_die "The chosen admin user does not exist."
|
2015-08-12 14:35:47 +02:00
|
|
|
|
|
|
|
# Check password not empty
|
2016-07-10 16:24:09 +02:00
|
|
|
[[ -n "$password" ]] \
|
|
|
|
|| ynh_die "You must set an admin password."
|
2015-08-31 15:16:42 +02:00
|
|
|
|
2015-08-31 16:39:08 +02:00
|
|
|
# Check timezone
|
2016-07-10 16:24:09 +02:00
|
|
|
[[ -n "$timezone" ]] \
|
|
|
|
|| ynh_die "Could not detect timezone, please check /etc/timezone." \
|
|
|
|
&& echo "Detected timezone: $timezone"
|
2015-08-12 14:35:47 +02:00
|
|
|
|
2016-07-10 16:24:09 +02:00
|
|
|
# Save app settings
|
|
|
|
ynh_app_setting_set "$app" admin "$admin"
|
|
|
|
ynh_app_setting_set "$app" ssoenabled "$ssoenabled"
|
|
|
|
ynh_app_setting_set "$app" port "$port"
|
|
|
|
ynh_app_setting_set "$app" path "$path"
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2016-07-10 16:24:09 +02:00
|
|
|
# Generate and save random MySQL password
|
|
|
|
db_pwd=$(ynh_string_random 12)
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$db_pwd"
|
2015-08-03 11:35:01 +02:00
|
|
|
|
|
|
|
# Use 'movim' as database name and user
|
|
|
|
db_user=movim
|
2016-07-10 16:24:09 +02:00
|
|
|
db_name=movim
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2016-07-10 16:24:09 +02:00
|
|
|
# Create MySQL database
|
|
|
|
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-08-03 12:05:52 +02:00
|
|
|
# Install packages
|
2016-07-10 16:24:09 +02:00
|
|
|
ynh_package_install php5-gd php5-curl php5-imagick php5-cli
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2016-07-10 17:34:37 +02:00
|
|
|
# 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"
|
2015-08-19 11:13:00 +02:00
|
|
|
|
2015-08-19 11:17:10 +02:00
|
|
|
# Create movim system user and set permissions
|
2015-08-21 17:45:36 +02:00
|
|
|
sudo useradd -d /var/www/movim -s /bin/sh movim
|
2016-07-10 17:34:37 +02:00
|
|
|
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 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."
|
|
|
|
|
|
|
|
# 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"
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-08-04 10:50:43 +02:00
|
|
|
# Copy init script or systemd service
|
|
|
|
sudo sed -i "s@YHURL@$domain$path@g" ../conf/movim.{service,init}
|
2016-07-10 17:34:37 +02:00
|
|
|
sudo sed -i "s@YHDIR@$DESTDIR@g" ../conf/movim.{service,init}
|
2015-08-10 17:28:11 +02:00
|
|
|
sudo sed -i "s@YHPORT@$port@g" ../conf/movim.{service,init}
|
2015-08-12 10:58:06 +02:00
|
|
|
initcheck=`pgrep -ox systemd`
|
|
|
|
if [ "$initcheck" = "1" ];
|
2015-08-04 10:50:43 +02:00
|
|
|
then
|
2015-09-10 16:37:25 +02:00
|
|
|
sudo cp ../conf/movim.service /etc/systemd/system/
|
2015-08-04 10:50:43 +02:00
|
|
|
sudo systemctl enable movim.service
|
|
|
|
sudo systemctl start movim.service
|
|
|
|
else
|
|
|
|
sudo cp ../conf/movim.init /etc/init.d/movim
|
|
|
|
sudo chmod 755 /etc/init.d/movim
|
2015-09-10 16:19:54 +02:00
|
|
|
sudo update-rc.d movim defaults
|
2015-08-04 10:50:43 +02:00
|
|
|
sudo /etc/init.d/movim start
|
|
|
|
fi
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-08-21 17:45:36 +02:00
|
|
|
# php-fpm configuration
|
2015-08-31 15:23:07 +02:00
|
|
|
sed -i "s@YHTZ@$timezone@g" ../conf/php-fpm.conf
|
2015-08-21 17:45:36 +02:00
|
|
|
sudo cp ../conf/php-fpm.conf /etc/php5/fpm/pool.d/movim.conf
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
# Nginx configuration
|
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
2016-07-10 17:34:37 +02:00
|
|
|
sed -i "s@ALIASTOCHANGE@$DESTDIR/@g" ../conf/nginx.conf
|
2015-08-10 17:28:11 +02:00
|
|
|
sed -i "s@YHPORT@$port@g" ../conf/nginx.conf
|
2015-08-21 16:18:30 +02:00
|
|
|
sed -i "s@//ws/@/ws/@g" ../conf/nginx.conf # Avoid duplicate /
|
2015-08-03 12:05:52 +02:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/movim.conf
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2016-07-10 17:56:37 +02:00
|
|
|
# SSOwat configuration
|
|
|
|
if [[ "$ssoenabled" = "0" ]]; then
|
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
|
|
|
exec_cmd php mud.php config --xmppwhitelist="$domain"
|
2015-12-16 13:53:46 +01:00
|
|
|
else
|
2016-07-10 17:56:37 +02:00
|
|
|
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" $DESTDIR/app/controllers/DisconnectController.php
|
2015-12-16 13:53:46 +01:00
|
|
|
fi
|
2015-08-03 12:05:52 +02:00
|
|
|
|
|
|
|
# Start Movim
|
2015-08-10 15:32:20 +02:00
|
|
|
sudo service php5-fpm restart
|
2015-08-21 17:45:36 +02:00
|
|
|
sudo service nginx reload
|