From 3e2a288ad7c5c5224de60671ec5ab48871bece14 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sat, 9 May 2020 21:20:43 +0200 Subject: [PATCH 01/13] add cronjobs --- README.md | 8 ++------ conf/invoiceninja.cron | 3 +++ scripts/install | 10 ++++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 conf/invoiceninja.cron diff --git a/README.md b/README.md index 1d93e28..05022f5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Invoice Ninja for YunoHost -[![Integration level](https://dash.yunohost.org/integration/invoiceninja.svg)](https://dash.yunohost.org/appci/app/invoiceninja) +[![Integration level](https://dash.yunohost.org/integration/invoiceninja.svg)](https://dash.yunohost.org/appci/app/invoiceninja) [![Install invoiceninja with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=invoiceninja) > *This package allow you to install invoiceninja quickly and simply on a YunoHost server. @@ -52,11 +52,7 @@ Configuration happens in the application itself. * Upstream app repository: https://github.com/invoiceninja/invoiceninja * YunoHost website: https://yunohost.org/ - ## TODOs -* Completely configure the env -* Mail settings -* Cronjobs -* Create initial user? +* If possible, create initial user * Test upgrade diff --git a/conf/invoiceninja.cron b/conf/invoiceninja.cron new file mode 100644 index 0000000..7e78cfd --- /dev/null +++ b/conf/invoiceninja.cron @@ -0,0 +1,3 @@ +0 8 * * * /var/www/invoiceninja/artisan ninja:send-invoices +0 8 * * * /var/www/invoiceninja/artisan ninja:send-reminders + diff --git a/scripts/install b/scripts/install index 5165446..98a64cf 100755 --- a/scripts/install +++ b/scripts/install @@ -239,6 +239,16 @@ ynh_script_progression --message="Configuring log rotation..." --time --weight=1 # Use logrotate to manage application logfile(s) ynh_use_logrotate +#================================================= +# ADD A CRON JOB +#================================================= + +cron_path="/etc/cron.d/$app" +cp -a ../conf/invoiceninja.cron "$cron_path" +chown root: "$cron_path" +chmod 644 "$cron_path" + + #================================================= # SETUP FAIL2BAN #================================================= From 7406db467397877ee27f1a58f48bdae75571ed1f Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sat, 9 May 2020 21:41:54 +0200 Subject: [PATCH 02/13] fix cron --- conf/invoiceninja.cron | 4 ++-- scripts/install | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/conf/invoiceninja.cron b/conf/invoiceninja.cron index 7e78cfd..0c6bf67 100644 --- a/conf/invoiceninja.cron +++ b/conf/invoiceninja.cron @@ -1,3 +1,3 @@ -0 8 * * * /var/www/invoiceninja/artisan ninja:send-invoices -0 8 * * * /var/www/invoiceninja/artisan ninja:send-reminders +0 8 * * * __USER__ /usr/bin/php__YNH_PHP_VERSION__ __DESTDIR__/artisan ninja:send-invoices +0 8 * * * __USER__ /usr/bin/php__YNH_PHP_VERSION__ __DESTDIR__/artisan ninja:send-reminders diff --git a/scripts/install b/scripts/install index 98a64cf..37aff6d 100755 --- a/scripts/install +++ b/scripts/install @@ -24,6 +24,8 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= +YNH_PHP_VERSION="7.0" + domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN @@ -248,6 +250,9 @@ cp -a ../conf/invoiceninja.cron "$cron_path" chown root: "$cron_path" chmod 644 "$cron_path" +ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$cron_path" +ynh_replace_string --match_string="__DESTDIR__" --replace_string="$final_path" --target_file="$cron_path" +ynh_replace_string --match_string="__YNH_PHP_VERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$cron_path" #================================================= # SETUP FAIL2BAN From d8ae4e93a871d2d6d7914fc819ff23adc89e183d Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sat, 9 May 2020 21:52:50 +0200 Subject: [PATCH 03/13] update backup, restore, change_url scripts --- scripts/backup | 20 -------------------- scripts/change_url | 24 +++--------------------- scripts/restore | 19 ------------------- 3 files changed, 3 insertions(+), 60 deletions(-) diff --git a/scripts/backup b/scripts/backup index d985aba..80032de 100755 --- a/scripts/backup +++ b/scripts/backup @@ -35,12 +35,6 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # STANDARD BACKUP STEPS #================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" - #================================================= # BACKUP THE APP MAIN DIR #================================================= @@ -86,26 +80,12 @@ ynh_script_progression --message="Backing up logrotate configuration..." --time ynh_backup --src_path="/etc/logrotate.d/$app" -#================================================= -# BACKUP SYSTEMD -#================================================= -ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 - -ynh_backup --src_path="/etc/systemd/system/$app.service" - #================================================= # BACKUP A CRON FILE #================================================= ynh_backup --src_path="/etc/cron.d/$app" -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 3f21bc8..bd17920 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -30,9 +30,9 @@ ynh_script_progression --message="Loading installation settings..." --time --wei final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Add settings here as needed by your application -#db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#db_user=$db_name -#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -70,12 +70,6 @@ fi #================================================= # STANDARD MODIFICATIONS #================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" - #================================================= # MODIFY URL IN NGINX CONF #================================================= @@ -105,21 +99,9 @@ then ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi -#================================================= -# SPECIFIC MODIFICATIONS -#================================================= -# ... -#================================================= - #================================================= # GENERIC FINALISATION #================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/restore b/scripts/restore index fe4ac6a..deb65ac 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,10 +14,6 @@ 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 @@ -102,27 +98,12 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1 - -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service - #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # RESTORE THE CRON FILE #================================================= From c53b7cf836afcf5f187cd7af3d3861a7a6632d4a Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sat, 9 May 2020 22:25:16 +0200 Subject: [PATCH 04/13] fix wrong location in nginx --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 7f97f6a..4d8d73f 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -27,6 +27,6 @@ location __PATH__/ { include conf.d/yunohost_panel.conf.inc; } -location @invoiceninja { +location @__PATH__ { rewrite ^(.+)$ /index.php?/$1 last; } From 4133114a750a682da812a0fdd5c46366ffc6ce95 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sun, 10 May 2020 10:08:25 +0200 Subject: [PATCH 05/13] use correct license in manifest --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index f0974d9..d1c7505 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,7 @@ }, "version": "1.0~ynh1", "url": "https://invoiceninja.org", - "license": "Attribution Assurance License", + "license": "AAL", "maintainer": { "name": "Sebastian Gumprich", "email": "yunohost AT gumpri DOT ch", From 70a42f354524fdd4e20f0011198a91ee17609d30 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sun, 10 May 2020 10:08:46 +0200 Subject: [PATCH 06/13] remove time and weight from scripts --- scripts/backup | 16 ++++++++-------- scripts/install | 30 +++++++++++++++--------------- scripts/remove | 20 ++++++++++---------- scripts/restore | 16 ++++++++-------- scripts/upgrade | 26 +++++++++++++------------- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/scripts/backup b/scripts/backup index 80032de..15f11c6 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -38,35 +38,35 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 +ynh_script_progression --message="Backing up the main app directory..." ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Backing up nginx web server configuration..." ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1 +ynh_script_progression --message="Backing up php-fpm configuration..." ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Backing up the MySQL database..." --time --weight=1 +ynh_script_progression --message="Backing up the MySQL database..." ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Backing up fail2ban configuration..." --time --weight=1 +ynh_script_progression --message="Backing up fail2ban configuration..." ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" @@ -76,7 +76,7 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" #================================================= # BACKUP LOGROTATE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Backing up logrotate configuration..." ynh_backup --src_path="/etc/logrotate.d/$app" @@ -90,4 +90,4 @@ ynh_backup --src_path="/etc/cron.d/$app" # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/install b/scripts/install index 5165446..22221fd 100755 --- a/scripts/install +++ b/scripts/install @@ -53,7 +53,7 @@ app=$YNH_APP_INSTANCE_NAME ### Use the execution time, given by --time, to estimate the weight of a step. ### A common way to do it is to set a weight equal to the execution time in second +1. ### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call. -ynh_script_progression --message="Validating installation parameters..." --time --weight=1 +ynh_script_progression --message="Validating installation parameters..." ### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" @@ -66,7 +66,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --time --weight=1 +ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url @@ -81,7 +81,7 @@ ynh_app_setting_set --app=$app --key=language --value=$language #================================================= # CREATE A MYSQL DATABASE #================================================= -ynh_script_progression --message="Creating a MySQL database..." --time --weight=1 +ynh_script_progression --message="Creating a MySQL database..." ### Use these lines if you need a database for the application. ### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. @@ -100,7 +100,7 @@ ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --time --weight=1 +ynh_script_progression --message="Setting up source files..." ### `ynh_setup_source` is used to install an app from a zip or tar.gz file, ### downloaded from an upstream source, like a git repository. @@ -113,7 +113,7 @@ ynh_setup_source --dest_dir="$final_path" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 +ynh_script_progression --message="Configuring nginx web server..." ### `ynh_add_nginx_config` will use the file conf/nginx.conf @@ -123,7 +123,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --time --weight=1 +ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app @@ -131,7 +131,7 @@ ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring php-fpm..." --time --weight=1 +ynh_script_progression --message="Configuring php-fpm..." ### `ynh_add_fpm_config` is used to set up a PHP config. ### You can remove it if your app doesn't use PHP. @@ -166,7 +166,7 @@ ynh_add_fpm_config chown -R $app: $final_path # Set the app as temporarily public for curl call -ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 +ynh_script_progression --message="Configuring SSOwat..." ynh_app_setting_set --app=$app --key=skipped_uris --value="/" # Reload SSOwat config yunohost app ssowatconf @@ -175,7 +175,7 @@ yunohost app ssowatconf ynh_systemd_action --service_name=nginx --action=reload # Installation with curl -ynh_script_progression --message="Finalizing installation..." --time --weight=1 +ynh_script_progression --message="Finalizing installation..." ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" # Remove the public access @@ -226,7 +226,7 @@ chown -R $app: $final_path/storage $final_path/bootstrap $final_path/public/logo #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --time --weight=1 +ynh_script_progression --message="Configuring log rotation..." ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. ### Use this helper only if there is effectively a log file for this app. @@ -242,15 +242,15 @@ ynh_use_logrotate #================================================= # SETUP FAIL2BAN #================================================= -#ynh_script_progression --message="Configuring fail2ban..." --time --weight=1 +ynh_script_progression --message="Configuring fail2ban..." # Create a dedicated fail2ban config -#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 +ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -262,7 +262,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -270,4 +270,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --time --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index adfcb34..94781aa 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -31,14 +31,14 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --time --weight=1 + ynh_script_progression --message="Removing $app service..." yunohost service remove $app fi #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Removing the MySQL database..." --time --weight=1 +ynh_script_progression --message="Removing the MySQL database..." # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name @@ -46,7 +46,7 @@ ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --time --weight=1 +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -54,7 +54,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -62,7 +62,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1 +ynh_script_progression --message="Removing php-fpm configuration..." # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -70,7 +70,7 @@ ynh_remove_fpm_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Removing logrotate configuration..." # Remove the app-specific logrotate config ynh_remove_logrotate @@ -78,10 +78,10 @@ ynh_remove_logrotate #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= -#ynh_script_progression --message="Removing fail2ban configuration..." --time --weight=1 +ynh_script_progression --message="Removing fail2ban configuration..." # Remove the dedicated fail2ban config -#ynh_remove_fail2ban_config +ynh_remove_fail2ban_config #================================================= # SPECIFIC REMOVE @@ -100,4 +100,4 @@ ynh_secure_remove --file="/etc/cron.d/$app" # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --time --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index deb65ac..a3e53b2 100755 --- a/scripts/restore +++ b/scripts/restore @@ -20,7 +20,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --time --weight=1 +ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME @@ -33,7 +33,7 @@ db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 +ynh_script_progression --message="Validating restoration parameters..." ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" @@ -51,14 +51,14 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 +ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 +ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create --username=$app @@ -79,7 +79,7 @@ ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the fail2ban configuration..." --time --weight=1 +ynh_script_progression --message="Restoring the fail2ban configuration..." ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" @@ -92,7 +92,7 @@ ynh_systemd_action --action=restart --service_name=fail2ban #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1 +ynh_script_progression --message="Restoring the MySQL database..." db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd @@ -121,7 +121,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server and php-fpm..." ynh_systemd_action --service_name=php7.0-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload @@ -130,4 +130,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --time --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 2fef348..844cdf3 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -39,7 +39,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then @@ -65,7 +65,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -94,7 +94,7 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --time --weight=1 + ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" @@ -103,7 +103,7 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config @@ -111,7 +111,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 +ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create --username=$app @@ -119,7 +119,7 @@ ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_add_fpm_config @@ -129,7 +129,7 @@ ynh_add_fpm_config #================================================= # Upgrade database via artisan #================================================= -ynh_script_progression --message="Upgrading the database..." --time --weight=1 +ynh_script_progression --message="Upgrading the database..." # Put the application into maintenance mode $final_path/artisan down --no-interaction --verbose @@ -147,7 +147,7 @@ $final_path/artisan up --no-interaction --verbose #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -157,7 +157,7 @@ ynh_use_logrotate --non-append #================================================= # UPGRADE FAIL2BAN #================================================= -ynh_script_progression --message="Reconfiguring fail2ban..." --time --weight=1 +ynh_script_progression --message="Reconfiguring fail2ban..." # Create a dedicated fail2ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" @@ -175,7 +175,7 @@ chown -R $app $final_path/storage $final_path/bootstrap $final_path/public/logo #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading SSOwat configuration..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -187,7 +187,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -195,4 +195,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed" --last From e9fdff2d51e78dd4c10207fa277366dfba846e21 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sun, 10 May 2020 21:00:34 +0200 Subject: [PATCH 07/13] do not display output of cronjobs --- conf/invoiceninja.cron | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/invoiceninja.cron b/conf/invoiceninja.cron index 0c6bf67..14ded0d 100644 --- a/conf/invoiceninja.cron +++ b/conf/invoiceninja.cron @@ -1,3 +1,3 @@ -0 8 * * * __USER__ /usr/bin/php__YNH_PHP_VERSION__ __DESTDIR__/artisan ninja:send-invoices -0 8 * * * __USER__ /usr/bin/php__YNH_PHP_VERSION__ __DESTDIR__/artisan ninja:send-reminders +0 8 * * * __USER__ /usr/bin/php__YNH_PHP_VERSION__ __DESTDIR__/artisan ninja:send-invoices -q +0 8 * * * __USER__ /usr/bin/php__YNH_PHP_VERSION__ __DESTDIR__/artisan ninja:send-reminders -q From 5696c025e3eb9134ead9f5cabe5bde87cc41d612 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Wed, 20 May 2020 12:22:51 +0200 Subject: [PATCH 08/13] add developers info to readme --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 05022f5..d10e099 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,16 @@ Configuration happens in the application itself. * If possible, create initial user * Test upgrade + + +Developers infos +---------------- + +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing --debug +or +sudo yunohost app upgrade ttrss -u https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing --debug +``` From f8e2822d3587d6fab7e45fee414c1c80b9f0446a Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Wed, 20 May 2020 12:29:16 +0200 Subject: [PATCH 09/13] add screenshot ro readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d10e099..da679e7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Invoice Ninja is the #1 open-source platform to create & email invoices, track p ## Screenshots -![](Link to an screenshot for this app) +![](https://www.invoiceninja.com/wp-content/uploads/2015/11/Create-Invoices-in-Seconds.png) ## Demo From a9aaac8c3421dc27b2535c2c9c919fcc10a87bf0 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 23 May 2020 14:28:52 +0200 Subject: [PATCH 10/13] Simplify description? (#3) * Simplify description? * Uhoh typo sorry --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index d1c7505..67136a7 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "id": "invoiceninja", "packaging_format": 1, "description": { - "en": "Invoice Ninja is the #1 open-source platform to create & email invoices, track payments and expenses, and time billable tasks & projects for clients." + "en": "Create and email invoices, track payments and expenses, and time tasks" }, "version": "1.0~ynh1", "url": "https://invoiceninja.org", From b151356e80fe45bf36ee6e6fbe8fd4e7b660e181 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sun, 7 Jun 2020 15:31:15 +0200 Subject: [PATCH 11/13] General improvements to various scripts (#4) * add check_process file * change nginx conf to allow install in root-path and subdomain * remove public-option * use php version variable * remove useless tasks in various install scripts * remove service removal step * run upgrade steps with sudo * fix upgrading * fix dbpwd variable and restore script * seed db on first install * use correct upgrade procedure --- check_process.default => check_process | 12 +--- conf/nginx.conf | 51 ++++++++++--- manifest.json | 9 --- scripts/backup | 21 +----- scripts/change_url | 2 +- scripts/install | 99 +++++--------------------- scripts/remove | 31 -------- scripts/restore | 38 +++------- scripts/upgrade | 79 +++++++++----------- 9 files changed, 109 insertions(+), 233 deletions(-) rename check_process.default => check_process (69%) diff --git a/check_process.default b/check_process similarity index 69% rename from check_process.default rename to check_process index 97a2bc5..06cffda 100644 --- a/check_process.default +++ b/check_process @@ -9,22 +9,17 @@ path="/path" (PATH) admin="john" (USER) language="fr" - is_public=1 (PUBLIC|public=1|private=0) - password="pass" - port="666" (PORT) ; Checks pkg_linter=1 setup_sub_dir=1 setup_root=1 setup_nourl=0 - setup_private=1 - setup_public=1 + setup_private=0 + setup_public=0 upgrade=1 - upgrade=1 from_commit=CommitHash + #upgrade=1 from_commit=CommitHash backup_restore=1 multi_instance=1 - # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. - # incorrect_path=1 port_already_use=0 change_url=1 ;;; Levels @@ -37,4 +32,3 @@ Notification=none ; commit=CommitHash name=Name and date of the commit. manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - diff --git a/conf/nginx.conf b/conf/nginx.conf index 4d8d73f..559b4a2 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,19 +1,33 @@ -location __PATH__/ { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; + +location ^~ __PATH__/ { # Path to source alias __FINALPATH__/public/ ; - try_files $uri $uri/ @__NAME__; + location __PATH__/ { + rewrite ^ __PATH__/index.php; + } # Force usage of https if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } - index index.php; + # Add headers to serve security related headers + more_set_headers "Strict-Transport-Security: max-age=15768000; includeSubDomains; preload;"; + more_set_headers "X-Content-Type-Options: nosniff"; + more_set_headers "X-XSS-Protection: 1; mode=block"; + more_set_headers "X-Robots-Tag: none"; + more_set_headers "X-Download-Options: noopen"; + more_set_headers "X-Permitted-Cross-Domain-Policies: none"; + more_set_headers "Referrer-Policy: no-referrer"; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; + #index index.php; + + location ~ ^__PATH__/index\.php(/.*|)$ { + fastcgi_split_path_info ^(.+?\.php)(/.*|)$; + set $path_info $fastcgi_path_info; fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; fastcgi_index index.php; @@ -23,10 +37,29 @@ location __PATH__/ { fastcgi_param SCRIPT_FILENAME $request_filename; } + # Adding the cache control header for js and css files + location ~ \.(?:css|js|woff2?|svg|gif)$ { + try_files $uri __PATH__/index.php$request_uri; + more_set_headers "Cache-Control: public, max-age=15778463"; + # Add headers to serve security related headers + more_set_headers "Strict-Transport-Security: max-age=15768000"; + more_set_headers "X-Content-Type-Options: nosniff"; + more_set_headers "X-XSS-Protection: 1; mode=block"; + more_set_headers "X-Robots-Tag: none"; + more_set_headers "X-Download-Options: noopen"; + more_set_headers "X-Permitted-Cross-Domain-Policies: none"; + more_set_headers "Referrer-Policy: no-referrer"; + + # Optional: Don't log access to assets + access_log off; + } + + location ~* \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ { + try_files $uri __FINALPATH__/index.php$request_uri; + # Optional: Don't log access to other assets + access_log off; + } + # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } - -location @__PATH__ { - rewrite ^(.+)$ /index.php?/$1 last; -} diff --git a/manifest.json b/manifest.json index 67136a7..037adac 100644 --- a/manifest.json +++ b/manifest.json @@ -52,15 +52,6 @@ }, "example": "johndoe" }, - { - "name": "is_public", - "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique?" - }, - "default": true - }, { "name": "language", "type": "string", diff --git a/scripts/backup b/scripts/backup index 15f11c6..ac9d0e4 100755 --- a/scripts/backup +++ b/scripts/backup @@ -26,6 +26,8 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Loading installation settings..." +YNH_PHP_VERSION="7.0" + app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -54,7 +56,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Backing up php-fpm configuration..." -ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE @@ -63,23 +65,6 @@ ynh_script_progression --message="Backing up the MySQL database..." ynh_mysql_dump_db --database="$db_name" > db.sql -#================================================= -# BACKUP FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Backing up fail2ban configuration..." - -ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" -ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" - -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= -ynh_script_progression --message="Backing up logrotate configuration..." - -ynh_backup --src_path="/etc/logrotate.d/$app" - #================================================= # BACKUP A CRON FILE #================================================= diff --git a/scripts/change_url b/scripts/change_url index bd17920..0b6c52d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -32,7 +32,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Add settings here as needed by your application db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP diff --git a/scripts/install b/scripts/install index bc04548..498b497 100755 --- a/scripts/install +++ b/scripts/install @@ -29,7 +29,6 @@ YNH_PHP_VERSION="7.0" domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN -is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE ### If it's a multi-instance app, meaning it can be installed several times independently @@ -73,9 +72,15 @@ ynh_script_progression --message="Storing installation settings..." 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=admin --value=$admin -ynh_app_setting_set --app=$app --key=is_public --value=$is_public ynh_app_setting_set --app=$app --key=language --value=$language +ynh_app_setting_set --app=$app --key=api_secret --value="$(ynh_string_random --length=32)" +ynh_app_setting_set --app=$app --key=app_key --value="$(ynh_string_random --length=32)" +ynh_app_setting_set --app=$app --key=phantomjs_key --value="$(ynh_string_random --length=32)" + +ynh_app_setting_set --app=$app --key=mail_from_address --value="$(ynh_user_get_info $admin mail)" +ynh_app_setting_set --app=$app --key=mail_from_name --value="$(ynh_user_get_info $admin firstname) $(ynh_user_get_info $admin lastname)" + #================================================= # STANDARD MODIFICATIONS #================================================= @@ -149,43 +154,6 @@ ynh_script_progression --message="Configuring php-fpm..." # Create a dedicated php-fpm config ynh_add_fpm_config -#================================================= -# SPECIFIC SETUP -#================================================= -# ... -#================================================= - -#================================================= -# SETUP APPLICATION WITH CURL -#================================================= - -### Use these lines only if the app installation needs to be finalized through -### web forms. We generally don't want to ask the final user, -### so we're going to use curl to automatically fill the fields and submit the -### forms. - -# Set right permissions for curl install -chown -R $app: $final_path - -# Set the app as temporarily public for curl call -ynh_script_progression --message="Configuring SSOwat..." -ynh_app_setting_set --app=$app --key=skipped_uris --value="/" -# Reload SSOwat config -yunohost app ssowatconf - -# Reload Nginx -ynh_systemd_action --service_name=nginx --action=reload - -# Installation with curl -ynh_script_progression --message="Finalizing installation..." -ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" - -# Remove the public access -if [ $is_public -eq 0 ] -then - ynh_app_setting_delete --app=$app --key=skipped_uris -fi - #================================================= # MODIFY A CONFIG FILE #================================================= @@ -201,15 +169,21 @@ ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --ta ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/.env" ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$final_path/.env" -ynh_replace_string --match_string="__API_SECRET__" --replace_string="$(ynh_string_random --length=32)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__APP_KEY__" --replace_string="$(ynh_string_random --length=32)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__PHANTOMJS_KEY__" --replace_string="$(ynh_string_random --length=32)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__API_SECRET__" --replace_string="$(ynh_app_setting_get --app=$app --key=api_secret)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__APP_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=app_key)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__PHANTOMJS_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=phantomjs_jey)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__MAIL_FROM_ADDRESS__" --replace_string="$(ynh_user_get_info $admin mail)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__MAIL_FROM_NAME__" --replace_string="$(ynh_user_get_info $admin firstname) $(ynh_user_get_info $admin lastname)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__MAIL_FROM_ADDRESS__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_address)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__MAIL_FROM_NAME__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_name)" --target_file="$final_path/.env" #================================================= # GENERIC FINALIZATION +#================================================= + +# Run the database migrations and initially fill the db +sudo $final_path/artisan migrate --no-interaction --verbose --force +sudo $final_path/artisan db:seed --force --no-interaction --verbose + #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -224,23 +198,6 @@ chown -R root: $final_path chmod -R 755 $final_path/storage chown -R $app: $final_path/storage $final_path/bootstrap $final_path/public/logo $final_path/.env - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." - -### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. -### Use this helper only if there is effectively a log file for this app. -### If you're not using this helper: -### - Remove the section "BACKUP LOGROTATE" in the backup script -### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script -### - And the section "SETUP LOGROTATE" in the upgrade script - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - #================================================= # ADD A CRON JOB #================================================= @@ -254,26 +211,6 @@ ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_fi ynh_replace_string --match_string="__DESTDIR__" --replace_string="$final_path" --target_file="$cron_path" ynh_replace_string --match_string="__YNH_PHP_VERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$cron_path" -#================================================= -# SETUP FAIL2BAN -#================================================= -ynh_script_progression --message="Configuring fail2ban..." - -# Create a dedicated fail2ban config -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring SSOwat..." - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" -fi - #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/remove b/scripts/remove index 94781aa..71939a8 100755 --- a/scripts/remove +++ b/scripts/remove @@ -24,17 +24,6 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST -#================================================= - -# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service..." - yunohost service remove $app -fi - #================================================= # REMOVE THE MYSQL DATABASE #================================================= @@ -67,22 +56,6 @@ ynh_script_progression --message="Removing php-fpm configuration..." # Remove the dedicated php-fpm config ynh_remove_fpm_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." - -# Remove the app-specific logrotate config -ynh_remove_logrotate - -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Removing fail2ban configuration..." - -# Remove the dedicated fail2ban config -ynh_remove_fail2ban_config - #================================================= # SPECIFIC REMOVE #================================================= @@ -92,10 +65,6 @@ ynh_remove_fail2ban_config # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" -#================================================= -# GENERIC FINALIZATION -#================================================= - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index a3e53b2..fca4651 100755 --- a/scripts/restore +++ b/scripts/restore @@ -22,12 +22,17 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Loading settings..." +YNH_PHP_VERSION="7.0" + app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) db_user=$db_name #================================================= @@ -70,52 +75,29 @@ ynh_system_user_create --username=$app # Restore permissions on app files chown -R root: $final_path +chmod -R 755 $final_path/storage +chown -R $app: $final_path/storage $final_path/bootstrap $final_path/public/logo $final_path/.env + #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" - -#================================================= -# RESTORE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the fail2ban configuration..." - -ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" -ynh_systemd_action --action=restart --service_name=fail2ban - -#================================================= -# SPECIFIC RESTORATION -#================================================= +ynh_restore_file --origin_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" #================================================= # RESTORE THE MYSQL DATABASE #================================================= ynh_script_progression --message="Restoring the MySQL database..." -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= - -yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" - #================================================= # RESTORE THE CRON FILE #================================================= ynh_restore_file --origin_path="/etc/cron.d/$app" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= @@ -123,7 +105,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= ynh_script_progression --message="Reloading nginx web server and php-fpm..." -ynh_systemd_action --service_name=php7.0-fpm --action=reload +ynh_systemd_action --service_name=php$YNH_PHP_VERSION-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 844cdf3..44cd3a9 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,10 +19,11 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) admin=$(ynh_app_setting_get --app=$app --key=admin) -is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +db_user=$db_name #================================================= # CHECK VERSION @@ -41,15 +42,6 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=0 - is_public=0 -fi - # If db_name doesn't exist, create it if [ -z "$db_name" ]; then db_name=$(ynh_sanitize_dbid --db_name=$app) @@ -124,6 +116,28 @@ ynh_script_progression --message="Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_add_fpm_config +#================================================= +# MODIFY A CONFIG FILE +#================================================= + +### `ynh_replace_string` is used to replace a string in a file. +### (It's compatible with sed regular expressions syntax) + +ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/.env" + +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/.env" +ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/.env" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/.env" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/.env" +ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$final_path/.env" + +ynh_replace_string --match_string="__API_SECRET__" --replace_string="$(ynh_app_setting_get --app=$app --key=api_secret)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__APP_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=app_key)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__PHANTOMJS_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=phantomjs_jey)" --target_file="$final_path/.env" + +ynh_replace_string --match_string="__MAIL_FROM_ADDRESS__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_address)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__MAIL_FROM_NAME__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_name)" --target_file="$final_path/.env" + #================================================= # SPECIFIC UPGRADE #================================================= @@ -132,35 +146,18 @@ ynh_add_fpm_config ynh_script_progression --message="Upgrading the database..." # Put the application into maintenance mode -$final_path/artisan down --no-interaction --verbose -# Run the database migrations -$final_path/artisan migrate --force --no-interaction --verbose +sudo $final_path/artisan down --no-interaction --verbose # Optimize the framework for better performance -$final_path/artisan optimize --force --no-interaction --verbose +sudo $final_path/artisan optimize --force --no-interaction --verbose + +# Run the database migrations +sudo $final_path/artisan migrate --no-interaction --verbose +sudo $final_path/artisan db:seed --class=UpdateSeeder --force --no-interaction --verbose # Bring the application out of maintenance mode -$final_path/artisan up --no-interaction --verbose - - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append - -#================================================= -# GENERIC FINALIZATION -#================================================= -# UPGRADE FAIL2BAN -#================================================= -ynh_script_progression --message="Reconfiguring fail2ban..." - -# Create a dedicated fail2ban config -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" +sudo $final_path/artisan up --no-interaction --verbose #================================================= # SECURE FILES AND DIRECTORIES @@ -170,19 +167,7 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failreg chown -R root: $final_path chmod -R 755 $final_path/storage -chown -R $app $final_path/storage $final_path/bootstrap $final_path/public/logo - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" -fi +chown -R $app: $final_path/storage $final_path/bootstrap $final_path/public/logo $final_path/.env #================================================= # RELOAD NGINX From 231aab4441a628ba692febfcac994b952f71a32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 11 Jun 2020 09:05:51 +0200 Subject: [PATCH 12/13] Update README.md (#6) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index da679e7..36603d3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Invoice Ninja for YunoHost -[![Integration level](https://dash.yunohost.org/integration/invoiceninja.svg)](https://dash.yunohost.org/appci/app/invoiceninja) +[![Integration level](https://dash.yunohost.org/integration/invoiceninja.svg)](https://dash.yunohost.org/appci/app/invoiceninja) ![](https://ci-apps.yunohost.org/ci/badges/invoiceninja.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/invoiceninja.maintain.svg) [![Install invoiceninja with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=invoiceninja) > *This package allow you to install invoiceninja quickly and simply on a YunoHost server. @@ -38,7 +38,7 @@ Configuration happens in the application itself. #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/invoiceninja%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/invoiceninja/) +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/invoiceninja%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/invoiceninja/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/invoiceninja%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/invoiceninja/) ## Limitations @@ -67,5 +67,5 @@ To try the testing branch, please proceed like that. ``` sudo yunohost app install https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing --debug or -sudo yunohost app upgrade ttrss -u https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing --debug +sudo yunohost app upgrade invoiceninja -u https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing --debug ``` From 14ad36cb23cb53b6a06138ef0ed76ce8b289ee65 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 15 Jun 2020 15:10:10 +0200 Subject: [PATCH 13/13] Apply example_ynh (#7) * Apply example_ynh * typo --- README.md | 14 ++--- issue_template.md | 46 +++++++++++++++ manifest.json | 2 +- pull_request_template.md | 2 +- scripts/_common.sh | 5 ++ scripts/backup | 31 +++++----- scripts/change_url | 24 ++++++-- scripts/install | 121 +++++++++++++-------------------------- scripts/remove | 3 +- scripts/restore | 15 +++-- scripts/upgrade | 71 ++++++++++++----------- 11 files changed, 183 insertions(+), 151 deletions(-) create mode 100644 issue_template.md diff --git a/README.md b/README.md index 36603d3..a9f5b8e 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ # Invoice Ninja for YunoHost [![Integration level](https://dash.yunohost.org/integration/invoiceninja.svg)](https://dash.yunohost.org/appci/app/invoiceninja) ![](https://ci-apps.yunohost.org/ci/badges/invoiceninja.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/invoiceninja.maintain.svg) -[![Install invoiceninja with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=invoiceninja) +[![Install Invoice Ninja with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=invoiceninja) -> *This package allow you to install invoiceninja quickly and simply on a YunoHost server. -If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* +> *This package allows you to install Invoice Ninja quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* ## Overview - Invoice Ninja is the #1 open-source platform to create & email invoices, track payments and expenses, and time billable tasks & projects for clients. **Shipped version:** v4.5.18 @@ -30,7 +29,7 @@ Configuration happens in the application itself. ## YunoHost specific features -#### Multi-users support +#### Multi-user support * There is no official LDAP support * The first user gets created after installing Invoice Ninja @@ -57,11 +56,12 @@ Configuration happens in the application itself. * If possible, create initial user * Test upgrade +--- -Developers infos +Developer info ---------------- -Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing). +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/invoiceninja_ynh/tree/testing). To try the testing branch, please proceed like that. ``` diff --git a/issue_template.md b/issue_template.md new file mode 100644 index 0000000..a12d565 --- /dev/null +++ b/issue_template.md @@ -0,0 +1,46 @@ +--- +name: Bug report +about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. + +--- + +**How to post a meaningful bug report** +1. *Read this whole template first.* +2. *Determine if you are on the right place:* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* + - *Otherwise, the issue may be due to Invoice Ninja itself. Refer to its documentation or repository for help.* + - *If you have a doubt, post here, we will figure it out together.* +3. *Delete the italic comments as you write over them below, and remove this guide.* +--- + +**Describe the bug** +*A clear and concise description of what the bug is.* + +**Versions** +- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* +- YunoHost version: x.x.x +- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes* + - If yes, please explain: +- Using, or trying to install package version/branch: +- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* + +**To Reproduce** +*Steps to reproduce the behavior.* +- *If you performed a command from the CLI, the command itself is enough. For example:* + ```sh + sudo yunohost app install invoiceninja + ``` +- *If you used the webadmin, please perform the equivalent command from the CLI first.* +- *If the error occurs in your browser, explain what you did:* + 1. *Go to '...'* + 2. *Click on '....'* + 3. *Scroll down to '....'* + 4. *See error* + +**Expected behavior** +*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* + +**Logs** +*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +*If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index 037adac..6f8e009 100644 --- a/manifest.json +++ b/manifest.json @@ -48,7 +48,7 @@ "type": "user", "ask": { "en": "Choose an admin user", - "fr": "Choisissez l’administrateur" + "fr": "Choisissez l'administrateur" }, "example": "johndoe" }, diff --git a/pull_request_template.md b/pull_request_template.md index 0287f9f..eb14a79 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -15,4 +15,4 @@ --- *If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* -[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/) +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/invoiceninja_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/invoiceninja_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..67a8f6f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,6 +4,11 @@ # COMMON VARIABLES #================================================= +# dependencies used by the app +pkg_dependencies="" + +YNH_PHP_VERSION="7.0" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index ac9d0e4..73cf595 100755 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= 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 @@ -24,55 +23,55 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." - -YNH_PHP_VERSION="7.0" +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP #================================================= +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Backing up php-fpm configuration..." -ynh_backup --src_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= -# BACKUP THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Backing up the MySQL database..." - -ynh_mysql_dump_db --database="$db_name" > db.sql - +# SPECIFIC BACKUP #================================================= # BACKUP A CRON FILE #================================================= ynh_backup --src_path="/etc/cron.d/$app" +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= +ynh_print_info --message="Backing up the MySQL database..." + +ynh_mysql_dump_db --database="$db_name" > db.sql + #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 0b6c52d..27cd9a0 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,7 +24,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -37,7 +37,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -73,7 +73,7 @@ fi #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Updating nginx web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -99,13 +99,27 @@ then ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_script_progression --message="Modifying a config file..." + +config="$final_path/.env" +ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" + +ynh_replace_string --match_string="$old_domain$old_path" --replace_string="$new_domain$new_path" --target_file="$config" + +ynh_store_file_checksum --file="$config" + #================================================= # GENERIC FINALISATION #================================================= #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -113,4 +127,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --time --last +ynh_script_progression --message="Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 498b497..d3df91d 100755 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= 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 @@ -24,40 +23,18 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -YNH_PHP_VERSION="7.0" - domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN language=$YNH_APP_ARG_LANGUAGE -### If it's a multi-instance app, meaning it can be installed several times independently -### The id of the app as stated in the manifest is available as $YNH_APP_ID -### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -### The app instance name is available as $YNH_APP_INSTANCE_NAME -### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -### - ynhexample__{N} for the subsequent installations, with N=3,4, ... -### The app instance name is probably what interests you most, since this is -### guaranteed to be unique. This is a good unique identifier to define installation path, -### db names, ... app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -### About --weight and --time -### ynh_script_progression will show to your final users the progression of each scripts. -### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script. -### --time is a packager option, it will show you the execution time since the previous call. -### This option should be removed before releasing your app. -### Use the execution time, given by --time, to estimate the weight of a step. -### A common way to do it is to set a weight equal to the execution time in second +1. -### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call. ynh_script_progression --message="Validating installation parameters..." -### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". -### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" @@ -90,15 +67,6 @@ ynh_app_setting_set --app=$app --key=mail_from_name --value="$(ynh_user_get_info #================================================= ynh_script_progression --message="Creating a MySQL database..." -### Use these lines if you need a database for the application. -### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. -### The password will be stored as 'mysqlpwd' into the app settings, -### and will be available as $db_pwd -### If you're not using these lines: -### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script -### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script -### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script - db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name @@ -109,10 +77,6 @@ ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= ynh_script_progression --message="Setting up source files..." -### `ynh_setup_source` is used to install an app from a zip or tar.gz file, -### downloaded from an upstream source, like a git repository. -### `ynh_setup_source` use the file conf/app.src - 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" @@ -122,8 +86,6 @@ ynh_setup_source --dest_dir="$final_path" #================================================= ynh_script_progression --message="Configuring nginx web server..." -### `ynh_add_nginx_config` will use the file conf/nginx.conf - # Create a dedicated nginx config ynh_add_nginx_config @@ -140,67 +102,51 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Configuring php-fpm..." -### `ynh_add_fpm_config` is used to set up a PHP config. -### You can remove it if your app doesn't use PHP. -### `ynh_add_fpm_config` will use the files conf/php-fpm.conf -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script -### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script -### With the reload at the end of the script. -### - And the section "PHP-FPM CONFIGURATION" in the upgrade script - # Create a dedicated php-fpm config ynh_add_fpm_config +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +#================================================= +# SPECIFIC SETUP #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_script_progression --message="Modifying a config file..." -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) +config="$final_path/.env" +ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$config" -ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/.env" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" +ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config" +ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/.env" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/.env" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/.env" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/.env" -ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$final_path/.env" +ynh_replace_string --match_string="__API_SECRET__" --replace_string="$(ynh_app_setting_get --app=$app --key=api_secret)" --target_file="$config" +ynh_replace_string --match_string="__APP_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=app_key)" --target_file="$config" +ynh_replace_string --match_string="__PHANTOMJS_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=phantomjs_jey)" --target_file="$config" -ynh_replace_string --match_string="__API_SECRET__" --replace_string="$(ynh_app_setting_get --app=$app --key=api_secret)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__APP_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=app_key)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__PHANTOMJS_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=phantomjs_jey)" --target_file="$final_path/.env" +ynh_replace_string --match_string="__MAIL_FROM_ADDRESS__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_address)" --target_file="$config" +ynh_replace_string --match_string="__MAIL_FROM_NAME__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_name)" --target_file="$config" -ynh_replace_string --match_string="__MAIL_FROM_ADDRESS__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_address)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__MAIL_FROM_NAME__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_name)" --target_file="$final_path/.env" +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum --file="$config" #================================================= -# GENERIC FINALIZATION +# BUILD THE APPLICATION #================================================= +ynh_script_progression --message="Building the application..." -# Run the database migrations and initially fill the db -sudo $final_path/artisan migrate --no-interaction --verbose --force -sudo $final_path/artisan db:seed --force --no-interaction --verbose - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -### For security reason, any app should set the permissions to root: before anything else. -### Then, if write authorization is needed, any access should be given only to directories -### that really need such authorization. - -# Set permissions to app files -chown -R root: $final_path - -chmod -R 755 $final_path/storage -chown -R $app: $final_path/storage $final_path/bootstrap $final_path/public/logo $final_path/.env +pushd "$final_path" + # Run the database migrations and initially fill the db + php$phpversion artisan migrate --no-interaction --verbose --force + php$phpversion artisan db:seed --force --no-interaction --verbose +popd #================================================= # ADD A CRON JOB #================================================= +ynh_script_progression --message="Adding a cron job..." cron_path="/etc/cron.d/$app" cp -a ../conf/invoiceninja.cron "$cron_path" @@ -211,6 +157,19 @@ ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_fi ynh_replace_string --match_string="__DESTDIR__" --replace_string="$final_path" --target_file="$cron_path" ynh_replace_string --match_string="__YNH_PHP_VERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$cron_path" +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= +ynh_script_progression --message="Securing files and directories..." + +# Set permissions to app files +chown -R root: $final_path + +chmod -R 755 $final_path/storage +chown -R $app: $final_path/storage $final_path/bootstrap $final_path/public/logo $final_path/.env + #================================================= # RELOAD NGINX #================================================= @@ -222,4 +181,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 71939a8..adfc93a 100755 --- a/scripts/remove +++ b/scripts/remove @@ -61,6 +61,7 @@ ynh_remove_fpm_config #================================================= # REMOVE THE CRON FILE #================================================= +ynh_script_progression --message="Removing the cron file..." # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" @@ -69,4 +70,4 @@ ynh_secure_remove --file="/etc/cron.d/$app" # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index fca4651..9005ecc 100755 --- a/scripts/restore +++ b/scripts/restore @@ -22,8 +22,6 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Loading settings..." -YNH_PHP_VERSION="7.0" - app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) @@ -32,8 +30,8 @@ admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) db_user=$db_name +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -50,6 +48,7 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the nginx configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -71,6 +70,7 @@ ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS #================================================= +ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files chown -R root: $final_path @@ -81,20 +81,23 @@ chown -R $app: $final_path/storage $final_path/bootstrap $final_path/public/logo #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Restoring PHP-FPM configuration..." -ynh_restore_file --origin_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # RESTORE THE MYSQL DATABASE #================================================= ynh_script_progression --message="Restoring the MySQL database..." +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # RESTORE THE CRON FILE #================================================= +ynh_script_progression --message="Restoring the cron file..." ynh_restore_file --origin_path="/etc/cron.d/$app" @@ -105,11 +108,11 @@ ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= ynh_script_progression --message="Reloading nginx web server and php-fpm..." -ynh_systemd_action --service_name=php$YNH_PHP_VERSION-fpm --action=reload +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 44cd3a9..46ac006 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,12 +29,6 @@ db_user=$db_name # CHECK VERSION #================================================= -### This helper will compare the version of the currently installed app and the version of the upstream package. -### $upgrade_type can have 2 different values -### - UPGRADE_APP if the upstream app version has changed -### - UPGRADE_PACKAGE if only the YunoHost package has changed -### ynh_check_app_version_changed will stop the upgrade if the app is up to date. -### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. upgrade_type=$(ynh_check_app_version_changed) #================================================= @@ -84,6 +78,9 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +config="$final_path/.env" +ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" + if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." @@ -99,6 +96,7 @@ ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CREATE DEDICATED USER @@ -116,52 +114,59 @@ ynh_script_progression --message="Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_add_fpm_config +#================================================= +# SPECIFIC UPGRADE #================================================= # MODIFY A CONFIG FILE #================================================= -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Modifying a config file..." -ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/.env" + ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/.env" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/.env" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/.env" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/.env" -ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$final_path/.env" + ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" + ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config" + ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" + ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config" + ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__API_SECRET__" --replace_string="$(ynh_app_setting_get --app=$app --key=api_secret)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__APP_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=app_key)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__PHANTOMJS_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=phantomjs_jey)" --target_file="$final_path/.env" + ynh_replace_string --match_string="__API_SECRET__" --replace_string="$(ynh_app_setting_get --app=$app --key=api_secret)" --target_file="$config" + ynh_replace_string --match_string="__APP_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=app_key)" --target_file="$config" + ynh_replace_string --match_string="__PHANTOMJS_KEY__" --replace_string="$(ynh_app_setting_get --app=$app --key=phantomjs_jey)" --target_file="$config" -ynh_replace_string --match_string="__MAIL_FROM_ADDRESS__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_address)" --target_file="$final_path/.env" -ynh_replace_string --match_string="__MAIL_FROM_NAME__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_name)" --target_file="$final_path/.env" + ynh_replace_string --match_string="__MAIL_FROM_ADDRESS__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_address)" --target_file="$config" + ynh_replace_string --match_string="__MAIL_FROM_NAME__" --replace_string="$(ynh_app_setting_get --app=$app --key=mail_from_name)" --target_file="$config" + + # Calculate and store the config file checksum into the app settings + ynh_store_file_checksum --file="$config" +fi #================================================= -# SPECIFIC UPGRADE -#================================================= -# Upgrade database via artisan +# UPGRADE DATABASE #================================================= ynh_script_progression --message="Upgrading the database..." -# Put the application into maintenance mode +pushd "$final_path" + # Put the application into maintenance mode + php$phpversion artisan down --no-interaction --verbose -sudo $final_path/artisan down --no-interaction --verbose + # Optimize the framework for better performance + php$phpversion artisan optimize --force --no-interaction --verbose -# Optimize the framework for better performance -sudo $final_path/artisan optimize --force --no-interaction --verbose + # Run the database migrations + php$phpversion artisan migrate --no-interaction --verbose + php$phpversion artisan db:seed --class=UpdateSeeder --force --no-interaction --verbose -# Run the database migrations -sudo $final_path/artisan migrate --no-interaction --verbose -sudo $final_path/artisan db:seed --class=UpdateSeeder --force --no-interaction --verbose - -# Bring the application out of maintenance mode -sudo $final_path/artisan up --no-interaction --verbose + # Bring the application out of maintenance mode + php$phpversion artisan up --no-interaction --verbose +popd #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." # Set permissions on app files chown -R root: $final_path @@ -180,4 +185,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression --message="Upgrade of $app completed"