1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nodebb_ynh.git synced 2024-09-03 19:46:29 +02:00
nodebb_ynh/scripts/install

223 lines
6.9 KiB
Text
Raw Normal View History

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
#=================================================
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
#=================================================
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-12-28 16:35:50 +01:00
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
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
2018-03-11 13:44:28 +01:00
ynh_install_app_dependencies mongodb-org
#=================================================
# INSTALL NODEJS
#=================================================
2018-01-28 15:58:21 +01:00
2017-12-28 16:57:01 +01:00
version=9.3.0
2017-12-27 13:06:07 +01:00
ynh_install_nodejs $version
2018-01-28 15:58:21 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2018-03-11 12:09:25 +01:00
# Create a system user
ynh_system_user_create $app
2017-07-25 00:02:33 +02:00
#=================================================
# NODEJS Version
#=================================================
ynh_use_nodejs
#=================================================
# 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
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
# 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-04-19 11:05:11 +02:00
#=================================================
# BEGINING OF THE INSTALLATION
#=================================================
2017-12-28 18:06:23 +01:00
systemctl start mongod
2017-04-19 11:05:11 +02:00
script_dir="$PWD"
pushd "$final_path"
ynh_use_nodejs
2017-12-28 19:15:49 +01:00
cp install/package.json .
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-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-12-28 17:37:56 +01:00
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
2018-03-11 12:44:17 +01:00
ynh_app_setting_set $app dbuser $dbuser
ynh_app_setting_set $app dbpass $dbpass
ynh_app_setting_set $app dbname $dbname
2017-04-18 18:17:30 +02:00
popd
2017-04-07 23:28:30 +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
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-12-28 17:12:59 +01:00
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"
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
#=================================================
pushd $final_path
2018-01-28 15:52:30 +01:00
./nodebb setup
2017-12-28 18:06:23 +01:00
./nodebb build
2017-04-08 00:38:52 +02:00
popd
2017-12-28 17:37:56 +01:00
chown -R $app:$app $final_path
2017-04-07 23:28:30 +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...
2018-01-28 15:58:21 +01:00
ynh_check_starting "NodeBB is now listening on: 0.0.0.0:4567" "/var/log/syslog" "60"
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
#=================================================
# RELOAD NGINX
#=================================================
2017-12-28 17:37:56 +01:00
systemctl reload nginx