1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jenkins_ynh.git synced 2024-09-03 19:26:18 +02:00

Merge branch 'testing' into upgrade

This commit is contained in:
yalh76 2021-03-05 14:13:45 +01:00
commit 50cadb6d29
16 changed files with 590 additions and 760 deletions

View file

@ -5,8 +5,8 @@
*[Lire ce readme en français.](./README_fr.md)* *[Lire ce readme en français.](./README_fr.md)*
> *This package allow you to install Jenkins quickly and simply on a YunoHost server. > *This package allows you to install Jenkins 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.* If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## Overview ## Overview
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project. The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
@ -28,35 +28,30 @@ Use the admin panel of your Jenkins to configure this app.
## Documentation ## Documentation
* Official documentation: https://jenkins.io/doc/ * Official documentation: https://jenkins.io/doc/
* YunoHost documentation: There no other documentations, feel free to contribute.
## YunoHost specific features ## YunoHost specific features
#### Multi-users support #### Multi-user support
Supported, with LDAP and SSO. Supported, with LDAP and SSO.
#### Supported architectures #### Supported architectures
* x86-64 - [![](https://ci-apps.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/jenkins/) * x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/jenkins/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/jenkins/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/jenkins/)
## Limitations
## Additionnal informations
## Links ## Links
* Report a bug: https://github.com/YunoHost-Apps/jenkins_ynh/issues * Report a bug: https://github.com/YunoHost-Apps/jenkins_ynh/issues
* Jenkins website: https://jenkins.io * App website: https://jenkins.io
* Jenkins repository: https://github.com/jenkinsci/jenkins * Upstream app repository: https://github.com/jenkinsci/jenkins
* YunoHost website: https://yunohost.org/ * YunoHost website: https://yunohost.org/
--- ---
## Developers infos ## Developer info
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing). Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing).
To try the testing branch, please proceed like that. To try the testing branch, please proceed like that.
``` ```

View file

