#!/bin/bash set -eu #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source /usr/share/yunohost/helpers source ./_common.sh #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= domain=$YNH_APP_ARG_DOMAIN path=$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 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 workdir=$(pwd) # find suitable port (default 3000) port=$(ynh_find_port 3000) # 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 # Check domain/path availability ynh_webpath_available $domain $path if [[ ! $? -eq 0 ]]; then ynh_die "domain not available" fi # Register/book a web path for an app ynh_webpath_register $app $domain $path 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." # 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 dependencies installdeps # Create destination mkdir -p $final_path # Create user id -u $serviceuser || useradd -d "$final_path" -M $serviceuser # 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" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_setup_source "$final_path" chown -R $serviceuser: $final_path cd $final_path/programs/server/ -u $serviceuser npm install --production cd $workdir systemctl reload nginx if [ "$is_public" = "Yes" ]; then ynh_app_setting_set "$app" skipped_uris "/" fi systemctl start $app.service systemctl enable $app.service # add rocketchat to services yunohost service add $app # wait for rocketchat to populate db and start waitforservice mongo < ../conf/rocketchat_ldap.js systemctl restart $app.service waitforservice yunohost app ssowatconf