2017-04-07 23:28:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
2018-01-28 15:58:21 +01:00
|
|
|
# GENERIC START
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#=================================================
|
2018-01-28 15:58:21 +01:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-01-28 15:58:21 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2018-03-11 12:28:28 +01:00
|
|
|
path_url=$YNH_APP_ARG_PATH # Assure la compatibilité avec les fonctions utilisant $path_url
|
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
|
|
|
#=================================================
|
2018-01-28 15:58:21 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
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
|
|
|
|
2018-03-11 12:28:28 +01:00
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
|
|
|
|
# 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" 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
|
|
|
|
#=================================================
|
|
|
|
|
2018-08-22 23:56:03 +02:00
|
|
|
ynh_install_app_dependencies mongodb
|
|
|
|
systemctl start mongodb
|
2017-07-08 18:06:56 +02:00
|
|
|
|
2019-01-06 01:16:29 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE A SQL BDD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
dbname=$app
|
|
|
|
dbuser=$app
|
|
|
|
dbpass=$(ynh_string_random)
|
|
|
|
ynh_app_setting_set $app dbuser $dbuser
|
|
|
|
ynh_app_setting_set $app dbpass $dbpass
|
|
|
|
ynh_app_setting_set $app dbname $dbname
|
|
|
|
mongo --shell "$dbname" --eval 'db.createUser( { user: "'${dbuser}'", pwd: "'${dbpass}'", roles: [ "readWrite" ] } );' <<< exit
|
|
|
|
mongo --shell "$dbname" --eval 'db.grantRolesToUser("'${dbuser}'",[{ role: "clusterMonitor", db: "admin" }]);' <<< exit
|
|
|
|
|
2017-07-08 18:06:56 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL NODEJS
|
|
|
|
#=================================================
|
2018-01-28 15:58:21 +01:00
|
|
|
|
2019-01-06 02:28:59 +01:00
|
|
|
ynh_install_nodejs 8.14.0
|
2018-01-28 15:58:21 +01:00
|
|
|
|
2017-07-08 18:06:56 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 12:09:25 +01:00
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create $app
|
2017-07-08 18:06:56 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Créer le dossier de log
|
2017-12-28 18:06:23 +01:00
|
|
|
mkdir -p /var/log/$app
|
|
|
|
touch /var/log/$app/nodebb.log
|
2017-07-08 18:06:56 +02:00
|
|
|
install_log=/var/log/$app/installation.log
|
2017-12-28 18:06:23 +01:00
|
|
|
touch $install_log
|
|
|
|
chown $app -R /var/log/$app
|
|
|
|
chown admin -R $install_log
|
2017-07-08 18:06:56 +02:00
|
|
|
|
|
|
|
# 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-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-12-28 17:12:59 +01:00
|
|
|
ynh_add_nginx_config
|
2018-08-22 23:56:03 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Add Systemd service
|
|
|
|
#=================================================
|
2017-12-27 13:16:05 +01:00
|
|
|
|
2017-12-28 17:12:59 +01:00
|
|
|
ynh_add_systemd_config
|
2017-07-08 18:06:56 +02:00
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
2018-01-28 15:52:30 +01:00
|
|
|
mv ../conf/config.json $final_path/config.json
|
|
|
|
ynh_replace_string "__URL__" "$domain" "$final_path/config.json"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/config.json"
|
|
|
|
ynh_replace_string "__SECRET__" "$secret" "$final_path/config.json"
|
|
|
|
ynh_replace_string "dbuser" "$dbuser" "$final_path/config.json"
|
|
|
|
ynh_replace_string "dbname" "$dbname" "$final_path/config.json"
|
|
|
|
ynh_replace_string "dbpass" "$dbpass" "$final_path/config.json"
|
|
|
|
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
|
|
|
#=================================================
|
|
|
|
|
2019-01-06 02:33:59 +01:00
|
|
|
chown -R $app:$app $final_path
|
2017-07-08 18:20:55 +02:00
|
|
|
pushd $final_path
|
2019-01-06 02:52:14 +01:00
|
|
|
exec_as "$app" ./nodebb setup -l
|
|
|
|
exec_as "$app" ./nodebb build -l
|
2017-04-08 00:38:52 +02:00
|
|
|
popd
|
2019-01-06 02:33:59 +01:00
|
|
|
|
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-12-28 17:37:56 +01:00
|
|
|
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-12-28 17:37:56 +01:00
|
|
|
yunohost service add $app --log "/var/log/$app/nodebb.log"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 12:12:45 +01:00
|
|
|
if [ $is_public -eq 0 ]
|
|
|
|
then # Remove the public access
|
|
|
|
ynh_app_setting_delete $app skipped_uris
|
|
|
|
fi
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
2017-04-07 23:28:30 +02:00
|
|
|
then
|
2018-03-11 12:12:45 +01:00
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2017-04-07 23:28:30 +02:00
|
|
|
fi
|
2018-08-22 23:56:03 +02:00
|
|
|
ynh_check_starting "NodeBB is now listening on: 0.0.0.0:4567" "/var/log/syslog" "90"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2017-07-08 18:06:56 +02:00
|
|
|
|
2017-12-28 17:37:56 +01:00
|
|
|
systemctl reload nginx
|