1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/scripts/install

145 lines
4.3 KiB
Text
Raw Normal View History

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
app="movim"
# Retrieve arguments
domain=$1
path=${2:-/}
2015-08-03 15:37:44 +02:00
admin=$3
2015-08-10 16:45:03 +02:00
password=$4
language=$5
2015-12-16 13:53:46 +01:00
ssoenabled=$6
2015-08-10 17:28:11 +02:00
port=$7
timezone=`cat /etc/timezone`
# 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" \
|| exit 1
2015-08-10 17:34:50 +02:00
# Check port availability
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
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
[[ -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
[[ -n "$timezone" ]] \
|| ynh_die "Could not detect timezone, please check /etc/timezone." \
&& echo "Detected timezone: $timezone"
2015-08-12 14:35:47 +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"
# Generate and save random MySQL password
db_pwd=$(ynh_string_random 12)
ynh_app_setting_set "$app" mysqlpwd "$db_pwd"
# Use 'movim' as database name and user
db_user=movim
db_name=movim
# Create MySQL database
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
2015-08-03 12:05:52 +02:00
# Install packages
ynh_package_install php5-gd php5-curl php5-imagick php5-cli
# 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
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-04 10:50:43 +02:00
# Copy init script or systemd service
sudo sed -i "s@YHURL@$domain$path@g" ../conf/movim.{service,init}
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
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
sudo update-rc.d movim defaults
2015-08-04 10:50:43 +02:00
sudo /etc/init.d/movim start
fi
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
# Nginx configuration
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
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 12:05:52 +02:00
# SSOwat Configuration
2015-12-16 13:53:46 +01:00
if [ $ssoenabled = "No" ];
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
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
sudo service php5-fpm restart
2015-08-21 17:45:36 +02:00
sudo service nginx reload