#!/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 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 # 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 # 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 "$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" # 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} sudo sed -i "s@YHPORT@${port}@g" ../conf/movim.{service,init} if [ -d /run/systemd/system ]; then sudo cp ../conf/movim.service /etc/systemd/system/ sudo systemctl --quiet daemon-reload sudo systemctl --quiet enable movim.service sudo systemctl --quiet 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@$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 # SSOwat configuration if [[ "$ssoenabled" = "0" ]]; then ynh_app_setting_set "$app" skipped_uris "/" exec_cmd php mud.php config --xmppwhitelist="$domain" else ynh_app_setting_set "$app" unprotected_uris "/" apply_sso_patch fi # Reload services sudo service php5-fpm restart sudo service nginx reload