@ -6,12 +6,12 @@
*[Read this readme in english.](./README.md)* *[Read this readme in english.](./README.md)*
> *Ce package vous permet d'installer Jenkins rapidement et simplement sur un serveur YunoHost. > *Ce package vous permet d'installer Jenkins rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, merci de regarder [ici](https://yunohost.org/#/install_fr) pour savoir comment l'installer et en profiter.* Si vous n'avez pas YunoHost, consultez [le guide](https://yunohost.org/#/install) pour apprendre comment l'installer.*
## Vue d'ensemble ## Vue d'ensemble
Premier serveur d'automatisation open source, Jenkins fournit des centaines de plugins pour supporter la construction, le déploiement et l'automatisation de n'importe quel projet. Premier serveur d'automatisation open source, Jenkins fournit des centaines de plugins pour supporter la construction, le déploiement et l'automatisation de n'importe quel projet.
**Version embarquée :** 2.263.4 **Version incluse :** 2.263.4
## Captures d'écran ## Captures d'écran
@ -30,35 +30,31 @@ Utiliser le panneau d'administration de Jenkins pour configurer cette applicatio
* Documentation officielle : https://jenkins.io/doc/ * Documentation officielle : https://jenkins.io/doc/
* Documentation YunoHost : Il n'y a pas d'autre documentation, n'hésitez pas à contribuer. * Documentation YunoHost : Il n'y a pas d'autre documentation, n'hésitez pas à contribuer.
## Fonctionnalités spécifiques à YunoHost ## Caractéristiques spécifiques YunoHost
#### Support multi-utilisateurs #### Support multi-utilisateurs
Supportée, avec LDAP et SSO. Supportée, avec LDAP et SSO.
#### Architectures supportées. #### Architectures supportées
* x86-64 - [![](https://ci-apps.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/jenkins/) * x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/jenkins/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/jenkins/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/jenkins%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/jenkins/)
## Limitations
## Informations additionnelles
## Liens ## Liens
* Reporter un bug : https://github.com/YunoHost-Apps/jenkins_ynh/issues * Signaler un bug : https://github.com/YunoHost-Apps/jenkins_ynh/issues
* Site de jenkins : https://jenkins.io * Site de l'application : https://jenkins.io
* Dépôt git de Jenkins : https://github.com/jenkinsci/jenkins * Dépôt de l'application principale : https://github.com/jenkinsci/jenkins
* Site de YunoHost : https://yunohost.org/ * Site web YunoHost : https://yunohost.org/
--- ---
## Informations à l'intention des développeurs ## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing). Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing).
Pour tester la branche testing, merci de procéder ainsi. Pour essayer la branche testing, procédez comme suit.
``` ```
sudo yunohost app install https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing --debug
ou ou

117
YEP.md
View file

@ -1,117 +0,0 @@
#### [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)
`Not applicable`
#### [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)
`Not applicable`
#### [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)
`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)
`Don't know`
[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)
`Not yet 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)
`Validated`
#### [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)
`Not yet validated`
[YEP 4.5 - Utiliser les hooks](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-45)
`Not applicable`
#### [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)
`Not yet validated`
[YEP 2.14 - Remplir correctement un fichier de conf](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-214)
`Not yet 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)
`Don't know`
#### 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

@ -17,7 +17,6 @@
upgrade=1 from_commit=0e1aae7be82034650e2c1f6c1ad6d68a41b80176 upgrade=1 from_commit=0e1aae7be82034650e2c1f6c1ad6d68a41b80176
backup_restore=1 backup_restore=1
multi_instance=0 multi_instance=0
incorrect_path=1
port_already_use=1 (8080) port_already_use=1 (8080)
change_url=1 change_url=1
;;; Options ;;; Options

View file

@ -1,30 +1,30 @@
location __PATH__ { location __PATH__ {
proxy_pass http://127.0.0.1:__PORT__; proxy_pass http://127.0.0.1:__PORT__;
proxy_redirect http://127.0.0.1:__PORT__ https://__DOMAIN____PATH__; proxy_redirect http://127.0.0.1:__PORT__ https://__DOMAIN____PATH__;
proxy_set_header Host $host:$server_port; proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true; proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-User $remote_user; proxy_set_header X-Forwarded-User $remote_user;
sendfile off; sendfile off;
proxy_max_temp_file_size 0; proxy_max_temp_file_size 0;
client_max_body_size 10m; client_max_body_size 10m;
client_body_buffer_size 128k; client_body_buffer_size 128k;
proxy_connect_timeout 90; proxy_connect_timeout 90;
proxy_send_timeout 90; proxy_send_timeout 90;
proxy_read_timeout 90; proxy_read_timeout 90;
proxy_buffer_size 4k; proxy_buffer_size 4k;
proxy_buffers 4 32k; proxy_buffers 4 32k;
proxy_busy_buffers_size 64k; proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; proxy_temp_file_write_size 64k;
# Include SSOWAT user panel. # Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc; include conf.d/yunohost_panel.conf.inc;

View file

@ -1,63 +1,63 @@
{ {
"name": "Jenkins", "name": "Jenkins",
"id": "jenkins", "id": "jenkins",
"packaging_format": 1, "packaging_format": 1,
"description": { "description": {
"en": "Extendable continuous integration server", "en": "Extendable continuous integration server",
"fr": "Serveur d'intégration continue extensible" "fr": "Serveur d'intégration continue extensible"
}, },
"version": "2.263.4~ynh1", "version": "2.263.1~ynh1",
"url": "https://jenkins.io/index.html", "url": "https://jenkins.io/index.html",
"license": "MIT", "license": "MIT",
"maintainer": { "maintainer": {
"name": "None...", "name": "",
"email": "" "email": ""
}, },
"previous_maintainers": [{ "previous_maintainers": [{
"name": "Julien Malik et Maniack Crudelis", "name": "Julien Malik et Maniack Crudelis",
"email": "maniackc_dev@crudelis.fr" "email": "maniackc_dev@crudelis.fr"
}], }],
"requirements": { "requirements": {
"yunohost": ">= 4.0.0" "yunohost": ">= 4.1.3"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [
"nginx" "nginx"
], ],
"arguments": { "arguments": {
"install" : [ "install" : [
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
"ask": { "ask": {
"en": "Choose a domain for Jenkins", "en": "Choose a domain for Jenkins",
"fr": "Choisissez un domaine pour Jenkins" "fr": "Choisissez un domaine pour Jenkins"
}, },
"example": "domain.org" "example": "example.com"
}, },
{ {
"name": "path", "name": "path",
"type": "path", "type": "path",
"ask": { "ask": {
"en": "Choose a path for Jenkins", "en": "Choose a path for Jenkins",
"fr": "Choisissez un chemin pour Jenkins" "fr": "Choisissez un chemin pour Jenkins"
}, },
"example": "/jenkins", "example": "/jenkins",
"default": "/jenkins" "default": "/jenkins"
}, },
{ {
"name": "is_public", "name": "is_public",
"type": "boolean", "type": "boolean",
"ask": { "ask": {
"en": "Is it a public site?", "en": "Is it a public application?",
"fr": "Est-ce un site public ?" "fr": "Est-ce une application publique ?"
}, },
"default": true, "default": true,
"help": { "help": {
"en": "A public Jenkins will be accessible by everyone unless you configure the security into jenkins admin panel.", "en": "A public Jenkins will be accessible by everyone unless you configure the security into jenkins admin panel.",
"fr": "Un Jenkins public sera accessible par tout le monde à moins que vous ne configuriez la sécurité dans le panneau d'administration de jenkins." "fr": "Un Jenkins public sera accessible par tout le monde à moins que vous ne configuriez la sécurité dans le panneau d'administration de jenkins."
} }
} }
] ]
} }
} }

View file

@ -4,25 +4,13 @@
# COMMON VARIABLES # COMMON VARIABLES
#================================================= #=================================================
app_depencencies="openjdk-11-jdk daemon net-tools" # dependencies used by the app
pkg_dependencies="openjdk-11-jdk daemon net-tools"
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS
#================================================= #=================================================
#=================================================
# PACKAGE CHECK BYPASSING...
#=================================================
IS_PACKAGE_CHECK () {
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]
then
return 0
else
return 1
fi
}
#================================================= #=================================================
# BOOLEAN CONVERTER # BOOLEAN CONVERTER
#================================================= #=================================================
@ -41,393 +29,10 @@ bool_to_true_false () {
echo "$var" echo "$var"
} }
#=================================================
# FUTUR OFFICIAL HELPERS
#=================================================
# Install or update the main directory yunohost.multimedia
#
# usage: ynh_multimedia_build_main_dir
ynh_multimedia_build_main_dir () {
local ynh_media_release="v1.2"
local checksum="806a827ba1902d6911095602a9221181"
# Download yunohost.multimedia scripts
wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz 2>&1
# Check the control sum
echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
|| ynh_die "Corrupt source"
# Check if the package acl is installed. Or install it.
ynh_package_is_installed 'acl' \
|| ynh_package_install acl
# Extract
mkdir yunohost.multimedia-master
tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
./yunohost.multimedia-master/script/ynh_media_build.sh
}
# Add a directory in yunohost.multimedia
# This "directory" will be a symbolic link to a existing directory.
#
# usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# | arg: -d, --dest_dir= - Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
ynh_multimedia_addfolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
}
# Move a directory in yunohost.multimedia, and replace by a symbolic link
#
# usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# It will be moved to "Destination directory"
# A symbolic link will replace it.
# | arg: -d, --dest_dir= - Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
ynh_multimedia_movefolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
}
# Allow an user to have an write authorisation in multimedia directories
#
# usage: ynh_multimedia_addaccess user_name
#
# | arg: -u, --user_name= - The name of the user which gain this access.
ynh_multimedia_addaccess () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [u]=user_name=)
local user_name
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
groupadd -f multimedia
usermod -a -G multimedia $user_name
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS
#================================================= #=================================================
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
# | arg: -m --app_message= - The file with the content to send to the administrator.
# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
ynh_send_readme_to_admin() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
local app_message
local recipients
local type
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
app_message="${app_message:-}"
recipients="${recipients:-root}"
type="${type:-install}"
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# 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
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# 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")
# Subject base
local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
# Adapt the subject according to the type of mail required.
if [ "$type" = "backup" ]; then
mail_subject="$mail_subject has just been backup."
elif [ "$type" = "change_url" ]; then
mail_subject="$mail_subject has just been moved to a new URL!"
elif [ "$type" = "remove" ]; then
mail_subject="$mail_subject has just been removed!"
elif [ "$type" = "restore" ]; then
mail_subject="$mail_subject has just been restored!"
elif [ "$type" = "upgrade" ]; then
mail_subject="$mail_subject has just been upgraded!"
else # install
mail_subject="$mail_subject has just been installed!"
fi
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$(if [ -n "$app_message" ]
then
cat "$app_message"
else
echo "...No specific information..."
fi)
---
Automatic diagnosis data from YunoHost
__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
# Store the message into a file for further modifications.
echo "$mail_message" > mail_to_send
# If a html email is required. Apply html tags to the message.
if [ "$admin_mail_html" -eq 1 ]
then
# Insert 'br' tags at each ending of lines.
ynh_replace_string "$" "<br>" mail_to_send
# Insert starting HTML tags
sed --in-place '1s@^@<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n@' mail_to_send
# Keep tabulations
ynh_replace_string " " "\&#160;\&#160;" mail_to_send
ynh_replace_string "\t" "\&#160;\&#160;" mail_to_send
# Insert url links tags
ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "<a href=\"\2\">\1</a>" mail_to_send
# Insert pre tags
ynh_replace_string "__PRE_TAG1__" "<pre>" mail_to_send
ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
# Insert finishing HTML tags
echo -e "\n</body>\n</html>" >> mail_to_send
# Otherwise, remove tags to keep a plain text.
else
# Remove URL tags
ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
ynh_replace_string "__URL_TAG2__" ": " mail_to_send
# Remove PRE tags
ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
fi
# Define binary to use for mail command
if [ -e /usr/bin/bsd-mailx ]
then
local mail_bin=/usr/bin/bsd-mailx
else
local mail_bin=/usr/bin/mail.mailutils
fi
if [ "$admin_mail_html" -eq 1 ]
then
content_type="text/html"
else
content_type="text/plain"
fi
# Send the email to the recipients
cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
}
#================================================= #=================================================
# FUTURE OFFICIAL HELPERS
ynh_debian_release () {
lsb_release --codename --short
}
is_stretch () {
if [ "$(ynh_debian_release)" == "stretch" ]
then
return 0
else
return 1
fi
}
is_jessie () {
if [ "$(ynh_debian_release)" == "jessie" ]
then
return 0
else
return 1
fi
}
#================================================= #=================================================
ynh_maintenance_mode_ON () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
mkdir -p /var/www/html/
# Create an html to serve as maintenance notice
echo "<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="3">
<title>Your app $app is currently under maintenance!</title>
<style>
body {
width: 70em;
margin: 0 auto;
}
</style>
</head>
<body>
<h1>Your app $app is currently under maintenance!</h1>
<p>This app has been put under maintenance by your administrator at $(date)</p>
<p>Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.</p>
</body>
</html>" > "/var/www/html/maintenance.$app.html"
# Create a new nginx config file to redirect all access to the app to the maintenance notice instead.
echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice
rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect;
# Use another location, to not be in conflict with the original config file
location ${path_url}_maintenance/ {
alias /var/www/html/ ;
try_files maintenance.$app.html =503;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
# The current config file will redirect all requests to the root of the app.
# To keep the full path, we can use the following rewrite rule:
# rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect;
# The difference will be in the $1 at the end, which keep the following queries.
# But, if it works perfectly for a html request, there's an issue with any php files.
# This files are treated as simple files, and will be downloaded by the browser.
# Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was.
systemctl reload nginx
}
ynh_maintenance_mode_OFF () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
# Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app.
echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
sleep 4
# Then remove the temporary files used for the maintenance.
rm "/var/www/html/maintenance.$app.html"
rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
}
#=================================================
# Create a changelog for an app after an upgrade.
#
# The changelog is printed into the file ./changelog for the time of the upgrade.
#
# In order to create a changelog, ynh_app_changelog will get info from /etc/yunohost/apps/$app/status.json
# In order to find the current commit use by the app.
# The remote repository, and the branch.
# The changelog will be only the commits since the current revision.
#
# Because of the need of those info, ynh_app_changelog works only
# with apps that have been installed from a list.
#
# usage: ynh_app_changelog
ynh_app_changelog () {
get_value_from_settings ()
{
local value="$1"
# Extract a value from the status.json file of an installed app.
grep "$value\": \"" /etc/yunohost/apps/$app/status.json | sed "s/.*$value\": \"\([^\"]*\).*/\1/"
}
local current_revision="$(get_value_from_settings revision)"
local repo="$(get_value_from_settings url)"
local branch="$(get_value_from_settings branch)"
# ynh_app_changelog works only with an app installed from a list.
if [ -z "$current_revision" ] || [ -z "$repo" ] || [ -z "$branch" ]
then
ynh_print_warn "Unable to build the changelog..."
touch changelog
return 0
fi
# Fetch the history of the repository, without cloning it
mkdir git_history
(cd git_history
ynh_exec_warn_less git init
ynh_exec_warn_less git remote add -f origin $repo
# Get the line of the current commit of the installed app in the history.
local line_to_head=$(git log origin/$branch --pretty=oneline | grep --line-number "$current_revision" | cut -d':' -f1)
# Cut the history before the current commit, to keep only newer commits.
# Then use sed to reorganise each lines and have a nice list of commits since the last upgrade.
# This list is redirected into the file changelog
git log origin/$branch --pretty=oneline | head --lines=$(($line_to_head-1)) | sed 's/^\([[:alnum:]]*\)\(.*\)/*(\1) -> \2/g' > ../changelog)
# Remove 'Merge pull request' commits
sed -i '/Merge pull request #[[:digit:]]* from/d' changelog
# As well as conflict resolving commits
sed -i '/Merge branch .* into/d' changelog
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# If a html email is required. Apply html to the changelog.
if [ "$admin_mail_html" -eq 1 ]
then
sed -in-place "s@\*(\([[:alnum:]]*\)) -> \(.*\)@* __URL_TAG1__\2__URL_TAG2__${repo}/commit/\1__URL_TAG3__@g" changelog
fi
}

