2017-04-07 23:28:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
source _common.sh
|
2017-04-07 23:28:30 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# Nettoyage des résidus d'installation non pris en charge par le script remove.
|
|
|
|
if test -n "$PID_TAIL"
|
|
|
|
then
|
|
|
|
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
|
|
|
|
sudo rm -f "$tempfile"
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2017-07-23 17:46:25 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if sudo yunohost domain list | grep -q $domain # Vérifie la liste des domaines
|
|
|
|
then # Si le domaine existe dans Yunohost
|
|
|
|
if sudo yunohost app map | grep -q $domain # Vérifie la liste des apps par domaine
|
|
|
|
then # Si une app est installée sur ce domaine.
|
2017-07-23 17:46:25 +02:00
|
|
|
WARNING echo "An app is already installed on the domain $domain. cryptpad needs a whole domain or subdomain to himself."
|
2017-04-07 23:28:30 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
|
|
|
|
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
ynh_app_setting_set $app domain "$domain"
|
|
|
|
ynh_app_setting_set $app is_public "$is_public"
|
|
|
|
ynh_app_setting_set $app path_url "$path_url"
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
port=$(ynh_find_port 3000) # Cherche un port libre.
|
|
|
|
ynh_app_setting_set $app port $port
|
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# INSTALL NODEJS
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
ynh_install_nodejs $NODEJS_VERSION
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# CREATE DEDICATED USER
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
ynh_system_user_create $app
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# HANDLE LOG FILES AND LOGROTATE
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
# 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
|
2017-04-07 23:28:30 +02:00
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
# Configuration de logrotate
|
|
|
|
ynh_use_logrotate
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2017-07-23 22:53:29 +02:00
|
|
|
ynh_setup_source $final_path
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# Files owned by root, www-data can just read
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
sudo chown $app: $final_path -R
|
|
|
|
sudo chmod 755 $final_path -R
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
ynh_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADD SYSTEMD SERVICE
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
|
|
|
|
ynh_systemd_config
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 00:14:35 +02:00
|
|
|
# INSTALL CRYPTPAD
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
script_dir="$PWD"
|
2017-07-23 17:46:25 +02:00
|
|
|
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"
|
2017-04-08 00:38:52 +02:00
|
|
|
popd
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-04-08 00:00:54 +02:00
|
|
|
# CONFIGURE SERVER.JS
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-04-08 12:08:18 +02:00
|
|
|
sudo mv ../conf/config.js $final_path/config.js
|
2017-07-23 17:46:25 +02:00
|
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/config.js"
|
2017-07-23 22:53:29 +02:00
|
|
|
ynh_replace_string "__URL__" "$domain$path_url" "$final_path/config.js"
|
2017-04-08 00:00:54 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL MODULES FOR CRYPTPAD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#npm install cryptpad-level-store;
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Ajoute le service au monitoring de Yunohost.
|
2017-07-23 17:46:25 +02:00
|
|
|
sudo yunohost service add $app --log "/var/log/$app/$app.log"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# START CRYPTPAD IN BACKGROUND
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
sudo systemctl start $app
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
if [ $is_public -eq 1 ];
|
2017-04-07 23:28:30 +02:00
|
|
|
then
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
sudo systemctl reload nginx
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2017-07-23 21:23:00 +02:00
|
|
|
# TODO wait for service availability
|