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 11:20:02 +02:00
|
|
|
sudo yunohost app checkurl $domain -a $app
|
2016-04-29 16:32:48 +02:00
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2017-07-18 13:16:23 +02:00
|
|
|
ynh_die
|
2016-04-29 16:32:48 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Save specific settings
|
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
|
|
|
|
|
|
|
# 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-18 14:51:10 +02:00
|
|
|
# Create destination
|
2017-07-19 11:13:17 +02:00
|
|
|
final_path="/var/www/$app"
|
|
|
|
[[ -d $final_path ]] && ynh_die \
|
2017-07-19 11:16:50 +02:00
|
|
|
"The destination directory '$final_path' already exists.\
|
2017-07-19 11:13:17 +02:00
|
|
|
You should safely delete it before installing this app."
|
|
|
|
|
2017-07-18 14:51:10 +02:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
|
2017-07-19 11:13:17 +02:00
|
|
|
# Copy and set systemd configuration
|
2016-04-29 21:02:20 +02:00
|
|
|
sed -i "s@CHANGEMETOROOTURL@$domain/@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"
|
|
|
|
sed -i "s@#APP#@${app}@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@#DESTDIR#@${final_path}@g" ../conf/nginx.conf
|
|
|
|
|
|
|
|
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-18 15:44:12 +02:00
|
|
|
sudo tar -xzf $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar -C $final_path
|
2017-07-18 15:46:39 +02:00
|
|
|
sudo ls -lah $final_path
|
2017-07-18 15:44:12 +02:00
|
|
|
sudo mv $final_path/bundle/** $final_path
|
2017-07-18 17:10:38 +02:00
|
|
|
sudo mv $final_path/bundle/.node_version.txt $final_path
|
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-18 16:14:16 +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 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 11:13:17 +02:00
|
|
|
x=$(( $x - 1 )); sleep 1; if $(curl -m 1 -s localhost:3000/api/v1/info | \
|
|
|
|
grep -e "success.*true" >/dev/null 2>%1); then isup=true; break; fi; done && if $isup; \
|
2017-07-19 11:30:12 +02:00
|
|
|
then echo "service is up"; else ynh_die; 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
|