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 () {
|
2019-01-18 19:56:43 +01:00
|
|
|
# Clean installation remaining that are not handle by the remove script.
|
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)
|
|
|
|
|
|
|
|
# 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
|
2018-09-30 11:52:12 +02:00
|
|
|
ynh_app_setting_set $app overwrite_settings "1"
|
|
|
|
ynh_app_setting_set $app overwrite_nginx "1"
|
|
|
|
ynh_app_setting_set $app overwrite_systemd "1"
|
2015-03-19 20:49:50 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Find a free port
|
|
|
|
port=$(ynh_find_port 8095)
|
|
|
|
# Open this port
|
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
|
2019-01-18 19:56:43 +01:00
|
|
|
# Download, check integrity and uncompress the source from app.src
|
|
|
|
ynh_setup_source "$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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Create a dedicated nginx config
|
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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Create a dedicated system user
|
|
|
|
ynh_system_user_create $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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Configure Lutim
|
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"
|
2018-09-30 11:52:12 +02:00
|
|
|
ynh_app_setting_set $app secret "$secret"
|
2019-01-18 19:56:43 +01:00
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "$final_path/lutim.conf"
|
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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Create a dedicated systemd config
|
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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Use a perl path adapted to the system architecture
|
2015-08-19 21:33:40 +02:00
|
|
|
arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu)
|
|
|
|
if [ "$?" -ne 0 ]
|
|
|
|
then
|
2019-01-18 19:56:43 +01:00
|
|
|
ynh_die "Unable to find the perl directory for your architecture."
|
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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Making log a 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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Set permissions to app files
|
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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Use logrotate to manage application logfile(s)
|
2017-03-19 19:16:10 +01:00
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
2019-01-18 19:56:43 +01:00
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
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 ]
|
2019-01-18 19:56:43 +01:00
|
|
|
then
|
|
|
|
# If the app is private, viewing images stays publicly accessible.
|
2017-03-19 19:16:10 +01:00
|
|
|
if [ "$path_url" == "/" ]; then
|
2019-01-18 19:56:43 +01:00
|
|
|
# If the path is /, clear it to prevent any error with the regex.
|
|
|
|
path_url=""
|
2017-03-19 19:16:10 +01:00
|
|
|
fi
|
2019-01-18 19:56:43 +01:00
|
|
|
# Modify the domain to be used in a regex
|
2017-03-19 19:16:10 +01:00
|
|
|
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
|
|
|
|
2019-01-13 19:10:28 +01:00
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
2017-05-24 16:48:26 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK LUTIM BOOTING
|
|
|
|
#=================================================
|
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Wait for lutim to be fully started
|
2019-01-13 19:10:28 +01:00
|
|
|
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SEND A README FOR THE ADMIN
|
|
|
|
#=================================================
|
|
|
|
|
2019-01-20 17:44:06 +01:00
|
|
|
# Get main domain and buid the url of the admin panel of the app.
|
|
|
|
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
|
|
|
|
|
2017-12-16 23:22:54 +01:00
|
|
|
message="You can find a config file at $final_path/lutim.conf
|
|
|
|
|
2019-01-20 17:44:06 +01:00
|
|
|
You can configure this app easily by using the experimental config-panel feature: $admin_panel/config-panel.
|
|
|
|
You can also find some specific actions for this app by using the experimental action feature: $admin_panel/actions.
|
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/lutim_ynh"
|
2017-12-16 23:22:54 +01:00
|
|
|
|
2019-01-20 17:44:06 +01:00
|
|
|
ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="install"
|