mirror of
https://github.com/YunoHost-Apps/nodebb_ynh.git
synced 2024-09-03 19:46:29 +02:00
208 lines
6.6 KiB
Bash
208 lines
6.6 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# 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
|
|
admin_user=$YNH_APP_ARG_ADMIN_USER
|
|
admin_mail=$YNH_APP_ARG_ADMIN_MAIL
|
|
admin_pass=$YNH_APP_ARG_ADMIN_PASS
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
secret=$(ynh_string_random)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
ynh_app_setting_set $app is_public $is_public
|
|
ynh_app_setting_set "$app" admin_user "$admin_user"
|
|
ynh_app_setting_set "$app" secret "$secret"
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# FIND AND OPEN A PORT
|
|
#=================================================
|
|
|
|
port=$(ynh_find_port 4567) # Cherche un port libre.
|
|
ynh_app_setting_set $app port $port
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
|
|
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
|
|
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
|
|
sudo apt-get update
|
|
sudo apt-get install -yy -qq mongodb-org
|
|
|
|
#=================================================
|
|
# INSTALL NODEJS
|
|
#=================================================
|
|
|
|
version=9.3.0
|
|
ynh_install_nodejs $version
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
|
|
ynh_system_user_create $app /home/$app # Créer un utilisateur système dédié à l'app
|
|
|
|
#=================================================
|
|
# NODEJS Version
|
|
#=================================================
|
|
|
|
ynh_use_nodejs
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
#=================================================
|
|
|
|
# Créer le dossier de log
|
|
mkdir -p /var/log/$app
|
|
touch /var/log/$app/nodebb.log
|
|
install_log=/var/log/$app/installation.log
|
|
touch $install_log
|
|
chown $app -R /var/log/$app
|
|
chown admin -R $install_log
|
|
|
|
# Configuration de logrotate
|
|
ynh_use_logrotate
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
final_path=/var/www/$app
|
|
ynh_app_setting_set $app final_path $final_path
|
|
ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
|
|
|
|
#=================================================
|
|
# BEGINING OF THE INSTALLATION
|
|
#=================================================
|
|
|
|
systemctl start mongod
|
|
script_dir="$PWD"
|
|
pushd "$final_path"
|
|
ynh_use_nodejs
|
|
cp install/package.json .
|
|
npm install --production >> $install_log 2>&1
|
|
npm install mongo
|
|
popd
|
|
|
|
#=================================================
|
|
# CREATE A SQL BDD
|
|
#=================================================
|
|
|
|
pushd $final_path
|
|
dbname=$app
|
|
dbuser=$app
|
|
dbpass=$(ynh_string_random)
|
|
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
|
|
popd
|
|
|
|
#=================================================
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
#=================================================
|
|
|
|
ynh_add_nginx_config
|
|
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
|
|
sudo chown root: $nginxconf
|
|
sudo chmod 600 $nginxconf
|
|
cat $nginxconf
|
|
|
|
ynh_add_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"
|
|
cat /etc/systemd/system/$app.service
|
|
|
|
#=================================================
|
|
# CONFIGURE SERVER.JS
|
|
#=================================================
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# CONFIGURE NODEBB
|
|
#=================================================
|
|
|
|
pushd $final_path
|
|
./nodebb setup
|
|
./nodebb build
|
|
popd
|
|
chown -R $app:$app $final_path
|
|
|
|
#=================================================
|
|
# START NodeBB IN BACKGROUND
|
|
#=================================================
|
|
|
|
cat /etc/systemd/system/$app.service
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable "$app".service
|
|
|
|
#=================================================
|
|
# START ETHERPAD IN BACKGROUND
|
|
#=================================================
|
|
|
|
systemctl start $app # Démarre Nodebb. Le démarrage est fait le plus tôt possible, car il est très long...
|
|
ynh_check_starting "NodeBB is now listening on: 0.0.0.0:4567" "/var/log/syslog" "60"
|
|
|
|
#=================================================
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
yunohost service add $app --log "/var/log/$app/nodebb.log"
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
|
|
if [ $is_public -eq 1 ];
|
|
then
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
systemctl reload nginx
|