mirror of
https://github.com/YunoHost-Apps/lutim_ynh.git
synced 2024-09-03 19:36:24 +02:00
256 lines
9.7 KiB
Bash
256 lines
9.7 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
secret=$(ynh_string_random)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=2
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
# Register (book) web path
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..." --weight=2
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
|
ynh_app_setting_set --app=$app --key=always_encrypt --value=$always_encrypt
|
|
ynh_app_setting_set --app=$app --key=secret --value="$secret"
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# FIND AND OPEN A PORT
|
|
#=================================================
|
|
ynh_script_progression --message="Finding an available port..." --weight=3
|
|
|
|
# Find an available port
|
|
port=$(ynh_find_port --port=8095)
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing dependencies..." --weight=60
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring system user..." --weight=2
|
|
|
|
# Create a system user
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
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"
|
|
|
|
chmod 750 "$final_path"
|
|
chmod -R o-rwx "$final_path"
|
|
chown -R $app:$app "$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=2
|
|
|
|
workers="$(( $(nproc) * 2 ))"
|
|
ynh_add_config --template="../conf/lutim.conf.template" --destination="$final_path/lutim.conf"
|
|
|
|
chmod 400 "$final_path/lutim.conf"
|
|
chown $app:$app "$final_path/lutim.conf"
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# SETUP CRON
|
|
#=================================================
|
|
|
|
ynh_add_config --template="../conf/cron_lutim" --destination="/etc/cron.d/$app"
|
|
chmod +x $final_path/script/lutim
|
|
|
|
#=================================================
|
|
# INSTALL LUTIM WITH CARTON
|
|
#=================================================
|
|
ynh_script_progression --message="Installing $app 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 --message="Unable to find the perl directory for your architecture."
|
|
fi
|
|
ynh_replace_string --match_string="__ARCHDIR__" --replace_string="$arch_dir" --target_file="$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"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=2
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=2
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app --log="$final_path/log/production.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --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"
|
|
ynh_systemd_action --action=stop
|
|
|
|
# Set right permissions on new files created at first start
|
|
chown -R $app:$app $final_path
|
|
|
|
# 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"
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
# 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.
|
|
ynh_permission_create --permission="upload images" --allowed="visitors"
|
|
|
|
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=$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]/.*$"
|
|
|
|
# If the app is not public, then the "visitors" group doesn't have this permission
|
|
ynh_permission_update --permission="upload images" --remove="visitors"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
echo "You can find a config file at $final_path/lutim.conf
|
|
|
|
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__.
|
|
|
|
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
|
|
|
|
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|