2017-07-23 17:46:25 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
# Set app specific variables
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
# Check destination directory
|
|
|
|
DESTDIR="/var/www/$app"
|
|
|
|
[[ ! -d $DESTDIR ]] && ynh_die \
|
|
|
|
"The destination directory '$DESTDIR' does not exist.\
|
|
|
|
The app is not correctly installed, you should remove it first."
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path_url=$(ynh_normalize_url_path "$(ynh_app_setting_get "$app" path_url)")
|
|
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
|
|
port=$(ynh_app_setting_get "$app" port)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Use prior backup and restore on error only if backup feature
|
|
|
|
# exists on installed instance
|
|
|
|
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
|
|
|
|
ynh_backup_before_upgrade # Backup the current version of the app
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_backup_after_failed_upgrade
|
|
|
|
}
|
|
|
|
ynh_abort_if_errors # Stop script if an error is detected
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL NODEJS
|
|
|
|
#=================================================
|
|
|
|
ynh_install_nodejs $NODEJS_VERSION
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-30 21:33:54 +02:00
|
|
|
# Setup logrotate
|
|
|
|
ynh_use_logrotate /var/log/${app}/*.log --non-append
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
ynh_setup_source $final_path
|
|
|
|
|
2017-07-25 08:25:22 +02:00
|
|
|
# Set files ownership during installation
|
2017-07-23 17:46:25 +02:00
|
|
|
sudo chown $app: $final_path -R
|
|
|
|
sudo chmod 755 $final_path -R
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADD SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
|
2017-07-25 00:26:36 +02:00
|
|
|
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
|
|
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
2017-07-23 17:46:25 +02:00
|
|
|
ynh_systemd_config
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL CRYPTPAD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
script_dir="$PWD"
|
|
|
|
pushd "$final_path"
|
|
|
|
sudo chown -R $app: $final_path
|
|
|
|
sudo_path npm install
|
|
|
|
sudo_path npm install -g bower
|
|
|
|
sudo su -l $app -s /bin/bash -c "cd $final_path && env PATH=$PATH bower install"
|
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURE SERVER.JS
|
|
|
|
#=================================================
|
|
|
|
|
2017-08-01 22:19:08 +02:00
|
|
|
# Backup configuration file if changed
|
|
|
|
ynh_backup_if_checksum_is_different "$final_path/config.js"
|
|
|
|
|
|
|
|
# Copy default configuration file
|
|
|
|
sudo mv "$final_path/config.example.js" "$final_path/config.js"
|
|
|
|
|
|
|
|
# Set service port
|
|
|
|
ynh_replace_string "httpPort: 3000" "httpPort: $port" "$final_path/config.js"
|
|
|
|
# Tune CSP to allow for YunoHost tile
|
|
|
|
ynh_replace_string "\"script-src 'self'\"" "\"script-src 'self' 'unsafe-eval'\"" "$final_path/config.js"
|
|
|
|
# Remove donate button
|
|
|
|
ynh_replace_string "removeDonateButton: false" "removeDonateButton: true" "$final_path/config.js"
|
|
|
|
# Disable analytics unsolicited communications
|
|
|
|
ynh_replace_string "adminEmail: 'i.did.not.read.my.config@cryptpad.fr'" "adminEmail: false" "$final_path/config.js"
|
|
|
|
|
|
|
|
# Store file checksum to detected user modifications on upgrade
|
|
|
|
ynh_store_file_checksum "$final_path/config.js"
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2017-07-25 08:25:22 +02:00
|
|
|
#=================================================
|
|
|
|
# SET FILES OWNERSHIP
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-25 14:23:58 +02:00
|
|
|
sudo chown -R root: $final_path
|
|
|
|
sudo chown -R $app: $final_path/datastore $final_path/pins $final_path/blob $final_path/blobstage
|
2017-07-25 08:25:22 +02:00
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL MODULES FOR CRYPTPAD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#npm install cryptpad-level-store;
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Ajoute le service au monitoring de Yunohost.
|
|
|
|
sudo yunohost service add $app --log "/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START CRYPTPAD IN BACKGROUND
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo systemctl start $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ $is_public -eq 1 ];
|
|
|
|
then
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
sudo systemctl restart php5-fpm
|
2017-07-25 00:26:36 +02:00
|
|
|
sudo systemctl reload nginx
|