2017-04-07 23:28:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
source _common.sh
|
2017-04-07 23:28:30 +02:00
|
|
|
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
|
2017-07-23 17:46:25 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2019-01-05 20:09:35 +01:00
|
|
|
admin_email=$YNH_APP_ARG_EMAIL
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
|
|
#=================================================
|
|
|
|
|
2018-04-16 20:31:39 +02:00
|
|
|
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)
|
2017-04-07 23:28:30 +02:00
|
|
|
|
2018-04-16 20:31:39 +02:00
|
|
|
# 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
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
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"
|
2017-07-25 00:26:36 +02:00
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
2018-08-22 10:27:30 +02:00
|
|
|
# Find a free port
|
2019-01-05 20:09:35 +01:00
|
|
|
port=$(ynh_find_port 4000)
|
2018-08-22 10:27:30 +02:00
|
|
|
# Open this port
|
|
|
|
yunohost firewall allow --no-upnp TCP $port 2>&1
|
2017-04-07 23:28:30 +02:00
|
|
|
ynh_app_setting_set $app port $port
|
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# INSTALL NODEJS
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
2017-07-25 00:26:36 +02:00
|
|
|
|
2018-09-04 09:42:13 +02:00
|
|
|
ynh_install_nodejs $nodejs_version
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# CREATE DEDICATED USER
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-08-22 10:27:30 +02:00
|
|
|
# Create a system user
|
2017-07-23 17:46:25 +02:00
|
|
|
ynh_system_user_create $app
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2018-08-22 10:27:30 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-08-22 10:27:30 +02:00
|
|
|
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"
|
2018-04-16 20:31:39 +02:00
|
|
|
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
2018-04-16 20:53:22 +02:00
|
|
|
# NGINX CONFIGURATION
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2018-08-22 10:27:30 +02:00
|
|
|
# Create a dedicated nginx config
|
2018-04-16 20:53:22 +02:00
|
|
|
ynh_add_nginx_config
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-08-22 10:27:30 +02:00
|
|
|
# SETUP SYSTEMD
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-08-22 10:27:30 +02:00
|
|
|
# Create a dedicated systemd config
|
2018-04-16 20:53:22 +02:00
|
|
|
ynh_add_systemd_config
|
2018-08-22 10:27:30 +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"
|
2019-01-05 19:46:24 +01:00
|
|
|
systemctl daemon-reload
|
2018-08-22 10:27:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Créer le dossier de log
|
|
|
|
#=================================================
|
2017-04-07 23:28:30 +02:00
|
|
|
|
2018-08-22 10:27:30 +02:00
|
|
|
sudo mkdir -p /var/log/$app
|
2019-01-05 20:38:13 +01:00
|
|
|
sudo touch /var/log/$app/cryptpad.log
|
2018-08-22 10:27:30 +02:00
|
|
|
install_log=/var/log/$app/installation.log
|
|
|
|
sudo touch $install_log
|
|
|
|
sudo chown $app -R /var/log/$app
|
|
|
|
sudo chown admin -R $install_log
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-07-23 00:14:35 +02:00
|
|
|
# INSTALL CRYPTPAD
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
script_dir="$PWD"
|
2017-07-23 17:46:25 +02:00
|
|
|
pushd "$final_path"
|
2019-01-05 19:27:10 +01:00
|
|
|
npm install --allow-root
|
|
|
|
npm install -g bower --allow-root
|
2019-01-05 19:21:29 +01:00
|
|
|
bower install --allow-root
|
2017-04-08 00:38:52 +02:00
|
|
|
popd
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-04-08 00:00:54 +02:00
|
|
|
# CONFIGURE SERVER.JS
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-08-01 22:19:08 +02:00
|
|
|
# Copy default configuration file
|
2018-04-16 20:31:39 +02:00
|
|
|
mv "$final_path/config.example.js" "$final_path/config.js"
|
2019-01-05 20:09:35 +01:00
|
|
|
ynh_replace_string "_domain = 'http://localhost:3000/'" "_domain = 'https://$domain$path_url'" "$final_path/config.js"
|
2017-08-01 22:19:08 +02:00
|
|
|
# Set service port
|
|
|
|
ynh_replace_string "httpPort: 3000" "httpPort: $port" "$final_path/config.js"
|
|
|
|
# Tune CSP to allow for YunoHost tile
|
2018-12-05 23:13:20 +01:00
|
|
|
#ynh_replace_string "\"script-src 'self'\"" "\"script-src 'self' 'unsafe-eval'\"" "$final_path/config.js"
|
2017-08-01 22:19:08 +02:00
|
|
|
# Remove donate button
|
|
|
|
ynh_replace_string "removeDonateButton: false" "removeDonateButton: true" "$final_path/config.js"
|
|
|
|
# Disable analytics unsolicited communications
|
2019-01-05 20:19:24 +01:00
|
|
|
ynh_replace_string "adminEmail: 'i.did.not.read.my.config@cryptpad.fr'" "adminEmail: '$admin_email'" "$final_path/config.js"
|
|
|
|
cp $final_path/config.js $final_path/config.example
|
2017-08-01 22:19:08 +02:00
|
|
|
# Store file checksum to detected user modifications on upgrade
|
|
|
|
ynh_store_file_checksum "$final_path/config.js"
|
2017-04-08 00:00:54 +02:00
|
|
|
|
2017-07-25 08:25:22 +02:00
|
|
|
#=================================================
|
|
|
|
# SET FILES OWNERSHIP
|
|
|
|
#=================================================
|
|
|
|
|
2018-04-16 20:31:39 +02:00
|
|
|
chown -R root: $final_path
|
|
|
|
mkdir $final_path/datastore $final_path/pins $final_path/blob $final_path/blobstage
|
2019-01-05 19:21:29 +01:00
|
|
|
chown -R $app:$app $final_path/datastore $final_path/pins $final_path/blob $final_path/blobstage
|
2017-07-25 08:25:22 +02:00
|
|
|
|
2017-04-08 00:00:54 +02:00
|
|
|
#=================================================
|
2019-01-05 20:38:13 +01:00
|
|
|
# START CRYPTPAD IN BACKGROUND
|
2017-04-08 00:00:54 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-01-05 20:38:13 +01:00
|
|
|
systemctl start $app
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Ajoute le service au monitoring de Yunohost.
|
2018-04-16 20:31:39 +02:00
|
|
|
yunohost service add $app --log "/var/log/$app/$app.log"
|
2017-04-07 23:28:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
if [ $is_public -eq 1 ];
|
2017-04-07 23:28:30 +02:00
|
|
|
then
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
2019-01-05 20:38:13 +01:00
|
|
|
ynh_check_starting "loading rpc module..." "/var/log/$app/cryptpad.log" "120"
|
2017-04-07 23:28:30 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2018-04-16 20:21:45 +02:00
|
|
|
systemctl reload nginx
|