1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rocketchat_ynh.git synced 2024-09-03 20:16:25 +02:00
rocketchat_ynh/scripts/install

130 lines
3.8 KiB
Text
Raw Normal View History

2016-04-29 16:32:48 +02:00
#!/bin/bash
set -eu
2016-04-29 16:32:48 +02:00
2017-07-18 13:03:45 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ./_common.sh
2017-07-18 13:03:45 +02:00
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-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)
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-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
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
ynh_app_setting_set $app port $port
2017-07-19 17:07:36 +02:00
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app path $path
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
sudo n $NODE_VERSION
2016-04-29 16:32:48 +02:00
2017-07-18 14:51:10 +02:00
# Create destination
sudo mkdir -p $final_path
# Create user
sudo useradd -d "$final_path" -M $serviceuser
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
2017-07-21 10:54:41 +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
# 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
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/
sudo 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
2017-07-21 10:54:41 +02:00
sudo systemctl start rocketchat.service
sudo systemctl enable rocketchat.service
2016-04-29 16:32:48 +02:00
2017-07-21 10:54:41 +02:00
# add rocketchat to services
sudo yunohost service add rocketchat
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
2017-07-21 10:54:41 +02:00
sudo systemctl restart rocketchat.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