#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE FAILURE OF THE SCRIPT #================================================= 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 path_url=$YNH_APP_ARG_PATH app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app config_path=/home/yunohost.app/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= port=$(ynh_find_port 9001) # Look for an available port ynh_app_setting_set $app port $port #================================================= # INSTALL NODEJS #================================================= ynh_install_nodejs $nodejs_version #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_app_setting_set $app final_path $final_path ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src #================================================= # NGINX CONFIGURATION #================================================= ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_system_user_create $app $final_path #================================================= # SPECIFIC SETUP #================================================= # HANDLE LOG FILES AND LOGROTATE #================================================= # Create log directory mkdir -p /var/log/$app touch /var/log/$app/installation.log install_log=/var/log/$app/installation.log touch $install_log chown $app -R /var/log/$app # Setup logrotate ynh_use_logrotate #================================================= # INSTALL #================================================= # Install dependencies and proceed with the installation nodedir=$(ynh_get_nodejs_bindir $nodejs_version) (cd $final_path && PATH=$nodedir:$PATH npm install --production > $install_log 2>&1) #================================================= # CONFIGURE #================================================= cp ../conf/app.json "$final_path/config/app.json" ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config/app.json" cp ../conf/db.json "$final_path/config/db.json" ynh_store_file_checksum "$final_path/config/app.json" ynh_store_file_checksum "$final_path/config/db.json" #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Set files ownership to etherpad chown -R $app: $final_path chmod 600 "$final_path/config/db.json" # Restrict access to db.json #================================================= # SETUP SYSTEMD #================================================= #ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" ynh_replace_string "__NODE_DIR__" "$nodedir" "../conf/systemd.service" ynh_replace_string "__PORT__" "$port" "../conf/systemd.service" ynh_replace_string "__FINAL_PATH__" "$final_path" "../conf/systemd.service" ynh_add_systemd_config #================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= systemctl start $app.service # Add service to YunoHost monitoring panel yunohost service add $app #================================================= # SETUP FAIL2BAN #================================================= #ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" " .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5 #================================================= # RELOAD NGINX #================================================= systemctl reload nginx