2015-03-19 20:49:50 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-06-15 23:56:45 +02:00
|
|
|
|
2017-03-21 00:44:14 +01:00
|
|
|
source _common.sh
|
2017-03-19 19:16:10 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2017-09-05 00:25:58 +02:00
|
|
|
# Load common variables for all scripts.
|
|
|
|
source _variables
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2017-12-05 19:36:40 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
# Nettoyage des résidus d'installation non pris en charge par le script remove.
|
2017-12-16 23:22:54 +01:00
|
|
|
ynh_clean_check_starting
|
2017-12-05 19:36:40 +01:00
|
|
|
}
|
|
|
|
ynh_abort_if_errors
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2016-06-15 23:56:45 +02:00
|
|
|
|
2016-11-08 13:33:28 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-03-19 19:16:10 +01:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-11-08 13:33:28 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
always_encrypt=$YNH_APP_ARG_ALWAYS_ENCRYPT
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-09-05 00:25:58 +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)
|
|
|
|
|
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2015-03-27 23:20:31 +01:00
|
|
|
|
2016-12-14 16:10:00 +01:00
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
|
|
|
ynh_app_setting_set $app always_encrypt $always_encrypt
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2018-05-20 20:55:15 +02:00
|
|
|
#=================================================
|
|
|
|
# ACTIVATE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
port=$(ynh_find_port 8095) # Cherche un port libre.
|
|
|
|
# Ouvre le port dans le firewall
|
2017-12-16 23:22:54 +01:00
|
|
|
ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port
|
2017-03-19 19:16:10 +01:00
|
|
|
ynh_app_setting_set $app port $port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2016-12-14 16:10:00 +01:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
ynh_install_app_dependencies $app_depencencies
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2016-06-15 23:56:45 +02:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
ynh_add_nginx_config
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
ynh_system_user_create $app # Créer un utilisateur système dédié à l'app
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# SETUP LUTIM
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
|
|
|
## Copie et configuration du fichier de conf.
|
2017-09-05 00:25:58 +02:00
|
|
|
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/lutim.conf"
|
|
|
|
ynh_replace_string "__PATH__" "$path_url" "$final_path/lutim.conf"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/lutim.conf"
|
|
|
|
ynh_replace_string "__ENCRYPT__" "$always_encrypt" "$final_path/lutim.conf"
|
2017-03-19 19:16:10 +01:00
|
|
|
secret=$(ynh_string_random)
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_replace_string "__SECRET__" "$secret" "$final_path/lutim.conf"
|
|
|
|
ynh_store_file_checksum "$final_path/lutim.conf" # Enregistre la somme de contrôle du fichier de config
|
2016-06-05 00:53:04 +02:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
ynh_add_systemd_config
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
cp ../conf/cron_lutim /etc/cron.d/$app
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path/" /etc/cron.d/$app
|
2017-09-05 00:25:58 +02:00
|
|
|
chmod +x $final_path/script/lutim
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL LUTIM WITH CARTON
|
|
|
|
#=================================================
|
2016-05-15 12:15:08 +02:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
mkdir -p /var/log/$app/
|
2017-12-05 19:36:40 +01:00
|
|
|
(cd $final_path
|
|
|
|
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2015-08-19 21:33:40 +02:00
|
|
|
# Configure le path du dossier perl en fonction de l'architecture système
|
|
|
|
arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu)
|
|
|
|
if [ "$?" -ne 0 ]
|
|
|
|
then
|
2017-03-19 19:16:10 +01:00
|
|
|
ynh_die "Impossible de trouver le dossier relatif à l'architecture système."
|
2015-08-19 21:33:40 +02:00
|
|
|
fi
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_replace_string "__ARCHDIR__" "$arch_dir" "$final_path/script/lutim"
|
2015-08-19 21:33:40 +02:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOG FILE
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2015-03-26 13:07:01 +01:00
|
|
|
# Making log symbolic link to /var/log
|
2017-09-05 00:25:58 +02:00
|
|
|
touch /var/log/$app/production.log
|
2017-09-08 13:10:22 +02:00
|
|
|
chown $app -R /var/log/$app
|
2017-09-05 00:25:58 +02:00
|
|
|
ln -s /var/log/$app/production.log "$final_path/log/production.log"
|
2015-03-26 13:07:01 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# SECURING FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2016-03-31 22:41:54 +02:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
chown -R $app: $final_path
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALISATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
yunohost service add lutim -l $final_path/log/production.log
|
2015-03-26 13:07:01 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
|
|
if [ $is_public -eq 0 ]
|
|
|
|
then # Si l'app est privée, seul le visionnage des images reste public
|
|
|
|
if [ "$path_url" == "/" ]; then
|
|
|
|
path_url="" # Si path correspond à la racine, supprime le / pour éviter une erreur de la regex.
|
|
|
|
fi
|
|
|
|
# Modifie le domaine pour qu'il passe dans une regex
|
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_app_setting_set $app protected_regex "$domain_regex$path_url/stats$","$domain_regex$path_url/manifest.webapp$","$domain_regex$path_url/$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/m/.*$"
|
2017-03-19 19:16:10 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2018-07-13 17:33:54 +02:00
|
|
|
ynh_system_reload --service_name=nginx
|
2017-05-24 16:48:26 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK LUTIM BOOTING
|
|
|
|
#=================================================
|
|
|
|
|
2017-12-16 23:22:54 +01:00
|
|
|
# Wait for lutim fully started
|
2018-07-13 17:33:54 +02:00
|
|
|
ynh_check_starting --line_to_match="Manager.*started" --app_log="/var/log/$app/production.log" --timeout="120"
|
2017-12-16 23:22:54 +01:00
|
|
|
|
|
|
|
# Set right permissions on new files created at first start
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
2018-05-20 20:55:15 +02:00
|
|
|
#=================================================
|
|
|
|
# DEACTIVE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_OFF
|
|
|
|
|
2017-12-16 23:22:54 +01:00
|
|
|
#=================================================
|
|
|
|
# SEND A README FOR THE ADMIN
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
message="You can find a config file at $final_path/lutim.conf
|
|
|
|
|
|
|
|
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/lutim_ynh"
|
|
|
|
|
2018-07-13 17:33:54 +02:00
|
|
|
ynh_send_readme_to_admin --app_message="$message" --recipients="root"
|