2017-04-07 23:28:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-27 19:57:37 +02:00
|
|
|
set -eu
|
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-08 18:06:56 +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
|
|
|
|
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
|
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-12-27 13:16:05 +01:00
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
|
|
#=================================================
|
|
|
|
|
2017-12-27 13:16:05 +01:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
2017-12-27 13:16:05 +01:00
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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_name "$admin_name"
|
|
|
|
ynh_app_setting_set "$app" secret "$secret"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-08 18:06:56 +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
|
2017-12-27 13:06:07 +01:00
|
|
|
echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
|
2017-04-19 20:43:13 +02:00
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -yy -qq mongodb-org
|
2017-07-08 18:06:56 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL NODEJS
|
|
|
|
#=================================================
|
2017-12-27 13:06:07 +01:00
|
|
|
version=8.9.3
|
|
|
|
ynh_install_nodejs $version
|
2017-07-08 18:06:56 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app /home/$app # Créer un utilisateur système dédié à l'app
|
|
|
|
|
2017-07-25 00:02:33 +02:00
|
|
|
#=================================================
|
|
|
|
# NODEJS Version
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_use_nodejs
|
|
|
|
|
2017-07-08 18:06:56 +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/nodebb.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-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
|
2017-12-27 13:16:05 +01:00
|
|
|
ynh_setup_source "$final_path" # 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
|
2017-07-24 20:41:17 +02:00
|
|
|
sudo chown $app: $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-07-08 18:20:55 +02:00
|
|
|
ynh_use_nodejs
|
2017-12-27 13:06:07 +01:00
|
|
|
npm install --production >> $install_log 2>&1
|
|
|
|
npm install mongo
|
2017-04-19 11:05:11 +02:00
|
|
|
popd
|
|
|
|
|
2017-07-08 18:06:56 +02:00
|
|
|
sudo yunohost firewall allow Both $port
|
|
|
|
|
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
|
|
|
|
|
|
|
#=================================================
|
2017-07-08 18:06:56 +02:00
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-07-08 18:06:56 +02:00
|
|
|
ynh_nginx_config
|
|
|
|
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
sudo chown root: $nginxconf
|
|
|
|
sudo chmod 600 $nginxconf
|
2017-12-27 13:16:05 +01:00
|
|
|
cat $nginxconf
|
|
|
|
|
2017-07-08 18:06:56 +02:00
|
|
|
ynh_systemd_config
|
|
|
|
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "/etc/systemd/system/$app.service"
|
|
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "/etc/systemd/system/$app.service"
|
|
|
|
ynh_replace_string "__NODE__" "$nodejs_path" "/etc/systemd/system/$app.service"
|
2017-12-27 13:16:05 +01:00
|
|
|
cat /etc/systemd/system/$app.service
|
2017-04-07 23:28:30 +02:00
|
|
|
|
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-12-27 13:16:05 +01:00
|
|
|
cat $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
|
|
|
#=================================================
|
|
|
|
|
2017-07-08 18:20:55 +02:00
|
|
|
pushd $final_path
|
2017-04-08 00:00:54 +02:00
|
|
|
sudo chown -R $app: $final_path
|
2017-12-27 13:16:05 +01:00
|
|
|
./nodebb setup <<< \
|
2017-05-26 21:42:05 +02:00
|
|
|
"$admin_name"
|
2017-12-27 13:16:05 +01:00
|
|
|
./nodebb build
|
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-07-08 18:06:56 +02:00
|
|
|
#=================================================
|
|
|
|
# START NodeBB IN BACKGROUND
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
cat /etc/systemd/system/$app.service
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl enable "$app".service
|
2017-07-08 19:22:54 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START ETHERPAD IN BACKGROUND
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-08 18:06:56 +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-08 18:23:00 +02:00
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-25 13:51: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-08 18:06:56 +02:00
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
sudo systemctl reload nginx
|
2017-07-25 13:12:16 +02:00
|
|
|
cat $final_path/config.json
|
2017-07-25 13:05:09 +02:00
|
|
|
sudo systemctl status nodebb
|