2017-04-07 23:28:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source .fonctions
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-04-21 17:17:55 +02:00
|
|
|
set -eu
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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-19 20:43:13 +02:00
|
|
|
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
|
|
|
|
echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -yy -qq mongodb-org
|
2017-04-18 13:18:56 +02:00
|
|
|
sudo curl -sL https://deb.nodesource.com/setup_7.x | sudo bash -
|
2017-04-19 20:43:13 +02:00
|
|
|
sudo apt-get install -yy -qq nodejs
|
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 23:05:26 +02:00
|
|
|
sudo chmod 755 $final_path -R
|
|
|
|
sudo chown www-data:www-data $final_path -R
|
2017-04-07 23:28:30 +02:00
|
|
|
|
2017-04-19 11:05:11 +02:00
|
|
|
#=================================================
|
|
|
|
# BEGINING OF THE INSTALLATION
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-19 20:43:13 +02:00
|
|
|
sudo service mongod start
|
2017-04-19 11:05:11 +02:00
|
|
|
script_dir="$PWD"
|
|
|
|
pushd "$final_path"
|
2017-04-20 01:24:01 +02:00
|
|
|
sudo npm install --production
|
2017-04-19 11:05:11 +02:00
|
|
|
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)
|
2017-04-19 21:05:49 +02:00
|
|
|
sudo mongo --shell "$dbname" --eval 'db.createUser( { user: "'${dbuser}'", pwd: "'${dbpass}'", roles: [ "readWrite" ] } );' <<< exit
|
|
|
|
sudo mongo --shell "$dbname" --eval 'db.grantRolesToUser("'${dbuser}'",[{ role: "clusterMonitor", db: "admin" }]);' <<< exit
|
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
|
2017-04-20 11:44:38 +02:00
|
|
|
sudo sed -i "s@__URL__@$domain@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
2017-04-07 23:28:30 +02:00
|
|
|
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-20 01:24:01 +02:00
|
|
|
sudo adduser --system --group nodebb
|
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
|
2017-04-20 00:12:12 +02:00
|
|
|
sudo sed -i "s@__URL__@$domain@g" $final_path/config.json
|
2017-04-18 18:17:30 +02:00
|
|
|
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
|
2017-04-19 12:50:23 +02:00
|
|
|
sudo sed -i "s@dbpass@$dbpass@g" $final_path/config.json
|
2017-04-18 18:17:30 +02:00
|
|
|
|
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-20 01:24:01 +02:00
|
|
|
sudo chown -R nodebb:nodebb $final_path
|
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.
|
2017-04-19 23:19:59 +02:00
|
|
|
sudo yunohost service add $app --log "/var/log/$app/nodebb.log"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START ETHERPAD IN BACKGROUND
|
|
|
|
#=================================================
|
2017-04-20 00:19:26 +02:00
|
|
|
sudo sed -i "s@__PATH__@$final_path@g" ../conf/nodebb.service
|
2017-04-20 00:12:12 +02:00
|
|
|
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
|
|
|
|
id -u "$app" &>/dev/null || sudo adduser "$app" \
|
|
|
|
--ingroup "$app" --system --quiet --shell /bin/bash
|
|
|
|
sudo cp ../conf/"$app".service /etc/systemd/system/
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl enable "$app".service
|
2017-05-12 23:15:46 +02:00
|
|
|
sleep 10
|
2017-04-20 01:24:01 +02:00
|
|
|
sudo systemctl start $app # Démarre Nodebb. Le démarrage est fait le plus tôt possible, car il est très long...
|
2017-04-23 11:12:06 +02:00
|
|
|
sleep 10
|
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
|
|
|
|
#=================================================
|
2017-05-12 23:15:46 +02:00
|
|
|
sleep 10
|
2017-04-07 23:28:30 +02:00
|
|
|
sudo systemctl reload nginx
|