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
|
|
|
|
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
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
|
2017-07-21 14:35:08 +02:00
|
|
|
# Create user
|
2017-08-17 23:38:22 +02:00
|
|
|
id -u $serviceuser || sudo 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
|
2017-07-21 10:54:41 +02:00
|
|
|
sed -i "s@#ROOTURL#@$domain@g" ../conf/rocketchat.service
|
|
|
|
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/rocketchat.service
|
2017-07-21 11:56:40 +02:00
|
|
|
sed -i "s@#PORT#@$port@g" ../conf/rocketchat.service
|
|
|
|
sed -i "s@#USER#@$serviceuser@g" ../conf/rocketchat.service
|
2018-05-05 12:37:51 +02:00
|
|
|
sed -i "s@#DESTDIR#@$final_path@g" ../conf/rocketchat.service
|
|
|
|
sed -i "s@#DBNAME#@$dbname@g" ../conf/rocketchat.service
|
|
|
|
sudo cp ../conf/rocketchat.service /etc/systemd/system/$app.service
|
2017-07-19 11:27:56 +02:00
|
|
|
sudo 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"
|
2017-07-19 13:17:28 +02:00
|
|
|
sed -i "s@#APP#@$app@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@#PATH#@$path@g" ../conf/nginx.conf
|
2017-07-19 13:32:24 +02:00
|
|
|
sed -i "s@#PORT#@$port@g" ../conf/nginx.conf
|
2017-07-19 11:13:17 +02:00
|
|
|
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf
|
2018-05-05 12:37:51 +02:00
|
|
|
|
|
|
|
#set db name into ldap config
|
|
|
|
sed -i "s@#DBNAME#@$dbname@g" ../conf/rocketchat_ldap.js
|
2017-07-19 11:13:17 +02:00
|
|
|
|
|
|
|
sudo cp ../conf/nginx.conf "$nginx_conf"
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-18 11:48:53 +02:00
|
|
|
# download and extract rocketchat
|
2017-10-31 23:14:59 +01:00
|
|
|
echo "Downloading rocket.chat-$ROCKETCHAT_VERSION.gtar from https://download.rocket.chat/build/rocket.chat-${ROCKETCHAT_VERSION}.tgz."
|
|
|
|
sudo curl -s -L -o $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar "https://download.rocket.chat/build/rocket.chat-${ROCKETCHAT_VERSION}.tgz"
|
2017-07-24 15:48:53 +02:00
|
|
|
SHA_DOWNLOAD=$(sha256sum $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar | grep -o "^[a-f0-9]*")
|
|
|
|
if [[ ! "$SHA_DOWNLOAD" == "$ROCKETCHAT_SHASUM" ]]; then
|
|
|
|
ynh_die "The sha256sum does not match the configured one"
|
|
|
|
fi
|
|
|
|
|
2017-07-19 13:10:43 +02:00
|
|
|
sudo tar -xzf $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar -C $final_path --strip-components=1 bundle
|
2017-07-21 14:35:08 +02:00
|
|
|
sudo rm $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar
|
|
|
|
|
|
|
|
sudo chown -R $serviceuser: $final_path
|
2016-04-29 16:32:48 +02:00
|
|
|
|
|
|
|
cd $final_path/programs/server/
|
|
|
|
|
2018-04-30 13:00:10 +02:00
|
|
|
sudo -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
|
|
|
|
|
|
|
sudo 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
|
|
|
|
2018-05-05 12:37:51 +02:00
|
|
|
sudo systemctl start $app.service
|
|
|
|
sudo systemctl enable $app.service
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-21 10:54:41 +02:00
|
|
|
# add rocketchat to services
|
2018-05-05 12:37:51 +02:00
|
|
|
sudo 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
|
|
|
|
2017-07-21 12:02:12 +02:00
|
|
|
sudo mongo < ../conf/rocketchat_ldap.js
|
2016-04-29 18:08:30 +02:00
|
|
|
|
2018-05-05 12:37:51 +02:00
|
|
|
sudo 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
|
|
|
|
2016-04-29 16:32:48 +02:00
|
|
|
sudo yunohost app ssowatconf
|