2016-04-29 16:32:48 +02:00
|
|
|
#!/bin/bash
|
2017-07-18 13:16:23 +02:00
|
|
|
set -eu
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-18 13:03:45 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-09-27 19:52:56 +02:00
|
|
|
source ./_common.sh
|
2017-07-18 13:03:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-07-19 11:13:17 +02:00
|
|
|
path=$YNH_APP_ARG_PATH
|
2017-07-18 13:03:45 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2017-07-18 14:42:10 +02:00
|
|
|
language=$YNH_APP_ARG_LANG
|
2017-07-18 13:03:45 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2018-05-05 12:37:51 +02:00
|
|
|
dbname=$app
|
2017-07-21 11:43:20 +02:00
|
|
|
serviceuser=rocketchat
|
2017-07-18 13:03:45 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Check for supported architecture
|
|
|
|
arch="$(uname -m)"
|
|
|
|
if [[ "$arch" != "x86_64" ]]; then
|
|
|
|
script_die "This app requires an x86_64 machine, but this one is '${arch}'."
|
|
|
|
fi
|
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
workdir=$(pwd)
|
|
|
|
|
2017-07-21 10:54:41 +02:00
|
|
|
# find suitable port (default 3000)
|
|
|
|
port=$(ynh_find_port 3000)
|
|
|
|
|
2018-05-05 11:51:14 +02:00
|
|
|
# if path do not begin with / add a / at the begining
|
|
|
|
if [ "${path:0:1}" != "/" ]; then
|
|
|
|
path="/$path"
|
|
|
|
fi
|
|
|
|
# if path do not end with / add a / at the end
|
|
|
|
if [ "${path:${#path}-1}" != "/" ] && [ ${#path} -gt 1 ]; then
|
|
|
|
path="$path/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-04-29 16:32:48 +02:00
|
|
|
# Check domain/path availability
|
2017-10-31 22:29:52 +01:00
|
|
|
ynh_webpath_available $domain $path
|
2016-04-29 16:32:48 +02:00
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2017-07-19 13:00:22 +02:00
|
|
|
ynh_die "domain not available"
|
2016-04-29 16:32:48 +02:00
|
|
|
fi
|
|
|
|
|
2017-10-31 22:29:52 +01:00
|
|
|
# Register/book a web path for an app
|
|
|
|
ynh_webpath_register $app $domain $path
|
|
|
|
|
2017-07-21 10:54:41 +02:00
|
|
|
final_path="/var/lib/$app"
|
2017-07-19 17:07:36 +02:00
|
|
|
[[ -d $final_path ]] && ynh_die \
|
|
|
|
"The destination directory '$final_path' already exists.\
|
|
|
|
You should safely delete it before installing this app."
|
|
|
|
|
2016-04-29 16:32:48 +02:00
|
|
|
# Save specific settings
|
2017-07-21 14:35:08 +02:00
|
|
|
ynh_app_setting_set $app node_version $NODE_VERSION
|
|
|
|
ynh_app_setting_set $app rocketchat_version $ROCKETCHAT_VERSION
|
2017-07-21 11:43:20 +02:00
|
|
|
ynh_app_setting_set $app serviceuser $serviceuser
|
2017-07-21 14:35:08 +02:00
|
|
|
ynh_app_setting_set $app port $port
|
2017-07-19 17:07:36 +02:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2017-07-21 14:35:08 +02:00
|
|
|
ynh_app_setting_set $app path $path
|
2017-07-18 13:16:23 +02:00
|
|
|
ynh_app_setting_set $app is_public $is_public
|
2016-04-29 16:32:48 +02:00
|
|
|
|
|
|
|
#Install dependencies
|
2017-09-04 22:24:56 +02:00
|
|
|
installdeps
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-18 14:51:10 +02:00
|
|
|
# Create destination
|
2019-05-13 15:41:47 +02:00
|
|
|
mkdir -p $final_path
|
2017-07-18 14:51:10 +02:00
|
|
|
|
2017-07-21 14:35:08 +02:00
|
|
|
# Create user
|
2019-05-13 15:41:47 +02:00
|
|
|
id -u $serviceuser || useradd -d "$final_path" -M $serviceuser
|
2017-07-21 14:35:08 +02:00
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
# Copy and set systemd configuration
|
2019-05-13 15:41:47 +02:00
|
|
|
ynh_replace_string "#ROOTURL#" "$domain" ../conf/rocketchat.service
|
|
|
|
ynh_replace_string "#LOCATION#" "${path:-/}" ../conf/rocketchat.service
|
|
|
|
ynh_replace_string "#PORT#" "$port" ../conf/rocketchat.service
|
|
|
|
ynh_replace_string "#USER#" "$serviceuser" ../conf/rocketchat.service
|
|
|
|
ynh_replace_string "#DESTDIR#" "$final_path" ../conf/rocketchat.service
|
|
|
|
ynh_replace_string "#DBNAME#" "$dbname" ../conf/rocketchat.service
|
2018-10-19 21:46:26 +02:00
|
|
|
# absolute node path needed
|
|
|
|
NODE_BIN=$(which node)
|
2019-05-13 15:41:47 +02:00
|
|
|
ynh_replace_string "#NODE#" "$NODE_BIN" ../conf/rocketchat.service
|
|
|
|
cp ../conf/rocketchat.service /etc/systemd/system/$app.service
|
|
|
|
systemctl daemon-reload
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
# Copy and set nginx configuration
|
|
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
2019-05-13 15:41:47 +02:00
|
|
|
ynh_replace_string "#APP#" "$app" ../conf/nginx.conf
|
|
|
|
ynh_replace_string "#PATH#" "$path" ../conf/nginx.conf
|
|
|
|
ynh_replace_string "#PORT#" "$port" ../conf/nginx.conf
|
|
|
|
ynh_replace_string "#LOCATION#" "${path:-/}" ../conf/nginx.conf
|
2018-05-05 12:37:51 +02:00
|
|
|
|
|
|
|
#set db name into ldap config
|
2019-05-13 15:41:47 +02:00
|
|
|
ynh_replace_string "#DBNAME#" "$dbname" ../conf/rocketchat_ldap.js
|
2017-07-19 11:13:17 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
cp ../conf/nginx.conf "$nginx_conf"
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2017-07-24 15:48:53 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
ynh_setup_source "$final_path"
|
2017-07-21 14:35:08 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
chown -R $serviceuser: $final_path
|
2016-04-29 16:32:48 +02:00
|
|
|
|
|
|
|
cd $final_path/programs/server/
|
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
-u $serviceuser npm install --production
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-21 12:02:12 +02:00
|
|
|
cd $workdir
|
2017-07-21 10:54:41 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
systemctl reload nginx
|
2016-04-29 16:32:48 +02:00
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
2017-07-19 14:01:50 +02:00
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
2016-04-29 16:32:48 +02:00
|
|
|
fi
|
2017-07-18 16:14:16 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
systemctl start $app.service
|
|
|
|
systemctl enable $app.service
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-21 10:54:41 +02:00
|
|
|
# add rocketchat to services
|
2019-05-13 15:41:47 +02:00
|
|
|
yunohost service add $app
|
2017-07-19 13:32:24 +02:00
|
|
|
|
2017-07-21 10:54:41 +02:00
|
|
|
# wait for rocketchat to populate db and start
|
|
|
|
waitforservice
|
2016-04-29 21:50:20 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
mongo < ../conf/rocketchat_ldap.js
|
2016-04-29 18:08:30 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
systemctl restart $app.service
|
2016-04-29 18:08:30 +02:00
|
|
|
|
2017-07-21 10:54:41 +02:00
|
|
|
waitforservice
|
2017-07-19 12:34:48 +02:00
|
|
|
|
2019-05-13 15:41:47 +02:00
|
|
|
yunohost app ssowatconf
|