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

266 lines
11 KiB
Text
Raw Normal View History

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-09-05 00:25:58 +02:00
# Load common variables for all scripts.
2020-04-24 20:16:33 +02:00
source _common.sh
source /usr/share/yunohost/helpers
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.
2020-04-24 19:59:27 +02: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
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Validating installation parameters..." --weight=2
2015-03-19 20:49:50 +01:00
2017-09-05 00:25:58 +02:00
final_path=/var/www/$app
2020-01-02 18:40:15 +01:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-09-05 00:25:58 +02:00
# Register (book) web path
2020-01-02 18:40:15 +01:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2015-03-19 20:49:50 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Storing installation settings..." --weight=2
2015-03-27 23:20:31 +01:00
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
2020-02-12 12:15:20 +01:00
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=always_encrypt --value=$always_encrypt
2019-01-30 19:27:17 +01:00
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=overwrite_settings --value=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
2015-03-19 20:49:50 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Configuring firewall..." --weight=3
2017-03-19 19:16:10 +01:00
2019-01-18 19:56:43 +01:00
# Find a free port
2020-01-02 18:40:15 +01:00
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
2017-03-19 19:16:10 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Setting up source files..."
2015-03-19 20:49:50 +01:00
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
2015-11-18 00:28:42 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Installing dependencies..." --weight=60
2017-03-19 19:16:10 +01:00
2017-09-05 00:25:58 +02:00
ynh_install_app_dependencies $app_depencencies
2017-03-19 19:16:10 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-10-05 22:02:46 +02:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2016-06-15 23:56:45 +02:00
2020-10-05 22:02:46 +02: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
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Configuring system user..." --weight=2
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
#=================================================
2019-01-30 16:19:40 +01:00
ynh_script_progression --message="Configure Lutim" --weight=2
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"
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
2017-03-19 19:16:10 +01:00
secret=$(ynh_string_random)
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
ynh_app_setting_set --app=$app --key=secret --value="$secret"
2020-01-02 18:42:16 +01:00
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
2019-01-18 19:56:43 +01:00
# Calculate and store the config file checksum into the app settings
2020-01-02 18:40:15 +01:00
ynh_store_file_checksum --file="$final_path/lutim.conf"
2016-06-05 00:53:04 +02:00
2020-01-29 15:24:28 +01:00
#=================================================
# SETUP HOOKS FILE
#=================================================
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_addaccess"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_removeaccess"
2017-03-19 19:16:10 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Configuring a systemd service..." --weight=2
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
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path/" --target_file=/etc/cron.d/$app
2020-01-02 18:43:40 +01:00
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file=/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
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Installing Lutim with Carton..." --weight=60
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
2020-04-24 19:59:27 +02:00
ynh_die --message="Unable to find the perl directory for your architecture."
2015-08-19 21:33:40 +02:00
fi
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string="__ARCHDIR__" --replace_string="$arch_dir" --target_file="$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
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Configuring log rotation..." --weight=2
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
2020-01-02 18:40:15 +01:00
yunohost service add $app --log $final_path/log/production.log
2015-03-26 13:07:01 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Configuring SSOwat..."
2017-03-19 19:16:10 +01:00
2020-02-11 09:59:59 +01:00
ynh_permission_update --permission="main" --add="visitors"
2020-01-29 15:24:28 +01:00
2020-02-13 16:14:56 +01:00
# This is a fake permission without any URL.
# The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified.
# We can't use a real permission for now because the actual permision system doesn't support regex.
2020-02-11 09:59:59 +01:00
ynh_permission_create --permission="upload images" --allowed="visitors"
2020-01-29 15:24:28 +01:00
2020-02-11 09:59:59 +01:00
if [ $is_public -eq 0 ]
2019-01-18 19:56:43 +01:00
then
2020-04-24 19:59:27 +02:00
# 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')
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
2020-02-11 09:59:59 +01:00
2020-04-24 19:59:27 +02:00
# If the app is not public, then the "visitors" group doesn't have this permission
ynh_permission_update --permission="upload images" --remove="visitors"
2017-03-19 19:16:10 +01:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2020-10-05 22:02:46 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
2015-11-18 00:28:42 +01:00
2020-01-02 18:40:15 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2017-05-24 16:48:26 +02:00
#=================================================
# CHECK LUTIM BOOTING
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Restarting Lutim..." --weight=6
2017-05-24 16:48:26 +02:00
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"
2020-04-24 20:16:59 +02:00
ynh_systemd_action --action=stop
2017-12-16 23:22:54 +01:00
# Set right permissions on new files created at first start
chown -R $app: $final_path
2020-04-24 20:16:59 +02:00
# 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"
2017-12-16 23:22:54 +01:00
#=================================================
# 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"
2019-01-30 19:27:17 +01:00
echo "You can find a config file at $final_path/lutim.conf
2017-12-16 23:22:54 +01:00
2019-01-30 19:27:17 +01:00
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
2019-01-20 17:44:06 +01:00
2019-01-30 19:27:17 +01:00
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/lutim_ynh__URL_TAG3__." > mail_to_send
2017-12-16 23:22:54 +01:00
2020-01-02 18:40:15 +01:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
2019-01-30 16:19:40 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2020-10-05 22:02:46 +02:00
ynh_script_progression --message="Installation of Lutim completed" --last