View file

@ -67,7 +67,7 @@ ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#================================================= #=================================================
ynh_script_progression --message="Reload nginx" ynh_script_progression --message="Reload nginx"
ynh_systemd_action --action=reload --service_name=nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -13,10 +14,10 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
# Exit if an error occurs during the execution of the script
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting ynh_clean_check_starting
} }
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#================================================= #=================================================

View file

@ -7,6 +7,7 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_maintenance_mode
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -26,6 +27,9 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2 ynh_script_progression --message="Loading installation settings..." --weight=2
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app=$app --key=port)
#================================================= #=================================================
@ -37,6 +41,23 @@ path_url=$old_path
domain=$old_domain domain=$old_domain
ynh_maintenance_mode_ON ynh_maintenance_mode_ON
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
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 # CHECK WHICH PARTS SHOULD BE CHANGED
#================================================= #=================================================
@ -53,18 +74,15 @@ then
change_path=1 change_path=1
fi fi
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
@ -77,7 +95,6 @@ if [ $change_path -eq 1 ]
then then
# Make a backup of the original NGINX config file if modified # Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper # Set global variables for NGINX helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
@ -95,7 +112,6 @@ then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path" ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi fi
@ -107,6 +123,8 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Updating Jenkins setup..." ynh_script_progression --message="Updating Jenkins setup..."
ynh_backup_if_checksum_is_different --file="/etc/default/jenkins"
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Add the path, in case of sub-path installation, into jenkins' boot options # Add the path, in case of sub-path installation, into jenkins' boot options
@ -126,20 +144,24 @@ then
fi fi
fi fi
#================================================= ynh_store_file_checksum --file="/etc/default/jenkins"
# RESTART JENKINS IN BACKGROUND
#=================================================
ynh_script_progression --message="Restarting Jenkins..." --weight=30
# Wait for Jenkins to be fully started #=================================================
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="300" # GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=30
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="300"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=2 ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --action=reload --service_name=nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# DEACTIVE MAINTENANCE MODE # DEACTIVE MAINTENANCE MODE

