1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/cryptpad_ynh.git synced 2024-09-03 18:26:14 +02:00
cryptpad_ynh/scripts/install

193 lines
5.8 KiB
Text
Raw Normal View History

2017-04-07 23:28:30 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
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
path_url=$YNH_APP_ARG_PATH
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
#=================================================
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-04-07 23:28:30 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
port=$(ynh_find_port 3000) # Cherche un port libre.
ynh_app_setting_set $app port $port
#=================================================
# INSTALL NODEJS
2017-04-07 23:28:30 +02:00
#=================================================
ynh_install_nodejs $NODEJS_VERSION
2017-04-07 23:28:30 +02:00
#=================================================
# CREATE DEDICATED USER
2017-04-07 23:28:30 +02:00
#=================================================
ynh_system_user_create $app
2017-04-07 23:28:30 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# HANDLE LOG FILES AND LOGROTATE
2017-04-07 23:28:30 +02:00
#=================================================
# Créer le dossier de log
2018-04-16 20:31:39 +02:00
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown $app -R /var/log/$app
2017-04-07 23:28:30 +02:00
2017-07-30 21:33:17 +02:00
# Setup logrotate
ynh_use_logrotate
2017-04-07 23:28:30 +02:00
2018-04-16 20:31:39 +02:00
2017-04-07 23:28:30 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
2017-04-07 23:28:30 +02:00
#=================================================
ynh_app_setting_set $app final_path $final_path
2018-04-16 20:31:39 +02:00
ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src
2017-04-07 23:28:30 +02:00
2017-07-25 08:25:22 +02:00
# Set files ownership during installation
2018-04-16 20:31:39 +02:00
chown $app: $final_path -R
chmod 755 $final_path -R
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
#=================================================
ynh_nginx_config
#=================================================
# ADD SYSTEMD SERVICE
2017-04-07 23:28:30 +02:00
#=================================================
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_systemd_config
2017-04-07 23:28:30 +02:00
#=================================================
# INSTALL CRYPTPAD
2017-04-07 23:28:30 +02:00
#=================================================
script_dir="$PWD"
pushd "$final_path"
2018-04-16 20:31:39 +02:00
chown -R $app: $final_path
npm install
npm install -g bower
sudo su -l $app -s /bin/bash -c "cd $final_path && env PATH=$PATH bower install"
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
#=================================================
# Copy default configuration file
2018-04-16 20:31:39 +02:00
mv "$final_path/config.example.js" "$final_path/config.js"
# Set service port
ynh_replace_string "httpPort: 3000" "httpPort: $port" "$final_path/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.js"
# Disable analytics unsolicited communications
ynh_replace_string "adminEmail: 'i.did.not.read.my.config@cryptpad.fr'" "adminEmail: false" "$final_path/config.js"
# 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
chown -R $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
#=================================================
# INSTALL MODULES FOR CRYPTPAD
#=================================================
#npm install cryptpad-level-store;
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
#=================================================
# START CRYPTPAD IN BACKGROUND
2017-04-07 23:28:30 +02:00
#=================================================
2018-04-16 20:31:39 +02:00
systemctl start $app
2017-04-07 23:28:30 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 1 ];
2017-04-07 23:28:30 +02:00
then
ynh_app_setting_set "$app" unprotected_uris "/"
fi
2018-04-16 20:20:35 +02:00
#=================================================
# App need to sleep
#=================================================
sleep 30
2017-04-07 23:28:30 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2018-04-16 20:21:45 +02:00
systemctl reload nginx
systemctl cryptpad status