diff --git a/conf/config.json b/conf/config.json new file mode 100644 index 0000000..4541317 --- /dev/null +++ b/conf/config.json @@ -0,0 +1 @@ +%7B%0D%0A%20%20%20%20%22baseurl%22%3A%20%22__DOMAIN__%22%2C%0D%0A%20%20%20%20%22hostname%22%3A%20%22__HOSTNAME__%22%2C%0D%0A%20%20%20%20%22server%22%3A%20%7B%0D%0A%20%20%20%20%20%20%20%20%22host%22%3A%20%22localhost%22%2C%0D%0A%20%20%20%20%20%20%20%20%22port%22%3A%20__PORT__%0D%0A%20%20%20%20%20%20%20%20%7D%2C%0D%0A%20%20%20%20%22log_level%22%3A%20%22debug%22%2C%0D%0A%20%20%20%20%22log_path%22%3A%20%22%2Fvar%2Flog%2F__APP__%2Flogs%22%2C%0D%0A%20%20%20%20%22db%22%3A%20%7B%0D%0A%20%20%20%20%20%20%20%20%22dialect%22%3A%20%22postgres%22%2C%0D%0A%20%20%20%20%20%20%20%20%22storage%22%3A%20%22%22%2C%0D%0A%20%20%20%20%20%20%20%20%22host%22%3A%20%22localhost%22%2C%0D%0A%20%20%20%20%20%20%20%20%22database%22%3A%20%22__APP__%22%2C%0D%0A%20%20%20%20%20%20%20%20%22username%22%3A%20%22__DB_USER__%22%2C%0D%0A%20%20%20%20%20%20%20%20%22password%22%3A%20%22__DB_PWD__%22%2C%0D%0A%20%20%20%20%20%20%20%20%22logging%22%3A%20false%2C%0D%0A%20%20%20%20%20%20%20%20%22dialectOptions%22%3A%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%22autoJsonMap%22%3A%20true%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%2C%0D%0A%20%20%20%20%22user_locale%22%3A%20%22__DATA_DIR__%2Fuser_locale%22%2C%0D%0A%20%20%20%20%22upload_path%22%3A%20%22__DATA_DIR__%2Fuploads%22%2C%0D%0A%20%20%20%20%22plugins_path%22%3A%20%22__DATA_DIR__%2Fplugins%22%2C%0D%0A%7D \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..0b28d19 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1 @@ +location%20__PATH__%2F%20%7B%0D%0A%20%20%20%20%0D%0A%20%20%20%20proxy_pass%20%20%20%20%20%20%20http%3A%2F%2F127.0.0.1%3A__PORT__%3B%0D%0A%20%20%20%20proxy_set_header%20X-Real-IP%20%24remote_addr%3B%0D%0A%20%20%20%20proxy_set_header%20Host%20%24host%3B%0D%0A%20%20%20%20proxy_set_header%20X-Forwarded-For%20%24proxy_add_x_forwarded_for%3B%0D%0A%20%20%20%20%0D%0A%20%20%20%20%23%20Include%20SSOWAT%20user%20panel.%0D%0A%20%20%20%20include%20conf.d%2Fyunohost_panel.conf.inc%3B%0D%0A%20%20%20%20%7D%22 \ No newline at end of file diff --git a/conf/php_extra-fpm.conf b/conf/php_extra-fpm.conf new file mode 100644 index 0000000..e69de29 diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..9a01bde --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1 @@ +%5BUnit%5D%0D%0ADescription%3DGancio%20%3A%20federated%20agenda%0D%0AAfter%3Dnetwork.target%0D%0A%0D%0A%5BService%5D%0D%0AType%3Dsimple%0D%0AUser%3D__APP__%0D%0AGroup%3D__APP__%0D%0AWorkingDirectory%3D__INSTALL_DIR__%2F%0D%0AEnvironment%3D%22__YNH_NODE_LOAD_PATH__%22%0D%0AExecStart%3D__YNH_NPM__%20gancio%20start%20--config%20.%2Fconfig.json%0D%0A%0D%0A%23%20Sandboxing%20options%20to%20harden%20security%0D%0A%23%20Depending%20on%20specificities%20of%20your%20service%2Fapp%2C%20you%20may%20need%20to%20tweak%20these%0D%0A%23%20..%20but%20this%20should%20be%20a%20good%20baseline%0D%0A%23%20Details%20for%20these%20options%3A%20https%3A%2F%2Fwww.freedesktop.org%2Fsoftware%2Fsystemd%2Fman%2Fsystemd.exec.html%0D%0ANoNewPrivileges%3Dyes%0D%0APrivateTmp%3Dyes%0D%0APrivateDevices%3Dyes%0D%0ARestrictAddressFamilies%3DAF_UNIX%20AF_INET%20AF_INET6%20AF_NETLINK%0D%0ARestrictNamespaces%3Dyes%0D%0ARestrictRealtime%3Dyes%0D%0ADevicePolicy%3Dclosed%0D%0AProtectClock%3Dyes%0D%0AProtectHostname%3Dyes%0D%0AProtectProc%3Dinvisible%0D%0AProtectSystem%3Dfull%0D%0AProtectControlGroups%3Dyes%0D%0AProtectKernelModules%3Dyes%0D%0AProtectKernelTunables%3Dyes%0D%0ALockPersonality%3Dyes%0D%0ASystemCallArchitectures%3Dnative%0D%0ASystemCallFilter%3D~%40clock%20%40debug%20%40module%20%40mount%20%40obsolete%20%40reboot%20%40setuid%20%40swap%20%40cpu-emulation%20%40privileged%0D%0A%0D%0A%23%20Denying%20access%20to%20capabilities%20that%20should%20not%20be%20relevant%20for%20webapps%0D%0A%23%20Doc%3A%20https%3A%2F%2Fman7.org%2Flinux%2Fman-pages%2Fman7%2Fcapabilities.7.html%0D%0ACapabilityBoundingSet%3D~CAP_RAWIO%20CAP_MKNOD%0D%0ACapabilityBoundingSet%3D~CAP_AUDIT_CONTROL%20CAP_AUDIT_READ%20CAP_AUDIT_WRITE%0D%0ACapabilityBoundingSet%3D~CAP_SYS_BOOT%20CAP_SYS_TIME%20CAP_SYS_MODULE%20CAP_SYS_PACCT%0D%0ACapabilityBoundingSet%3D~CAP_LEASE%20CAP_LINUX_IMMUTABLE%20CAP_IPC_LOCK%0D%0ACapabilityBoundingSet%3D~CAP_BLOCK_SUSPEND%20CAP_WAKE_ALARM%0D%0ACapabilityBoundingSet%3D~CAP_SYS_TTY_CONFIG%0D%0ACapabilityBoundingSet%3D~CAP_MAC_ADMIN%20CAP_MAC_OVERRIDE%0D%0ACapabilityBoundingSet%3D~CAP_NET_ADMIN%20CAP_NET_BROADCAST%20CAP_NET_RAW%0D%0ACapabilityBoundingSet%3D~CAP_SYS_ADMIN%20CAP_SYS_PTRACE%20CAP_SYSLOG%0D%0A%0D%0A%5BInstall%5D%0D%0AWantedBy%3Dmulti-user.target \ No newline at end of file diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..74b5759 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,113 @@ +packaging_format = 2 + +id = "gancio" +name = "Gancio" + +description.en = "A shared agenda for local communities, federated with the fediverse." +description.fr = "Un agenda partagé pour les communautés locales, fédéré avec le fédiverse." + +version = "1.6.10~ynh1" + +maintainers = ["Lapineige"] + +[upstream] +# NB: Only the "license" key is mandatory. Remove entries for which there's no relevant data +license = "AGPL v3" +website = "https://gancio.org" +demo = "https://demo.gancio.org/" +admindoc = "https://gancio.org/install/" +userdoc = "https://gancio.org/usage" +code = "https://framagit.org/les/gancio" +# 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] +yunohost = ">= 11.1.21" +# List of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386'] +architectures = "['all']" +multi_instance = "False" +ldap = "false" +sso = "false" +# 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] + # this is a generic question - ask strings are automatically handled by YunoHost's core + type = "domain" + + [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 = "visitors" + + [install.language] + ask.en = "Choose the application language" + ask.fr = "Choisissez la langue de l'application" + type = "select" + choices = "['en', 'fr', 'en', 'it', 'zh', 'pt', 'nl', 'ru']" + default = "en" + + [install.admin] + # this is a generic question - ask strings are automatically handled by YunoHost's core + type = "user" + [install.password] + # 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 + 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] + # See the packaging documentation for the full set + # of explanation regarding the behavior and properties for each of those + [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 = "" + sha256 = "" + + # 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 + + # autoupdate.strategy = "latest_github_tag" + [resources.system_user] + # This will provision/deprovision a unix system user + [resources.install_dir] + # This will create/remove the install dir as /var/www/$app + # and store the corresponding setting $install_dir + + [resources.data_dir] + # This will create/remove the data dir as /home/yunohost.app/$app + # and store the corresponding setting $data_dir + subdirs = ['uploads', 'user_locale'] + [resources.permissions] + # 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) + main.url = "/" + + [resources.ports] + # This will pick a random port for reverse-proxying and store it as the $port setting + [resources.apt] + # 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) + packages = "" + # 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" + [resources.database] + # This will automatically provision/deprovison a MySQL DB and store the corresponding credentials in settings $db_user, $db_name, $db_pwd + type = postgresql + \ No newline at end of file diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..fe6c17d --- /dev/null +++ b/scripts/backup @@ -0,0 +1,78 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version 0.6. +# 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. +#================================================= +# 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..." + +### 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. +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup --src_path="$install_dir" + +#================================================= +# BACKUP THE DATA DIR +#================================================= + + # 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. + # Only relevant if there is a "data_dir" resource for this app +ynh_backup --src_path="$data_dir" --is_big +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" +#================================================= +# BACKUP VARIOUS FILES +#================================================= + +ynh_backup --src_path="/etc/cron.d/$app" + +ynh_backup --src_path="/etc/$app/" + + +#================================================= +# BACKUP THE DATABASE +#================================================= +ynh_print_info --message="Backing up the postgresql 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) + +ynh_mysql_dump_db --database="$db_name" > db.sql +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..90cd7aa --- /dev/null +++ b/scripts/config @@ -0,0 +1,105 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version 0.6. +# 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. +# 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... ). +#================================================= +# 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 \ No newline at end of file diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..e7fd9cb --- /dev/null +++ b/scripts/install @@ -0,0 +1,129 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version 0.6. +# 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. +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source _common.sh +source /usr/share/yunohost/helpers + +# 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) +# +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." --weight=10 + +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +#================================================= +# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Setting up source files..." --weight=1 + +### `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 +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" + +# $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 +chown -R $app:www-data "$install_dir" + + +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +# Create a dedicated NGINX config using the conf/nginx.conf template +ynh_add_nginx_config + +# Create a dedicated systemd config +ynh_add_systemd_config + + yunohost service add $app --description="A federated shared agenda for local communities." --log="/var/log/$app/$app.log" + + # Use logrotate to manage application logfile(s) +ynh_use_logrotate + + +#================================================= +# APP INITIAL CONFIGURATION +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +ynh_add_config --template="config.json" --destination="$install_dir/config.json" + +# 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/config.json" +chown $app:$app "$install_dir/config.json" + +### 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" + +#================================================= +# 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 +#================================================= +# SETUP APPLICATION WITH CURL +#================================================= + +#### 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 +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Installation of $app completed" --last \ No newline at end of file diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..a691112 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,57 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version 0.6. +# 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. +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source _common.sh +source /usr/share/yunohost/helpers + +# 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) +#================================================= +# REMOVE SYSTEM CONFIGURATIONS +#================================================= +# REMOVE SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 + +# This should be a symetric version of what happens in the install script +# 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 +ynh_remove_nginx_config + +ynh_remove_logrotate +# Remove other various files specific to the app... such as : + +ynh_secure_remove --file="/etc/cron.d/$app" + +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 \ No newline at end of file diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..efe99ab --- /dev/null +++ b/scripts/restore @@ -0,0 +1,79 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version 0.6. +# 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. +#================================================= +# 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" + +# $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 +chown -R $app:www-data "$install_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" +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= + 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 + #================================================= +# 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 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + +yunohost service add $app --description="A federated shared agenda for local communities." --log="/var/log/$app/$app.log" +ynh_restore_file --origin_path="/etc/logrotate.d/$app" +# 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... +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..46cd020 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,132 @@ +#!/bin/bash +#### App file generated with YoloGen, the Yunohost app generator, version 0.6. +# 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. +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +# 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. +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +#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 initiaze 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 +#================================================= +# 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" +#================================================= +# "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 + +# $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 +chown -R $app:www-data "$install_dir" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# This should be a literal copypasta of what happened in the install's "System configuration" section +ynh_add_nginx_config + +ynh_add_systemd_config + +yunohost service add $app --description="A federated shared agenda for local communities." --log="/var/log/$app/$app.log" +ynh_use_logrotate --non-append +#================================================= +# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +### 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) +ynh_add_config --template="config.json" --destination="$install_dir/config.json" + +# 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/some_config_file" +chown $app:$app "$install_dir/some_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" +#================================================= +# 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" +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last \ No newline at end of file