View file

@ -1,16 +1,17 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# GENERIC STARTING # GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE FAILURE OF THE SCRIPT # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
@ -36,7 +37,7 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..." ynh_script_progression --message="Validating installation parameters..."
@ -53,9 +54,6 @@ ynh_script_progression --message="Storing installation settings..." --weight=3
ynh_app_setting_set --app=$app --key=domain --value=$domain 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=path --value=$path_url
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1 ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
@ -66,7 +64,7 @@ ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
#================================================= #=================================================
ynh_script_progression --message="Finding an available port..." --weight=2 ynh_script_progression --message="Finding an available port..." --weight=2
# Find a free port # Find an available port
port=$(ynh_find_port --port=8080) port=$(ynh_find_port --port=8080)
ynh_app_setting_set --app=$app --key=port --value=$port ynh_app_setting_set --app=$app --key=port --value=$port
@ -75,7 +73,16 @@ ynh_app_setting_set --app=$app --key=port --value=$port
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." --weight=30 ynh_script_progression --message="Installing dependencies..." --weight=30
ynh_install_app_dependencies $app_depencencies ynh_install_app_dependencies $pkg_dependencies
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="../conf"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
@ -116,13 +123,19 @@ pid_change_port=$!
ynh_script_progression --message="Installing Jenkins..." --weight=30 ynh_script_progression --message="Installing Jenkins..." --weight=30
# Download jenkins deb file and install it. # Download jenkins deb file and install it.
ynh_setup_source --dest_dir="../conf"
dpkg --install --force-confnew ../conf/jenkins.deb dpkg --install --force-confnew ../conf/jenkins.deb
#================================================= #=================================================
# SETUP JENKINS # SETUP APPLICATION
#================================================= #=================================================
ynh_script_progression --message="Configuring Jenkins..." ynh_script_progression --message="Setuping application..." --weight=30
# Set the app as temporarily public for jenkins-cli.jar
ynh_script_progression --message="Configuring SSOwat..."
# Making the app public for curl
ynh_permission_update --permission="main" --add="visitors"
# Reload SSOwat config
yunohost app ssowatconf
# Ignore Setup Wizard # Ignore Setup Wizard
ynh_replace_string --match_string="\-Djava.awt.headless=true" --replace_string="& -Djenkins.install.runSetupWizard=false" --target_file=/etc/default/jenkins ynh_replace_string --match_string="\-Djava.awt.headless=true" --replace_string="& -Djenkins.install.runSetupWizard=false" --target_file=/etc/default/jenkins
@ -133,51 +146,29 @@ then
sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path_url@g" /etc/default/jenkins sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path_url@g" /etc/default/jenkins
fi fi
#=================================================
# FORCE PUBLIC ACCESS
#=================================================
ynh_script_progression --message="Forcing public access for the installation..." --weight=5
# Jenkins has to be public, at least for jenkins-cli.jar
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
ynh_systemd_action --action=reload --service_name=nginx
yunohost app ssowatconf
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log=/var/log/$app/$app.log
#=================================================
# CHECK JENKINS STARTING
#=================================================
ynh_script_progression --message="Starting Jenkins..." --weight=25
config_OK=0 config_OK=0
timeout=3600 timeout=3600
# Add the domain to /etc/hosts, to prevent any dns delay # Add the domain to /etc/hosts, to prevent any dns delay
echo "127.0.0.1 $domain #jenkins" | tee -a /etc/hosts echo "127.0.0.1 $domain #jenkins" | tee -a /etc/hosts
# Wait for Jenkins to be fully started # Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout" ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout"
# Enable Jenkins CLI Protocol/2 for jenkins-cli # Enable Jenkins CLI Protocol/2 for jenkins-cli
# That the only protocol that allow connection without an authenticated user... # That the only protocol that allow connection without an authenticated user...
ynh_replace_string --match_string="<slaveAgentPort>0</slaveAgentPort>" --replace_string="&\n<enabledAgentProtocols><string>CLI2-connect</string></enabledAgentProtocols>" --target_file=/var/lib/jenkins/config.xml ynh_replace_string --match_string="<slaveAgentPort>0</slaveAgentPort>" --replace_string="&\n<enabledAgentProtocols><string>CLI2-connect</string></enabledAgentProtocols>" --target_file=$final_path/config.xml
# Wait for Jenkins to be fully started # Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout" ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout"
ynh_script_progression --message="Installing plugins..." --weight=60 ynh_script_progression --message="Installing plugins..." --weight=60
# If the log says that jenkins has started, install the plugins # If the log says that jenkins has started, install the plugins
wget -nv --no-check-certificate https://$domain${path_url%/}/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar 2>&1 wget -nv --no-check-certificate https://$domain${path_url%/}/jnlpJars/jenkins-cli.jar -O $final_path/jenkins-cli.jar 2>&1
for i in `seq 1 $timeout` for i in `seq 1 $timeout`
do do
# Wait for an update of plugin repositories # Wait for an update of plugin repositories
if test -e /var/lib/jenkins/updates/default.json; then if test -e $final_path/updates/default.json; then
break; break;
else else
echo -n "." echo -n "."
@ -185,10 +176,13 @@ do
fi fi
done done
ynh_replace_string --match_string="<useSecurity>true</useSecurity>" --replace_string="<useSecurity>false</useSecurity>" --target_file=/var/lib/jenkins/config.xml # Remove the public access
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout" ynh_permission_update --permission="main" --remove="visitors"
jenkins_cli="ynh_exec_warn_less java -jar /var/lib/jenkins/jenkins-cli.jar -s http://${domain}:${port}${path_url%/}" ynh_replace_string --match_string="<useSecurity>true</useSecurity>" --replace_string="<useSecurity>false</useSecurity>" --target_file=$final_path/config.xml
ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout"
jenkins_cli="ynh_exec_warn_less java -jar $final_path/jenkins-cli.jar -s http://${domain}:${port}${path_url%/}"
# Install plugins for http authentication and ldap. # Install plugins for http authentication and ldap.
$jenkins_cli install-plugin reverse-proxy-auth-plugin $jenkins_cli install-plugin reverse-proxy-auth-plugin
@ -217,36 +211,72 @@ $jenkins_cli install-plugin ssh-slaves # SSH Slaves plugin
# Install extra comfort plugins # Install extra comfort plugins
# Handle terminal colours. Enhance the readability of the terminal. # Handle terminal colours. Enhance the readability of the terminal.
$jenkins_cli install-plugin ansicolor $jenkins_cli install-plugin ansicolor
# MOnitoring of the local file system. Allow to monitor a directory and trig a job if a file has been modified. # Monitoring of the local file system. Allow to monitor a directory and trig a job if a file has been modified.
$jenkins_cli install-plugin fstrigger $jenkins_cli install-plugin fstrigger
# Set global security with ldap # Set global security with ldap
cp ../conf/config.xml /var/lib/jenkins/ cp ../conf/config.xml $final_path/
chown jenkins: /var/lib/jenkins/config.xml chown jenkins: $final_path/config.xml
ynh_script_progression --message="Restarting Jenkins..." --weight=20 # Clean hosts file
sed -i '/#jenkins/d' /etc/hosts
# Wait for Jenkins to be fully started #=================================================
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout" # STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_script_progression --message="Storing the config file checksum..."
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="/etc/default/jenkins"
ynh_store_file_checksum --file="$final_path/config.xml"
#=================================================
# 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
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Extendable continuous integration server" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=20
# Start a systemd service
ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=9 ynh_script_progression --message="Configuring permissions..." --weight=9
if [ $is_public -eq 0 ] # Make app public if necessary
if [ $is_public -eq 1 ]
then then
# Remove the public access # Everyone can access the app.
ynh_app_setting_delete --app=$app --key=unprotected_uris # The "main" permission is automatically created before the install script.
# /path/github-webhook has to be accessible for github's webhooks ynh_permission_update --permission="main" --add="visitors"
ynh_app_setting_set --app=$app --key=skipped_uris --value="/github-webhook"
fi fi
#================================================= # /path/github-webhook has to be accessible for github's webhooks
# CLEAN HOSTS FILE ynh_permission_create --permission="github-webhook" --url "/github-webhook" --allowed="visitors" --show_tile="false" --protected="true"
#=================================================
sed -i '/#jenkins/d' /etc/hosts #=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# GENERIC STARTING # GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -17,11 +17,12 @@ ynh_script_progression --message="Loading installation settings..." --weight=4
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# REMOVE SERVICE FROM ADMIN PANEL # REMOVE SERVICE INTEGRATION IN YUNOHOST
#================================================= #=================================================
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
@ -31,24 +32,51 @@ then
yunohost service remove $app yunohost service remove $app
fi fi
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped LSB" --log_path="systemd"
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Removing dependencies..." --weight=20 ynh_script_progression --message="Removing dependencies..." --weight=20
ynh_apt purge jenkins
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_package_autopurge $app
ynh_remove_app_dependencies ynh_remove_app_dependencies
ynh_secure_remove --file="/var/lib/jenkins"
#================================================= #=================================================
# REMOVE THE NGINX CONFIGURATION # REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=2 ynh_script_progression --message="Removing NGINX web server configuration..." --weight=2
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
# Remove a directory securely
ynh_secure_remove --file="/etc/default/jenkins"
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -6,7 +6,10 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_maintenance_mode
source ../settings/scripts/ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -52,21 +55,23 @@ ynh_script_progression --message="Activating maintenance mode..." --weight=2
ynh_maintenance_mode_ON ynh_maintenance_mode_ON
#================================================= #=================================================
# STANDARD RESTORE STEPS # STANDARD RESTORATION STEPS
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # 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" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# SPECIFIC RESTORE # SPECIFIC RESTORATION
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=20 ynh_script_progression --message="Reinstalling dependencies..." --weight=20
ynh_install_app_dependencies $app_depencencies # Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# FIX THE PORT TO USE # FIX THE PORT TO USE
@ -115,18 +120,18 @@ ynh_secure_remove --file="/etc/default/jenkins"
ynh_restore_file --origin_path=/etc/default/$app ynh_restore_file --origin_path=/etc/default/$app
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/$app.log" yunohost service add $app --description="Extendable continuous integration server" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# CHECK JENKINS STARTING # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Restarting Jenkins..." --weight=20 ynh_script_progression --message="Starting a systemd service..." --weight=20
# Wait for Jenkins to be fully started ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
#================================================= #=================================================
# DEACTIVE MAINTENANCE MODE # DEACTIVE MAINTENANCE MODE
@ -149,6 +154,15 @@ If you're facing an issue or want to improve this app, please open a new issue i
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=restore ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=restore
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -1,12 +1,14 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# GENERIC STARTING # GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_maintenance_mode
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -18,13 +20,14 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) 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) port=$(ynh_app_setting_get --app=$app --key=port)
overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx) overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
@ -59,6 +62,18 @@ then
apt-get update apt-get update
fi fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
# Create a permission if needed
if ! ynh_permission_exists --permission="github-webhook"; then
ynh_permission_create --permission="github-webhook" --url "/github-webhook" --allowed="visitors" --show_tile="false" --protected="true"
fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
@ -81,13 +96,25 @@ ynh_script_progression --message="Activating maintenance mode..." --weight=2
ynh_maintenance_mode_ON ynh_maintenance_mode_ON
ynh_backup_if_checksum_is_different --file="/etc/default/jenkins"
ynh_backup_if_checksum_is_different --file="$final_path/config.xml"
#================================================= #=================================================
# UPGRADE JENKINS # STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped LSB" --log_path="systemd"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading Jenkins..." --weight=40 ynh_script_progression --message="Upgrading source files..." --weight=40
# Download jenkins deb file and install it. # Download jenkins deb file and install it.
ynh_setup_source --dest_dir="../conf" ynh_setup_source --dest_dir="../conf"
dpkg --install --force-confnew ../conf/jenkins.deb dpkg --install --force-confnew ../conf/jenkins.deb
@ -106,13 +133,6 @@ then
fi fi
fi fi
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=12
ynh_install_app_dependencies $app_depencencies
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
@ -127,23 +147,20 @@ then
fi fi
#================================================= #=================================================
# SETUP SSOWAT # UPGRADE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..." ynh_script_progression --message="Upgrading dependencies..." --weight=12
if [ $is_public -eq 1 ] ynh_install_app_dependencies $pkg_dependencies
then
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
else
ynh_app_setting_delete --app=$app --key=unprotected_uris
fi
#=================================================
# SPECIFIC UPGRADE
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2 ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_systemd_action --action=reload --service_name=nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# CHECK JENKINS STARTING # CHECK JENKINS STARTING
@ -151,7 +168,7 @@ ynh_systemd_action --action=reload --service_name=nginx
ynh_script_progression --message="Restarting Jenkins..." --weight=25 ynh_script_progression --message="Restarting Jenkins..." --weight=25
# Wait for Jenkins to be fully started # Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600" ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
#================================================= #=================================================
# DEACTIVE MAINTENANCE MODE # DEACTIVE MAINTENANCE MODE
@ -165,35 +182,56 @@ ynh_maintenance_mode_OFF
#================================================= #=================================================
ynh_script_progression --message="Upgrading jenkins-cli.jar..." ynh_script_progression --message="Upgrading jenkins-cli.jar..."
wget -nv --no-check-certificate https://$domain${path_url%/}/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar.temp 2>&1 wget -nv --no-check-certificate https://127.0.0.1${path_url%/}/jnlpJars/jenkins-cli.jar -O $final_path/jenkins-cli.jar.temp 2>&1
cp -f /var/lib/jenkins/jenkins-cli.jar.temp /var/lib/jenkins/jenkins-cli.jar mv -f $final_path/jenkins-cli.jar.temp $final_path/jenkins-cli.jar
#================================================= #=================================================
# UPGRADE PLUGINS # UPGRADE PLUGINS
#================================================= #=================================================
ynh_script_progression --message="Upgrading plugins..." --weight=40 ynh_script_progression --message="Upgrading plugins..." --weight=40
cp /var/lib/jenkins/config.xml /var/lib/jenkins/config.xml.bak cp $final_path/config.xml $final_path/config.xml.bak
ynh_replace_string --match_string="<useSecurity>true</useSecurity>" --replace_string="<useSecurity>false</useSecurity>" --target_file=/var/lib/jenkins/config.xml ynh_replace_string --match_string="<useSecurity>true</useSecurity>" --replace_string="<useSecurity>false</useSecurity>" --target_file=$final_path/config.xml
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600" ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
jenkins_cli="ynh_exec_warn_less java -jar /var/lib/jenkins/jenkins-cli.jar -s http://${domain}:${port}${path_url%/}" jenkins_cli="ynh_exec_warn_less java -jar $final_path/jenkins-cli.jar -s http://127.0.0.1:${port}${path_url%/}"
UPDATE_LIST=$($jenkins_cli list-plugins | grep -e ')$' | awk '{ print $1 }' ) UPDATE_LIST=$($jenkins_cli list-plugins | grep -oP '^(.*?) ')
for plugin in ${UPDATE_LIST} for plugin in ${UPDATE_LIST}
do do
$jenkins_cli install-plugin "$plugin" || true $jenkins_cli install-plugin "$plugin" || true
done done
mv /var/lib/jenkins/config.xml.bak /var/lib/jenkins/config.xml mv $final_path/config.xml.bak $final_path/config.xml
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="/etc/default/jenkins"
ynh_store_file_checksum --file="$final_path/config.xml"
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # GENERIC FINALIZATION
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Securing files and directories..."
yunohost service add $app --log=/var/log/$app/$app.log # Set permissions on app files
chown -R $app:$app $final_path
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Extendable continuous integration server" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="restart" --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN
@ -202,21 +240,20 @@ yunohost service add $app --log=/var/log/$app/$app.log
# Get main domain and buid the url of the admin panel of the app. # Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
# Build the changelog
ynh_app_changelog || true
echo "You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. echo "You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/jenkins_ynh__URL_TAG3__. If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/jenkins_ynh__URL_TAG3__." > mail_to_send
---
Changelog since your last upgrade:
$(cat changelog)" > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -0,0 +1,80 @@
#!/bin/bash
ynh_maintenance_mode_ON () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
mkdir -p /var/www/html/
# Create an html to serve as maintenance notice
echo "<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="3">
<title>Your app $app is currently under maintenance!</title>
<style>
body {
width: 70em;
margin: 0 auto;
}
</style>
</head>
<body>
<h1>Your app $app is currently under maintenance!</h1>
<p>This app has been put under maintenance by your administrator at $(date)</p>
<p>Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.</p>
</body>
</html>" > "/var/www/html/maintenance.$app.html"
# Create a new nginx config file to redirect all access to the app to the maintenance notice instead.
echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice
rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect;
# Use another location, to not be in conflict with the original config file
location ${path_url}_maintenance/ {
alias /var/www/html/ ;
try_files maintenance.$app.html =503;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
# The current config file will redirect all requests to the root of the app.
# To keep the full path, we can use the following rewrite rule:
# rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect;
# The difference will be in the $1 at the end, which keep the following queries.
# But, if it works perfectly for a html request, there's an issue with any php files.
# This files are treated as simple files, and will be downloaded by the browser.
# Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was.
systemctl reload nginx
}
ynh_maintenance_mode_OFF () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
# Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app.
echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
sleep 4
# Then remove the temporary files used for the maintenance.
rm "/var/www/html/maintenance.$app.html"
rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
}

