1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/cryptpad_ynh.git synced 2024-09-03 18:26:14 +02:00
cryptpad_ynh/scripts/upgrade
frju365 c73768d3ea wss correction ! (#7) (Thanks JimboJoe)
* wss correction !

* Update systemd.service

* [Fix] system.service

* [Fix] Systemd.service

* [Fix] path !

* Update upgrade

* Update install

* Update systemd.service

* Update systemd.service

* Update install

* Update systemd.service

* Update install

* Update config.js

* [Fix] Version 8.2.1
2017-07-25 00:26:36 +02:00

158 lines
4.8 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
#=================================================
# Créer le dossier de log
sudo mkdir -p /var/log/$app
sudo touch /var/log/$app/$app.log
install_log=/var/log/$app/installation.log
sudo touch $install_log
sudo chown $app -R /var/log/$app
sudo chown admin -R $install_log
# Configuration de logrotate
ynh_use_logrotate
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
ynh_setup_source $final_path
#=================================================
# Files owned by root, www-data can just read
#=================================================
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"
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
#=================================================
sudo mv ../conf/config.js $final_path/config.js
ynh_replace_string "__URL__" "$path_url" "$final_path/config.js"
ynh_replace_string "__PORT__" "$port" "$final_path/config.js"
#=================================================
# 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