1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rocketchat_ynh.git synced 2024-09-03 20:16:25 +02:00
* Repackage
This commit is contained in:
Éric Gaspar 2021-07-10 19:40:17 +02:00 committed by GitHub
parent 03fefbb48a
commit 1c5b51b6fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 1037 additions and 349 deletions

View file

@ -1,7 +0,0 @@
language: node_js
before_install:
- git clone https://github.com/YunoHost/package_linter /tmp/package_linter
script:
- /tmp/package_linter/package_linter.py ./

View file

@ -1,36 +1,48 @@
# rocketchat_ynh
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
Rocketchat for yunohost
# RocketChat for YunoHost
[![Integration level](https://dash.yunohost.org/integration/rocketchat.svg)](https://dash.yunohost.org/appci/app/rocketchat)
[![Install Rocketchat with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=rocketchat)
[![Integration level](https://dash.yunohost.org/integration/rocketchat.svg)](https://dash.yunohost.org/appci/app/rocketchat) ![](https://ci-apps.yunohost.org/ci/badges/rocketchat.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/rocketchat.maintain.svg)
[![Install RocketChat with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=rocketchat)
## Install with
*[Lire ce readme en français.](./README_fr.md)*
You can either :
> *This package allows you to install RocketChat quickly and simply on a YunoHost server.
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
* Install from the Yunohost Admin web interface, by providing this URL: [https://github.com/YunoHost-Apps/rocketchat_ynh](https://github.com/YunoHost-Apps/rocketchat_ynh)
* Install from the command-line: `yunohost app install https://github.com/YunoHost-Apps/rocketchat_ynh`
## Overview
**Please note that currently the installation does not work on raspberry pi or arm architecture in general.**
the ultimate chat platform
## Backup information
**Shipped version:** 3.16.0~ynh1
Backup stores:
**Demo:** https://cloud.rocket.chat/trial
- rocketchat app dir
- rocketchat mongodb (via mongodump)
- nginx configuration
- systemd service configuration
## Screenshots
#### Supported architectures
![](./doc/screenshots/screenshot.jpg)
* x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/rocketchat%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/rocketchat/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/rocketchat%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/rocketchat/)
* Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/rocketchat%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/rocketchat/)
## Documentation and resources
## Links
* Official app website: https://rocket.chat/
* Official user documentation: https://yunohost.org/apps
* Official admin documentation: https://docs.rocket.chat/
* Upstream app code repository: https://github.com/RocketChat/Rocket.Chat
* YunoHost documentation for this app: https://yunohost.org/app_rocketchat
* Report a bug: https://github.com/YunoHost-Apps/rocketchat_ynh/issues
* Report a bug: [Issues](/../../issues)
* Rocketchat website: https://rocket.chat/
* YunoHost website: https://yunohost.org/
## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/rocketchat_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/rocketchat_ynh/tree/testing --debug
or
sudo yunohost app upgrade rocketchat -u https://github.com/YunoHost-Apps/rocketchat_ynh/tree/testing --debug
```
**More info regarding app packaging:** https://yunohost.org/packaging_apps

44
README_fr.md Normal file
View file

@ -0,0 +1,44 @@
# RocketChat pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/rocketchat.svg)](https://dash.yunohost.org/appci/app/rocketchat) ![](https://ci-apps.yunohost.org/ci/badges/rocketchat.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/rocketchat.maintain.svg)
[![Installer RocketChat avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=rocketchat)
*[Read this readme in english.](./README.md)*
*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet d'installer RocketChat rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
## Vue d'ensemble
the ultimate chat platform
**Version incluse :** 3.16.0~ynh1
**Démo :** https://cloud.rocket.chat/trial
## Captures d'écran
![](./doc/screenshots/screenshot.jpg)
## Documentations et ressources
* Site officiel de l'app : https://rocket.chat/
* Documentation officielle utilisateur : https://yunohost.org/apps
* Documentation officielle de l'admin : https://docs.rocket.chat/
* Dépôt de code officiel de l'app : https://github.com/RocketChat/Rocket.Chat
* Documentation YunoHost pour cette app : https://yunohost.org/app_rocketchat
* Signaler un bug : https://github.com/YunoHost-Apps/rocketchat_ynh/issues
## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/rocketchat_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit.
```
sudo yunohost app install https://github.com/YunoHost-Apps/rocketchat_ynh/tree/testing --debug
ou
sudo yunohost app upgrade rocketchat -u https://github.com/YunoHost-Apps/rocketchat_ynh/tree/testing --debug
```
**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps

25
check_process Normal file
View file

@ -0,0 +1,25 @@
;; Test complet
; Manifest
domain="domain.tld"
path="/path"
is_public=1
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
#upgrade=1 from_commit=CommitHash
backup_restore=1
multi_instance=0
change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=CommitHash
name=Name and date of the commit.
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1&password=pass&port=666&

View file

@ -1,7 +1,7 @@
SOURCE_URL=https://releases.rocket.chat/0.73.2/download
SOURCE_SUM=3dc3eb11f383f7b72b0f23fedb305b6a566fa536a1e5087a4398255deeb864d8
SOURCE_URL=https://releases.rocket.chat/3.16.0/download
SOURCE_SUM=c77aeed2a5eda4a3e9dfde8cfb742f32138638a3a44d0e9e38005992fcadb45b
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=rocket.chat-0.73.2.tgz
SOURCE_FILENAME=rocket.chat-3.16.0.tgz
SOURCE_EXTRACT=true

44
conf/mongod.conf Normal file
View file

@ -0,0 +1,44 @@
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
engine: wiredTiger
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
replication:
replSetName: "rs01"
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:

View file

@ -1,20 +1,19 @@
location ^~ #LOCATION# {
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location ^~ __PATH__/ {
# Force HTTPS
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
proxy_pass http://127.0.0.1:__PORT__;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass http://localhost:#PORT##PATH#;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
more_clear_input_headers 'Accept-Encoding';
}

View file

@ -1,18 +0,0 @@
[Unit]
Description=rocketchat
After=network.target
[Service]
Type=simple
WorkingDirectory=#DESTDIR#
User=#USER#
ExecStart=#NODE# main.js
Restart=always
SyslogIdentifier=rocketchat
Environment="BIND_IP=127.0.0.1"
Environment="ROOT_URL=https://#ROOTURL##LOCATION#"
Environment="PORT=#PORT#"
Environment="MONGO_URL=mongodb://localhost:27017/#DBNAME#"
[Install]
WantedBy=multi-user.target

View file

@ -1,4 +1,4 @@
use #DBNAME#
use __DB_NAME__
db.rocketchat_settings.update(

21
conf/systemd.service Normal file
View file

@ -0,0 +1,21 @@
[Unit]
Description=The Rocket.Chat server
Wants=__MONGODB_SERVICENAME__.service
After=network.target remote-fs.target nss-lookup.target nginx.service __MONGODB_SERVICENAME__.service
[Service]
User=__APP__
WorkingDirectory=__FINALPATH__
Environment="PATH=__ENV_PATH__"
Environment="NODE_ENV=production"
ExecStart=__YNH_NODE__ main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=__APP__
Environment=MONGO_URL=mongodb://127.0.0.1:27017/__APP__?replicaSet=rs01
Environment=MONGO_OPLOG_URL=mongodb://127.0.0.1:27017/local?replicaSet=rs01
Environment=ROOT_URL=https://__DOMAIN____PATH__
Environment=PORT=__PORT__
[Install]
WantedBy=multi-user.target

0
doc/DISCLAIMER.md Normal file
View file

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

View file

@ -1,60 +1,50 @@
{
"packaging_format": 1,
"name": "RocketChat",
"id": "rocketchat",
"packaging_format": 1,
"description": {
"en": "the ultimate chat platform"
"en": "the ultimate chat platform",
"fr": "the ultimate chat platform"
},
"version": "3.16.0~ynh1",
"url": "https://rocket.chat",
"upstream": {
"license": "GPL-3.0",
"website": "https://rocket.chat/",
"demo": "https://cloud.rocket.chat/trial",
"admindoc": "https://docs.rocket.chat/",
"userdoc": "https://yunohost.org/apps",
"code": "https://github.com/RocketChat/Rocket.Chat"
},
"license": "GPL-3.0",
"version": "0.73.2",
"maintainer": {
"name": "selamanse",
"email": "selamanse@scheinfrei.info",
"url": "https://github.com/selamanse"
"name": "",
"email": ""
},
"multi_instance": false,
"services": [
"nginx"
],
"requirements": {
"yunohost": ">> 2.5.6"
"yunohost": ">> 4.2.4"
},
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for Rocketchat"
},
"example": "domain.org"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for RocketChat"
},
"example": "/rocketchat",
"default": "/rocketchat"
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public application?"
},
"default": "Yes"
},
{
"name": "lang",
"type": "string",
"ask": {
"en": "Select default language"
},
"choices": ["English"],
"default": "English"
"default": true
}
]
}

View file

@ -1,82 +1,372 @@
# common.sh
#!/bin/bash
ROCKETCHAT_VERSION=0.73.2
ROCKETCHAT_SHASUM=3dc3eb11f383f7b72b0f23fedb305b6a566fa536a1e5087a4398255deeb864d8
ROCKETCHAT_DOWNLOAD_URI=https://releases.rocket.chat/${ROCKETCHAT_VERSION}/download
NODE_VERSION=8.11.4
DEBIAN_ISSUE=$(grep 9 /etc/debian_version >/dev/null && echo stretch || echo jessie)
#=================================================
# COMMON VARIABLES
#=================================================
checkcmd() {
curl -m 1 -s localhost:$port$path/api/v1/info | \
python -c "import sys, json; print json.load(sys.stdin)['success']" 2>/dev/null | \
grep "True" >/dev/null 2>&1
nodejs_version=12
# dependencies used by the app
pkg_dependencies="apt-transport-https build-essential gzip curl fontconfig graphicsmagick"
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
MONGO_DEBIAN_SERVICENAME="mongodb"
MONGO_CE_SERVICENAME="mongod"
MONGO_DEBIAN_DEPENDENCIES="mongodb mongodb-server mongo-tools"
MONGO_CE_DEPENDENCIES="mongodb-org mongodb-org-server mongodb-org-tools"
MONGO_DEBIAN_CONFIG="/etc/mongodb.conf"
MONGO_CE_CONFIG="/etc/mongod.conf"
MONGO_CE_REPO="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main"
MONGO_CE_KEY="https://www.mongodb.org/static/pgp/server-4.4.asc"
# Execute a mongo command
#
# example: ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("wekan")'
# example: ynh_mongo_exec --command="db.getMongo().getDBNames().indexOf(\"wekan\")"
#
# usage: ynh_mongo_exec [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" [--eval]
# | arg: -u, --user= - The user name to connect as
# | arg: -p, --password= - The user password
# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to
# | arg: -d, --database= - The database to connect to
# | arg: -h, --host= - The host to connect to
# | arg: -P, --port= - The port to connect to
# | arg: -c, --command= - The command to evaluate
# | arg: -e, --eval - Evaluate instead of execute the command.
#
#
ynh_mongo_exec() {
# Declare an array to define the options of this helper.
local legacy_args=upadhPce
local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= [e]=eval )
local user
local password
local authenticationdatabase
local database
local host
local port
local command
local eval
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
user="${user:-}"
password="${password:-}"
authenticationdatabase="${authenticationdatabase:-}"
database="${database:-}"
host="${host:-}"
port="${port:-}"
eval=${eval:-0}
# If user is provided
if [ -n "$user" ]
then
user="--username=$user"
# If password is provided
if [ -n "$password" ]
then
password="--password=$password"
fi
# If authenticationdatabase is provided
if [ -n "$authenticationdatabase" ]
then
authenticationdatabase="--authenticationDatabase=$authenticationdatabase"
else
authenticationdatabase="--authenticationDatabase=admin"
fi
else
password=""
authenticationdatabase=""
fi
# If host is provided
if [ -n "$host" ]
then
host="--host=$host"
fi
# If port is provided
if [ -n "$port" ]
then
port="--port=$port"
fi
# If eval is not provided
if [ $eval -eq 0 ]
then
# If database is provided
if [ -n "$database" ]
then
database="use $database"
else
database=""
fi
mongo --quiet $user $password $authenticationdatabase $host $port <<EOF
$database
${command}
quit()
EOF
else
# If database is provided
if [ -n "$database" ]
then
database="$database"
else
database=""
fi
mongo --quiet $database $user $password $authenticationdatabase $host $port --eval="$command"
fi
}
waitforservice() {
isup=false
x=90
while [ $x -gt 0 ]; do
echo "Waiting approx. $x seconds..."
x=$(( $x - 1 ))
sleep 1
# Drop a database
#
# [internal]
#
# If you intend to drop the database *and* the associated user,
# consider using ynh_mongo_remove_db instead.
#
# usage: ynh_mongo_drop_db --database=database
# | arg: -d, --database= - The database name to drop
#
#
ynh_mongo_drop_db() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=( [d]=database= )
local database
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
if checkcmd; then
isup=true; break;
fi;
done
if $isup; then
echo "service is up"
else
ynh_die "$app could not be started"
fi
ynh_mongo_exec --database="$database" --command='db.runCommand({dropDatabase: 1})'
}
installnode(){
if [ $DEBIAN_ISSUE == "stretch" ]; then
sudo curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install -y nodejs
else
sudo apt-get install -y npm
# Using npm install inherits and n, and the node version required by Rocket.Chat:
sudo npm install -g inherits n
sudo n $NODE_VERSION
fi
echo "node version is now: "
node --version
# Dump a database
#
# example: ynh_mongo_dump_db --database=wekan > ./dump.bson
#
# usage: ynh_mongo_dump_db --database=database
# | arg: -d, --database= - The database name to dump
# | ret: the mongodump output
#
#
ynh_mongo_dump_db() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=( [d]=database= )
local database
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
mongodump --quiet --db="$database" --archive
}
installdeps(){
# Create a user
#
# [internal]
#
# usage: ynh_mongo_create_user --db_user=user --db_pwd=pwd --db_name=name
# | arg: -u, --db_user= - The user name to create
# | arg: -p, --db_pwd= - The password to identify user by
# | arg: -n, --db_name= - Name of the database to grant privilegies
#
#
ynh_mongo_create_user() {
# Declare an array to define the options of this helper.
local legacy_args=unp
local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= )
local db_user
local db_name
local db_pwd
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
if [ $(dpkg --print-architecture) == "armhf" ]; then
#Install mongodb for debian armhf
sudo apt-get update
sudo apt-get install -y mongodb-server
# start mongodb service
sudo systemctl enable mongodb.service
sudo systemctl start mongodb.service
# add mongodb to services
sudo yunohost service add mongodb -l /var/log/mongodb/mongodb.log
else
#Install mongodb for debian x86/x64
sudo apt-get install dirmngr && sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb http://repo.mongodb.org/apt/debian ${DEBIAN_ISSUE}/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
# start mongodb service
sudo systemctl enable mongod.service
sudo systemctl start mongod.service
# add mongodb to services
sudo yunohost service add mongod -l /var/log/mongodb/mongod.log
fi
#Install other dependencies
sudo apt-get install -y build-essential gzip curl graphicsmagick
installnode
# Create the user and set the user as admin of the db
ynh_mongo_exec --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );'
# Add clustermonitoring rights
ynh_mongo_exec --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);'
}
# Check if a mongo database exists
#
# usage: ynh_mongo_database_exists --database=database
# | arg: -d, --database= - The database for which to check existence
# | exit: Return 1 if the database doesn't exist, 0 otherwise
#
#
ynh_mongo_database_exists() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=([d]=database=)
local database
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
if [ $(ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("'${database}'")' --eval) -lt 0 ]
then
return 1
else
return 0
fi
}
# Restore a database
#
# example: ynh_mongo_restore_db --database=wekan < ./dump.bson
#
# usage: ynh_mongo_restore_db --database=database
# | arg: -d, --database= - The database name to restore
#
#
ynh_mongo_restore_db() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=( [d]=database= )
local database
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
mongorestore --quiet --db="$database" --archive
}
# Drop a user
#
# [internal]
#
# usage: ynh_mongo_drop_user --db_user=user --db_name=name
# | arg: -u, --db_user= - The user to drop
# | arg: -n, --db_name= - Name of the database
#
#
ynh_mongo_drop_user() {
# Declare an array to define the options of this helper.
local legacy_args=un
local -A args_array=( [u]=db_user= [n]=db_name= )
local db_user
local db_name
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
ynh_mongo_exec --database="$db_name" --command='db.dropUser("'$db_user'", {w: "majority", wtimeout: 5000})'
}
# Create a database, an user and its password. Then store the password in the app's config
#
# usage: ynh_mongo_setup_db --db_user=user --db_name=name [--db_pwd=pwd]
# | arg: -u, --db_user= - Owner of the database
# | arg: -n, --db_name= - Name of the database
# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated
#
# After executing this helper, the password of the created database will be available in $db_pwd
# It will also be stored as "mongopwd" into the app settings.
#
#
ynh_mongo_setup_db() {
# Declare an array to define the options of this helper.
local legacy_args=unp
local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= )
local db_user
local db_name
db_pwd=""
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local new_db_pwd=$(ynh_string_random) # Generate a random password
# If $db_pwd is not provided, use new_db_pwd instead for db_pwd
db_pwd="${db_pwd:-$new_db_pwd}"
# Create the user and grant access to the database
ynh_mongo_create_user --db_user="$db_user" --db_pwd="$db_pwd" --db_name="$db_name"
# Store the password in the app's config
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
}
# Remove a database if it exists, and the associated user
#
# usage: ynh_mongo_remove_db --db_user=user --db_name=name
# | arg: -u, --db_user= - Owner of the database
# | arg: -n, --db_name= - Name of the database
#
#
ynh_mongo_remove_db() {
# Declare an array to define the options of this helper.
local legacy_args=un
local -A args_array=( [u]=db_user= [n]=db_name= )
local db_user
local db_name
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
if ynh_mongo_database_exists --database=$db_name; then # Check if the database exists
ynh_mongo_drop_db --database=$db_name # Remove the database
else
ynh_print_warn --message="Database $db_name not found"
fi
# Remove mongo user if it exists
ynh_mongo_drop_user --db_user=$db_user --db_name=$db_name
}
# Install MongoDB and integrate MongoDB service in YunoHost
#
# usage: ynh_install_mongo
#
#
ynh_install_mongo() {
ynh_print_info --message="Installing MongoDB..."
# Define Mongo Service Name
if $(dpkg --compare-versions $(cat /etc/debian_version) gt "10.0")
then
ynh_print_info --message="Installing MongoDB Community Edition..."
ynh_install_extra_app_dependencies --repo="$MONGO_CE_REPO" --package="$MONGO_CE_DEPENDENCIES" --key="$MONGO_CE_KEY"
MONGODB_SERVICENAME=$MONGO_CE_SERVICENAME
else
ynh_print_info --message="Installing MongoDB Debian..."
ynh_install_app_dependencies $MONGO_DEBIAN_DEPENDENCIES
MONGODB_SERVICENAME=$MONGO_DEBIAN_SERVICENAME
fi
mongodb_servicename=$MONGODB_SERVICENAME
# Make sure MongoDB is started and enabled
systemctl is-enabled $MONGODB_SERVICENAME -q || systemctl enable $MONGODB_SERVICENAME --quiet
systemctl is-active $MONGODB_SERVICENAME -q || ynh_systemd_action --service_name=$MONGODB_SERVICENAME --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$MONGODB_SERVICENAME.log"
# Integrate MongoDB service in YunoHost
yunohost service add $MONGODB_SERVICENAME --description="MongoDB daemon" --log="/var/log/mongodb/$MONGODB_SERVICENAME.log"
}
# Remove MongoDB
# Only remove the MongoDB service integration in YunoHost for now
# if MongoDB package as been removed
#
# usage: ynh_remove_mongo
#
#
ynh_remove_mongo() {
# Only remove the mongodb service if it is not installed.
if ! ynh_package_is_installed --package="mongodb*"
then
ynh_print_info --message="Removing MongoDB service..."
# Define Mongo Service Name
if [ "$(lsb_release --codename --short)" = "buster" ]; then
MONGODB_SERVICENAME=$MONGO_CE_SERVICENAME
else
MONGODB_SERVICENAME=$MONGO_DEBIAN_SERVICENAME
fi
# Remove the mongodb service
yunohost service remove $MONGODB_SERVICENAME
# ynh_secure_remove --file=$MONGO_ROOT_PWD_FILE
fi
}

View file

@ -1,11 +1,24 @@
#!/bin/bash
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
@ -14,8 +27,9 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# STANDARD BACKUP STEPS
@ -23,17 +37,31 @@ domain=$(ynh_app_setting_get $app domain)
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE CONFIGURATION
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/systemd/system/$app.service" "conf/service"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service" "conf/service"
#=================================================
# BACKUP THE MONGODB DATABASE
#=================================================
ynh_print_info --message="Backing up the MongoDB database..."
mongodump -o "./dump"
ynh_mongo_dump_db --database="$db_name" > ./dump.bson
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,5 +1,4 @@
#!/bin/bash
set -eu
#=================================================
# GENERIC START
@ -7,13 +6,16 @@ set -eu
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
source ./_common.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -22,129 +24,166 @@ ynh_abort_if_errors
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANG
app=$YNH_APP_INSTANCE_NAME
dbname=$app
serviceuser=rocketchat
#=================================================
# CHECK IF THE APP CAN BE INSTALLED
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
# 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
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
workdir=$(pwd)
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
# find suitable port (default 3000)
port=$(ynh_find_port 3000)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=2
# 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
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=2
# Check domain/path availability
ynh_webpath_available $domain $path
if [[ ! $? -eq 0 ]]; then
ynh_die "domain not available"
fi
# Find an available port
port=$(ynh_find_port --port=3000)
ynh_app_setting_set --app=$app --key=port --value=$port
# Register/book a web path for an app
ynh_webpath_register $app $domain $path
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=20
final_path="/var/lib/$app"
[[ -d $final_path ]] && ynh_die \
"The destination directory '$final_path' already exists.\
You should safely delete it before installing this app."
ynh_install_app_dependencies $pkg_dependencies
# Save specific settings
ynh_app_setting_set $app node_version $NODE_VERSION
ynh_app_setting_set $app rocketchat_version $ROCKETCHAT_VERSION
ynh_app_setting_set $app serviceuser $serviceuser
ynh_app_setting_set $app port $port
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
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_mongo
#Install dependencies
installdeps
#=================================================
# CREATE A MONGODB DATABASE
#=================================================
ynh_script_progression --message="Creating a MongoDB database..."
# Create destination
mkdir -p $final_path
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name
# Create user
id -u $serviceuser || useradd -d "$final_path" -M $serviceuser
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Copy and set systemd configuration
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
# absolute node path needed
NODE_BIN=$(which node)
ynh_replace_string "#NODE#" "$NODE_BIN" ../conf/rocketchat.service
cp ../conf/rocketchat.service /etc/systemd/system/$app.service
systemctl daemon-reload
# Copy and set nginx configuration
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
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
#set db name into ldap config
ynh_replace_string "#DBNAME#" "$dbname" ../conf/rocketchat_ldap.js
cp ../conf/nginx.conf "$nginx_conf"
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=2
ynh_setup_source "$final_path"
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir=$final_path
chown -R $serviceuser: $final_path
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
cd $final_path/programs/server/
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
sudo -u $serviceuser npm install --production
# Create a dedicated nginx config
ynh_add_nginx_config
cd $workdir
#=================================================
# SPECIFIC SETUP
#==============================================
# INSTALL ROCKETCHAT
#==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=20
systemctl reload nginx
if [ "$is_public" = "Yes" ];
pushd $final_path/programs/server
ynh_use_nodejs
ynh_exec_as $app env $ynh_node_load_PATH npm install 2>/dev/null
popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_add_systemd_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Configuring a mongod..." --weight=1
sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
#echo -e "replication:\n replSetName: \"rs01\"" | tee -a /etc/mongod.conf
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a MongoDB service..." --weight=2
# Start a mongod service
ynh_exec_warn_less systemctl enable mongod --quiet
ynh_systemd_action --service_name=mongod --action=restart
#mongo --eval "printjson(rs.initiate())"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="➔ System ➔ startup"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary or protect it
if [ $is_public -eq 1 ]
then
ynh_app_setting_set "$app" skipped_uris "/"
ynh_permission_update --permission="main" --add="visitors"
fi
systemctl start $app.service
systemctl enable $app.service
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
# add rocketchat to services
yunohost service add $app
ynh_systemd_action --service_name=nginx --action=reload
# wait for rocketchat to populate db and start
waitforservice
#=================================================
# END OF SCRIPT
#=================================================
mongo < ../conf/rocketchat_ldap.js
systemctl restart $app.service
waitforservice
yunohost app ssowatconf
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -1,5 +1,4 @@
#!/bin/bash
set -u
#=================================================
# GENERIC START
@ -7,25 +6,89 @@ set -u
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
source ./_common.sh
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
final_path=$(ynh_app_setting_get $app final_path)
systemctl stop $app.service
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# remove Rocketchat from services
yunohost service remove $app
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
ynh_secure_remove $final_path
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
ynh_secure_remove /var/log/$app
ynh_secure_remove /etc/systemd/system/$app.service
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service..." --weight=1
yunohost service remove $app
fi
# remove database!!!
mongo rocketchat --eval "db.dropDatabase()"
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
systemctl daemon-reload
systemctl reload nginx
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE THE MONGODB DATABASE
#=================================================
ynh_script_progression --message="Removing the MongoDB database..."
# Remove a database if it exists, along with the associated user
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
ynh_remove_mongo
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -1,94 +1,128 @@
#!/bin/bash
set -eu
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Fetch helpers file if not in current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source /usr/share/yunohost/helpers
source _common.sh
#=================================================
# GENERIC START
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat access to unset variables as an error
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
serviceuser=$(ynh_app_setting_get $app serviceuser)
port=$(ynh_app_setting_get $app port)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
# Check domain/path availability
ynh_webpath_available $domain $path
if [[ ! $? -eq 0 ]]; then
ynh_die "domain not available"
fi
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
# Check destination directory
[[ -d $final_path ]] && ynh_die \
"The destination directory '$final_path' already exists.\
You should safely delete it before restoring this app."
# Create destination
mkdir -p $final_path
# Create user
id -u $serviceuser || useradd -d "$final_path" -M $serviceuser
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
ynh_restore
#=================================================
# RELOAD THE NGINX CONFIGURATION
# RESTORE THE NGINX CONFIGURATION
#=================================================
systemctl reload nginx
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RELOAD AND ENABLE THE SYSTEMD CONFIGURATION
# RECREATE THE DEDICATED USER
#=================================================
systemctl daemon-reload
systemctl enable rocketchat
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# RESTORE PERMISSIONS IN THE APP MAIN DIR
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
chown -R $serviceuser: $final_path
ynh_restore_file --origin_path="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# INSTALL DEPENDENCIES
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
installdeps
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_mongo
#=================================================
# RESTORE THE MONGODB
# RESTORE THE MONGODB DATABASE
#=================================================
ynh_script_progression --message="Restoring the MongoDB database..."
mongorestore ./dump
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mongo_restore_db --database="$db_name" < ./dump.bson
#=================================================
# START APP RELATED SERVICES
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
systemctl start rocketchat
waitforservice
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -1,5 +1,4 @@
#!/bin/bash
set -eu
#=================================================
# GENERIC START
@ -7,40 +6,165 @@ set -eu
# IMPORT GENERIC HELPERS
#=================================================
source ./_common.sh
source _common.sh
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
serviceuser=$(ynh_app_setting_get $app serviceuser)
path=$(ynh_app_setting_get $app path)
port=$(ynh_app_setting_get $app port)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# BACKUP THE APPLICATION
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
### If nobody installed your app before 4.1,
### then you may safely remove these lines
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade > >(tee "upgrade.log")
ynh_backup_before_upgrade
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
systemctl stop rocketchat
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_secure_remove $final_path
mkdir -p $final_path
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
# update to latest required node setup
installnode
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=4
ynh_setup_source "$final_path"
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
chown -R $serviceuser: $final_path
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
cd $final_path/programs/server/
npm install --production
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
chown -R $serviceuser: $final_path
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
systemctl start rocketchat
waitforservice
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=7
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_mongo
#==============================================
# INSTALL ROCKETCHAT
#==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=20
pushd $final_path/programs/server
ynh_use_nodejs
ynh_exec_as $app env $ynh_node_load_PATH npm install 2>/dev/null
popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Configuring a mongod..." --weight=1
echo -e "replication:\n replSetName: \"rs01\"" | tee -a /etc/mongod.conf
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=10
ynh_systemd_action --service_name=mongod --action=restart --log_path=systemd
ynh_systemd_action --service_name=$app --action=start --log_path="/var/log/$app/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last