mirror of
https://github.com/YunoHost-Apps/codimd_ynh.git
synced 2024-09-03 18:16:32 +02:00
Merge pull request #33 from ericgaspar/enh-testing-mysql
add backup, restore, upgrade script
This commit is contained in:
commit
a5e1dfc4c6
18 changed files with 976 additions and 443 deletions
70
README.md
70
README.md
|
@ -1,25 +1,63 @@
|
|||
# CodiMD for YunoHost
|
||||
|
||||
A collaborative editor to work on notes written in Markdown
|
||||
[![Integration level](https://dash.yunohost.org/integration/codimd.svg)](https://dash.yunohost.org/appci/app/codimd) ![](https://ci-apps.yunohost.org/ci/badges/codimd.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/codimd.maintain.svg)
|
||||
[![Install CodiMD with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=codimd)
|
||||
|
||||
*[Lire ce readme en français.](./README_fr.md)*
|
||||
|
||||
> *This package allows you to install CodiMD 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
|
||||
CodiMD is a real-time collaborative word processing web service. It uses Markdown language.
|
||||
|
||||
**Shipped version:** 1.6.0
|
||||
|
||||
**Status**: In progress, do *not* consider this app as stable and fully working (yet)
|
||||
|
||||
**To be implemented**:
|
||||
- Upgrade (right now you need to remove the app and install its new version - your documents are likely to be lost…)
|
||||
- Backup and restore system
|
||||
|
||||
Links:
|
||||
- [Yunohost project](https://yunohost.org)
|
||||
- [CodiMD website](https://github.com/codimd/server/)
|
||||
- [Demo](https://demo.codimd.org/)
|
||||
|
||||
[![Install CodiMD with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=codimd)
|
||||
|
||||
|
||||
### Screenshot
|
||||
## Screenshots
|
||||
|
||||
![](https://demo.codimd.org/screenshot.png)
|
||||
|
||||
## Demo
|
||||
|
||||
* [Official demo](https://demo.codimd.org/)
|
||||
|
||||
## Configuration
|
||||
|
||||
You can configure CodiMD by editing this file `/var/www/codimd/config.json` using this the [documentation](https://github.com/codimd/server/blob/master/docs/configuration-config-file.md)
|
||||
|
||||
## Documentation
|
||||
|
||||
* Official documentation: https://hackmd.io/c/codimd-documentation/
|
||||
* YunoHost documentation: https://yunohost.org/#/app_codimd
|
||||
|
||||
## YunoHost specific features
|
||||
|
||||
#### Multi-user support
|
||||
|
||||
* Is LDAP supported? **Yes**
|
||||
* Can the app be used by multiple users? **Yes**
|
||||
|
||||
#### Supported architectures
|
||||
|
||||
* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/codimd/)
|
||||
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/codimd/)
|
||||
|
||||
## Links
|
||||
|
||||
* Report a bug: https://github.com/YunoHost-Apps/codimd_ynh/issues
|
||||
* Upstream app repository: https://github.com/codimd/server/
|
||||
* YunoHost website: https://yunohost.org/
|
||||
|
||||
---
|
||||
|
||||
Developer info
|
||||
----------------
|
||||
|
||||
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/codimd_ynh/tree/testing).
|
||||
|
||||
To try the testing branch, please proceed like that.
|
||||
```
|
||||
sudo yunohost app install https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
|
||||
or
|
||||
sudo yunohost app upgrade codimd -u https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
|
||||
```
|
||||
|
|
63
README_fr.md
Normal file
63
README_fr.md
Normal file
|
@ -0,0 +1,63 @@
|
|||
# CodiMD pour YunoHost
|
||||
|
||||
[![Niveau d'intégration](https://dash.yunohost.org/integration/codimd.svg)](https://dash.yunohost.org/appci/app/codimd) ![](https://ci-apps.yunohost.org/ci/badges/codimd.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/codimd.maintain.svg)
|
||||
[![Installer CodiMD avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=codimd)
|
||||
|
||||
*[Read this readme in english.](./README.md)*
|
||||
|
||||
> *Ce package vous permet d'installer CodiMD rapidement et simplement sur un serveur Yunohost.
|
||||
Si vous n'avez pas YunoHost, consultez [le guide](https://yunohost.org/#/install) pour apprendre comment l'installer.*
|
||||
|
||||
## Vue d'ensemble
|
||||
CodiMD est un service web de traitement de texte collaboratif en temps réel. Il utilise le langage Markdown.
|
||||
|
||||
**Version incluse :** 1.6.0
|
||||
|
||||
## Captures d'écran
|
||||
|
||||
![](https://demo.codimd.org/screenshot.png)
|
||||
|
||||
## Démo
|
||||
|
||||
* [Démo officielle](https://demo.codimd.org/)
|
||||
|
||||
## Configuration
|
||||
|
||||
Vous pouvez configurer CodiMD en modifiant le fichier `/var/www/codimd/config.json` et en vous aidant de la [documentation](https://github.com/codimd/server/blob/master/docs/configuration-config-file.md)
|
||||
|
||||
## Documentation
|
||||
|
||||
* Documentation officielle : https://hackmd.io/c/codimd-documentation/
|
||||
* Documentation YunoHost : https://yunohost.org/#/app_codimd_fr
|
||||
|
||||
## Caractéristiques spécifiques YunoHost
|
||||
|
||||
#### Support multi-utilisateur
|
||||
|
||||
* L'authentification LDAP est-elle prise en charge ? **Oui**
|
||||
* L'application peut-elle être utilisée par plusieurs utilisateurs ? **Oui**
|
||||
|
||||
#### Architectures supportées
|
||||
|
||||
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/codimd/)
|
||||
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/codimd/)
|
||||
|
||||
## Liens
|
||||
|
||||
* Signaler un bug : https://github.com/YunoHost-Apps/codimd_ynh/issues
|
||||
* Dépôt de l'application principale : https://github.com/codimd/server/
|
||||
* Site web YunoHost : https://yunohost.org/
|
||||
|
||||
---
|
||||
|
||||
Informations pour les développeurs
|
||||
----------------
|
||||
|
||||
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/codimd_ynh/tree/testing).
|
||||
|
||||
Pour essayer la branche testing, procédez comme suit.
|
||||
```
|
||||
sudo yunohost app install https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
|
||||
ou
|
||||
sudo yunohost app upgrade codimd -u https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
|
||||
```
|
22
check_process
Normal file
22
check_process
Normal file
|
@ -0,0 +1,22 @@
|
|||
;; Test complet
|
||||
; Manifest
|
||||
domain="domain.tld" (DOMAIN)
|
||||
admin="john" (USER)
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=1
|
||||
setup_root=1
|
||||
setup_nourl=0
|
||||
setup_private=1
|
||||
setup_public=1
|
||||
upgrade=1
|
||||
backup_restore=1
|
||||
multi_instance=1
|
||||
port_already_use=0
|
||||
change_url=0
|
||||
;;; Levels
|
||||
Level 5=auto
|
||||
;;; Options
|
||||
Email=
|
||||
Notification=none
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
var path = require('path');
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
{
|
||||
"production": {
|
||||
"protocolUseSSL": true,
|
||||
"domain": "__DOMAIN__",
|
||||
"port": __PORT__,
|
||||
"port": "__PORT__",
|
||||
"loglevel": "info",
|
||||
"useCDN": false,
|
||||
"allowGravatar": false,
|
||||
"allowFreeURL": true,
|
||||
"hsts": {
|
||||
"enable": true,
|
||||
"maxAgeSeconds": 31536000,
|
||||
|
@ -20,7 +20,7 @@
|
|||
"upgradeInsecureRequests": "auto",
|
||||
"addDefaults": true,
|
||||
"addDisqus": true,
|
||||
"addGoogleAnalytics": true
|
||||
"addGoogleAnalytics": false
|
||||
},
|
||||
"db": {
|
||||
"username": "__DB_USER__",
|
||||
|
@ -29,6 +29,19 @@
|
|||
"host": "localhost",
|
||||
"port": "5432",
|
||||
"dialect": "postgres"
|
||||
},
|
||||
"ldap": {
|
||||
"url": "ldap://127.0.0.1:389",
|
||||
"bindDn": null,
|
||||
"bindCredentials": null,
|
||||
"searchBase": "ou=users,dc=yunohost,dc=org",
|
||||
"searchFilter": "(&(|(objectclass=posixAccount))(uid={{username}})(permission=cn=__APP__.main,ou=permission,dc=yunohost,dc=org))",
|
||||
"usernameField": "cn",
|
||||
"useridField": "uid",
|
||||
"providerName": "YunoHost"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ location ^~ / {
|
|||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
||||
proxy_pass http://127.0.0.1:__PORT__/;
|
||||
proxy_pass http://127.0.0.1:__PORT__;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
|
@ -15,4 +15,11 @@ location ^~ / {
|
|||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# setup for image upload
|
||||
client_max_body_size 8192m;
|
||||
proxy_max_temp_file_size 8192m;
|
||||
|
||||
proxy_read_timeout 300;
|
||||
proxy_connect_timeout 300;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[Unit]
|
||||
Description=__APP__ daemon
|
||||
After=syslog.target network.target
|
||||
Description=__APP__: collaborative Markdown notes
|
||||
After=network.target
|
||||
After=postgresql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
|
@ -9,8 +10,10 @@ Group=__APP__
|
|||
WorkingDirectory=__FINALPATH__
|
||||
Environment="PATH=__ENV_PATH__"
|
||||
Environment="NODE_ENV=production"
|
||||
ExecStart=/usr/bin/yarn start
|
||||
ExecStart=__YNH_NPM__ start
|
||||
Restart=always
|
||||
PrivateTmp=true
|
||||
PrivateDevices=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
46
issue_template.md
Normal file
46
issue_template.md
Normal file
|
@ -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 CodiMD 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 codimd`*
|
||||
|
||||
**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 codimd
|
||||
```
|
||||
- *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.*
|
|
@ -3,39 +3,44 @@
|
|||
"id": "codimd",
|
||||
"packaging_format": 1,
|
||||
"description": {
|
||||
"en": "A collaborative editor to work on notes written in Markdown",
|
||||
"fr": "Un éditeur collaboratif pour travailler sur des notes en Markdown"
|
||||
"en": "Collaborative editor to work on notes written in Markdown",
|
||||
"fr": "Éditeur collaboratif pour travailler sur des notes en Markdown"
|
||||
},
|
||||
"version": "1.6.0~ynh1",
|
||||
"version": "1.6.0~ynh2",
|
||||
"url": "https://github.com/codimd/server",
|
||||
"license": "AGPL-v3",
|
||||
"license": "AGPL-3.0-only",
|
||||
"maintainer": {
|
||||
"name": "liberodark"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 3.6"
|
||||
"yunohost": ">= 3.8.1"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"multi_instance": true,
|
||||
"services": [
|
||||
"nginx"
|
||||
],
|
||||
"arguments": {
|
||||
"install": [{
|
||||
"install" : [
|
||||
{
|
||||
"name": "domain",
|
||||
"type": "domain",
|
||||
"ask": {
|
||||
"en": "Choose a domain name for CodiMD",
|
||||
"fr": "Choisissez un nom de domaine pour CodiMD"
|
||||
},
|
||||
"example": "example.com"
|
||||
"example": "codimd.domain.org"
|
||||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Is it a public site ?",
|
||||
"en": "Is it a public site?",
|
||||
"fr": "Est-ce un site public ?"
|
||||
},
|
||||
"help": {
|
||||
"en": "If enabled, CodiMD will be accessible by people who do not have an account. This can be changed later via the webadmin.",
|
||||
"fr": "Si cette case est cochée, CodiMD sera accessible aux personnes n’ayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin."
|
||||
},
|
||||
"default": true
|
||||
}
|
||||
]
|
||||
|
|
18
pull_request_template.md
Normal file
18
pull_request_template.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
## Problem
|
||||
- *Description of why you made this PR*
|
||||
|
||||
## Solution
|
||||
- *And how do you fix that problem*
|
||||
|
||||
## PR Status
|
||||
- [ ] Code finished.
|
||||
- [ ] Tested with Package_check.
|
||||
- [ ] Fix or enhancement tested.
|
||||
- [ ] Upgrade from last version tested.
|
||||
- [ ] Can be reviewed and tested.
|
||||
|
||||
## Package_check results
|
||||
---
|
||||
*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/codimd_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/codimd_ynh%20PR-NUM-%20(USERNAME)/)
|
|
@ -7,7 +7,7 @@
|
|||
# dependencies used by the app
|
||||
pkg_dependencies="postgresql apt-transport-https"
|
||||
|
||||
nodejs_version="10"
|
||||
nodejs_version=10
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
|
@ -19,4 +19,4 @@ nodejs_version="10"
|
|||
|
||||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
||||
#=================================================
|
||||
|
|
75
scripts/backup
Normal file
75
scripts/backup
Normal file
|
@ -0,0 +1,75 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
ynh_clean_check_starting
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
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)
|
||||
|
||||
#=================================================
|
||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||
#=================================================
|
||||
ynh_print_info --message="Declaring files to be backed up..."
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="$final_path"
|
||||
|
||||
#=================================================
|
||||
# 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 THE POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up the Postgresql database..."
|
||||
|
||||
ynh_psql_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)."
|
124
scripts/change_url
Normal file
124
scripts/change_url
Normal file
|
@ -0,0 +1,124 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
old_domain=$YNH_APP_OLD_DOMAIN
|
||||
old_path=$YNH_APP_OLD_PATH
|
||||
|
||||
new_domain=$YNH_APP_NEW_DOMAIN
|
||||
new_path=$YNH_APP_NEW_PATH
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
# Needed for helper "ynh_add_nginx_config"
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up $app before changing its url (may take a while)..." --weight=1
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
|
||||
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||
#=================================================
|
||||
|
||||
change_domain=0
|
||||
if [ "$old_domain" != "$new_domain" ]
|
||||
then
|
||||
change_domain=1
|
||||
fi
|
||||
|
||||
change_path=0
|
||||
if [ "$old_path" != "$new_path" ]
|
||||
then
|
||||
change_path=1
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# 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"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating Nginx web server configuration..." --weight=1
|
||||
|
||||
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
|
||||
# Change the path in the nginx config file
|
||||
if [ $change_path -eq 1 ]
|
||||
then
|
||||
# Make a backup of the original nginx config file if modified
|
||||
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||
# Set global variables for nginx helper
|
||||
domain="$old_domain"
|
||||
path_url="$new_path"
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
fi
|
||||
|
||||
# Change the domain for nginx
|
||||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# 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="systemd" --line_match="HTTP Server listening"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading Nginx web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Change of URL completed for $app" --last
|
223
scripts/install
223
scripts/install
|
@ -6,7 +6,6 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source ynh_add_extra_apt_repos__3
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
@ -14,6 +13,9 @@ source /usr/share/yunohost/helpers
|
|||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
ynh_clean_check_starting
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
|
@ -24,113 +26,81 @@ ynh_abort_if_errors
|
|||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path_url="/"
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Validating installation parameters..."
|
||||
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
||||
|
||||
final_path=/var/www/$app
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
# Register (book) web path
|
||||
ynh_webpath_register "$app" "$domain" $path_url
|
||||
|
||||
port=$(ynh_find_port 3000)
|
||||
|
||||
db_user=$app
|
||||
db_name=$app
|
||||
db_pass=$(ynh_string_random 20)
|
||||
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Storing installation settings..."
|
||||
ynh_script_progression --message="Storing installation settings..." --weight=2
|
||||
|
||||
ynh_app_setting_set "$app" domain "$domain"
|
||||
ynh_app_setting_set "$app" path $path_url
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
ynh_app_setting_set "$app" port "$port"
|
||||
ynh_app_setting_set "$app" db_pass "$db_pass"
|
||||
ynh_app_setting_set "$app" final_path "$final_path"
|
||||
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
||||
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
||||
|
||||
#==============================================
|
||||
# INSTALL POSTGRES
|
||||
#==============================================
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# FIND AND OPEN A PORT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring firewall..." --weight=2
|
||||
|
||||
# Find an available port
|
||||
port=$(ynh_find_port --port=3000)
|
||||
ynh_app_setting_set --app=$app --key=port --value=$port
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..." --weight=20
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
# Install Nodejs
|
||||
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
|
||||
# Install Yarn
|
||||
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
|
||||
ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
#=================================================
|
||||
# CREATE A POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
|
||||
|
||||
#==============================================
|
||||
# CREATE DB
|
||||
#==============================================
|
||||
ynh_script_progression --message="Creating a database..."
|
||||
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||
db_user=$db_name
|
||||
db_pwd=$(ynh_string_random --length=30)
|
||||
|
||||
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
||||
|
||||
ynh_psql_test_if_first_run
|
||||
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pass"
|
||||
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up source files..."
|
||||
ynh_script_progression --message="Setting up source files..." --weight=2
|
||||
|
||||
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 "$final_path"
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
|
||||
# Main config File
|
||||
ynh_replace_string "__PORT__" "$port" "../conf/config.json.example"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "../conf/config.json.example"
|
||||
ynh_replace_string "__PATH__" "${path_url:1}" "../conf/config.json.example"
|
||||
ynh_replace_string "__DB_USER__" "$db_user" "../conf/config.json.example"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/config.json.example"
|
||||
ynh_replace_string "__DB_PASS__" "$db_pass" "../conf/config.json.example"
|
||||
cp ../conf/config.json.example "$final_path"/config.json
|
||||
ynh_store_file_checksum "$final_path/config.json"
|
||||
|
||||
# DB Config File
|
||||
ynh_replace_string "__DB_USER__" "$db_user" "../conf/.sequelizerc.example"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/.sequelizerc.example"
|
||||
ynh_replace_string "__DB_PASS__" "$db_pass" "../conf/.sequelizerc.example"
|
||||
cp ../conf/.sequelizerc.example "$final_path"/.sequelizerc
|
||||
|
||||
#==============================================
|
||||
# INSTALL CODIMD
|
||||
#==============================================
|
||||
ynh_script_progression --message="Building application... (this will take some time and resources!)"
|
||||
|
||||
pushd "$final_path" || exit
|
||||
|
||||
# ---- This is copypasta from https://raw.githubusercontent.com/codimd/server/master/bin/setup
|
||||
if [ ! -f config.json ]; then
|
||||
cp config.json.example config.json
|
||||
fi
|
||||
|
||||
if [ ! -f .sequelizerc ]; then
|
||||
cp .sequelizerc.example .sequelizerc
|
||||
fi
|
||||
|
||||
yarn install --non-interactive
|
||||
yarn install --non-interactive --production=false # FIXME: this doesn't sounds like what we want to have for a real deployment ? idk
|
||||
# ---- End copypasta from https://raw.githubusercontent.com/codimd/server/master/bin/setup
|
||||
|
||||
yarn run build
|
||||
#node_modules/.bin/sequelize db:migrate
|
||||
popd || exit
|
||||
ynh_setup_source --dest_dir=$final_path
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring nginx web server..."
|
||||
ynh_script_progression --message="Configuring Nginx web server..." --weight=2
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
@ -138,50 +108,115 @@ ynh_add_nginx_config
|
|||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring system user..."
|
||||
ynh_script_progression --message="Configuring system user..." --weight=3
|
||||
|
||||
# Create a system user
|
||||
ynh_system_user_create "$app"
|
||||
chown -R "$app":"$app" "$final_path"
|
||||
ynh_system_user_create --username=$app --home_dir=$final_path
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#==============================================
|
||||
# INSTALL CODIMD
|
||||
#==============================================
|
||||
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=240
|
||||
|
||||
pushd "$final_path" || ynh_die
|
||||
|
||||
ynh_use_nodejs
|
||||
yarn install --frozen-lockfile
|
||||
ynh_exec_warn_less yarn run build
|
||||
|
||||
popd || ynh_die
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring a systemd service..."
|
||||
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
||||
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="../conf/systemd.service"
|
||||
|
||||
ynh_replace_string "__APP__" "$app" "../conf/systemd.service"
|
||||
ynh_replace_string "__FINALPATH__" "$final_path" "../conf/systemd.service"
|
||||
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
||||
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
|
||||
ynh_add_systemd_config
|
||||
|
||||
yunohost service add "$app" --description "CodiMD daemon"
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Modifying a config file..."
|
||||
|
||||
# Main config File
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__PATH__" --replace_string="${path_url:1}" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/config.json.example"
|
||||
|
||||
cp ../conf/config.json.example "$final_path/config.json"
|
||||
|
||||
ynh_store_file_checksum --file="$final_path/config.json"
|
||||
|
||||
# DB Config File
|
||||
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/.sequelizerc.example"
|
||||
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/.sequelizerc.example"
|
||||
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/.sequelizerc.example"
|
||||
|
||||
cp ../conf/.sequelizerc.example "$final_path/.sequelizerc"
|
||||
|
||||
ynh_store_file_checksum --file="$final_path/.sequelizerc"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Securing files and directories..."
|
||||
|
||||
# Set permissions to app files
|
||||
chown -R $app:$app $final_path
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring log rotation..." --weight=2
|
||||
|
||||
# Use logrotate to manage application logfile(s)
|
||||
ynh_use_logrotate
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
yunohost service add $app --description "Collaborative Markdown notes" --log="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
||||
|
||||
ynh_script_progression --message="Starting $app..."
|
||||
|
||||
ynh_systemd_action --service_name="$app" --action="start"
|
||||
# Start a systemd service
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server listening"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring SSOwat..." --weight=1
|
||||
|
||||
ynh_script_progression --message="Configuring SSOwat..."
|
||||
|
||||
# If app is public, add url to SSOWat conf as skipped_uris
|
||||
if [ "$is_public" -eq 1 ]; then
|
||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
# 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
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Reloading nginx web server..."
|
||||
ynh_script_progression --message="Reloading Nginx web server..." --weight=2
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
|
|
|
@ -12,32 +12,33 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..."
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
db_name=$app
|
||||
db_user=$app
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
db_user=$db_name
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE SERVICE FROM ADMIN PANEL
|
||||
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
# Remove a service from the admin panel, added by `yunohost service add`
|
||||
if yunohost service status "$app" >/dev/null 2>&1
|
||||
# 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"
|
||||
ynh_script_progression --message="Removing $app service..." --weight=1
|
||||
yunohost service remove $app
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STOP AND REMOVE SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping and removing the systemd service"
|
||||
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
|
||||
|
||||
# Remove the dedicated systemd config
|
||||
ynh_remove_systemd_config
|
||||
|
@ -45,15 +46,15 @@ ynh_remove_systemd_config
|
|||
#=================================================
|
||||
# REMOVE THE POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the PostgreSQL database"
|
||||
ynh_script_progression --message="Removing the PostgreSQL database..." --weight=2
|
||||
|
||||
# Remove a database if it exists, along with the associated user
|
||||
ynh_psql_remove_db "$db_name" "$db_name"
|
||||
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing dependencies"
|
||||
ynh_script_progression --message="Removing dependencies..." --weight=1
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
@ -63,31 +64,39 @@ ynh_remove_nodejs
|
|||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing app main directory"
|
||||
ynh_script_progression --message="Removing app main directory..." --weight=6
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove "$final_path"
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing nginx web server configuration"
|
||||
ynh_script_progression --message="Removing Nginx web server configuration..." --weight=5
|
||||
|
||||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
|
||||
|
||||
# Remove the app-specific logrotate config
|
||||
ynh_remove_logrotate
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# REMOVE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the dedicated system user"
|
||||
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
|
||||
|
||||
# Delete a system user
|
||||
ynh_system_user_delete "$app"
|
||||
ynh_system_user_delete --username=$app
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removal of $app completed"
|
||||
ynh_script_progression --message="Removal of $app completed" --last
|
||||
|
|
145
scripts/restore
Normal file
145
scripts/restore
Normal file
|
@ -0,0 +1,145 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
ynh_clean_check_starting
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
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)
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
ynh_script_progression --message="Validating restoration parameters..." --weight=2
|
||||
|
||||
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
||||
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die --message="There is already a directory: $final_path "
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# 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"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the app main directory..." --weight=60
|
||||
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring user rights..."
|
||||
|
||||
# Restore permissions on app files
|
||||
chown -R $app:$app $final_path
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reinstalling dependencies..." --weight=7
|
||||
|
||||
# Define and install dependencies
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
# Install Nodejs
|
||||
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
|
||||
# Install Yarn
|
||||
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6
|
||||
|
||||
ynh_psql_test_if_first_run
|
||||
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
||||
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEMD
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the systemd configuration..." --weight=5
|
||||
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
||||
systemctl enable $app.service
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
yunohost service add $app --description "collaborative Markdown editor" --log "/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server listening"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=5
|
||||
|
||||
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading Nginx web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoration completed for $app" --last
|
225
scripts/upgrade
Normal file
225
scripts/upgrade
Normal file
|
@ -0,0 +1,225 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=2
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
|
||||
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)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Checking version..."
|
||||
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=120
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_script_progression --message="Upgrading source files..." --weight=160
|
||||
|
||||
# Create a temporary directory
|
||||
tmpdir="$(mktemp -d)"
|
||||
|
||||
# Backup the config file in the temp dir
|
||||
cp -a "$final_path/config.json" "$tmpdir/config.json"
|
||||
cp -a "$final_path/.sequelizerc" "$tmpdir/.sequelizerc"
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file=$final_path
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir=$final_path
|
||||
|
||||
#Copy the admin saved settings from tmp directory to final path
|
||||
cp -a "$tmpdir/config.json" "$final_path/config.json"
|
||||
cp -a "$tmpdir/.sequelizerc" "$final_path/.sequelizerc"
|
||||
|
||||
# Remove the tmp directory securely
|
||||
ynh_secure_remove --file="$tmpdir"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading Nginx web server configuration..." --weight=2
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..." --weight=18
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
# Install Nodejs
|
||||
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
|
||||
# Install Yarn
|
||||
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
||||
|
||||
# Create a dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#==============================================
|
||||
# INSTALL CODIMD
|
||||
#==============================================
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=160
|
||||
|
||||
pushd "$final_path" || ynh_die
|
||||
|
||||
ynh_use_nodejs
|
||||
yarn install --frozen-lockfile
|
||||
ynh_exec_warn_less yarn run build
|
||||
|
||||
popd || ynh_die
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Modifying a config file..." --weight=2
|
||||
|
||||
ynh_backup_if_checksum_is_different --file="$final_path/config.json"
|
||||
|
||||
# Main config File
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__PATH__" --replace_string="${path_url:1}" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/config.json.example"
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/config.json.example"
|
||||
|
||||
cp ../conf/config.json.example "$final_path/config.json"
|
||||
|
||||
# Recalculate and store the checksum of the file for the next upgrade.
|
||||
ynh_store_file_checksum --file="$final_path/config.json"
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=2
|
||||
|
||||
# Use logrotate to manage app-specific logfile(s)
|
||||
ynh_use_logrotate --non-append
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring a systemd service..." --weight=2
|
||||
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="../conf/systemd.service"
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Securing files and directories..."
|
||||
|
||||
# Set permissions on app files
|
||||
chown -R $app:$app $final_path
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
|
||||
|
||||
# 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
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
yunohost service add $app --description "Collaborative Markdown notes" --log="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server listening"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading Nginx web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Upgrade of $app completed" --last
|
|
@ -1,294 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Pin a repository.
|
||||
#
|
||||
# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append]
|
||||
# | arg: -p, --package - Packages concerned by the pin. Or all, *.
|
||||
# | arg: -i, --pin - Filter for the pin.
|
||||
# | arg: -p, --priority - Priority for the pin
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
#
|
||||
# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning.
|
||||
#
|
||||
ynh_pin_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pirna
|
||||
declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append )
|
||||
local package
|
||||
local pin
|
||||
local priority
|
||||
local name
|
||||
local append
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
package="${package:-*}"
|
||||
priority=${priority:-50}
|
||||
name="${name:-$app}"
|
||||
append=${append:-0}
|
||||
|
||||
if [ "$append" -eq 1 ]
|
||||
then
|
||||
append="tee -a"
|
||||
else
|
||||
append="tee"
|
||||
fi
|
||||
|
||||
mkdir -p "/etc/apt/preferences.d"
|
||||
echo "Package: $package
|
||||
Pin: $pin
|
||||
Pin-Priority: $priority" \
|
||||
| $append "/etc/apt/preferences.d/$name"
|
||||
}
|
||||
|
||||
# Add a repository.
|
||||
#
|
||||
# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append]
|
||||
# | arg: -u, --uri - Uri of the repository.
|
||||
# | arg: -s, --suite - Suite of the repository.
|
||||
# | arg: -c, --component - Component of the repository.
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
#
|
||||
# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable
|
||||
# uri suite component
|
||||
# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable
|
||||
#
|
||||
ynh_add_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=uscna
|
||||
declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append )
|
||||
local uri
|
||||
local suite
|
||||
local component
|
||||
local name
|
||||
local append
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
append=${append:-0}
|
||||
|
||||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="tee -a"
|
||||
else
|
||||
append="tee"
|
||||
fi
|
||||
|
||||
mkdir -p "/etc/apt/sources.list.d"
|
||||
# Add the new repo in sources.list.d
|
||||
echo "deb $uri $suite $component" \
|
||||
| $append "/etc/apt/sources.list.d/$name.list"
|
||||
}
|
||||
|
||||
# Add an extra repository correctly, pin it and get the key.
|
||||
#
|
||||
# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append]
|
||||
# | arg: -r, --repo - Complete url of the extra repository.
|
||||
# | arg: -k, --key - url to get the public key.
|
||||
# | arg: -p, --priority - Priority for the pin
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
ynh_install_extra_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=rkpna
|
||||
declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append )
|
||||
local repo
|
||||
local key
|
||||
local priority
|
||||
local name
|
||||
local append
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
append=${append:-0}
|
||||
key=${key:-0}
|
||||
priority=${priority:-}
|
||||
|
||||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="--append"
|
||||
wget_append="tee -a"
|
||||
else
|
||||
append=""
|
||||
wget_append="tee"
|
||||
fi
|
||||
|
||||
# Split the repository into uri, suite and components.
|
||||
# Remove "deb " at the beginning of the repo.
|
||||
repo="${repo#deb }"
|
||||
|
||||
# Get the uri
|
||||
local uri="$(echo "$repo" | awk '{ print $1 }')"
|
||||
|
||||
# Get the suite
|
||||
local suite="$(echo "$repo" | awk '{ print $2 }')"
|
||||
|
||||
# Get the components
|
||||
local component="${repo##$uri $suite }"
|
||||
|
||||
# Add the repository into sources.list.d
|
||||
ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append
|
||||
|
||||
# Pin the new repo with the default priority, so it won't be used for upgrades.
|
||||
# Build $pin from the uri without http and any sub path
|
||||
local pin="${uri#*://}"
|
||||
pin="${pin%%/*}"
|
||||
# Set a priority only if asked
|
||||
if [ -n "$priority" ]
|
||||
then
|
||||
priority="--priority=$priority"
|
||||
fi
|
||||
ynh_pin_repo --package="*" --pin="origin \"$pin\"" "$priority" --name="$name" $append
|
||||
|
||||
# Get the public key for the repo
|
||||
if [ -n "$key" ]
|
||||
then
|
||||
mkdir -p "/etc/apt/trusted.gpg.d"
|
||||
wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/"$name".gpg > /dev/null
|
||||
fi
|
||||
|
||||
# Update the list of package with the new repo
|
||||
ynh_package_update
|
||||
}
|
||||
|
||||
# Remove an extra repository and the assiociated configuration.
|
||||
#
|
||||
# usage: ynh_remove_extra_repo [--name=name]
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
ynh_remove_extra_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=n
|
||||
declare -Ar args_array=( [n]=name= )
|
||||
local name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
|
||||
ynh_secure_remove "/etc/apt/sources.list.d/$name.list"
|
||||
ynh_secure_remove "/etc/apt/preferences.d/$name"
|
||||
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg"
|
||||
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc"
|
||||
|
||||
# Update the list of package to exclude the old repo
|
||||
ynh_package_update
|
||||
}
|
||||
|
||||
# Install packages from an extra repository properly.
|
||||
#
|
||||
# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name]
|
||||
# | arg: -r, --repo - Complete url of the extra repository.
|
||||
# | arg: -p, --package - The packages to install from this extra repository
|
||||
# | arg: -k, --key - url to get the public key.
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
ynh_install_extra_app_dependencies () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=rpkn
|
||||
declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= )
|
||||
local repo
|
||||
local package
|
||||
local key
|
||||
local name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
key=${key:-0}
|
||||
|
||||
# Set a key only if asked
|
||||
if [ -n "$key" ]
|
||||
then
|
||||
key="--key=$key"
|
||||
fi
|
||||
# Add an extra repository for those packages
|
||||
ynh_install_extra_repo --repo="$repo" "$key" --priority=995 --name="$name"
|
||||
|
||||
# Install requested dependencies from this extra repository.
|
||||
ynh_add_app_dependencies --package="$package"
|
||||
|
||||
# Remove this extra repository after packages are installed
|
||||
ynh_remove_extra_repo --name="$app"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
||||
# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies
|
||||
|
||||
# Define and install dependencies with a equivs control file
|
||||
# This helper can/should only be called once per app
|
||||
#
|
||||
# usage: ynh_install_app_dependencies dep [dep [...]]
|
||||
# | arg: dep - the package name to install in dependence
|
||||
# You can give a choice between some package with this syntax : "dep1|dep2"
|
||||
# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
|
||||
# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_install_app_dependencies () {
|
||||
local dependencies=$@
|
||||
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
|
||||
dependencies=${dependencies//|/ | }
|
||||
local manifest_path="../manifest.json"
|
||||
if [ ! -e "$manifest_path" ]; then
|
||||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||
fi
|
||||
|
||||
local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file.
|
||||
if [ ${#version} -eq 0 ]; then
|
||||
version="1.0"
|
||||
fi
|
||||
local dep_app=${app//_/-} # Replace all '_' by '-'
|
||||
|
||||
# Handle specific versions
|
||||
if [[ "$dependencies" =~ [\<=\>] ]]
|
||||
then
|
||||
# Replace version specifications by relationships syntax
|
||||
# https://www.debian.org/doc/debian-policy/ch-relationships.html
|
||||
# Sed clarification
|
||||
# [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice.
|
||||
# [\<=\>] matches < = or >
|
||||
# \+ matches one or more occurence of the previous characters, for >= or >>.
|
||||
# [^,]\+ matches all characters except ','
|
||||
# Ex: package>=1.0 will be replaced by package (>= 1.0)
|
||||
dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')"
|
||||
fi
|
||||
|
||||
cat > /tmp/"${dep_app}"-ynh-deps.control << EOF # Make a control file for equivs-build
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Package: ${dep_app}-ynh-deps
|
||||
Version: ${version}
|
||||
Depends: ${dependencies}
|
||||
Architecture: all
|
||||
Description: Fake package for $app (YunoHost app) dependencies
|
||||
This meta-package is only responsible of installing its dependencies.
|
||||
EOF
|
||||
ynh_package_install_from_equivs /tmp/"${dep_app}"-ynh-deps.control \
|
||||
|| ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies
|
||||
rm /tmp/"${dep_app}"-ynh-deps.control
|
||||
ynh_app_setting_set --app="$app" --key=apt_dependencies --value="$dependencies"
|
||||
}
|
||||
|
||||
ynh_add_app_dependencies () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pr
|
||||
declare -Ar args_array=( [p]=package= [r]=replace)
|
||||
local package
|
||||
local replace
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
replace=${replace:-0}
|
||||
|
||||
local current_dependencies=""
|
||||
if [ "$replace" -eq 0 ]
|
||||
then
|
||||
local dep_app=${app//_/-} # Replace all '_' by '-'
|
||||
if ynh_package_is_installed --package="${dep_app}-ynh-deps"
|
||||
then
|
||||
current_dependencies="$(dpkg-query --show --showformat='${Depends}' "${dep_app}"-ynh-deps) "
|
||||
fi
|
||||
|
||||
current_dependencies=${current_dependencies// | /|}
|
||||
fi
|
||||
|
||||
ynh_install_app_dependencies "${current_dependencies}${package}"
|
||||
}
|
Loading…
Reference in a new issue