diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d9f1363..0000000 --- a/.travis.yml +++ /dev/null @@ -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 ./ diff --git a/README.md b/README.md index 53160c9..d86ec8d 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,54 @@ -# rocketchat_ynh +# RocketChat for YunoHost -Rocketchat for yunohost +[![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) -[![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) +*[Lire ce readme en français.](./README_fr.md)* -## Install with +> *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.* -You can either : +## Overview +Quick description of this app. -* 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` +**Shipped version:** 3.12.0 -**Please note that currently the installation does not work on raspberry pi or arm architecture in general.** +## Screenshots -## Backup information +![](Link to a screenshot of this app.) -Backup stores: +## Demo -- rocketchat app dir -- rocketchat mongodb (via mongodump) -- nginx configuration -- systemd service configuration +* [Official demo](Link to a demo site for this app.) + +## Configuration + +How to configure this app: From an admin panel, a plain file with SSH, or any other way. + +## Documentation + + * Official documentation: Link to the official documentation of this app + * YunoHost documentation: If specific documentation is needed, feel free to contribute. + +## YunoHost specific features + +#### Multi-user support + +Are LDAP and HTTP auth supported? +Can the app be used by multiple users? + +#### Supported architectures + +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/rocketchat%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/rocketchat/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/rocketchat%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/rocketchat/) + +## Limitations + +* Any known limitations. + +## Additional information + +* Other info you would like to add about this app. #### Supported architectures @@ -31,6 +58,20 @@ Backup stores: ## Links - * Report a bug: [Issues](/../../issues) - * Rocketchat website: https://rocket.chat/ + * Report a bug: https://github.com/YunoHost-Apps/rocketchat_ynh/issues + * App website: https://rocket.chat/ + * Upstream app repository: https://github.com/RocketChat/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 +``` diff --git a/check_process b/check_process new file mode 100644 index 0000000..aa8ac7f --- /dev/null +++ b/check_process @@ -0,0 +1,26 @@ +;; Test complet + ; Manifest + domain="domain.tld" + path="/path" + admin="john" + is_public=1 + password="password" + ; 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& \ No newline at end of file diff --git a/conf/app.src b/conf/app.src index 5e807eb..e31c739 100644 --- a/conf/app.src +++ b/conf/app.src @@ -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 \ No newline at end of file diff --git a/conf/mongod.conf b/conf/mongod.conf new file mode 100644 index 0000000..4bedf87 --- /dev/null +++ b/conf/mongod.conf @@ -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: diff --git a/conf/nginx.conf b/conf/nginx.conf index e29a459..e5ac8f3 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -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'; } diff --git a/conf/rocketchat.service b/conf/rocketchat.service deleted file mode 100644 index 7afc22b..0000000 --- a/conf/rocketchat.service +++ /dev/null @@ -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 diff --git a/conf/rocketchat_ldap.js b/conf/rocketchat_ldap.js index ccb0f77..62293ff 100644 --- a/conf/rocketchat_ldap.js +++ b/conf/rocketchat_ldap.js @@ -1,4 +1,4 @@ -use #DBNAME# +use __DB_NAME__ db.rocketchat_settings.update( diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..8402af0 --- /dev/null +++ b/conf/systemd.service @@ -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://localhost:27017/__APP__?replicaSet=rs01 +Environment=MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 +Environment=ROOT_URL=https://__DOMAIN____PATH__ +Environment=PORT=__PORT__ + +[Install] +WantedBy=multi-user.target diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/screenshots/screenshot.jpg b/doc/screenshots/screenshot.jpg new file mode 100644 index 0000000..555257d Binary files /dev/null and b/doc/screenshots/screenshot.jpg differ diff --git a/manifest.json b/manifest.json index 0ce0e4f..d246846 100644 --- a/manifest.json +++ b/manifest.json @@ -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 } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index eddb1d4..157327b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -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 < ./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 } diff --git a/scripts/backup b/scripts/backup index f5a45d0..3ca4521 100644 --- a/scripts/backup +++ b/scripts/backup @@ -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)." diff --git a/scripts/install b/scripts/install index 23f4aad..e08c219 100644 --- a/scripts/install +++ b/scripts/install @@ -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,159 @@ 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 -#Install dependencies -installdeps +# Install Yarn +#ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -# Create destination -mkdir -p $final_path +ynh_install_mongo -# Create user -id -u $serviceuser || useradd -d "$final_path" -M $serviceuser +#================================================= +# CREATE A MONGODB DATABASE +#================================================= +ynh_script_progression --message="Creating a MongoDB database..." -# 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 +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 -# 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 +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=3 -#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 --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 +#================================================= + +echo -e "replication:\n replSetName: \"rs01\"" | sudo 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 systemd service..." --weight=2 + +# Start a systemd service +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="➔ System ➔ startup" +ynh_systemd_action --service_name=mongod --action=restart --log_path=systemd + +#================================================= +# 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 +ynh_script_progression --message="Installation of $app completed" --last -systemctl restart $app.service - -waitforservice - -yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index 9e77aa1..b66ebcb 100644 --- a/scripts/remove +++ b/scripts/remove @@ -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 diff --git a/scripts/restore b/scripts/restore index adf14de..c456ca4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,94 +1,160 @@ #!/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 + +# 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 source _common.sh -#================================================= -# GENERIC START #================================================= # 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 +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -# 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 +# RESTORE THE APP MAIN DIR #================================================= -systemctl daemon-reload -systemctl enable rocketchat +ynh_script_progression --message="Restoring the app main directory..." --weight=1 + +ynh_restore_file --origin_path="$final_path" #================================================= -# RESTORE PERMISSIONS IN THE APP MAIN DIR +# RECREATE THE DEDICATED USER #================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 -chown -R $serviceuser: $final_path +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app #================================================= -# INSTALL DEPENDENCIES +# RESTORE USER RIGHTS #================================================= -installdeps +# Restore permissions on app files +chown -R root: $final_path #================================================= -# RESTORE THE MONGODB +# RESTORE THE PHP-FPM CONFIGURATION #================================================= -mongorestore ./dump +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= -# START APP RELATED SERVICES +# RESTORE FAIL2BAN CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 + +ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" +ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" +ynh_systemd_action --action=restart --service_name=fail2ban + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." --weight=1 + +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the MySQL database..." --weight=1 + +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + +#================================================= +# 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" + +#================================================= +# RESTORE VARIOUS FILES #================================================= -systemctl start rocketchat -waitforservice +ynh_restore_file --origin_path="/etc/cron.d/$app" + +ynh_restore_file --origin_path="/etc/$app/" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + +#================================================= +# 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 +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 5b31d0e..2c35b81 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,5 +1,4 @@ #!/bin/bash -set -eu #================================================= # GENERIC START @@ -7,40 +6,175 @@ 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..." --time --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) +language=$(ynh_app_setting_get --app=$app --key=language) +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..." --time --weight=1 + +# If db_name doesn't exist, create it +#if [ -z "$db_name" ]; then +# db_name=$(ynh_sanitize_dbid --db_name=$app) +# ynh_app_setting_set --app=$app --key=db_name --value=$db_name +#fi + +# 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 + +if ! ynh_permission_exists --permission="admin"; then + # Create the required permissions + ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin +fi + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --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..." --time --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..." --time --weight=1 -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..." --time --weight=1 -chown -R $serviceuser: $final_path + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi -systemctl start rocketchat -waitforservice +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#============================================== +# 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 + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=1 + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 + +ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service" + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --time --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..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=mongod --action=restart --log_path=systemd + +#================================================= +# UPGRADE FAIL2BAN +#================================================= +ynh_script_progression --message="Reconfiguring Fail2Ban..." --time --weight=1 + +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --time --last