2017-04-07 23:28:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source .fonctions
|
|
|
|
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
|
|
|
|
path_url="" # Assure la compatibilité avec les fonctions utilisant $path_url
|
2017-04-19 00:56:02 +02:00
|
|
|
admin_name=$YNH_APP_ARG_ADMIN_NAME
|
|
|
|
admin_pass=$YNH_APP_ARG_ADMIN_PASS
|
|
|
|
admin_email=$YNH_APP_ARG_ADMIN_EMAIL
|
2017-04-07 23:28:30 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-04-19 00:56:02 +02:00
|
|
|
secret=$(ynh_string_random)
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# 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.
|
|
|
|
WARNING echo "An app is already installed on the domain $domain. Mypads needs a whole domain or subdomain to himself."
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
2017-04-19 00:56:02 +02:00
|
|
|
ynh_app_setting_set "$app" admin_pass "$admin_pass"
|
|
|
|
ynh_app_setting_set "$app" admin_name "$admin_name"
|
|
|
|
ynh_app_setting_set "$app" admin_email "$admin_email"
|
|
|
|
ynh_app_setting_set "$app" secret "$secret"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-18 18:17:30 +02:00
|
|
|
port=$(ynh_find_port 4567) # Cherche un port libre.
|
2017-04-07 23:28:30 +02:00
|
|
|
ynh_app_setting_set $app port $port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-18 13:18:56 +02:00
|
|
|
sudo curl -sL https://deb.nodesource.com/setup_7.x | sudo bash -
|
2017-04-18 18:17:30 +02:00
|
|
|
sudo apt-get install -yy -qq nodejs mongodb
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
|
|
|
|
|
2017-04-19 11:05:11 +02:00
|
|
|
#=================================================
|
|
|
|
# BEGINING OF THE INSTALLATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
script_dir="$PWD"
|
|
|
|
pushd "$final_path"
|
|
|
|
sudo npm install
|
|
|
|
sudo npm install -g mongo
|
|
|
|
popd
|
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE A SQL BDD
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-18 18:17:30 +02:00
|
|
|
pushd $final_path
|
|
|
|
dbname=$app
|
|
|
|
dbuser=$app
|
|
|
|
dbpass=$(ynh_string_random)
|
|
|
|
sudo mongo <<< \
|
2017-04-19 01:59:57 +02:00
|
|
|
"use $dbname;"
|
2017-04-19 12:42:17 +02:00
|
|
|
sudo mongo --shell "$dbname" <<< \
|
|
|
|
'db.createUser( { user: "$dbuser", pwd: "$dbpass", roles: [ "readWrite" ] } );'
|
|
|
|
sudo mongo --shell "$dbname" <<< \
|
|
|
|
'db.grantRolesToUser("$dbuser",[{ role: "clusterMonitor", db: "admin" }]);'
|
2017-04-18 18:17:30 +02:00
|
|
|
popd
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Et copie le fichier de config nginx
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
# Modifie les variables dans le fichier de configuration nginx
|
|
|
|
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-08 11:45:46 +02:00
|
|
|
sudo useradd -N $app -d $final_path # Créer un utilisateur système dédié à l'app
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Créer le dossier de log
|
|
|
|
sudo mkdir -p /var/log/$app
|
|
|
|
sudo touch /var/log/$app/cryptpad.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
|
|
|
|
|
2017-04-18 18:17:30 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE SERVER.JS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo mv ../conf/config.json $final_path/config.json
|
|
|
|
sudo sed -i "s@__URL__@$path_url@g" $final_path/config.json
|
|
|
|
sudo sed -i "s@__PORT__@$port@g" $final_path/config.json
|
|
|
|
sudo sed -i "s@__SECRET__@$secret@g" $final_path/config.json
|
|
|
|
sudo sed -i "s@dbuser@$dbuser@g" $final_path/config.json
|
|
|
|
sudo sed -i "s@dbname@$dbname@g" $final_path/config.json
|
|
|
|
sudo sed -i "s@dbuser@$dbpass@g" $final_path/config.json
|
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
2017-04-19 11:05:11 +02:00
|
|
|
# CONFIGURE NODEBB
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
pushd "$final_path"
|
2017-04-08 00:00:54 +02:00
|
|
|
sudo chown -R $app: $final_path
|
2017-04-18 18:39:00 +02:00
|
|
|
sudo ./nodebb setup <<< \
|
2017-04-19 00:56:02 +02:00
|
|
|
"$admin_name
|
|
|
|
$admin_email
|
2017-04-18 18:39:00 +02:00
|
|
|
$admin_pass"
|
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
|
|
|
#=================================================
|
|
|
|
# INSTALL MODULES FOR CRYPTPAD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#npm install cryptpad-level-store;
|
2017-04-07 23:28:30 +02:00
|
|
|
|
2017-04-08 18:23:00 +02:00
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Ajoute le service au monitoring de Yunohost.
|
|
|
|
sudo yunohost service add $app --log "/var/log/$app/cryptpad.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START ETHERPAD IN BACKGROUND
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-18 18:17:30 +02:00
|
|
|
|
|
|
|
pushd $final_path
|
|
|
|
./nodebb start # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long...
|
|
|
|
popd
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$is_public" = 0 ];
|
|
|
|
then
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo systemctl reload nginx
|