#!/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 serviceuser=rocketchat workdir=$(pwd) # find suitable port (default 3000) port=$(ynh_find_port 3000) # 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 sudo mkdir -p $final_path # Create user id -u $serviceuser || sudo useradd -d "$final_path" -M $serviceuser # Copy and set systemd configuration sed -i "s@#ROOTURL#@$domain@g" ../conf/rocketchat.service sed -i "s@#LOCATION#@${path:-/}@g" ../conf/rocketchat.service sed -i "s@#PORT#@$port@g" ../conf/rocketchat.service sed -i "s@#USER#@$serviceuser@g" ../conf/rocketchat.service sudo cp ../conf/rocketchat.service /etc/systemd/system/ sudo systemctl daemon-reload # Copy and set nginx configuration nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" sed -i "s@#APP#@$app@g" ../conf/nginx.conf sed -i "s@#PATH#@$path@g" ../conf/nginx.conf sed -i "s@#PORT#@$port@g" ../conf/nginx.conf sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf sed -i "s@#DESTDIR#@$final_path@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "$nginx_conf" # download and extract rocketchat echo "Downloading rocket.chat-$ROCKETCHAT_VERSION.gtar from https://download.rocket.chat/build/rocket.chat-${ROCKETCHAT_VERSION}.tgz." sudo curl -s -L -o $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar "https://download.rocket.chat/build/rocket.chat-${ROCKETCHAT_VERSION}.tgz" SHA_DOWNLOAD=$(sha256sum $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar | grep -o "^[a-f0-9]*") if [[ ! "$SHA_DOWNLOAD" == "$ROCKETCHAT_SHASUM" ]]; then ynh_die "The sha256sum does not match the configured one" fi sudo tar -xzf $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar -C $final_path --strip-components=1 bundle sudo rm $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar sudo chown -R $serviceuser: $final_path cd $final_path/programs/server/ sudo npm install --production cd $workdir sudo systemctl reload nginx if [ "$is_public" = "Yes" ]; then ynh_app_setting_set "$app" skipped_uris "/" fi sudo systemctl start rocketchat.service sudo systemctl enable rocketchat.service # add rocketchat to services sudo yunohost service add rocketchat # wait for rocketchat to populate db and start waitforservice sudo mongo < ../conf/rocketchat_ldap.js sudo systemctl restart rocketchat.service waitforservice sudo yunohost app ssowatconf