View file

@ -0,0 +1,140 @@
#!/bin/bash
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
# | arg: -m --app_message= - The file with the content to send to the administrator.
# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
ynh_send_readme_to_admin() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
local app_message
local recipients
local type
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
app_message="${app_message:-}"
recipients="${recipients:-root}"
type="${type:-install}"
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# 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
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# 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")
# Subject base
local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
# Adapt the subject according to the type of mail required.
if [ "$type" = "backup" ]; then
mail_subject="$mail_subject has just been backup."
elif [ "$type" = "change_url" ]; then
mail_subject="$mail_subject has just been moved to a new URL!"
elif [ "$type" = "remove" ]; then
mail_subject="$mail_subject has just been removed!"
elif [ "$type" = "restore" ]; then
mail_subject="$mail_subject has just been restored!"
elif [ "$type" = "upgrade" ]; then
mail_subject="$mail_subject has just been upgraded!"
else # install
mail_subject="$mail_subject has just been installed!"
fi
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$(if [ -n "$app_message" ]
then
cat "$app_message"
else
echo "...No specific information..."
fi)
---
Automatic diagnosis data from YunoHost
__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
# Store the message into a file for further modifications.
echo "$mail_message" > mail_to_send
# If a html email is required. Apply html tags to the message.
if [ "$admin_mail_html" -eq 1 ]
then
# Insert 'br' tags at each ending of lines.
ynh_replace_string "$" "<br>" mail_to_send
# Insert starting HTML tags
sed --in-place '1s@^@<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n@' mail_to_send
# Keep tabulations
ynh_replace_string " " "\&#160;\&#160;" mail_to_send
ynh_replace_string "\t" "\&#160;\&#160;" mail_to_send
# Insert url links tags
ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "<a href=\"\2\">\1</a>" mail_to_send
# Insert pre tags
ynh_replace_string "__PRE_TAG1__" "<pre>" mail_to_send
ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
# Insert finishing HTML tags
echo -e "\n</body>\n</html>" >> mail_to_send
# Otherwise, remove tags to keep a plain text.
else
# Remove URL tags
ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
ynh_replace_string "__URL_TAG2__" ": " mail_to_send
# Remove PRE tags
ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
fi
# Define binary to use for mail command
if [ -e /usr/bin/bsd-mailx ]
then
local mail_bin=/usr/bin/bsd-mailx
else
local mail_bin=/usr/bin/mail.mailutils
fi
if [ "$admin_mail_html" -eq 1 ]
then
content_type="text/html"
else
content_type="text/plain"
fi
# Send the email to the recipients
cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
}