diff --git a/tools/yunopackage/requirements.txt b/tools/yunopackage/requirements.txt new file mode 100644 index 0000000..e955e75 --- /dev/null +++ b/tools/yunopackage/requirements.txt @@ -0,0 +1,9 @@ +Flask==3.0.0 +Flask_Misaka==1.0.0 +Flask_WTF==1.2.1 +Jinja2==3.1.2 +misaka==2.1.1 +WTForms==3.0.1 +flask_cors==4.0.0 +werkzeug==3.0.0 +markupsafe=2.1.3 diff --git a/tools/yunopackage/static/stylesheet.css b/tools/yunopackage/static/stylesheet.css new file mode 100644 index 0000000..14fda0f --- /dev/null +++ b/tools/yunopackage/static/stylesheet.css @@ -0,0 +1,316 @@ +:root { + color-scheme:light; + --yiq-contrasted-threshold: 150; + --white: hsl(0, 0%, 100%); + --white-h: 0; + --white-s: 0%; + --white-l: 100%; + --black: hsl(0, 0%, 0%); + --black-h: 0; + --black-s: 0%; + --black-l: 0%; + --blue: hsl(211, 64%, 50%); + --blue-h: 211; + --blue-s: 64%; + --blue-l: 50%; + --indigo: hsl(263, 90%, 51%); + --indigo-h: 263; + --indigo-s: 90%; + --indigo-l: 51%; + --purple: hsl(280, 61%, 50%); + --purple-h: 280; + --purple-s: 61%; + --purple-l: 50%; + --pink: hsl(332, 79%, 58%); + --pink-h: 332; + --pink-s: 79%; + --pink-l: 58%; + --red: hsl(354, 70%, 54%); + --red-h: 354; + --red-s: 70%; + --red-l: 54%; + --orange: hsl(27, 98%, 54%); + --orange-h: 27; + --orange-s: 98%; + --orange-l: 54%; + --yellow: hsl(45, 100%, 66%); + --yellow-h: 45; + --yellow-s: 100%; + --yellow-l: 66%; + --green: hsl(134, 61%, 41%); + --green-h: 134; + --green-s: 61%; + --green-l: 41%; + --teal: hsl(162, 73%, 46%); + --teal-h: 162; + --teal-s: 73%; + --teal-l: 46%; + --cyan: hsl(188, 78%, 41%); + --cyan-h: 188; + --cyan-s: 78%; + --cyan-l: 41%; + --gray-100: hsl(210, 17%, 98%); + --gray-100-h: 210; + --gray-100-s: 17%; + --gray-100-l: 98%; + --gray-200: hsl(210, 16%, 93%); + --gray-200-h: 210; + --gray-200-s: 16%; + --gray-200-l: 93%; + --gray-300: hsl(210, 14%, 89%); + --gray-300-h: 210; + --gray-300-s: 14%; + --gray-300-l: 89%; + --gray-400: hsl(210, 14%, 83%); + --gray-400-h: 210; + --gray-400-s: 14%; + --gray-400-l: 83%; + --gray-500: hsl(210, 11%, 71%); + --gray-500-h: 210; + --gray-500-s: 11%; + --gray-500-l: 71%; + --gray-600: hsl(208, 7%, 46%); + --gray-600-h: 208; + --gray-600-s: 7%; + --gray-600-l: 46%; + --gray-700: hsl(210, 9%, 31%); + --gray-700-h: 210; + --gray-700-s: 9%; + --gray-700-l: 31%; + --gray-800: hsl(210, 10%, 23%); + --gray-800-h: 210; + --gray-800-s: 10%; + --gray-800-l: 23%; + --gray-900: hsl(210, 11%, 15%); + --gray-900-h: 210; + --gray-900-s: 11%; + --gray-900-l: 15% +} + + + +h1,.h1 { + font-size:2.25rem + align="center"; +} + +h2, .h2 { + font-size: 1.35rem; +} + +h3, .h3 { + font-size: 1.26rem; +} + +h1, +h2, +h3, +h4, +h5, +h6 { + margin-top:.8rem; + margin-bottom:.2rem; + font-weight:500; + line-height:1.2; +} + +body { + /* font-family: 'source_sans_proregular'; */ + font-family: FiraGO,Fira Sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji"; + font-size: 1em; + line-height: 2.2; + color: var(--gray-900); + text-align: left; + + width: 100%; + padding-right: 15px; + padding-left: 15px; + margin-right: auto; + margin-left: auto; + max-width: 85%; +} + + + + +.message { + padding: 10px; + margin: 5px; + background-color: #2980b9; + color:#FFF; +} + +.text-secondary { + color: var(--gray-600) !important; +} + +.alert { + padding: 20px; + margin: 5px; + color: #970020; + background-color: #ffd5de; +} + +.grayed_hint { + color: darkgray; +} + +.box { + border:20px solid black + padding: 50px auto; + position: relative; +} + +.code-block { + background-color: #282c34; + color: #ebf2ff; + border-radius: 5px; + padding: 10px; + + overflow: auto; + height: 400px; + + white-space: pre; + + font-family: 'Courier New', Courier, monospace; + font-size: 14px; + line-height: 1.5; +} + + + +.btn { + display:inline-block; + font-weight:400; + color:var(--gray-900); + text-align:center; + vertical-align:middle; + user-select:none; + background-color:transparent; + border:1px solid transparent; + padding:.375rem .75rem; + font-size:.9rem; + line-height:1.5; + border-radius:.25rem; + transition:color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out +} + +.btn-primary { + color:hsla(0,0%,calc(-100 * (var(--blue-l) - calc(calc(var(--yiq-contrasted-threshold) / 2.56) * 1%))),1); + background-color:var(--blue); + border-color:var(--blue); + font-size: larger; +} +.btn-primary:hover { + color:hsla(0,0%,calc(-100 * (calc(var(--blue-l) + -7.5%) - calc(calc(var(--yiq-contrasted-threshold) / 2.56) * 1%))),1); + background-color:hsla(var(--blue-h),var(--blue-s),calc(var(--blue-l) + -7.5%),var(--blue-a, 1)); + border-color:hsla(var(--blue-h),var(--blue-s),calc(var(--blue-l) + -10%),var(--blue-a, 1)) +} +.btn-primary:focus, +.btn-primary.focus { + color:hsla(0,0%,calc(-100 * (calc(var(--blue-l) + -7.5%) - calc(calc(var(--yiq-contrasted-threshold) / 2.56) * 1%))),1); + background-color:hsla(var(--blue-h),var(--blue-s),calc(var(--blue-l) + -7.5%),var(--blue-a, 1)); + border-color:hsla(var(--blue-h),var(--blue-s),calc(var(--blue-l) + -10%),var(--blue-a, 1)); + box-shadow:0 0 0 .2rem hsla(calc((0 + var(--blue-h)) / 2),calc((0% + var(--blue-s)) / 2),calc((calc(-100 * (var(--blue-l) - calc(calc(var(--yiq-contrasted-threshold) / 2.56) * 1%))) + var(--blue-l)) / 2),.5) +} +.btn-primary.disabled, +.btn-primary:disabled { + color:hsla(0,0%,calc(-100 * (var(--blue-l) - calc(calc(var(--yiq-contrasted-threshold) / 2.56) * 1%))),1); + background-color:var(--blue); + border-color:var(--blue) +} + +.btn-center { + margin-left:auto; + margin-right:auto; + display: flex; + align-items: center; +} + +.btn-sm, +.btn-group-sm>.btn { + padding:.25rem .5rem; + //font-size:.7875rem; + line-height:1.5; + border-radius:.2rem; +} + + +.form-control { + #display: block; + #width: 100%; + #height: calc(1.5em + .75rem + 2px); + padding: .375rem .75rem; + padding-right: 0.5rem; + margin-left:0.75rem; + font-size: .9rem; + font-weight: 400; + line-height: 1.5; + color: var(--gray-700); + background-color: var(--white); + background-clip: padding-box; + border: 1px solid var(--gray-400); + border-radius: .25rem; + transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out; +} +.form-control.is-invalid { + border-color: var(--red); + padding-right: calc(1.5em + .75rem) !important; + background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='var%28--red%29' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='var%28--red%29' stroke='none'/%3e%3c/svg%3e"); + background-repeat: no-repeat; + background-position: right calc(.375em + .1875rem) center; + background-size: calc(.75em + .375rem) calc(.75em + .375rem); +} + + + +.custom-select { + + display: inline-block; + width: 100%; + height: calc(1.5em + .75rem + 2px); + padding: .375rem 1.75rem .375rem .75rem; + font-size: .9rem; + font-weight: 400; + line-height: 1.5; + color: var(--gray-700); + vertical-align: middle; + background: var(--white) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='var%28--gray-800%29' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right .75rem center/8px 10px no-repeat; + border: 1px solid var(--gray-400); + border-radius: .25rem; + appearance: none; + +} + + +.nav { + display:flex; + flex-wrap:wrap; + padding-left:0; + margin-bottom:0; + list-style:none +} +.nav-tabs .nav-item.show .nav-link { + color:var(--gray-700); + background-color:var(--white); + border-color:var(--gray-300) var(--gray-300) var(--white) +} + +nav a { + margin-left: 50px; + // text-decoration: none; // removing links underline is a bad idea +} + +footer .nav-item:before { + /* content:"\2022"; */ + width:1rem; + display:inline-block; + margin-left:-1.15rem; + padding-top:1rem!important; + margin-top:auto!important; +} + + +.test { + color:red; +} \ No newline at end of file diff --git a/tools/yunopackage/templates/_common.sh.j2 b/tools/yunopackage/templates/_common.sh.j2 new file mode 100644 index 0000000..ea830fd --- /dev/null +++ b/tools/yunopackage/templates/_common.sh.j2 @@ -0,0 +1,20 @@ +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= + +{% if parameters["use_nodejs"] -%} +nodejs_version={{ parameters["use_nodejs_version"]}} +{% endif -%} +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/tools/yunopackage/templates/backup.j2 b/tools/yunopackage/templates/backup.j2 new file mode 100644 index 0000000..1fcdc2c --- /dev/null +++ b/tools/yunopackage/templates/backup.j2 @@ -0,0 +1,111 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version {{ parameters['GENERATOR_VERSION'] }}. +{% if parameters["tutorial"] -%} # This is the tutorial version of the app. +# It contains extra commands to explain what should be done in case you want to adjust some part of the script. +# Once you are done, you may remove them. +{% endif -%} +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + +{% if parameters["tutorial"] -%} +### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs +### to be backuped and not an actual copy of any file. The actual backup that +### creates and fill the archive with the files happens in the core after this +### script is called. Hence ynh_backups calls takes basically 0 seconds to run. +{% endif -%} + +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup --src_path="$install_dir" + +{% if parameters["data_dir"] -%} +#================================================= +# BACKUP THE DATA DIR +#================================================= + + {% if parameters["tutorial"] -%} +# The --is_big parameters ensure this folder is not included in the backup by default (taking less space), except if BACKUP_CORE_ONLY=0 is passed before the backup command. You might want to document that for your users. + {% endif -%} +# Only relevant if there is a "data_dir" resource for this app +ynh_backup --src_path="$data_dir" --is_big +{% endif -%} +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +{% if parameters["use_php"] -%} +#================================================= +# BACKUP THE PHP-FPM CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +{% endif -%} +{% if parameters["use_fail2ban"] -%} +#================================================= +# BACKUP FAIL2BAN CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" +ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" +{% endif -%} +{% if parameters["use_logrotate"] -%} +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" +{% endif -%} +{% if parameters["use_systemd_service"] -%} +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" +{% endif -%} +#================================================= +# BACKUP VARIOUS FILES +#================================================= +{% if parameters["use_cron"] -%} +ynh_backup --src_path="/etc/cron.d/$app" +{% endif -%} +ynh_backup --src_path="/etc/$app/" + + +{% if parameters["use_db"] -%} +#================================================= +# BACKUP THE DATABASE +#================================================= +ynh_print_info --message="Backing up the {{ parameters['use_db'] }} database..." + +### (However, things like MySQL dumps *do* take some time to run, though the +### copy of the generated dump to the archive still happens later) + +{% if parameters["use_db"] == 'mysql' -%} +ynh_mysql_dump_db --database="$db_name" > db.sql +{% elif parameters["use_db"] == 'postgresql' -%} +ynh_psql_dump_db --database="$db_name" > db.sql +{% endif -%} +{% endif -%} +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/tools/yunopackage/templates/change_url.j2 b/tools/yunopackage/templates/change_url.j2 new file mode 100644 index 0000000..9d577d2 --- /dev/null +++ b/tools/yunopackage/templates/change_url.j2 @@ -0,0 +1,53 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version {{ parameters['GENERATOR_VERSION'] }}. +{% if parameters["tutorial"] -%} # This is the tutorial version of the app. +# It contains extra commands to explain what should be done in case you want to adjust some part of the script. +# Once you are done, you may remove them. +{% endif -%} +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +{% if parameters["use_systemd_service"] -%} +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +{% endif -%} +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 + +ynh_change_url_nginx_config + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# ... +#================================================= + +#================================================= +# GENERIC FINALISATION +#================================================= +{% if parameters["use_systemd_service"] -%} +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +{% endif -%} +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/tools/yunopackage/templates/config.j2 b/tools/yunopackage/templates/config.j2 new file mode 100644 index 0000000..4d16aa8 --- /dev/null +++ b/tools/yunopackage/templates/config.j2 @@ -0,0 +1,109 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version {{ parameters['GENERATOR_VERSION'] }}. +{% if parameters["tutorial"] -%} # This is the tutorial version of the app. +# It contains extra commands to explain what should be done in case you want to adjust some part of the script. +# Once you are done, you may remove them. +{% endif -%} + +{% if parameters["tutorial"] -%} +# In simple cases, you don't need a config script. + +# With a simple config_panel.toml, you can write in the app settings, in the +# upstream config file or replace complete files (logo ...) and restart services. + +# The config scripts allows you to go further, to handle specific cases +# (validation of several interdependent fields, specific getter/setter for a value, +# display dynamic informations or choices, pre-loading of config type .cube... ). +{% endif -%} +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) + +#================================================= +# SPECIFIC GETTERS FOR TOML SHORT KEY +#================================================= + +get__amount() { + # Here we can imagine to have an API call to stripe to know the amount of donation during a month + local amount = 200 + + # It's possible to change some properties of the question by overriding it: + if [ $amount -gt 100 ] + then + cat << EOF +style: success +value: $amount +ask: + en: A lot of donation this month: **$amount €** +EOF + else + cat << EOF +style: danger +value: $amount +ask: + en: Not so much donation this month: $amount € +EOF + fi +} + +get__prices() { + local prices = "$(grep "DONATION\['" "$install_dir/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')" + if [ "$prices" == "," ]; + then + # Return YNH_NULL if you prefer to not return a value at all. + echo YNH_NULL + else + echo $prices + fi +} + + +#================================================= +# SPECIFIC VALIDATORS FOR TOML SHORT KEYS +#================================================= +validate__publishable_key() { + + # We can imagine here we test if the key is really a publisheable key + (is_secret_key $publishable_key) && + echo 'This key seems to be a secret key' +} + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= +set__prices() { + + #--------------------------------------------- + # IMPORTANT: setter are trigger only if a change is detected + #--------------------------------------------- + for price in $(echo $prices | sed "s/,/ /"); do + frequency=$(echo $price | cut -d/ -f1) + currency=$(echo $price | cut -d/ -f2) + price_id=$(echo $price | cut -d/ -f3) + sed "d/DONATION\['$frequency'\]\['$currency'\]" "$install_dir/settings.py" + + echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$install_dir/settings.py" + done + + #--------------------------------------------- + # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too + #--------------------------------------------- + ynh_app_setting_set $app prices $prices +} + +#================================================= +# GENERIC FINALIZATION +#================================================= +ynh_app_config_run $1 diff --git a/tools/yunopackage/templates/index.html b/tools/yunopackage/templates/index.html new file mode 100644 index 0000000..ac67505 --- /dev/null +++ b/tools/yunopackage/templates/index.html @@ -0,0 +1,887 @@ + + +
+ + + + + + + + + + + + + + + +Version: {{ parameters['GENERATOR_VERSION'] }}
+
+
+{% set lines = template_manifest_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+{% set lines = template_install_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+{% set lines = template_remove_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+{% set lines = template_backup_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+{% set lines = template_restore_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+{% set lines = template_upgrade_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+{% set lines = template_config_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+{% set lines = template_change_url_content.splitlines() %}
+{% for line in lines %} {{ line }}
+{% endfor %}
+
+
+
+
+ {{parameters['systemd_config_file']}}
+
+
+
+
+ {{parameters['nginx_config_file']}}
+
+
+
+
+ {{parameters['custom_config_file_content']}}
+
+
+
+
+ {{parameters['cron_config_file']}}
+
+
+ + +
+ +{% endif %} + + + + + diff --git a/tools/yunopackage/templates/install.j2 b/tools/yunopackage/templates/install.j2 new file mode 100644 index 0000000..c3a926b --- /dev/null +++ b/tools/yunopackage/templates/install.j2 @@ -0,0 +1,284 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version {{ parameters['GENERATOR_VERSION'] }}. +{% if parameters["tutorial"] -%} # This is the tutorial version of the app. +# It contains extra commands to explain what should be done in case you want to adjust some part of the script. +# Once you are done, you may remove them. +{% endif -%} +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source _common.sh +source /usr/share/yunohost/helpers + +{% if parameters["tutorial"] -%} +# Install parameters are automatically saved as settings +# +# Settings are automatically loaded as bash variables +# in every app script context, therefore typically these will exist: +# - $domain +# - $path +# - $language +# ... etc +# +# Resources defined in the manifest are provisioned prior to this script +# and corresponding settings are also available, such as: +# - $install_dir +# - $port +# - $db_name +# ... + +# +# $app is the app id (i.e. 'example' for first install, +# or 'example__2', '__3', ... for multi-instance installs) +# +{% endif -%} + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." --weight=10 + +{% if parameters["use_nodejs_needs_yarn"] -%} +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +{% endif -%} + +#================================================= +# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Setting up source files..." --weight=1 + +{% if parameters["tutorial"] -%} +### `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 +{% endif -%} + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" + +{% if parameters["tutorial"] -%} +# $install_dir will automatically be initialized with some decent +# permission by default ... however, you may need to recursively reapply +# ownership to all files such as after the ynh_setup_source step +{% endif -%} +chown -R $app:www-data "$install_dir" {# TODO : we may need to allow people to configure this #} + +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +{% if use_php -%} + +{% if version == "tutorial" -%} +### `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 +### But wait : This should have been handled by our app generator ;) +{% endif -%} + +ynh_script_progression --message="Adding {{php_version}} configurations related to $app..." --weight=1 +# Create a dedicated PHP-FPM config using the conf/php-fpm.conf or conf/extra_php-fpm.conf +ynh_add_fpm_config +{% endif -%} + + +{% if use_php -%} + + {% if version == "tutorial" -%} +### `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 + {% endif -%} + +ynh_script_progression --message="Adding {{php_version}} configurations related to $app..." --weight=1 +# Create a dedicated PHP-FPM config using the conf/php-fpm.conf or conf/extra_php-fpm.conf +ynh_add_fpm_config +{% endif -%} + +# Create a dedicated NGINX config using the conf/nginx.conf template +ynh_add_nginx_config + +{% if parameters["use_systemd_service"] -%} + {% if version == "tutorial" -%} +### `ynh_systemd_config` is used to configure a systemd script for an app. +### It can be used for apps that use sysvinit (with adaptation) or systemd. +### Have a look at the app to be sure this app needs a systemd script. +### `ynh_systemd_config` will use the file conf/systemd.service +### If you're not using these lines: +### - You can remove those files in conf/. +### - Remove the section "BACKUP SYSTEMD" in the backup script +### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script +### - As well as the section "RESTORE SYSTEMD" in the restore script +### - And the section "SETUP SYSTEMD" in the upgrade script + {% endif -%} + +# Create a dedicated systemd config +ynh_add_systemd_config + + {% if version == "tutorial" -%} +### `yunohost service add` integrates a service in YunoHost. It then gets +### displayed in the admin interface and through the others `yunohost service` commands. +### (N.B.: this line only makes sense if the app adds a service to the system!) +### If you're not using these lines: +### - You can remove these files in conf/. +### - Remove the section "REMOVE SERVICE INTEGRATION IN YUNOHOST" in the remove script +### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script +### - And the section "INTEGRATE SERVICE IN YUNOHOST" in the upgrade script + {% endif -%} + +yunohost service add $app --description="{{ parameters['systemd_service_description'] }}" --log="/var/log/$app/$app.log" + + {% if version == "tutorial" -%} +### Additional options starting with 3.8: +### +### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed +### which will then be checked by YunoHost's diagnosis system +### (N.B. DO NOT USE THIS is the port is only internal!!!) +### +### --test_status "some command" a custom command to check the status of the service +### (only relevant if 'systemctl status' doesn't do a good job) +### +### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service +### +### Re-calling 'yunohost service add' during the upgrade script is the right way +### to proceed if you later realize that you need to enable some flags that +### weren't enabled on old installs (be careful it'll override the existing +### service though so you should re-provide all relevant flags when doing so) + +### `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 + {% endif -%} +{% endif -%} + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate + +{% if parameters["use_fail2ban"] -%} +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="{{ parameters['fail2ban_regex'] }}" +{% endif -%} + +{% if parameters["use_cron"] -%} +#================================================= +# ADD A CRON JOB +#================================================= +cron_path="/etc/cron.d/$app" +ynh_add_config --template="../conf/task.cron" --destination="$cron_path" +chown root: "$cron_path" +chmod 644 "$cron_path" +{% endif -%} + +#================================================= +# APP INITIAL CONFIGURATION +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +{% if version == "tutorial" -%} +### You can add specific configuration files. +### +### Typically, put your template conf file in ../conf/your_config_file +### The template may contain strings such as __FOO__ or __FOO_BAR__, +### which will automatically be replaced by the values of $foo and $foo_bar +### +### ynh_add_config will also keep track of the config file's checksum, +### which later during upgrade may allow to automatically backup the config file +### if it's found that the file was manually modified +### +### Check the documentation of `ynh_add_config` for more info. +{% endif -%} + +ynh_add_config --template="{{ parameters['custom_config_file'] }}" --destination="$install_dir/{{ parameters['custom_config_file'] }}" + +# FIXME: this should be handled by the core in the future +# You may need to use chmod 600 instead of 400, +# for example if the app is expected to be able to modify its own config +chmod 400 "$install_dir/{{ parameters['custom_config_file'] }}" +chown $app:$app "$install_dir/{{ parameters['custom_config_file'] }}" + +### For more complex cases where you want to replace stuff using regexes, +### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### When doing so, you also need to manually call ynh_store_file_checksum +### +### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" +### ynh_store_file_checksum --file="$install_dir/some_config_file" + +{% if parameters["use_nodejs_needs_yarn"] -%} +#================================================= +# INSTALL YARN +#================================================= +ynh_script_progression --message="Installing yarn dependency..." --weight=15 + +pushd $install_dir + ynh_use_nodejs + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install +popd +{% endif -%} + +#================================================= +# SETUP APPLICATION WITH CURL +#================================================= + +{% if version == "tutorial" -%} +### 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. +{% endif -%} + +#### TODO in Yunohost App Generator +# Installation with curl +ynh_script_progression --message="Finalizing installation..." --weight=1 +ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" + +#================================================= +# GENERIC FINALIZATION +#================================================= +{% if parameters["use_systemd_service"] -%} +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + + +{% if version == "tutorial" -%} +### `ynh_systemd_action` is used to start a systemd service for an app. +### Only needed if you have configure a systemd service +### If you're not using these lines: +### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script +### - As well as the section "START SYSTEMD SERVICE" in the restore script +### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script +### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script +{% endif -%} + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +{% endif -%} +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Installation of $app completed" --last diff --git a/tools/yunopackage/templates/manifest.j2 b/tools/yunopackage/templates/manifest.j2 new file mode 100644 index 0000000..510a892 --- /dev/null +++ b/tools/yunopackage/templates/manifest.j2 @@ -0,0 +1,179 @@ +packaging_format = 2 + +id = "{{ parameters['app_id'] }}" +name = "{{ parameters['app_name'] }}" + +{% if parameters['tutorial'] -%} +{% endif -%} + + +description.en = "{{ parameters['description_en'] }}" +description.fr = "{{ parameters['description_fr'] }}" + +version = "{{ parameters['version'] }}" + +maintainers = ["{{ parameters['maintainers'] }}"] + +[upstream] +# NB: Only the "license" key is mandatory. Remove entries for which there's no relevant data +license = "{{ parameters['license'] }}" +website = "{{ parameters['website'] }}" +demo = "{{ parameters['demo'] }}" +admindoc = "{{ parameters['admindoc'] }}" +userdoc = "{{ parameters['userdoc'] }}" +code = "{{ parameters['code'] }}" +# FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, YunoHost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) +cpe = "???" +# FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. +fund = "???" + + +[integration] +{% if parameters['yunohost_required_version'] -%} +yunohost = '>= {{ parameters['yunohost_required_version'] }}' +{% else -%} +yunohost = ">= 11.1.21" +{% endif -%} + +{% if parameters['tutorial'] -%} +# List of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386'] +{% endif -%} +architectures = "{{ parameters['architectures'] }}" # TODO : handle the "all" option (no ["all"]) +multi_instance = {{ parameters['multi_instance'] }} +ldap = {{ parameters['ldap'] }} +sso = {{ parameters['sso'] }} +# FIXME: replace with an **estimate** minimum disk and RAM requirements. e.g. 20M, 400M, 1G... You may have have a look at CI results +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" + +[install] + [install.domain] + {% if parameters['tutorial'] -%} + # this is a generic question - ask strings are automatically handled by YunoHost's core + {% endif -%} + type = "domain" + + {% if not parameters['use_whole_domain'] -%} + [install.path] + {% if parameters['tutorial'] -%} + # this is a generic question - ask strings are automatically handled by YunoHost's core + {% endif -%} + type = "path" + default = "/example" + {% endif -%} + + [install.init_main_permission] + # this is a generic question - ask strings are automatically handled by YunoHost's core + # This won't be saved as setting and will instead be used to initialize the SSOwat permission + type = "group" + default = "{{ parameters['visibility'] }}" + + [install.language] + ask.en = "Choose the application language" + ask.fr = "Choisissez la langue de l'application" + type = "select" + choices = {{ parameters['language'] |safe }} + default = "{{ parameters['default_language'] }}" + + [install.admin] + {% if parameters['tutorial'] -%} + # this is a generic question - ask strings are automatically handled by YunoHost's core + type = "user" + {% endif -%} + + [install.password] + {% if parameters['tutorial'] -%} + # this is a generic question - ask strings are automatically handled by YunoHost's core + # Note that user-provided passwords questions are not automatically saved as setting + {% endif -%} + help.en = "Use the help field to add an information for the admin about this question." + help.fr = "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question." + type = "password" + +[resources] + {% if parameters['tutorial'] -%} + # See the packaging documentation for the full set + # of explanation regarding the behavior and properties for each of those + {% endif -%} + + [resources.sources] + + [resources.sources.main] + # This will pre-fetch the asset which can then be deployed during the install/upgrade scripts with : + # ynh_setup_source --dest_dir="$install_dir" + # You can also define other assets than "main" and add --source_id="foobar" in the previous command + url = "{{parameters['source_url']}}" + sha256 = "{{parameters['sha256sum']}}" + + # These infos are used by https://github.com/YunoHost/apps/blob/master/tools/autoupdate_app_sources/autoupdate_app_sources.py + # to auto-update the previous asset urls and sha256sum + manifest version + # assuming the upstream's code repo is on github and relies on tags or releases + # See the 'sources' resource documentation for more details + + {% if parameters['auto_update'] -%} + autoupdate.strategy = "latest_github_tag" + {% else -%} + # autoupdate.strategy = "latest_github_tag" + {% endif -%} + + [resources.system_user] + {% if parameters['tutorial'] -%} + # This will provision/deprovision a unix system user + {% endif -%} + + [resources.install_dir] + {% if parameters['tutorial'] -%} + # This will create/remove the install dir as /var/www/$app + # and store the corresponding setting $install_dir + {% endif -%} + + {% if parameters['data_dir'] %} + [resources.data_dir] + {% if parameters['tutorial'] -%} + # This will create/remove the data dir as /home/yunohost.app/$app + # and store the corresponding setting $data_dir + {% endif -%} + {% if parameters['data_subdirs'] -%} + subdirs = {{ parameters['data_subdirs'].split(",") |safe}} + {% endif -%} + {% endif -%} + + [resources.permissions] + {% if parameters['tutorial'] -%} + # This will configure SSOwat permission for $domain/$path/ + # The initial allowed group of user is configured via the init_main_permission question (public=visitors, private=all_users) + {% endif -%} + main.url = "/" + + [resources.ports] + {% if parameters['tutorial'] -%} + # This will pick a random port for reverse-proxying and store it as the $port setting + {% endif -%} + + {% if parameters['dependencies'] or parameters['use_nodejs_needs_yarn'] -%} + [resources.apt] + {% if parameters['tutorial'] -%} + # This will automatically install/uninstall the following apt packages + # and implicitly define the $phpversion setting as 8.0 (if phpX.Y-foobar dependencies are listed) + {% endif -%} + packages = "{{ parameters['dependencies'] }} {% if parameters['use_db'] != 'false' -%} {{ parameters['use_db'] }} {% endif -%}" + {% endif -%} + + {% if parameters['tutorial'] -%} + {% if parameters['use_nodejs_needs_yarn'] -%} + # This will configure an extra repository to install yarn dependency + extras.yarn.repo = "deb https://dl.yarnpkg.com/debian/ stable main" + extras.yarn.key = "https://dl.yarnpkg.com/debian/pubkey.gpg" + extras.yarn.packages = "yarn" + {% endif -%} + {% endif -%} + + {% if parameters['use_db'] != 'false' -%} + [resources.database] + {% if parameters['tutorial'] -%} + # This will automatically provision/deprovison a database and store the corresponding credentials in settings $db_user, $db_name, $db_pwd + {% endif -%} + type = "{{ parameters['use_db'] }}" + {% endif -%} + diff --git a/tools/yunopackage/templates/remove.j2 b/tools/yunopackage/templates/remove.j2 new file mode 100644 index 0000000..af2ee26 --- /dev/null +++ b/tools/yunopackage/templates/remove.j2 @@ -0,0 +1,79 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version {{ parameters['GENERATOR_VERSION'] }}. +{% if parameters["tutorial"] -%} # This is the tutorial version of the app. +# It contains extra commands to explain what should be done in case you want to adjust some part of the script. +# Once you are done, you may remove them. +{% endif -%} +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source _common.sh +source /usr/share/yunohost/helpers + +{% if parameters["tutorial"] -%} +# Settings are automatically loaded as bash variables +# in every app script context, therefore typically these will exist: +# - $domain +# - $path +# - $language +# - $install_dir +# - $port +# ... + +# For remove operations : +# - the core will deprovision every resource defined in the manifest **after** this script is ran +# this includes removing the install directory, and data directory (if --purge was used) +{% endif -%} + +#================================================= +# REMOVE SYSTEM CONFIGURATIONS +#================================================= +# REMOVE SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 + +{% if parameters["tutorial"] -%} +# This should be a symetric version of what happens in the install script +{% endif -%} + +{% if parameters["use_systemd_service"] -%} +# 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 integration..." --weight=1 + yunohost service remove $app +fi + +ynh_remove_systemd_config +{% endif -%} + +ynh_remove_nginx_config + +{% if parameters["use_php"] -%} +ynh_remove_fpm_config +{% endif -%} + +{% if parameters["use_logrotate"] -%} +ynh_remove_logrotate +{% endif -%} + +{% if parameters["use_fail2ban"] -%} +ynh_remove_fail2ban_config +{% endif -%} + +# Remove other various files specific to the app... such as : +{% if parameters["use_cron"] -%} +ynh_secure_remove --file="/etc/cron.d/$app" +{% endif -%} + +ynh_secure_remove --file="/etc/$app" + +ynh_secure_remove --file="/var/log/$app" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last diff --git a/tools/yunopackage/templates/restore.j2 b/tools/yunopackage/templates/restore.j2 new file mode 100644 index 0000000..e95c451 --- /dev/null +++ b/tools/yunopackage/templates/restore.j2 @@ -0,0 +1,115 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version {{ parameters['GENERATOR_VERSION'] }}. +{% if parameters["tutorial"] -%} # This is the tutorial version of the app. +# It contains extra commands to explain what should be done in case you want to adjust some part of the script. +# Once you are done, you may remove them. +{% endif -%} +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=1 + +ynh_restore_file --origin_path="$install_dir" + +{% if parameters["tutorial"] -%} +# $install_dir will automatically be initialized with some decent +# permission by default ... however, you may need to recursively reapply +# ownership to all files such as after the ynh_setup_source step +{% endif -%} +chown -R $app:www-data "$install_dir" + +{% if parameters["data_dir"] -%} +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Restoring the data directory..." --weight=1 + +ynh_restore_file --origin_path="$data_dir" --not_mandatory + +# (Same as for install dir) +chown -R $app:www-data "$data_dir" +{% endif -%} + +{% if parameters["use_db"] -%} +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= + {% if parameters["use_db"] == 'mysql' -%} +ynh_script_progression --message="Restoring the MySQL database..." --weight=1 + +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + {% endif -%} + + {% if parameters["use_db"] == 'postgresql' -%} +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 + +ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + {% endif -%} +{% endif -%} +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +# RESTORE THE PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +# This should be a symetric version of what happens in the install script + +{% if parameters["use_php"] -%} +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +{% endif -%} + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +{% if parameters["use_systemd_service"] -%} +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + +yunohost service add $app --description="{{ parameters['systemd_service_description'] }}" --log="/var/log/$app/$app.log" +{% endif -%} + +{% if parameters["use_logrotate"] -%} +ynh_restore_file --origin_path="/etc/logrotate.d/$app" +{% endif -%} +{% if parameters["use_fail2ban"] -%} +ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" +ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" +ynh_systemd_action --action=restart --service_name=fail2ban +{% endif -%} +# Other various files... + +ynh_restore_file --origin_path="/etc/cron.d/$app" +ynh_restore_file --origin_path="/etc/$app/" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE +#================================================= +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +# Typically you only have either $app or php-fpm but not both at the same time... +{% if parameters["use_systemd_service"] -%} +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +{% endif -%} +{% if parameters["use_php"] -%} +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload +{% endif -%} + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/tools/yunopackage/templates/upgrade.j2 b/tools/yunopackage/templates/upgrade.j2 new file mode 100644 index 0000000..7099222 --- /dev/null +++ b/tools/yunopackage/templates/upgrade.j2 @@ -0,0 +1,180 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version {{ parameters['GENERATOR_VERSION'] }}. +{% if parameters["tutorial"] -%} # This is the tutorial version of the app. +# It contains extra commands to explain what should be done in case you want to adjust some part of the script. +# Once you are done, you may remove them. +{% endif -%} +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +{% if parameters["tutorial"] -%} +# Settings are automatically loaded as bash variables +# in every app script context, therefore typically these will exist: +# - $domain +# - $path +# - $language +# - $install_dir +# - $port +# ... + +# In the context of upgrade, +# - resources are automatically provisioned / updated / deleted (depending on existing resources) +# - a safety backup is automatically created by the core and will be restored if the upgrade fails + +### 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. +{% endif -%} +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +{% if parameters["tutorial"] -%} +#ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 + +# +# N.B. : the followings setting migrations snippets are provided as *EXAMPLES* +# of what you may want to do in some cases (e.g. a setting was not defined on +# some legacy installs and you therefore want to initialize stuff during upgrade) +# + +# If db_name doesn't exist, create it +#if [ -z "$db_name" ]; then +# db_name=$(ynh_sanitize_dbid --db_name=$app) +# ynh_app_setting_set --app=$app --key=db_name --value=$db_name +#fi + +# If install_dir doesn't exist, create it +#if [ -z "$install_dir" ]; then +# install_dir=/var/www/$app +# ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir +#fi +{% endif -%} + +{% if parameters["use_systemd_service"] -%} +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +{% endif -%} +#================================================= +# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=1 + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$install_dir" +fi + +{% if parameters["tutorial"] -%} +# $install_dir will automatically be initialized with some decent +# permission by default ... however, you may need to recursively reapply +# ownership to all files such as after the ynh_setup_source step +{% endif -%} +chown -R $app:www-data "$install_dir" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +{% if parameters["tutorial"] -%} +# This should be a literal copypasta of what happened in the install's "System configuration" section +{% endif -%} + +{% if parameters["use_php"] -%} +ynh_add_fpm_config +{% endif -%} + +ynh_add_nginx_config + +{% if parameters["use_systemd_service"] -%} +ynh_add_systemd_config + +yunohost service add $app --description="{{ parameters['systemd_service_description'] }}" --log="/var/log/$app/$app.log" +{% endif -%} + +{% if parameters["use_logrotate"] -%} +ynh_use_logrotate --non-append +{% endif -%} + +{% if parameters["use_fail2ban"] -%} +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="{{ parameters['fail2ban_regex'] }}" +{% endif -%} + +{% if parameters["use_cron"] -%} +#================================================= +# UPDATE THE CRON JOB +#================================================= +cron_path="/etc/cron.d/$app" +ynh_add_config --template="../conf/task.cron" --destination="$cron_path" +chown root: "$cron_path" +chmod 644 "$cron_path" +{% endif -%} + +#================================================= +# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +{% if parameters["tutorial"] -%} +### Same as during install +### +### The file will automatically be backed-up if it's found to be manually modified (because +### ynh_add_config keeps track of the file's checksum) +{% endif -%} + +ynh_add_config --template="{{ parameters['custom_config_file'] }}" --destination="$install_dir/{{ parameters['custom_config_file'] }}" + +{% if parameters["tutorial"] -%} +# FIXME: this should be handled by the core in the future +# You may need to use chmod 600 instead of 400, +# for example if the app is expected to be able to modify its own config +{% endif -%} +chmod 400 "$install_dir/some_config_file" +chown $app:$app "$install_dir/some_config_file" + +{% if parameters["tutorial"] -%} +### For more complex cases where you want to replace stuff using regexes, +### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### When doing so, you also need to manually call ynh_store_file_checksum +### +### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" +### ynh_store_file_checksum --file="$install_dir/some_config_file" +{% endif -%} + +{% if parameters["use_systemd_service"] -%} +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +{% endif -%} +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last