mirror of
https://github.com/YunoHost-Apps/movim_ynh.git
synced 2024-09-03 19:46:19 +02:00
130 lines
4.3 KiB
Bash
130 lines
4.3 KiB
Bash
#!/bin/bash
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
app="movim"
|
|
|
|
# Retrieve arguments
|
|
domain=$1
|
|
path=${2:-/}
|
|
admin=$3
|
|
password=$4
|
|
language=$5
|
|
ssoenabled=$6
|
|
port=$7
|
|
timezone=`cat /etc/timezone`
|
|
|
|
# Source YunoHost helpers
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|| exit 1
|
|
|
|
# Check port availability
|
|
sudo yunohost app checkport "$port" \
|
|
|| exit 1
|
|
|
|
# Check user availability
|
|
ynh_user_exists "$admin" \
|
|
|| ynh_die "The chosen admin user does not exist."
|
|
|
|
# Check password not empty
|
|
[[ -n "$password" ]] \
|
|
|| ynh_die "You must set an admin password."
|
|
|
|
# Check timezone
|
|
[[ -n "$timezone" ]] \
|
|
|| ynh_die "Could not detect timezone, please check /etc/timezone." \
|
|
&& echo "Detected timezone: $timezone"
|
|
|
|
# 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"
|
|
|
|
# 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}
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# 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@YHPORT@$port@g" ../conf/movim.{service,init}
|
|
initcheck=`pgrep -ox systemd`
|
|
if [ "$initcheck" = "1" ];
|
|
then
|
|
sudo cp ../conf/movim.service /etc/systemd/system/
|
|
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
|
|
sudo /etc/init.d/movim start
|
|
fi
|
|
|
|
# php-fpm configuration
|
|
sed -i "s@YHTZ@$timezone@g" ../conf/php-fpm.conf
|
|
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@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
|
|
|
|
# SSOwat Configuration
|
|
if [ $ssoenabled = "No" ];
|
|
then
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
|
sudo su -c "cd $final_path && php mud.php config --xmppwhitelist=$domain" movim
|
|
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
|
|
fi
|
|
|
|
# Start Movim
|
|
sudo service php5-fpm restart
|
|
sudo service nginx reload
|