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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
2017-07-18 11:48:53 +02:00
|
|
|
ROCKETCHAT_VERSION=0.57.2
|
|
|
|
NODE_VERSION=4.7.1
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
workdir=$(pwd)
|
|
|
|
|
2016-04-29 16:32:48 +02:00
|
|
|
# Check domain/path availability
|
2017-07-19 13:37:31 +02:00
|
|
|
sudo yunohost app checkurl $domain -a $app
|
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-07-19 17:07:36 +02:00
|
|
|
final_path="/var/www/$app"
|
|
|
|
[[ -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-19 17:07:36 +02:00
|
|
|
ynh_app_setting_set $app final_path $final_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-07-19 11:20:02 +02:00
|
|
|
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 >/dev/null
|
2016-04-29 16:32:48 +02:00
|
|
|
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
|
|
|
|
sudo apt-get update
|
2017-07-18 14:47:01 +02:00
|
|
|
sudo apt-get install -y mongodb-org gzip curl graphicsmagick npm
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-19 13:32:24 +02:00
|
|
|
# add mongodb to services
|
|
|
|
sudo yunohost service add mongod -l /var/log/mongodb/mongod.log
|
|
|
|
|
2016-04-29 16:32:48 +02:00
|
|
|
# Meteor needs at least this version of node to work.
|
2017-07-18 14:47:01 +02:00
|
|
|
sudo npm install -g n
|
2017-07-18 11:48:53 +02:00
|
|
|
sudo n $NODE_VERSION
|
2016-04-29 16:32:48 +02:00
|
|
|
|
2017-07-19 13:32:24 +02:00
|
|
|
# find suitable port (default 3000)
|
|
|
|
port=$(ynh_find_port 3000)
|
|
|
|
|
2017-07-18 14:51:10 +02:00
|
|
|
# Create destination
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
# Copy and set systemd configuration
|
2017-07-19 13:46:09 +02:00
|
|
|
sed -i "s@#ROOTURL#@$domain@g" ../conf/Rocketchat.service
|
|
|
|
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/Rocketchat.service
|
2017-07-19 13:32:24 +02:00
|
|
|
sed -i "s@#PORT#@/$port@g" ../conf/Rocketchat.service
|
2017-07-18 15:32:34 +02:00
|
|
|
sudo cp ../conf/Rocketchat.service /etc/systemd/system/
|
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
|
2017-07-19 13:17:28 +02:00
|
|
|
sed -i "s@#DESTDIR#@$final_path@g" ../conf/nginx.conf
|
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-07-19 11:20:02 +02:00
|
|
|
echo "Downloading rocket.chat-$ROCKETCHAT_VERSION.gtar from https://rocket.chat/releases/${ROCKETCHAT_VERSION}/download."
|
|
|
|
sudo curl -s -L -o $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar "https://rocket.chat/releases/${ROCKETCHAT_VERSION}/download"
|
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
|
2016-04-29 16:32:48 +02:00
|
|
|
|
|
|
|
cd $final_path/programs/server/
|
|
|
|
|
|
|
|
sudo npm install
|
|
|
|
|
|
|
|
cd $final_path/
|
|
|
|
|
|
|
|
sudo chown -R www-data: $final_path
|
|
|
|
|
|
|
|
sudo service nginx reload
|
|
|
|
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
|
|
|
|
2016-04-29 16:32:48 +02:00
|
|
|
sudo systemctl start Rocketchat.service
|
|
|
|
sudo systemctl enable Rocketchat.service
|
|
|
|
|
2017-07-19 13:32:24 +02:00
|
|
|
# add Rocketchat to services
|
|
|
|
sudo yunohost service add Rocketchat
|
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
# wait for rocketchat to populate db and start (oneliner has to be improved)
|
2017-07-19 11:30:12 +02:00
|
|
|
isup=false; x=45; while [ $x -gt 0 ];do echo "Waiting approx. $x seconds..."; \
|
2017-07-19 13:46:09 +02:00
|
|
|
x=$(( $x - 1 )); sleep 1; if $(curl -m 1 -s localhost:$port${path:-/}/api/v1/info | \
|
2017-07-19 11:13:17 +02:00
|
|
|
grep -e "success.*true" >/dev/null 2>%1); then isup=true; break; fi; done && if $isup; \
|
2017-07-19 13:00:22 +02:00
|
|
|
then echo "service is up"; else ynh_die "$app could not be started"; fi
|
2016-04-29 21:50:20 +02:00
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
cd $workdir
|
2016-04-29 18:08:30 +02:00
|
|
|
|
|
|
|
sudo mongo < ../conf/rocketchat_ldap.js
|
|
|
|
|
2017-07-19 12:34:48 +02:00
|
|
|
sudo systemctl restart Rocketchat.service
|
|
|
|
|
2016-04-29 16:32:48 +02:00
|
|
|
sudo yunohost app ssowatconf
|