#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get $app is_public) port=$(ynh_app_setting_get $app port) final_path=$(ynh_app_setting_get $app final_path) secret=$(ynh_app_setting_get $app secret) db_name=$(ynh_app_setting_get $app db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get $app psqlpwd) #================================================= # FIX OLD THINGS #================================================= if [ "$is_public" = "Yes" ]; then ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen is_public=1 elif [ "$is_public" = "No" ]; then ynh_app_setting_set $app is_public 0 is_public=0 fi if [ "${#final_path}" -eq 0 ] then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien script, code final_path en dur final_path=/var/www/$app fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= # Create a dedicated nginx config ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE #================================================= # SETUP LSTU #================================================= ynh_backup_if_checksum_is_different "$final_path/lstu.conf" cp ../conf/lstu.conf.template "${final_path}/lstu.conf" ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf" ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf" ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf" ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" secret=$(ynh_string_random 24) ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_store_file_checksum "${final_path}/lstu.conf" #================================================= # SECURING FILES AND DIRECTORIES #================================================= chown -R www-data $final_path #================================================= # SETUP SYSTEMD #================================================= # Create a dedicated systemd config ynh_add_systemd_config #================================================= # Install lstu's dependencies via carton #================================================= pushd $final_path carton install --deployment --without=sqlite --without=mysql popd #================================================= # SETUP LOGROTATE #================================================= # Use logrotate to manage application logfile(s) ynh_use_logrotate #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add $app --log "/var/log/$app.log" #================================================= # RESTART LSTU #================================================= systemctl reload $app #================================================= # SETUP SSOWAT #================================================= # Make app public or private ynh_app_setting_set $app skipped_uris "/" if [ $is_public -eq 0 ]; then # If the app is private, only the shortened URLs are publics if [ "$path_url" == "/" ]; then path_url="" fi ynh_app_setting_set $app protected_regex "$domain$path_url/login$","$domain$path_url/logout$","$domain$path_url/api$","$domain$path_url/extensions$","$domain$path_url/stats$","$domain$path_url/d/.*$","$domain$path_url/a$","$domain$path_url/$" else ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf" fi #================================================= # RELOAD NGINX #================================================= systemctl reload nginx yunohost app ssowatconf