1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00
lutim_ynh/scripts/install
2019-01-30 16:19:40 +01:00

246 lines
8.6 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source _variables
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
ynh_script_progression --message="Retrieve arguments from the manifest"
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
always_encrypt=$YNH_APP_ARG_ALWAYS_ENCRYPT
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
ynh_script_progression --message="Check if the app can be installed" --weight=2
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
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Store settings from manifest" --weight=2
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
ynh_app_setting_set $app overwrite_settings "1"
ynh_app_setting_set $app overwrite_nginx "1"
ynh_app_setting_set $app overwrite_systemd "1"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Find a free port" --weight=3
# Find a free port
port=$(ynh_find_port 8095)
# Open this port
ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port
ynh_app_setting_set $app port $port
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
# Download, check integrity and uncompress the source from app.src
ynh_setup_source "$final_path"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Install dependencies" --weight=60
ynh_install_app_dependencies $app_depencencies
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configure nginx" --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Create a dedicated user" --weight=2
# Create a dedicated system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# SETUP LUTIM
#=================================================
ynh_script_progression --message="Configure Lutim" --weight=2
# Configure Lutim
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
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"
secret=$(ynh_string_random)
ynh_replace_string "__SECRET__" "$secret" "$final_path/lutim.conf"
ynh_app_setting_set $app secret "$secret"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/lutim.conf"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configure systemd" --weight=2
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# SETUP CRON
#=================================================
cp ../conf/cron_lutim /etc/cron.d/$app
ynh_replace_string "__FINALPATH__" "$final_path/" /etc/cron.d/$app
chmod +x $final_path/script/lutim
#=================================================
# INSTALL LUTIM WITH CARTON
#=================================================
ynh_script_progression --message="Install Lutim with Carton" --weight=60
mkdir -p /var/log/$app/
(cd $final_path
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
# Use a perl path adapted to the system architecture
arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu)
if [ "$?" -ne 0 ]
then
ynh_die "Unable to find the perl directory for your architecture."
fi
ynh_replace_string "__ARCHDIR__" "$arch_dir" "$final_path/script/lutim"
#=================================================
# SETUP LOG FILE
#=================================================
# Making log a symbolic link to /var/log
touch /var/log/$app/production.log
chown $app -R /var/log/$app
ln -s /var/log/$app/production.log "$final_path/log/production.log"
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R $app: $final_path
#=================================================
# GENERIC FINALISATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configure logrotate" --weight=2
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add lutim -l $final_path/log/production.log
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Setup SSOwat"
ynh_app_setting_set $app skipped_uris "/"
if [ $is_public -eq 0 ]
then
# If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
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/.*$"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reload nginx" --weight=2
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# CHECK LUTIM BOOTING
#=================================================
ynh_script_progression --message="Restart Lutim" --weight=6
# Wait for lutim to be fully started
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
# Set right permissions on new files created at first start
chown -R $app: $final_path
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# 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"
message="You can find a config file at $final_path/lutim.conf
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.
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"
ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="install"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation completed" --last