2018-03-26 05:50:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2018-03-31 12:09:27 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-03-27 19:32:35 +02:00
|
|
|
source psql.sh
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2018-03-29 23:53:32 +02:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2018-03-26 05:50:46 +02:00
|
|
|
path_url="/"
|
2018-03-29 23:53:32 +02:00
|
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
|
|
admin_email=$(ynh_app_setting_get "$app" admin_email)
|
|
|
|
admin_pass=$(ynh_app_setting_get "$app" admin_pass)
|
|
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
|
|
port=$(ynh_app_setting_get "$app" port)
|
|
|
|
db_name=$(ynh_app_setting_get "$app" psql_db)
|
|
|
|
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Fix is_public as a boolean value
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_app_setting_set "$app" is_public 1
|
2018-03-26 05:50:46 +02:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_app_setting_set "$app" is_public 0
|
2018-03-26 05:50:46 +02:00
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
2018-03-29 23:38:29 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
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
|
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
# REMOVE APP MAIN DIR
|
|
|
|
#=================================================
|
2018-04-11 17:51:42 +02:00
|
|
|
|
|
|
|
# Create a temporary directory
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
# Backup the config file in the temp dir
|
|
|
|
cp -a "$final_path/config/local-production.json" "$tmpdir/local-production.json"
|
2018-03-26 05:50:46 +02:00
|
|
|
# Remove the app directory securely
|
|
|
|
ynh_secure_remove "$final_path"
|
|
|
|
|
|
|
|
# Define app's data directory
|
|
|
|
datadir="/home/yunohost.app/${app}/storage"
|
|
|
|
# Create app folders
|
|
|
|
mkdir -p "$datadir"
|
|
|
|
|
|
|
|
# Open this port
|
2018-03-29 23:53:32 +02:00
|
|
|
yunohost firewall allow Both "$port" 2>&1
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a system user
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_system_user_create "$app"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2018-03-31 12:09:27 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
2018-04-04 07:59:01 +02:00
|
|
|
# install nodejs
|
|
|
|
ynh_install_nodejs 8
|
|
|
|
|
2018-03-31 12:09:27 +02:00
|
|
|
# install yarn
|
|
|
|
wget https://github.com/yarnpkg/yarn/releases/download/v1.5.1/yarn_1.5.1_all.deb
|
|
|
|
echo "a4770cd8dcb13dc9a9218940dbd24b510ddf5eec78adb4e0da9ef3760b55a76e yarn_1.5.1_all.deb" | sha256sum -c || ynh_die
|
|
|
|
dpkg -i yarn_1.5.1_all.deb
|
|
|
|
|
|
|
|
# add backports (required to install ffmpeg)
|
|
|
|
echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list
|
|
|
|
ynh_package_update
|
|
|
|
|
|
|
|
# install postgresql, ffmpeg, redis
|
2018-04-06 19:15:17 +02:00
|
|
|
ynh_install_app_dependencies postgresql-9.4 ffmpeg redis-server redis-tools mailutils
|
2018-03-31 12:09:27 +02:00
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
2018-03-29 23:53:32 +02:00
|
|
|
path_url=$(ynh_normalize_url_path "$path_url")
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
2018-03-29 23:53:32 +02:00
|
|
|
cp ../conf/production.yaml "$final_path/config/production.yaml"
|
2018-04-11 17:51:42 +02:00
|
|
|
|
|
|
|
#Copy the admin saved settings from tmp directory to final path
|
|
|
|
cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json"
|
|
|
|
|
|
|
|
# Remove the tmp directory securely
|
|
|
|
ynh_secure_remove "$tmpdir"
|
2018-03-29 23:53:32 +02:00
|
|
|
(cd "$final_path" && yarn install --production --pure-lockfile)
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2018-03-29 23:53:32 +02:00
|
|
|
chown -R root:root "$final_path"
|
|
|
|
chown -R "$app" "$datadir"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Reload Nginx
|
|
|
|
systemctl reload nginx
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml"
|
|
|
|
ynh_replace_string "__db_name__" "$app" "$final_path/config/production.yaml"
|
|
|
|
ynh_replace_string "__app__" "$app" "$final_path/config/production.yaml"
|
|
|
|
ynh_replace_string "__db_pwd__" "$db_pwd" "$final_path/config/production.yaml"
|
|
|
|
ynh_replace_string "__email__" "$admin_email" "$final_path/config/production.yaml"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/config/production.yaml"
|
|
|
|
|
|
|
|
|
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "$final_path/config/production.yaml"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
|
2018-05-08 01:20:41 +02:00
|
|
|
# Set right permissions
|
|
|
|
chown -R "$app":"$app" "$final_path" "$datadir"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ $is_public -eq 0 ]
|
|
|
|
then # Remove the public access
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_app_setting_delete "$app" skipped_uris
|
2018-03-26 05:50:46 +02:00
|
|
|
fi
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2018-03-26 05:50:46 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
systemctl reload nginx
|
|
|
|
|
|
|
|
|
|
|
|
|