mirror of
https://github.com/YunoHost-Apps/cryptpad_ynh.git
synced 2024-09-03 18:26:14 +02:00
168 lines
5.3 KiB
Bash
168 lines
5.3 KiB
Bash
#!/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
|
|
#=================================================
|
|
|
|
# Setup logrotate
|
|
ynh_use_logrotate /var/log/${app}/*.log --non-append
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
final_path=/var/www/$app
|
|
ynh_app_setting_set $app final_path $final_path
|
|
ynh_setup_source $final_path
|
|
|
|
# Set files ownership during installation
|
|
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"
|
|
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
|
ynh_systemd_config
|
|
|
|
|
|
#=================================================
|
|
# INSTALL CRYPTPAD
|
|
#=================================================
|
|
|
|
script_dir="$PWD"
|
|
pushd "$final_path"
|
|
chown -R $app: $final_path
|
|
npm install
|
|
npm install -g bower
|
|
exec_login_as $app cd $final_path && env PATH=$PATH bower install
|
|
popd
|
|
|
|
#=================================================
|
|
# CONFIGURE SERVER.JS
|
|
#=================================================
|
|
|
|
# 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"
|
|
|
|
#=================================================
|
|
# SET FILES OWNERSHIP
|
|
#=================================================
|
|
|
|
sudo chown -R root: $final_path
|
|
sudo chown -R $app: $final_path/datastore $final_path/pins $final_path/blob $final_path/blobstage
|
|
|
|
#=================================================
|
|
# 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
|
|
sudo systemctl reload nginx
|