#!/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 is_public=$YNH_APP_ARG_IS_PUBLIC path_url=$YNH_APP_ARG_PATH admin_email=$YNH_APP_ARG_EMAIL app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" # 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 #================================================= # 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 path_url "$path_url" #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= # Find a free port port=$(ynh_find_port 4000) # Open this port yunohost firewall allow --no-upnp TCP $port 2>&1 ynh_app_setting_set $app port $port porti=$(ynh_find_port 5000) # Open this port yunohost firewall allow --no-upnp TCP $porti 2>&1 ynh_app_setting_set $app porti $porti #================================================= # INSTALL NODEJS #================================================= ynh_install_nodejs $nodejs_version #================================================= # CREATE DEDICATED USER #================================================= # Create a system user ynh_system_user_create $app #================================================= # SPECIFIC SETUP #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= # Create a dedicated nginx config ynh_add_nginx_config #================================================= # SETUP SYSTEMD #================================================= # Create a dedicated systemd config ynh_add_systemd_config ynh_replace_string "__NODEJS__" "$nodejs_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" systemctl daemon-reload #================================================= # Créer le dossier de log #================================================= mkdir -p /var/log/$app touch /var/log/$app/cryptpad.log install_log=/var/log/$app/installation.log touch $install_log chown $app: -R /var/log/$app chown admin: -R $install_log #================================================= # CONFIGURE SERVER.JS #================================================= # Copy default configuration file mv "../conf/config.js" "$final_path/config/config.js" ynh_replace_string "_domain = 'http://localhost:3000/'" "_domain = 'https://$domain$path_url'" "$final_path/config/config.js" # Set service port ynh_replace_string "__PORT__" "$port" "$final_path/config/config.js" ynh_replace_string "__PORTI__" "$porti" "$final_path/config/config.js" # Tune CSP to allow for YunoHost tile #ynh_replace_string "\"script-src 'self'\"" "\"script-src 'self' 'unsafe-eval'\"" "$final_path/config.js" # Remove donate button ynh_replace_string "removeDonateButton: false" "removeDonateButton: true" "$final_path/config/config.js" # Disable analytics unsolicited communications ynh_replace_string "__ADMIN_EMAIL_" "$admin_email" "$final_path/config/config.js" # Store file checksum to detected user modifications on upgrade ynh_store_file_checksum "$final_path/config/config.js" #================================================= # INSTALL CRYPTPAD #================================================= script_dir="$PWD" pushd "$final_path" npm install --allow-root npm install -g bower --allow-root bower install --allow-root popd #================================================= # INSTALL CRYPTPAD #================================================= script_dir="$PWD" pushd "$final_path" npm install --allow-root npm install -g bower --allow-root bower install --allow-root popd #================================================= # Set some permissions #================================================= chown $app:$app $final_path -R chown $app:$app /var/log/$app/cryptpad.log #================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= # Ajoute le service au monitoring de Yunohost. yunohost service add $app --log "/var/log/$app/$app.log" #================================================= # SETUP SSOWAT #================================================= if [ $is_public -eq 1 ]; then ynh_app_setting_set "$app" unprotected_uris "/" fi ynh_check_starting "loading rpc module..." "/var/log/$app/cryptpad.log" "15" #================================================= # RELOAD NGINX #================================================= systemctl reload nginx