1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/limesurvey_ynh.git synced 2024-09-03 19:36:32 +02:00

Merge pull request #37 from YunoHost-Apps/testing

Upgrade to LimeSurvey 3.5
This commit is contained in:
ljf (zamentur) 2018-03-14 19:12:55 +01:00 committed by GitHub
commit 941e3047ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 877 additions and 1054 deletions

View file

@ -1,21 +1,71 @@
LimeSurvey for YunoHost # LimeSurvey for YunoHost
===============
[![Integration level](https://dash.yunohost.org/integration/limesurvey.svg)](https://ci-apps.yunohost.org/jenkins/job/limesurvey%20%28Community%29/lastBuild/consoleFull)
[![Install LimeSurvey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=limesurvey)
> *This package allow you to install LimeSurvey quickly and simply on a YunoHost server.
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
## Overview
LimeSurvey is used to create advanced poll. LimeSurvey is used to create advanced poll.
http://www.limesurvey.org/ **Shipped version:** 2.62.5
**Package by:** ljf (I will maintain this package at least until beggining of 2018)
**Patches author:** Shnoulle
**Categories:** Productivity, Poll **Categories:** Productivity, Poll
**Upgrade this package:** ## Screenshots
`sudo yunohost app upgrade --verbose LimeSurvey -u https://github.com/YunoHost-Apps/limesurvey_ynh`
**Multi-user:** Yes. ![](https://www.limesurvey.org/images/news/LimeSurvey3Beta/generalsettings.PNG)
**Private/Public mode:** In private mode, only authorized YunoHost members can create poll, with the public mode, it's possible to create account to people with no YunoHost account. ## Configuration
Before to run the install YunoHost ask you an admin user, you can use it to connecte you on https://your_limesurvey_url/admin/
## Documentation
* YunoHost documentation: There no other documentations, feel free to contribute.
## YunoHost specific features
* In private mode, only authorized YunoHost members can create poll, with the public mode, it's possible to create account to people with no YunoHost account.
* SSO and LDAP are configured.
* Login secured by fail2ban
#### Multi-users support
Not supported.
#### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/limesurvey%20(Community)/)
* ARMv8-A - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/limesurvey%20(Community)%20(%7EARM%7E)/)
## Limitations
## Additionnal informations
## Links
* Report a bug: https://github.com/YunoHost-Apps/limesurvey_ynh/issues
* Website: https://www.limesurvey.org
* YunoHost website: https://yunohost.org/
---
Developers infos
----------------
**Package by:** ljf
**Patches author:** Shnoulle
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/limesurvey_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/limesurvey_ynh/tree/testing --verbose
or
sudo yunohost app upgrade leed -u https://github.com/YunoHost-Apps/limesurvey_ynh/tree/testing --verbose
```
**SSO/LDAP:** SSO and LDAP are configured.

117
YEP.md Normal file
View file

@ -0,0 +1,117 @@
#### [Level 0](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-0)
[YEP 1.1 - Nommer son app et son dépot](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11)
`Validated`
[YEP 1.2 - Inscrire l'app sur un "répertoire" connu](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-12)
`Validated`
#### [Level 1](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-1)
[YEP 2.2 - Utiliser bash pour les scripts principaux](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-22)
`Validated`
[YEP 2.5 - Copier correctement des fichiers](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-25)
`Don't know`
[YEP 2.7 - Donner des permissions suffisantes aux instructions bash](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-27)
`Validated`
[YEP 2.15 - Suivre les instructions d'installation de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-215)
`Validated`
#### [Level 2](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-2)
[YEP 1.5 - Mettre à jour régulièrement le statut de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11)
`Validated`
[YEP 2.18.2 - Gérer l'installation à la racine dun nom de domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2182)
`Validated` - *Automatically verified.*
[YEP 2.18.3 - Gérer l'installation sur un sous-domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2183)
`Validated` - *Automatically verified.*
[YEP 2.18.4 - Gérer l'installation sur un chemin /path](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2184)
`Validated` - *Automatically verified.*
[YEP 4.6 - Gère le multi-instance](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11)
`Validated` - *Automatically verified.*
#### [Level 3](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-3)
[YEP 2.3 - Sauvegarder les réponses lors de l'installation](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-23)
`Validated`
#### [Level 4](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-4)
[YEP 4.1 - Lier au ldap](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-41)
`Validated`
[YEP 4.2 - Lier l'authentification au sso](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-42)
`Validated`
#### [Level 5](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-5)
[YEP 1.3 - Indiquer la licence associée au paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13)
`Validated`
[YEP 2.1 - Respecter le format du manifeste](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-21)
`Validated` - *Automatically verified.*
[YEP 2.12 - Utiliser les commandes pratiques (helpers)](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-212)
`Validated`
[YEP 2.18.1 - Lancer le script d'installation d'une webapp correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2181)
`Validated`
#### [Level 6](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-6)
[YEP 1.4 - Informer sur l'intention de maintenir un paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-14)
`Validated`
[YEP 1.6 - Se tenir informé sur l'évolution du packaging d'apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-16)
`Validated`
[YEP 1.7 - Ajouter l'app à l'organisation YunoHost-Apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-17)
`Validated` - *Automatically verified.*
[YEP 1.8 - Publier des demandes de test](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-18)
`Not yet validated`
[YEP 1.9 - Documenter l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-19)
`Validated`
[YEP 1.10 - Garder un historique de version propre](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-110)
`Not yet validated`
[YEP 2.9 - Enlever toutes traces de l'app lors de la suppression](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-29)
`Validated`
[YEP 3.3 - Faciliter le contrôle de l'intégrité des sources](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-33)
`Validated`
[YEP 3.5 - Suivre les recommendations de la documentation de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-35)
`Validated`
[YEP 3.6 - Mettre à jour les versions contenant des CVE](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-36)
`Validated`
[YEP 4.3 - Fournir un script de sauvegarde YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-43)
`Validated` - *Automatically verified.*
[YEP 4.4 - Fournir un script de restauration YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-44)
`Validated` - *Automatically verified.*
#### [Level 7](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-7)
[YEP 2.6 - Annuler l'action si les valeurs d'entrées sont incorrectes](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-26)
`Validated`
[YEP 3.2 - Ouvrir un port correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-32)
`Not applicable`
#### [Level 8](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-8)
[YEP 2.4 - Détecter et gérer les erreurs](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-24)
`Validated`
[YEP 2.8 - Modifier correctement une configuration système](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-28)
`Validated`
[YEP 2.16 - Vérifier la disponibilité des dépendances sur ARM, x86 et x64](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-216)
`Not yet validated` - *Automatically verified.*
[YEP 2.18.5 - Gérer la tuile YunoHost pour faciliter la navigation entre les applications](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2185)
`Validated`
[YEP 3.4 - Isoler l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-34)
`Partially validated`
[YEP 4.5 - Utiliser les hooks](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-45)
`Validated`
#### [Level 9](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-9)
[YEP 2.10 - Configurer les logs de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-210)
`Not applicable`
[YEP 2.11 - Utiliser une variable plutôt que l'app id directement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-211)
`Validated`
[YEP 2.13 - Traduire le paquet en anglais](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-213)
`Validated`
[YEP 2.14 - Remplir correctement un fichier de conf](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-214)
`Validated`
[YEP 2.17 - Prendre en compte la version d'origine lors des mises à jour](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-217)
`Validated`
[YEP 4.2.1 - Déconnexion](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-421)
`Not yet validated`
#### Other YEP
[YEP 3.1 - Ne pas demander ou stocker de mot de passe LDAP](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-31)
`Validated`
[YEP 4.7 - Ajouter un module à la CLI](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-47)
`Not applicable`
[YEP 4.8 - Ajouter un module à l'admin web](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-48)
`Not applicable`
State of each YEP can be one of these: `Validated`, `Partially validated`, `Not yet validated`, `Not applicable`, `Don't know`.

View file

@ -1,3 +0,0 @@
SOURCE_URL=https://github.com/LimeSurvey/LimeSurvey/archive/2.64.5+170331.tar.gz
SOURCE_SUM=ede99fb149feed4a60ea83e540263c912a68fb46c7fca98cb7ff7c5d474f3dc4
SOURCE_FILE=limesurvey2.64.5+170331.tar.gz

View file

@ -14,24 +14,32 @@
setup_private=0 setup_private=0
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=a451e536d79ff0d2b73f3c0d888243a567e7c77e
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
wrong_user=1 wrong_user=1
wrong_path=1 wrong_path=1
incorrect_path=1 incorrect_path=1
corrupt_source=0 corrupt_source=1
fail_download_source=0 fail_download_source=1
port_already_use=0 port_already_use=0
final_path_already_use=0 final_path_already_use=1
change_url=0
;;; Levels ;;; Levels
Level 1=auto Level 1=auto
Level 2=auto Level 2=auto
Level 3=auto Level 3=auto
Level 4=1 Level 4=1
# https://github.com/YunoHost-Apps/limesurvey_ynh/issues/10 Level 5=auto
Level 5=1
Level 6=auto Level 6=auto
Level 7=auto Level 7=auto
Level 8=0 Level 8=0
Level 9=0 Level 9=0
Level 10=0 Level 10=0
;;; Options
Email=ljf+libresurvey_ynh@reflexlibre.net
Notification=down
;;; Upgrade options
; commit=a451e536d79ff0d2b73f3c0d888243a567e7c77e
name=2.62.5-2 a451e536d79ff0d2b73f3c0d888243a567e7c77e
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=en&is_public=1&

3
conf/app.src Normal file
View file

@ -0,0 +1,3 @@
SOURCE_URL=https://github.com/LimeSurvey/LimeSurvey/archive/3.5.0+180309.tar.gz
SOURCE_SUM=2e55d6123a6f53a8ae7b909fcc0bb435469e995ab4815f86d2b01990aeb76734
SOURCE_FILENAME=limesurvey-3-5-0-180309.tar.gz

View file

@ -9,7 +9,6 @@ INSERT INTO `lime_plugins` (`id`, `name`, `active`) VALUES
(9,'AuthLDAP',0); (9,'AuthLDAP',0);
INSERT INTO `lime_permissions` (`id`, `entity`, `entity_id`, `uid`, `permission`, `create_p`, `read_p`, `update_p`, `delete_p`, `import_p`, `export_p`) VALUES INSERT INTO `lime_permissions` (`id`, `entity`, `entity_id`, `uid`, `permission`, `create_p`, `read_p`, `update_p`, `delete_p`, `import_p`, `export_p`) VALUES
(1,'global',0,1,'superadmin',0,1,0,0,0,0),
(2,'global',0,2,'auth_ldap',0,1,0,0,0,0), (2,'global',0,2,'auth_ldap',0,1,0,0,0,0),
(3,'global',0,2,'surveys',1,0,0,0,0,0); (3,'global',0,2,'surveys',1,0,0,0,0,0);
@ -41,8 +40,6 @@ INSERT INTO `lime_plugin_settings` (`id`, `plugin_id`, `model`, `model_id`, `key
INSERT INTO `lime_settings_global` VALUES ('defaultlang','{{ language }}'),('AssetsVersion','2620'); INSERT INTO `lime_settings_global` VALUES ('defaultlang','{{ language }}'),('AssetsVersion','2620');
INSERT INTO `lime_users` VALUES (1,'{{ admin }}','9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08','Administrator',0,'{{ language }}','','default','default','default',NULL,1,'2017-02-02 01:03:08',NULL);
{% if is_public == "1" %} {% if is_public == "1" %}
UPDATE `lime_plugin_settings` SET value='\"0\"' WHERE `id`=21; UPDATE `lime_plugin_settings` SET value='\"0\"' WHERE `id`=21;
{% endif %} {% endif %}

3
conf/libreform.src Normal file
View file

@ -0,0 +1,3 @@
SOURCE_URL=https://github.com/zamentur/libreform/archive/40fad776c33271ecc028b9260fb7f9e300998e5f.tar.gz
SOURCE_SUM=4c0a96d610c6740ff7467cf1916a923949bf4c00e99a3cd33509335f884e138b
SOURCE_FILENAME=libreform-40fad776c33271ecc028b9260fb7f9e300998e5f.tar.gz

View file

@ -1,9 +1,14 @@
location {{ path }} { {% if path_url != "/" %}
alias {{ local_path }}/; rewrite ^{{ path_url }}$ {{ path_url }}/ permanent;
{% else %}
{% set path_url = "" %}
{% endif %}
location {{ path_url }}/ {
alias {{ final_path }}/;
index index.php; index index.php;
# if (!-e $request_filename) # if (!-e $request_filename)
#{ #{
# rewrite ^(.+)$ {{ path }}/index.php?q=$1 last; # rewrite ^(.+)$ {{ path_url }}/index.php?q=$1 last;
#} #}
if ($scheme = http) { if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;
@ -24,6 +29,6 @@ location {{ path }} {
include conf.d/yunohost_panel.conf.inc; include conf.d/yunohost_panel.conf.inc;
} }
location ~ ^{{ path }}(data|config|\.ht|db_structure\.xml|README) { location ~ ^{{ path_url }}(data|config|\.ht|db_structure\.xml|README) {
deny all; deny all;
} }

View file

@ -340,7 +340,7 @@ request_terminate_timeout = 1d
; Chdir to this directory at the start. ; Chdir to this directory at the start.
; Note: relative path can be used. ; Note: relative path can be used.
; Default Value: current directory or / when chroot ; Default Value: current directory or / when chroot
chdir = {{ local_path }} chdir = {{ final_path }}
; Redirect worker stdout and stderr into main error log. If not set, stdout and ; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs. ; stderr will be redirected to /dev/null according to FastCGI specs.

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
# TODO delete user with LimeSurvey cli # TODO delete user with LimeSurvey cli
# An action need to be added to the cli with a patch # An action need to be added to the cli with a patch
echo "[warn] You may need to delete this user in your LimeSurvey instances" echo "[warn] You may need to delete this user in your LibreSurvey instances"

View file

@ -2,7 +2,7 @@
"name": "LimeSurvey", "name": "LimeSurvey",
"id": "limesurvey", "id": "limesurvey",
"packaging_format": 1, "packaging_format": 1,
"version": "2.62.2", "version": "3.5.0-4",
"description": { "description": {
"en": "LimeSurvey is used to create advanced poll.", "en": "LimeSurvey is used to create advanced poll.",
"fr": "LimeSurvey est un outil de création et diffusion de sondage en ligne." "fr": "LimeSurvey est un outil de création et diffusion de sondage en ligne."
@ -10,12 +10,12 @@
"license": "GPL-2.0+", "license": "GPL-2.0+",
"maintainer": { "maintainer": {
"name": "ljf", "name": "ljf",
"email": "ljf@grimaud.me", "email": "ljf+limesurvey_ynh@reflexlibre.net",
"url": "http://www.limesurvey.org/" "url": "https://reflexlibre.net"
}, },
"url": "https://www.limesurvey.org/", "url": "https://www.limesurvey.org/",
"requirements": { "requirements": {
"yunohost": ">= 2.4" "yunohost": ">= 2.7.2"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [

View file

@ -1,106 +0,0 @@
From 7ca49326dafe4d9896e67aebe414edcd3ce8c1af Mon Sep 17 00:00:00 2001
From: Denis Chenu <denis@sondages.pro>
Date: Thu, 19 Jan 2017 00:02:45 +0100
Subject: [PATCH] [feature] Allow update via PHP cli
---
application/commands/UpdateCommand.php | 90 ++++++++++++++++++++++++++++++++++
1 files changed, 90 insertions(+)
create mode 100644 application/commands/UpdateCommand.php
diff --git a/application/commands/UpdateCommand.php b/application/commands/UpdateCommand.php
new file mode 100644
index 0000000..41ef107
--- /dev/null
+++ b/application/commands/UpdateCommand.php
@@ -0,0 +1,90 @@
+<?php
+ /*
+ * @author Denis Chenu <denis@sondages.pro>
+ * @license GPL v3
+ * @version 0.1
+ *
+ * Copyright (C) 2017 Denis Chenu
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+class UpdateCommand extends CConsoleCommand
+{
+ public function run(){
+ $this->_setConfigs();
+ $newDbVersion = (float)Yii::app()->getConfig('dbversionnumber');
+ $currentDbVersion = (float)Yii::app()->getConfig('DBVersion');
+ if($newDbVersion > $currentDbVersion){
+ echo "Update ".Yii::app()->db->connectionString.", prefix :".Yii::app()->db->tablePrefix." from {$currentDbVersion} to {$newDbVersion}\n";
+ Yii::import('application.helpers.common_helper', true);
+ Yii::import('application.helpers.update.updatedb_helper', true);
+ $result=db_upgrade_all($currentDbVersion);/* @todo : fix bad echoing here */
+ if ($result) {
+ //printf(gT("Database has been successfully upgraded to version %s"),$dbversionnumber)."\n";
+ echo "Database has been successfully upgraded to version $newDbVersion \n";
+ } else {
+ //echo gT("Please fix this error in your database and try again")."\n";
+ echo "Please fix this error in your database and try again\n";
+ }
+ } else {
+ echo "no need update ".$newDbVersion ." ". $currentDbVersion ."\n";
+ }
+ }
+
+ /**
+ * Fonction to set all needed (and unneeded) config
+ * @return void
+ */
+ private function _setConfigs(){
+ /* default config */
+ $aDefaultConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config-defaults.php');
+ foreach($aDefaultConfigs as $sConfig=>$defaultConfig){
+ Yii::app()->setConfig($sConfig,$defaultConfig);
+ }
+ /* Fix for badly set rootdir */
+ $sRootDir=realpath(Yii::app()->basePath. DIRECTORY_SEPARATOR . "..") ;
+ Yii::app()->setConfig('rootdir',$sRootDir);
+ Yii::app()->setConfig('publicdir',$sRootDir);
+ Yii::app()->setConfig('homedir',$sRootDir);
+ Yii::app()->setConfig('tempdir',$sRootDir.DIRECTORY_SEPARATOR."tmp");
+ Yii::app()->setConfig('imagedir',$sRootDir.DIRECTORY_SEPARATOR."images");
+ Yii::app()->setConfig('uploaddir',$sRootDir.DIRECTORY_SEPARATOR."upload");
+ Yii::app()->setConfig('standardtemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."templates");
+ Yii::app()->setConfig('usertemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."templates");
+ Yii::app()->setConfig('styledir',$sRootDir.DIRECTORY_SEPARATOR."styledir");
+ /* version */
+ $aVersionConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'version.php');
+ foreach($aVersionConfigs as $sConfig=>$versionConfig){
+ Yii::app()->setConfig($sConfig,$versionConfig);
+ }
+ /* LS 3 version */
+ Yii::app()->setConfig('runtimedir',$sRootDir.DIRECTORY_SEPARATOR."tmp".DIRECTORY_SEPARATOR."runtime");
+ if(file_exists(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'))
+ {
+ $config = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php');
+ if(is_array($config['config']) && !empty($config['config']))
+ {
+ foreach($config['config'] as $key=>$value)
+ Yii::app()->setConfig($key,$value);
+ }
+ }
+ $oSettings=SettingGlobal::model()->findAll();
+ if (count($oSettings) > 0)
+ {
+ foreach ($oSettings as $oSetting)
+ {
+ Yii::app()->setConfig($oSetting->getAttribute('stg_name'), $oSetting->getAttribute('stg_value'));
+ }
+ }
+ }
+
+}
+?>

View file

@ -1,88 +1,59 @@
#!/bin/bash #!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# App package root directory should be the parent folder # App package root directory should be the parent folder
PKG_DIR=$(cd ../; pwd) PKG_DIR=$(cd ../; pwd)
pkg_dependencies="php5-cli php5-imap python-pip php5-gd php5-ldap"
#=================================================
# SPECIFIC HELPERS
#=================================================
set_permissions () {
ynh_set_default_perm $final_path
find $final_path -type f -name "*.php" -print0 | xargs -0 chmod 400 \
|| echo "No file to modify"
#chown root: $final_path/application/config/config.php
chmod -R u+w $final_path/tmp
chmod -R u+w $final_path/upload
chmod -R u+w $final_path/application/config/
}
#=================================================
# COMMON HELPERS
#=================================================
ynh_set_default_perm () {
local DIRECTORY=$1
# Set permissions
chown -R $app:www-data $DIRECTORY
chmod -R 440 $DIRECTORY
find $DIRECTORY -type d -print0 | xargs -0 chmod 550 \
|| echo "No file to modify"
}
ynh_check_var () { ynh_check_var () {
test -n "$1" || ynh_die "$2" test -n "$1" || ynh_die "$2"
} }
ynh_exit_properly () {
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
exit 0
fi
trap '' EXIT
set +eu
echo -e "\e[91m \e[1m"
err "$app script has encountered an error."
if type -t CLEAN_SETUP > /dev/null; then
CLEAN_SETUP
fi
ynh_die
}
# Activate signal capture
# Exit if a command fail, and if a variable is used unset.
# Capturing exit signals on shell script
#
# example: CLEAN_SETUP () {
# # Clean residual file un remove by remove script
# }
# ynh_trap_on
ynh_trap_on () {
set -eu
trap ynh_exit_properly EXIT # Capturing exit signals on shell script
}
ynh_export () { ynh_export () {
local ynh_arg="" local ynh_arg=""
for var in $@; for var in $@;
do do
ynh_arg=$(echo $var | awk '{print toupper($0)}') ynh_arg=$(echo $var | awk '{print toupper($0)}')
if [ "$var" == "path_url" ]; then
ynh_arg="PATH"
fi
ynh_arg="YNH_APP_ARG_$ynh_arg" ynh_arg="YNH_APP_ARG_$ynh_arg"
export $var=${!ynh_arg} export $var=${!ynh_arg}
done done
} }
# Check availability of a web path
#
# example: ynh_path_validity $domain$path
#
# usage: ynh_path_validity $domain_and_path
# | arg: domain_and_path - complete path to check
ynh_path_validity () {
sudo yunohost app checkurl $1 -a $app
}
# Normalize the url path syntax
# Handle the slash at the beginning of path and its absence at ending
# Return a normalized url path
#
# example: url_path=$(ynh_normalize_url_path $url_path)
# ynh_normalize_url_path example -> /example
# ynh_normalize_url_path /example -> /example
# ynh_normalize_url_path /example/ -> /example
#
# usage: ynh_normalize_url_path path_to_normalize
# | arg: url_path_to_normalize - URL path to normalize before using it
ynh_normalize_url_path () {
path=$1
test -n "$path" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
if [ "${path:0:1}" != "/" ]; then # If the first character is not a /
path="/$path" # Add / at begin of path variable
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and that not the only character.
path="${path:0:${#path}-1}" # Delete the last character
fi
echo $path
}
# Check the path doesn't exist # Check the path doesn't exist
# usage: ynh_local_path_available PATH # usage: ynh_final_path_available PATH
ynh_local_path_available () { ynh_final_path_available () {
if [ -e "$1" ] if [ -e "$1" ]
then then
ynh_die "This path '$1' already contains a folder" ynh_die "This path '$1' already contains a folder"
@ -94,31 +65,14 @@ ynh_local_path_available () {
ynh_save_args () { ynh_save_args () {
for var in $@; for var in $@;
do do
ynh_app_setting_set $app $var ${!var} local setting_var="$var"
if [ "$var" == "path_url" ]; then
setting_var="path"
fi
ynh_app_setting_set $app $setting_var ${!var}
done done
} }
# Create a database, an user and its password. Then store the password in the app's config
#
# User of database will be store in db_user's variable.
# Name of database will be store in db_name's variable.
# And password in db_pwd's variable.
#
# usage: ynh_mysql_generate_db user name
# | arg: user - Proprietary of the database
# | arg: name - Name of the database
ynh_mysql_generate_db () {
export db_user=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _
export db_name=${2//[-.]/_}
export db_pwd=$(ynh_string_random) # Generate a random password
ynh_check_var "$db_pwd" "db_pwd empty"
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config
}
# Execute a command as another user # Execute a command as another user
# usage: ynh_exec_as USER COMMAND [ARG ...] # usage: ynh_exec_as USER COMMAND [ARG ...]
ynh_exec_as() { ynh_exec_as() {
@ -133,143 +87,81 @@ ynh_exec_as() {
fi fi
} }
# Get sources, setup it into dest directory and deploy patches
# Try to find locally the sources and download it if missing.
# Check the integrity with an hash program (default: sha256sum)
# Source hash and location are get from a "SOURCE_ID.src" file,
# by default the SOURCE_ID is "app".
# Patches should be located in a "patches" dir, they should be
# named like "SOURCE_ID-*.patch".
#
# example: ynh_setup_source "/var/www/limesurvey/" "limesurvey"
#
# usage: ynh_setup_source DEST_DIR [USER [SOURCE_ID]]
ynh_setup_source () { # usage: ynh_save_persistent MODE RELATIVE_PATH
local DEST=$1
local AS_USER=${2:-admin}
local SOURCE_ID=${3:-app}
local SOURCE_FILE="$YNH_APP_ID.tar.gz"
local SUM_PRG="sha256sum"
source ../$SOURCE_ID.src
local LOCAL_SOURCE="/opt/yunohost-apps-src/$YNH_APP_ID/$SOURCE_FILE"
if test -e $LOCAL_SOURCE; then
cp $LOCAL_SOURCE $SOURCE_FILE
else
wget -nv $SOURCE_URL -O $SOURCE_FILE
fi
echo "$SOURCE_SUM $SOURCE_FILE" |$SUM_PRG -c --status \
|| ynh_die "Corrupt source"
sudo mkdir -p "$DEST"
sudo chown $AS_USER: "$DEST"
if [ "$(echo ${SOURCE_FILE##*.})" == "gz" ]; then
ynh_exec_as "$AS_USER" tar xf $SOURCE_FILE -C "$DEST" --strip-components 1
elif [ "$(echo ${SOURCE_FILE##*.})" == "bz2" ]; then
ynh_exec_as "$AS_USER" tar xjf $SOURCE_FILE -C "$DEST" --strip-components 1
elif [ "$(echo ${SOURCE_FILE##*.})" == "zip" ]; then
mkdir -p "/tmp/$SOURCE_FILE"
ynh_exec_as "$AS_USER" unzip -q $SOURCE_FILE -d "/tmp/$SOURCE_FILE"
ynh_exec_as "$AS_USER" mv "/tmp/$SOURCE_FILE"/./. "$DEST"
rmdir "$/tmp/$SOURCE_FILE"
else
false
fi
# Apply patches
if [ -f ${PKG_DIR}/patches/$SOURCE_ID-*.patch ]; then
(cd "$DEST" \
&& for p in ${PKG_DIR}/patches/$SOURCE_ID-*.patch; do \
ynh_exec_as "$AS_USER" patch -p1 < $p; done) \
|| ynh_die "Unable to apply patches"
fi
# Apply persistent modules (upgrade only)
ynh_restore_persistent modules
# Apply persistent data (upgrade only)
ynh_restore_persistent data
}
# TODO support SOURCE_ID
ynh_save_persistent () { ynh_save_persistent () {
local TYPE=$1 local TYPE=$1
local DIR=/tmp/ynh-persistent/$TYPE/$app/app local DIR=/tmp/ynh-persistent/$app
sudo mkdir -p $DIR set +u
sudo touch $DIR/dir_names i=${#YNH_PERSISTENT_DIR[@]}
shift i=${i:-0}
i=1 set -u
for PERSISTENT_DIR in $@; [ "$i" -eq "0" ] && ynh_secure_remove $DIR && mkdir -p $DIR
do if [ -e $final_path/$2 ]; then
if [ -e $local_path/$PERSISTENT_DIR ]; then mv $final_path/$2 $DIR/$i
sudo mv $local_path/$PERSISTENT_DIR $DIR/$i YNH_PERSISTENT_MODE[$i]=$1
sudo su -c "echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names" YNH_PERSISTENT_DIR[$i]=$2
((i++))
fi fi
done
} }
# TODO support SOURCE_ID ynh_keep_if_no_upgrade () {
for elt in $@;
do
ynh_save_persistent KEEP_IF_NO_UPGRADE $elt
done
}
ynh_keep () {
for elt in $@;
do
ynh_save_persistent KEEP $elt
done
}
# usage: ynh_restore_persistent
ynh_restore_persistent () { ynh_restore_persistent () {
local TYPE=$1 local DIR=/tmp/ynh-persistent/$app
local DIR=/tmp/ynh-persistent/$TYPE/$app/app
shift
if [ -d $DIR ]; then if [ -d $DIR ]; then
i=1 i=0
for PERSISTENT_DIR in $(cat $DIR/dir_names); for PERSISTENT_DIR in "${YNH_PERSISTENT_DIR[@]}";
do do
if [ "$TYPE" = "modules" ]; then if [ "${YNH_PERSISTENT_MODE[$i]}" = "KEEP_IF_NO_UPGRADE" ]; then
for updated_subdir in $(ls $local_path/$PERSISTENT_DIR); if [ ! -e $final_path/$PERSISTENT_DIR ]; then
do mv $DIR/$i $final_path/$PERSISTENT_DIR
sudo rm -Rf $DIR/$i/$updated_subdir
done
fi fi
if [ -d $DIR/$i ]; then
sudo mv $DIR/$i/* $local_path/$PERSISTENT_DIR/ 2> /dev/null || true
else else
sudo mv $DIR/$i $local_path/$PERSISTENT_DIR 2> /dev/null || true if [ -e $final_path/$PERSISTENT_DIR ]; then
ynh_secure_remove $final_path/$PERSISTENT_DIR
fi fi
((i++)) mv $DIR/$i $final_path/$PERSISTENT_DIR
fi
((i+=1))
done done
sudo rm -Rf $DIR ynh_secure_remove $DIR
fi fi
} }
ynh_mv_to_home () { ynh_mv_to_home () {
local APP_PATH="/home/yunohost.app/$app/" local APP_PATH="/home/yunohost.app/$app/"
local DATA_PATH="$1" local DATA_PATH="$1"
sudo mkdir -p "$APP_PATH" mkdir -p "$APP_PATH"
sudo chown $app: "$APP_PATH" chown $app: "$APP_PATH"
ynh_exec_as "$app" mv "$DATA_PATH" "$APP_PATH" ynh_exec_as "$app" mv "$DATA_PATH" "$APP_PATH"
ynh_exec_as "$app" ln -s "$APP_PATH$DATA_PATH" "$DATA_PATH" ynh_exec_as "$app" ln -s "$APP_PATH$DATA_PATH" "$DATA_PATH"
} }
ynh_set_default_perm () {
local DIRECTORY=$1
# Set permissions
sudo chown -R $app:$app $DIRECTORY
sudo chmod -R 664 $DIRECTORY
sudo find $DIRECTORY -type d -print0 | xargs -0 sudo chmod 775 \
|| echo "No file to modify"
}
ynh_sso_access () { ynh_sso_access () {
ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set $app unprotected_uris "/"
if [[ $is_public -eq 0 ]]; then if [[ $is_public -eq 0 ]]; then
ynh_app_setting_set $app protected_uris "$1" ynh_app_setting_set $app protected_uris "$1"
fi fi
sudo yunohost app ssowatconf yunohost app ssowatconf
} }
ynh_exit_if_up_to_date () { ynh_exit_if_up_to_date () {
if [ "${version}" = "${last_version}" ]; then if [ "${version}" = "${last_version}" ]; then
info "Up-to-date, nothing to do" info "Up-to-date, nothing to do"
exit 0 ynh_die "Up-to-date, nothing to do" 0
fi fi
} }
@ -311,64 +203,6 @@ ynh_read_manifest () {
fi fi
} }
ynh_app_dependencies (){
export dependencies=$1
export project_url=$(ynh_read_manifest 'url')
export version=$(ynh_read_manifest 'version')
export dep_app=${app/__/-}
mkdir -p ../conf
cat > ../conf/app-ynh-deps.control.j2 << EOF
Section: misc
Priority: optional
Homepage: {{ project_url }}
Standards-Version: 3.9.2
Package: {{ dep_app }}-ynh-deps
Version: {{ version }}
Depends: {{ dependencies }}
Architecture: all
Description: meta package for {{ app }} (YunoHost app) dependencies
This meta-package is only responsible of installing its dependencies.
EOF
ynh_configure app-ynh-deps.control ./$dep_app-ynh-deps.control
ynh_package_install_from_equivs ./$dep_app-ynh-deps.control \
|| ynh_die "Unable to install dependencies"
}
# Create a system user
#
# usage: ynh_system_user_create user_name [home_dir]
# | arg: user_name - Name of the system user that will be create
# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home
ynh_system_user_create () {
if ! ynh_system_user_exists "$1" # Check if the user exists on the system
then # If the user doesn't exist
if [ $# -ge 2 ]; then # If a home dir is mentioned
user_home_dir="-d $2"
else
user_home_dir="--no-create-home"
fi
sudo useradd $user_home_dir --system --user-group $1 --shell /usr/sbin/nologin || ynh_die "Unable to create $1 system account"
fi
}
# Delete a system user
#
# usage: ynh_system_user_delete user_name
# | arg: user_name - Name of the system user that will be create
ynh_system_user_delete () {
if ynh_system_user_exists "$1" # Check if the user exists on the system
then
sudo userdel $1
else
echo "The user $1 was not found" >&2
fi
}
ynh_configure () { ynh_configure () {
local TEMPLATE=$1 local TEMPLATE=$1
@ -378,82 +212,179 @@ ynh_configure () {
sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST" sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST"
} }
ynh_configure_nginx () { ynh_add_nginx_config () {
ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
sudo service nginx reload ynh_backup_if_checksum_is_different "$finalnginxconf"
ynh_configure nginx.conf "$finalnginxconf"
ynh_store_file_checksum "$finalnginxconf"
service nginx reload
} }
ynh_configure_php_fpm () { ynh_add_fpm_config () {
finalphpconf=/etc/php5/fpm/pool.d/$app.conf # Configure PHP-FPM 7.0 by default
ynh_configure php-fpm.conf /etc/php5/fpm/pool.d/$app.conf local fpm_config_dir="/etc/php/7.0/fpm"
sudo chown root: $finalphpconf local fpm_service="php7.0-fpm"
# Configure PHP-FPM 5 on Debian Jessie
if is_jessie; then
fpm_config_dir="/etc/php5/fpm"
fpm_service="php5-fpm"
fi
ynh_app_setting_set $app fpm_config_dir "$fpm_config_dir"
ynh_app_setting_set $app fpm_service "$fpm_service"
finalphpconf="$fpm_config_dir/pool.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalphpconf"
ynh_configure php-fpm.conf "$finalphpconf"
sudo chown root: "$finalphpconf"
ynh_store_file_checksum "$finalphpconf"
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini if [ -e "../conf/php-fpm.ini.j2" ]
sudo cp ../conf/php-fpm.ini $finalphpini then
sudo chown root: $finalphpini finalphpini="$fpm_config_dir/conf.d/20-$app.ini"
ynh_backup_if_checksum_is_different "$finalphpini"
sudo service php5-fpm reload ynh_configure php-fpm.ini "$finalphpini"
chown root: "$finalphpini"
ynh_store_file_checksum "$finalphpini"
fi
systemctl reload $fpm_service
} }
# Find a free port and return it # Send an email to inform the administrator
# #
# example: port=$(ynh_find_port 8080) # usage: ynh_send_readme_to_admin app_message [recipients]
# # | arg: app_message - The message to send to the administrator.
# usage: ynh_find_port begin_port # | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# | arg: begin_port - port to start to search # example: "root admin@domain"
ynh_find_port () { # If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
port=$1 # example: "root admin@domain user1 user2"
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port." ynh_send_readme_to_admin() {
while netcat -z 127.0.0.1 $port # Check if the port is free local app_message="${1:-...No specific information...}"
local recipients="${2:-root}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do do
port=$((port+1)) # Else, pass to next port # Keep root or a real email address as it is
done if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
echo $port then
} recipients="$recipients $mail"
### REMOVE SCRIPT
# Remove a database if it exist and the associated user
#
# usage: ynh_mysql_remove_db user name
# | arg: user - Proprietary of the database
# | arg: name - Name of the database
ynh_mysql_remove_db () {
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist
ynh_mysql_drop_db $2 # Remove the database
ynh_mysql_drop_user $1 # Remove the associated user to database
else else
echo "Database $2 not found" >&2 # But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$app_message
---
Automatic diagnosis data from YunoHost
$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
# Send the email to the recipients
echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
}
# Exit without error if the package is up to date
#
# This helper should be used to avoid an upgrade of a package
# when it's not needed.
#
# To force an upgrade, even if the package is up to date,
# you have to set the variable YNH_FORCE_UPGRADE before.
# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
#
# usage: ynh_abort_if_up_to_date
ynh_abort_if_up_to_date () {
local force_upgrade=${YNH_FORCE_UPGRADE:-0}
local package_check=${PACKAGE_CHECK_EXEC:-0}
local version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0)
local last_version=$(ynh_read_manifest "version" || echo 1.0)
if [ "$version" = "$last_version" ]
then
if [ "$force_upgrade" != "0" ]
then
echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2
unset YNH_FORCE_UPGRADE
elif [ "$package_check" != "0" ]
then
echo "Upgrade forced for package check." >&2
else
ynh_die "Up-to-date, nothing to do" 0
fi
fi fi
} }
ynh_rm_nginx_conf () { # Remove any logs for all the following commands.
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then #
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" # usage: ynh_print_OFF
sudo service nginx reload # WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging.
ynh_print_OFF () {
set +x
}
# Restore the logging after ynh_print_OFF
#
# usage: ynh_print_ON
ynh_print_ON () {
set -x
# Print an echo only for the log, to be able to know that ynh_print_ON has been called.
echo ynh_print_ON > /dev/null
}
ynh_version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
# In upgrade script allow to test if the app is less than or equal a specific version
#
# usage: ynh_version_le "0.5"
ynh_version_le() {
local version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0)
ynh_version_gt "$1" "${version}"
}
ynh_debian_release () {
lsb_release --codename --short
}
is_stretch () {
if [ "$(ynh_debian_release)" == "stretch" ]
then
return 0
else
return 1
fi fi
} }
ynh_rm_php_fpm_conf () { is_jessie () {
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then if [ "$(ynh_debian_release)" == "jessie" ]
sudo rm "/etc/php5/fpm/pool.d/$app.conf" then
fi return 0
if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then else
sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" return 1
fi
sudo service php5-fpm reload
}
REMOVE_LOGROTATE_CONF () {
if [ -e "/etc/logrotate.d/$app" ]; then
sudo rm "/etc/logrotate.d/$app"
fi fi
} }
ynh_secure_rm () { # Reload (or other actions) a service and print a log in case of failure.
[[ "/var/www /opt /home/yunohost.app" =~ $1 ]] \ #
|| (test -n "$1" && sudo rm -Rf $1 ) # usage: ynh_system_reload service_name [action]
# | arg: service_name - Name of the service to reload
# | arg: action - Action to perform with systemctl. Default: reload
ynh_system_reload () {
local service_name=$1
local action=${2:-reload}
# Reload, restart or start and print the log if the service fail to start or reload
systemctl $action $service_name || ( journalctl --lines=20 -u $service_name >&2 && false)
} }

View file

@ -1,34 +1,53 @@
#!/bin/bash #!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status #=================================================
set -e # GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
# Source YNH helpers #=================================================
. /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE
#=================================================
backup_dir=$1 # Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
# Get app instance name
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path)
local_path=$(ynh_app_setting_get $app local_path) db_name=$(ynh_app_setting_get $app db_name)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
my_ynh_backup () { #=================================================
ynh_backup $@ # STANDARD BACKUP STEPS
echo $2 $1 >> $backup_dir/list #=================================================
} # BACKUP OF THE MAIN DIR OF THE APP
#=================================================
# Copy the app files ynh_backup "$final_path"
my_ynh_backup "$local_path" "sources"
# Copy the conf files #=================================================
my_ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" # BACKUP OF THE NGINX CONFIGURATION
my_ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "conf/php-fpm.conf" #=================================================
my_ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "conf/php-fpm.ini"
# Save database ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
mysqldump -u "$app" -p"$dbpass" --no-create-db "$app" > ./dump.sql #=================================================
# BACKUP OF THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# BACKUP OF THE SQL BDD
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql

View file

@ -1,62 +1,171 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh source _common.sh
ynh_trap_on #=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
user=$app
# Retrieve arguments # Retrieve arguments
ynh_export domain path admin is_public language ynh_export domain path_url admin is_public language
export local_path=/var/www/$app
export prefix=lime_ export prefix=lime_
export db_name=$(ynh_sanitize_dbid $app)
export db_user=$db_name
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#================================================= #=================================================
ynh_check_var "$app" "app name not set"
ynh_user_exists "$admin" || ynh_die "User does not exist: $admin" export final_path=/var/www/$app
ynh_normalize_url_path "$path" test ! -e "$final_path" || ynh_die "This path already contains a folder"
ynh_path_validity "$domain$path"
ynh_local_path_available "$local_path" # Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#================================================= #=================================================
# SETUP THE APP BY MODIFYING THE SYSTEM # STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_save_args domain path admin is_public language local_path prefix ynh_install_app_dependencies $pkg_dependencies
ynh_app_dependencies php5-imap #=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_save_args domain admin is_public language final_path prefix path_url db_name db_user
ynh_mysql_generate_db "$user" "$app" #=================================================
# CREATE A SQL BDD
#=================================================
ynh_system_user_create "$user" "$local_path" ynh_mysql_setup_db $db_user $db_name
export db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_setup_source "$local_path" "$user" #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_configure config.php "$local_path/application/config/config.php" # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
# Fill LimeSurvey database #=================================================
sed "s/\`prefix_/\`$prefix/g" $local_path/installer/sql/create-mysql.sql > ./structure.sql # NGINX CONFIGURATION
mysql -u $db_user -p$db_pwd $db_user < ./structure.sql #=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set permissions
set_permissions
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE
#=================================================
ynh_configure config.php "$final_path/application/config/config.php"
#=================================================
# INSTALL
#=================================================
ls_cli=$final_path/application/commands/console.php
fullname=$(ynh_user_get_info "$admin" "fullname")
mail=$(ynh_user_get_info "$admin" "mail")
# Permission should be correctly set before to do this
ynh_exec_as "$app" php $ls_cli install "$admin" "$(ynh_string_random 24)" "$fullname" "$mail"
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/application/config/config.php"
#=================================================
# LOAD SQL SPECIFIC CONFIG
#=================================================
ynh_configure data.sql ./data.sql ynh_configure data.sql ./data.sql
mysql -u $db_user -p$db_pwd $db_user < ./data.sql mysql -u $db_user -p$db_pwd $db_user < ./data.sql
# Randomize Password user #=================================================
ls_cli=$local_path/application/commands/console.php # Add nice themes
set +x #=================================================
ynh_exec_as "$user" php $ls_cli resetpassword "$admin" "$(ynh_string_random 24)" #ynh_setup_source "$final_path/upload/templates/libreform" libreform
set -x #ynh_setup_source "$final_path/upload/templates/librepoll" librepoll
#=================================================
# GENERIC FINALISATION
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set permissions # Set permissions
ynh_set_default_perm $local_path set_permissions
sudo chmod -R u+w $local_path/tmp
sudo chmod -R u+w $local_path/upload
sudo chmod -R u+w $local_path/application/config/
sudo yunohost app addaccess $app -u $admin #=================================================
# SETUP FAIL2BAN
#=================================================
#ynh_add_fail2ban_config "/var/log/nginx/${domain}-error.log" "PHP message: Leed: wrong login for .* client: <HOST>" 5
#=================================================
# SETUP SSOWAT
#=================================================
yunohost app addaccess $app -u $admin
ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts"
ynh_configure_php_fpm #=================================================
ynh_configure_nginx # RELOAD NGINX
#=================================================
systemctl reload nginx
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
ynh_print_OFF
message="You can now create a poll on this address: https://${domain}${path_url}/admin/
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/limesurvey_ynh"
ynh_send_readme_to_admin "$message" "$admin"
ynh_print_ON

View file

@ -1,27 +1,68 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh source _common.sh
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
user=$app
local_path=$(ynh_app_setting_get $app local_path) final_path=$(ynh_app_setting_get $app final_path)
final_path=${final_path:-/var/www/$app}
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
ynh_mysql_remove_db "$user" "$app" #=================================================
# STANDARD REMOVE
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_secure_rm "$local_path" #=================================================
ynh_secure_rm "/home/yunohost.app/$app" # REMOVE THE SQL BDD
#=================================================
ynh_rm_nginx_conf # Remove a database if it exists, along with the associated user
ynh_rm_php_fpm_conf ynh_mysql_remove_db $db_name $db_name
# Delete user after php5-fpm is restarted without the app conf #=================================================
# We can't delete it before because php5-fpm use it # REMOVE THE MAIN DIR OF THE APP
ynh_system_user_delete "$user" #=================================================
dep_app=${app/__/-} # Remove the app directory securely
ynh_package_remove $dep_app-ynh-deps ynh_secure_remove "$final_path"
ynh_secure_remove "/home/yunohost.app/$app"
sudo yunohost app ssowatconf #=================================================
echo -e "\e[0m" # Restore norml color # REMOVE THE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE THE PHP-FPM CONFIGURATION
#=================================================
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
#=================================================
# GENERIC FINALISATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app

View file

@ -1,527 +1,94 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
#================================================ #=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# App package root directory should be the parent folder # Exit if an error occurs during the execution of the script
PKG_DIR=$(cd ../; pwd) ynh_abort_if_errors
ynh_check_var () { #=================================================
test -n "$1" || ynh_die "$2" # LOAD SETTINGS
} #=================================================
ynh_exit_properly () {
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
exit 0
fi
trap '' EXIT
set +eu
echo -e "\e[91m \e[1m"
err "$app script has encountered an error."
if type -t CLEAN_SETUP > /dev/null; then
CLEAN_SETUP
fi
ynh_die
}
# Activate signal capture
# Exit if a command fail, and if a variable is used unset.
# Capturing exit signals on shell script
#
# example: CLEAN_SETUP () {
# # Clean residual file un remove by remove script
# }
# ynh_trap_on
ynh_trap_on () {
set -eu
trap ynh_exit_properly EXIT # Capturing exit signals on shell script
}
ynh_export () {
local ynh_arg=""
for var in $@;
do
ynh_arg=$(echo $var | awk '{print toupper($0)}')
ynh_arg="YNH_APP_ARG_$ynh_arg"
export $var=${!ynh_arg}
done
}
# Check availability of a web path
#
# example: ynh_path_validity $domain$path
#
# usage: ynh_path_validity $domain_and_path
# | arg: domain_and_path - complete path to check
ynh_path_validity () {
sudo yunohost app checkurl $1 -a $app
}
# Normalize the url path syntax
# Handle the slash at the beginning of path and its absence at ending
# Return a normalized url path
#
# example: url_path=$(ynh_normalize_url_path $url_path)
# ynh_normalize_url_path example -> /example
# ynh_normalize_url_path /example -> /example
# ynh_normalize_url_path /example/ -> /example
#
# usage: ynh_normalize_url_path path_to_normalize
# | arg: url_path_to_normalize - URL path to normalize before using it
ynh_normalize_url_path () {
path=$1
test -n "$path" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
if [ "${path:0:1}" != "/" ]; then # If the first character is not a /
path="/$path" # Add / at begin of path variable
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and that not the only character.
path="${path:0:${#path}-1}" # Delete the last character
fi
echo $path
}
# Check the path doesn't exist
# usage: ynh_local_path_available PATH
ynh_local_path_available () {
if [ -e "$1" ]
then
ynh_die "This path '$1' already contains a folder"
fi
}
# Save listed var in YunoHost app settings
# usage: ynh_save_args VARNAME1 [VARNAME2 [...]]
ynh_save_args () {
for var in $@;
do
ynh_app_setting_set $app $var ${!var}
done
}
# Create a database, an user and its password. Then store the password in the app's config
#
# User of database will be store in db_user's variable.
# Name of database will be store in db_name's variable.
# And password in db_pwd's variable.
#
# usage: ynh_mysql_generate_db user name
# | arg: user - Proprietary of the database
# | arg: name - Name of the database
ynh_mysql_generate_db () {
export db_user=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _
export db_name=${2//[-.]/_}
export db_pwd=$(ynh_string_random) # Generate a random password
ynh_check_var "$db_pwd" "db_pwd empty"
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config
}
# Execute a command as another user
# usage: ynh_exec_as USER COMMAND [ARG ...]
ynh_exec_as() {
local USER=$1
shift 1
if [[ $USER = $(whoami) ]]; then
eval "$@"
else
# use sudo twice to be root and be allowed to use another user
sudo sudo -u "$USER" "$@"
fi
}
# Get sources, setup it into dest directory and deploy patches
# Try to find locally the sources and download it if missing.
# Check the integrity with an hash program (default: sha256sum)
# Source hash and location are get from a "SOURCE_ID.src" file,
# by default the SOURCE_ID is "app".
# Patches should be located in a "patches" dir, they should be
# named like "SOURCE_ID-*.patch".
#
# example: ynh_setup_source "/var/www/limesurvey/" "limesurvey"
#
# usage: ynh_setup_source DEST_DIR [USER [SOURCE_ID]]
ynh_setup_source () {
local DEST=$1
local AS_USER=${2:-admin}
local SOURCE_ID=${3:-app}
local SOURCE_FILE="$YNH_APP_ID.tar.gz"
local SUM_PRG="sha256sum"
source ../$SOURCE_ID.src
local LOCAL_SOURCE="/opt/yunohost-apps-src/$YNH_APP_ID/$SOURCE_FILE"
if test -e $LOCAL_SOURCE; then
cp $LOCAL_SOURCE $SOURCE_FILE
else
wget -nv $SOURCE_URL -O $SOURCE_FILE
fi
echo "$SOURCE_SUM $SOURCE_FILE" |$SUM_PRG -c --status \
|| ynh_die "Corrupt source"
sudo mkdir -p "$DEST"
sudo chown $AS_USER: "$DEST"
if [ "$(echo ${SOURCE_FILE##*.})" == "gz" ]; then
ynh_exec_as "$AS_USER" tar xf $SOURCE_FILE -C "$DEST" --strip-components 1
elif [ "$(echo ${SOURCE_FILE##*.})" == "bz2" ]; then
ynh_exec_as "$AS_USER" tar xjf $SOURCE_FILE -C "$DEST" --strip-components 1
elif [ "$(echo ${SOURCE_FILE##*.})" == "zip" ]; then
mkdir -p "/tmp/$SOURCE_FILE"
ynh_exec_as "$AS_USER" unzip -q $SOURCE_FILE -d "/tmp/$SOURCE_FILE"
ynh_exec_as "$AS_USER" mv "/tmp/$SOURCE_FILE"/./. "$DEST"
rmdir "$/tmp/$SOURCE_FILE"
else
false
fi
# Apply patches
if [ -f ${PKG_DIR}/patches/$SOURCE_ID-*.patch ]; then
(cd "$DEST" \
&& for p in ${PKG_DIR}/patches/$SOURCE_ID-*.patch; do \
ynh_exec_as "$AS_USER" patch -p1 < $p; done) \
|| ynh_die "Unable to apply patches"
fi
# Apply persistent modules (upgrade only)
ynh_restore_persistent modules
# Apply persistent data (upgrade only)
ynh_restore_persistent data
}
# TODO support SOURCE_ID
ynh_save_persistent () {
local TYPE=$1
local DIR=/tmp/ynh-persistent/$TYPE/$app/app
sudo mkdir -p $DIR
sudo touch $DIR/dir_names
shift
i=1
for PERSISTENT_DIR in $@;
do
if [ -e $local_path/$PERSISTENT_DIR ]; then
sudo mv $local_path/$PERSISTENT_DIR $DIR/$i
sudo su -c "echo -n '$PERSISTENT_DIR ' >> $DIR/dir_names"
((i++))
fi
done
}
# TODO support SOURCE_ID
ynh_restore_persistent () {
local TYPE=$1
local DIR=/tmp/ynh-persistent/$TYPE/$app/app
shift
if [ -d $DIR ]; then
i=1
for PERSISTENT_DIR in $(cat $DIR/dir_names);
do
if [ "$TYPE" = "modules" ]; then
for updated_subdir in $(ls $local_path/$PERSISTENT_DIR);
do
sudo rm -Rf $DIR/$i/$updated_subdir
done
fi
if [ -d $DIR/$i ]; then
sudo mv $DIR/$i/* $local_path/$PERSISTENT_DIR/ 2> /dev/null || true
else
sudo mv $DIR/$i $local_path/$PERSISTENT_DIR 2> /dev/null || true
fi
((i++))
done
sudo rm -Rf $DIR
fi
}
ynh_mv_to_home () {
local APP_PATH="/home/yunohost.app/$app/"
local DATA_PATH="$1"
sudo mkdir -p "$APP_PATH"
sudo chown $app: "$APP_PATH"
ynh_exec_as "$app" mv "$DATA_PATH" "$APP_PATH"
ynh_exec_as "$app" ln -s "$APP_PATH$DATA_PATH" "$DATA_PATH"
}
ynh_set_default_perm () {
local DIRECTORY=$1
# Set permissions
sudo chown -R $app:$app $DIRECTORY
sudo chmod -R 664 $DIRECTORY
sudo find $DIRECTORY -type d -print0 | xargs -0 sudo chmod 775 \
|| echo "No file to modify"
}
ynh_sso_access () {
ynh_app_setting_set $app unprotected_uris "/"
if [[ $is_public -eq 0 ]]; then
ynh_app_setting_set $app protected_uris "$1"
fi
sudo yunohost app ssowatconf
}
ynh_exit_if_up_to_date () {
if [ "${version}" = "${last_version}" ]; then
info "Up-to-date, nothing to do"
exit 0
fi
}
log() {
echo "${1}"
}
info() {
log "[INFO] ${1}"
}
warn() {
log "[WARN] ${1}"
}
err() {
log "[ERR] ${1}"
}
to_logs() {
# When yunohost --verbose or bash -x
if $_ISVERBOSE; then
cat
else
cat > /dev/null
fi
}
ynh_read_json () {
sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])"
}
ynh_read_manifest () {
if [ -f '../manifest.json' ] ; then
ynh_read_json '../manifest.json' "$1"
else
ynh_read_json '../settings/manifest.json' "$1"
fi
}
ynh_app_dependencies (){
export dependencies=$1
export project_url=$(ynh_read_manifest 'url')
export version=$(ynh_read_manifest 'version')
export dep_app=${app/__/-}
mkdir -p ../conf
cat > ../conf/app-ynh-deps.control.j2 << EOF
Section: misc
Priority: optional
Homepage: {{ project_url }}
Standards-Version: 3.9.2
Package: {{ dep_app }}-ynh-deps
Version: {{ version }}
Depends: {{ dependencies }}
Architecture: all
Description: meta package for {{ app }} (YunoHost app) dependencies
This meta-package is only responsible of installing its dependencies.
EOF
ynh_configure app-ynh-deps.control ./$dep_app-ynh-deps.control
ynh_package_install_from_equivs ./$dep_app-ynh-deps.control \
|| ynh_die "Unable to install dependencies"
}
# Create a system user
#
# usage: ynh_system_user_create user_name [home_dir]
# | arg: user_name - Name of the system user that will be create
# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home
ynh_system_user_create () {
if ! ynh_system_user_exists "$1" # Check if the user exists on the system
then # If the user doesn't exist
if [ $# -ge 2 ]; then # If a home dir is mentioned
user_home_dir="-d $2"
else
user_home_dir="--no-create-home"
fi
sudo useradd $user_home_dir --system --user-group $1 --shell /usr/sbin/nologin || ynh_die "Unable to create $1 system account"
fi
}
# Delete a system user
#
# usage: ynh_system_user_delete user_name
# | arg: user_name - Name of the system user that will be create
ynh_system_user_delete () {
if ynh_system_user_exists "$1" # Check if the user exists on the system
then
sudo userdel $1
else
echo "The user $1 was not found" >&2
fi
}
ynh_configure () {
local TEMPLATE=$1
local DEST=$2
type j2 2>/dev/null || sudo pip install j2cli
j2 "${PKG_DIR}/conf/$TEMPLATE.j2" > "${PKG_DIR}/conf/$TEMPLATE"
sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST"
}
ynh_configure_nginx () {
ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
sudo service nginx reload
}
ynh_configure_php_fpm () {
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
ynh_configure php-fpm.conf /etc/php5/fpm/pool.d/$app.conf
sudo chown root: $finalphpconf
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
sudo cp ../conf/php-fpm.ini $finalphpini
sudo chown root: $finalphpini
sudo service php5-fpm reload
}
# Find a free port and return it
#
# example: port=$(ynh_find_port 8080)
#
# usage: ynh_find_port begin_port
# | arg: begin_port - port to start to search
ynh_find_port () {
port=$1
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
while netcat -z 127.0.0.1 $port # Check if the port is free
do
port=$((port+1)) # Else, pass to next port
done
echo $port
}
### REMOVE SCRIPT
# Remove a database if it exist and the associated user
#
# usage: ynh_mysql_remove_db user name
# | arg: user - Proprietary of the database
# | arg: name - Name of the database
ynh_mysql_remove_db () {
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist
ynh_mysql_drop_db $2 # Remove the database
ynh_mysql_drop_user $1 # Remove the associated user to database
else
echo "Database $2 not found" >&2
fi
}
ynh_rm_nginx_conf () {
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo service nginx reload
fi
}
ynh_rm_php_fpm_conf () {
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then
sudo rm "/etc/php5/fpm/pool.d/$app.conf"
fi
if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then
sudo rm "/etc/php5/fpm/conf.d/20-$app.ini"
fi
sudo service php5-fpm reload
}
REMOVE_LOGROTATE_CONF () {
if [ -e "/etc/logrotate.d/$app" ]; then
sudo rm "/etc/logrotate.d/$app"
fi
}
ynh_secure_rm () {
[[ "/var/www /opt /home/yunohost.app" =~ $1 ]] \
|| (test -n "$1" && sudo rm -Rf $1 )
}
ynh_check_restore () {
for dest in $(cat ./list| cut -d ' ' -f2);
do
([[ -e $dest ]] && ynh_die \
"The destination directory '$dest' already exists.\
You should safely delete it before restoring this app.") || true
done
}
ynh_restore () {
while IFS= read -r instruction
do
sudo cp -a ./$instruction
done < ./list
}
#================================================
ynh_trap_on
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
user=$app
export domain=$(ynh_app_setting_get $app domain) export domain=$(ynh_app_setting_get $app domain)
export path=$(ynh_app_setting_get $app path) export path_url=$(ynh_app_setting_get $app path)
export admin=$(ynh_app_setting_get $app admin) export admin=$(ynh_app_setting_get $app admin)
dbpass=$(ynh_app_setting_get $app mysqlpwd) export final_path=$(ynh_app_setting_get $app final_path)
export local_path=$(ynh_app_setting_get $app local_path)
export is_public=$(ynh_app_setting_get $app is_public) export is_public=$(ynh_app_setting_get $app is_public)
export prefix=$(ynh_app_setting_get $app prefix) export prefix=$(ynh_app_setting_get $app prefix)
dbname=$app export db_name=$(ynh_app_setting_get $app db_name)
dbuser=$user export db_user=$(ynh_app_setting_get $app db_user)
export db_pwd=$(ynh_app_setting_get $app mysqlpwd)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
#ynh_path_validity "$domain$path" ynh_webpath_available $domain $path_url \
ynh_check_restore || ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#================================================= #=================================================
# RESTORE THE APP BY MODIFYING THE SYSTEM # STANDARD RESTORE STEPS
#================================================= #=================================================
ynh_app_dependencies php5-imap # INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies $pkg_dependencies
ynh_system_user_create "$user" "$local_path" #=================================================
# RESTORE OF THE SQL BDD
#=================================================
# Create and restore the database ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
# Restore file #=================================================
# RESTORE FILES
#=================================================
# Restore files
ynh_restore ynh_restore
# Fix app ownerships & permissions #=================================================
ynh_set_default_perm $local_path # RECREATE THE DEDICATED USER
sudo chmod -R u+w $local_path/tmp #=================================================
sudo chmod -R u+w $local_path/upload ynh_system_user_create "$app" "$final_path"
sudo chmod -R u+w $local_path/application/config/
#=================================================
# RESTORE USER RIGHTS
#=================================================
set_permissions
#=================================================
# SETUP SSOWAT
#=================================================
ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts"
# Reload services #=================================================
sudo service php5-fpm restart || true # GENERIC FINALISATION
sudo service nginx reload || true #=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_system_reload php5-fpm
ynh_system_reload nginx
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
message="If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/leed_ynh"
ynh_send_readme_to_admin "$message" "$admin"

View file

@ -1,70 +1,152 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh source _common.sh
ynh_trap_on #=================================================
# LOAD SETTINGS
#=================================================
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
user=$app
export domain=$(ynh_app_setting_get $app domain) export domain=$(ynh_app_setting_get $app domain)
export path=$(ynh_app_setting_get $app path) export path_url=$(ynh_app_setting_get $app path)
export admin=$(ynh_app_setting_get $app admin) export admin=$(ynh_app_setting_get $app admin)
db_pwd=$(ynh_app_setting_get $app mysqlpwd) export final_path=$(ynh_app_setting_get $app final_path)
export local_path=$(ynh_app_setting_get $app local_path)
export is_public=$(ynh_app_setting_get $app is_public) export is_public=$(ynh_app_setting_get $app is_public)
is_public=${is_public:-0}
export prefix=$(ynh_app_setting_get $app prefix) export prefix=$(ynh_app_setting_get $app prefix)
export db_pwd=$(ynh_app_setting_get $app mysqlpwd)
export db_name=$(ynh_app_setting_get $app db_name)
export db_user=$(ynh_app_setting_get $app db_user)
#=================================================
# CHECK VERSION
#=================================================
ynh_abort_if_up_to_date
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# 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
#=================================================
# CHECK THE PATH
#=================================================
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
#=================================================
# STEP Migrations
#=================================================
if ynh_version_le "2.0.5" ; then
is_public=${is_public:-0}
prefix=${prefix:-prefix_} prefix=${prefix:-prefix_}
version=$(ynh_read_json "/etc/yunohost/apps/$app/manifest.json" 'version' 2> /dev/null || echo '2.0.5') db_name=${db_name:-$app}
last_version=$(ynh_read_manifest 'version') final_path=$(ynh_app_setting_get $app local_path)
ynh_exit_if_up_to_date ynh_install_app_dependencies $pkg_dependencies
ynh_check_var "$app" "app name not set" # Move the upload dir to final_path if needed
ynh_user_exists "$admin" || err "User does not exist: $admin"
ynh_normalize_url_path "$path"
if [ "${version}" = "2.0.5" ]; then
ynh_save_args path is_public prefix
ynh_app_dependencies php5-imap
ynh_system_user_create "$user" "$local_path"
# Move the upload dir to local_path if needed
# The upload dir can't be symlinked in home (not supported by LS) # The upload dir can't be symlinked in home (not supported by LS)
upload_path=/home/yunohost.app/$app/upload upload_path=/home/yunohost.app/$app/upload
if [ -h $local_path/upload ]; then if [ -h $final_path/upload ]; then
sudo rm $local_path/upload rm $final_path/upload
sudo mv $upload_path $local_path/ mv $upload_path $final_path/
fi fi
ynh_app_setting_delete $app skipped_uris ynh_app_setting_delete $app skipped_uris
ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts" ynh_sso_access "/index.php?r=admin,/index.php?r=plugins,/scripts"
ynh_configure_php_fpm
ynh_configure_nginx
ynh_configure migrations/2.0.5.sql ./2.0.5.sql ynh_configure migrations/2.0.5.sql ./2.0.5.sql
mysql -u $app -p$db_pwd $app < ./2.0.5.sql mysql -u $app -p$db_pwd $db_name < ./2.0.5.sql
fi
if ynh_version_le "2.62.2-1" ; then
is_public=${is_public:-0}
prefix=${prefix:-prefix_}
db_name=${db_name:-$app}
final_path=$(ynh_app_setting_get $app local_path)
ynh_save_args path_url is_public prefix db_name final_path db_user
fi
if ynh_version_le "2.62.2-2" ; then
# Move old templates and themes in backup dir
mv $final_path/upload/templates /home/yunohost.backup/$app.bkp/old-templates
mkdir -p /home/yunohost.backup/$app.bkp/old-themes
mv $final_path/themes/* /home/yunohost.backup/$app.bkp/old-themes/
fi fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Backup config, plugins and themes and delete previous files # Backup config, plugins and themes and delete previous files
ynh_save_persistent modules themes plugins ynh_keep_if_no_upgrade themes/admin/* themes/question/* themes/survey/* plugins/*
ynh_save_persistent data application/config/config.php upload ynh_keep application/config/config.php upload
# Copie new files and restore config, plugins, upload and themes # Copie new files and restore config, plugins, upload and themes
sudo rm -Rf $local_path ynh_secure_remove $final_path
ynh_setup_source "$local_path" "$user" ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
# Set permissions # Restore config, plugins and themes
ynh_set_default_perm $local_path ynh_restore_persistent
sudo chmod -R u+w $local_path/tmp
sudo chmod -R u+w $local_path/upload #=================================================
sudo chmod -R u+w $local_path/application/config/ # NGINX CONFIGURATION
#=================================================
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app # Create the dedicated user, if not exist
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
set_permissions
#=================================================
# UPGRADE DB
#=================================================
# Migrate DB # Migrate DB
cd $local_path/application/commands cd $final_path/application/commands
ynh_exec_as "$app" php console.php update ynh_exec_as "$app" php console.php updatedb
#=================================================
# RELOAD NGINX
#=================================================
ynh_system_reload nginx
#=================================================
# Send message to the admin
#=================================================
if ynh_version_le "2.62.2-2" ; then
message="LimeSurvey has been upgraded from version to version 3, note this new version change completely the survey themes system. If you have added or created manually some templates they won't be available in your LimeSurvey, a copy of their source code has been done in /home/yunohost.backup/$app-old-templates/. See https://manual.limesurvey.org/New_Template_System_in_LS3.x"
ynh_warn "$message"
ynh_send_readme_to_admin "$message" "$admin"
fi