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

Merge pull request #2 from maniackcrudelis/master

Refonte du package
This commit is contained in:
Maniack Crudelis 2016-12-03 00:41:53 +01:00 committed by GitHub
commit 7bb92eaaa5
13 changed files with 867 additions and 128 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.swp
*~
Notes

202
LICENSE Normal file
View file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

15
README.md Normal file
View file

@ -0,0 +1,15 @@
Jenkins for YunoHost
==================
[Yunohost project](https://yunohost.org/#/)
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
https://jenkins.io
Le script installe les paquets *ca-certificates-java*, *daemon*, *default-jre-headless*, *java-common*, *jenkins*, *libasyncns0*, *libflac8*, *libice6*, *libnspr4*, *libnss3*, *libogg0*, *libpcsclite1*, *libpulse0*, *libsctp1*, *libsm6*, *libsndfile1*, *libvorbis0a*, *libvorbisenc2*, *libx11-xcb1*, *libxtst6*, *lksctp-tools*, *openjdk-7-jre-headless*, *tzdata-java*, *x11-common*.
**Mise à jour du package:**
sudo yunohost app upgrade jenkins -u https://github.com/YunoHost-Apps/jenkins_ynh
**Multi-utilisateur:** Oui, avec support ldap.

23
check_process Normal file
View file

@ -0,0 +1,23 @@
;; Test complet
auto_remove=1
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
is_public="Yes" (PUBLIC|public=Yes|private=No)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=0
wrong_user=0
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=0
port_already_use=1 (8080)
final_path_already_use=0

51
conf/config.xml Normal file
View file

@ -0,0 +1,51 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<disabledAdministrativeMonitors/>
<version>1.0</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.FullControlOnceLoggedInAuthorizationStrategy">
<denyAnonymousReadAccess>false</denyAnonymousReadAccess>
</authorizationStrategy>
<securityRealm class="hudson.security.LDAPSecurityRealm" plugin="ldap@1.13">
<server>ldap://localhost:389/</server>
<rootDN>dc=yunohost,dc=org</rootDN>
<inhibitInferRootDN>false</inhibitInferRootDN>
<userSearchBase></userSearchBase>
<userSearch>uid={0}</userSearch>
<groupMembershipStrategy class="jenkins.security.plugins.ldap.FromGroupSearchLDAPGroupMembershipStrategy">
<filter></filter>
</groupMembershipStrategy>
<managerPasswordSecret></managerPasswordSecret>
<disableMailAddressResolver>false</disableMailAddressResolver>
<displayNameAttributeName>displayname</displayNameAttributeName>
<mailAddressAttributeName>mail</mailAddressAttributeName>
<userIdStrategy class="jenkins.model.IdStrategy$CaseInsensitive"/>
<groupIdStrategy class="jenkins.model.IdStrategy$CaseInsensitive"/>
</securityRealm>
<disableRememberMe>false</disableRememberMe>
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
<workspaceDir>${ITEM_ROOTDIR}/workspace</workspaceDir>
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
<markupFormatter class="hudson.markup.EscapedMarkupFormatter"/>
<jdks/>
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
<clouds/>
<scmCheckoutRetryCount>0</scmCheckoutRetryCount>
<views>
<hudson.model.AllView>
<owner class="hudson" reference="../../.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
</hudson.model.AllView>
</views>
<primaryView>All</primaryView>
<slaveAgentPort>0</slaveAgentPort>
<label></label>
<nodeProperties/>
<globalNodeProperties/>
</hudson>

View file

@ -1,27 +1,31 @@
location YNH_LOCATION { location __PATH__ {
proxy_pass http://127.0.0.1:YNH_PORT; proxy_pass http://127.0.0.1:__PORT__;
proxy_redirect http://127.0.0.1:__PORT__ https://__DOMAIN____PATH__;
proxy_redirect off; proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-User $remote_user;
proxy_set_header X-Real-IP $remote_addr; sendfile off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto $scheme;
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 4m; proxy_connect_timeout 90;
proxy_send_timeout 4m; proxy_send_timeout 90;
proxy_read_timeout 4m; 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;
sendfile off; # Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
} }

View file

@ -1,53 +1,54 @@
{ {
"name": "Jenkins", "name": "Jenkins",
"id": "jenkins", "id": "jenkins",
"description": { "packaging_format": 1,
"en": "Serveur d'intégration continue extensible", "requirements": {
"fr": "Extendable continuous integration server" "yunohost": ">= 2.4"
}, },
"developer": { "description": {
"name": "Julien Malik", "en": "Serveur d'intégration continue extensible",
"email": "julien.malik@paraiso.me" "fr": "Extendable continuous integration server"
}, },
"multi_instance": "false", "url": "https://jenkins.io/index.html",
"arguments": { "license": "free",
"install" : [ "maintainer": {
{ "name": "Julien Malik et Maniack Crudelis",
"name": "domain", "email": "maniackc_dev@crudelis.fr"
"ask": { },
"en": "Choose a domain for Jenkins", "multi_instance": false,
"fr": "Choisissez un domaine pour Jenkins" "services": [
}, "nginx"
"example": "domain.org" ],
}, "arguments": {
{ "install" : [
"name": "path", {
"ask": { "name": "domain",
"en": "Choose a path for Jenkins", "type": "domain",
"fr": "Choisissez un path pour Jenkins" "ask": {
}, "en": "Choose a domain for Jenkins",
"example": "/jenkins", "fr": "Choisissez un domaine pour Jenkins"
"default": "/jenkins" },
}, "example": "domain.org"
{ },
"name": "is_public", {
"ask": { "name": "path",
"en": "Is it a public site?", "type": "path",
"fr": "Est-ce un site public ?" "ask": {
}, "en": "Choose a path for Jenkins",
"choices": ["Yes", "No"], "fr": "Choisissez un chemin pour Jenkins"
"default": "Yes" },
}, "example": "/jenkins",
{ "default": "/jenkins"
"name": "port", },
"ask": { {
"en": "Internal running port ?", "name": "is_public",
"fr": "Port de fonctionnement interne ?" "ask": {
}, "en": "Is it a public site?",
"example": "8080", "fr": "Est-ce un site public ?"
"default": "8080" },
} "choices": ["Yes", "No"],
] "default": "Yes"
} }
]
}
} }

211
scripts/.fonctions Executable file
View file

@ -0,0 +1,211 @@
#!/bin/bash
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
# $1 = Variable à vérifier
# $2 = Texte à afficher en cas d'erreur
test -n "$1" || (echo "$2" >&2 && false)
}
EXIT_PROPERLY () { # Provoque l'arrêt du script en cas d'erreur. Et nettoye les résidus.
trap '' ERR
echo -e "\e[91m \e[1m" # Shell in light red bold
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" >&2
CLEAN_SETUP # Appel la fonction de nettoyage spécifique du script install.
# Compense le bug de ssowat qui ne supprime pas l'entrée de l'app en cas d'erreur d'installation.
sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json
ynh_die
}
TRAP_ON () { # Activate signal capture
trap EXIT_PROPERLY ERR # Capturing exit signals on error
}
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien.
# Mais pas la fonction TRAP_OFF...
# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction.
trap '' ERR # Ignoring exit signals
}
CHECK_USER () { # Vérifie la validité de l'user admin
# $1 = Variable de l'user admin.
ynh_user_exists "$1" || (echo "Wrong admin" >&2 && false)
}
CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin.
if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
path="/$path" # Ajoute un / en début de path
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère.
path="${path:0:${#path}-1}" # Supprime le dernier caractère
fi
}
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path -a $app
}
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
final_path=/var/www/$app
if [ -e "$final_path" ]
then
echo "This path already contains a folder" >&2
false
fi
}
GENERATE_DB () { # Créer une base de données et un utilisateur dédié au nom de l'app.
# $1 = Nom de la base de donnée
db_user=$1
# Génère un mot de passe aléatoire.
# db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
db_pwd=$(ynh_string_random)
CHECK_VAR "$db_pwd" "db_pwd empty"
# Utilise '$app' comme nom d'utilisateur et de base de donnée
# Initialise la base de donnée et stocke le mot de passe mysql.
ynh_mysql_create_db $db_user $db_user $db_pwd
ynh_app_setting_set $app mysqlpwd $db_pwd
}
SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path
# $1 = Nom de l'archive téléchargée.
wget -nv -i ../sources/source_url -O $1
# Vérifie la somme de contrôle de la source téléchargée.
md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
# Décompresse la source
if [ "$(echo ${1##*.})" == "gz" ]; then
tar -x -f $1
elif [ "$(echo ${1##*.})" == "zip" ]; then
unzip -q $1
else
false # Format d'archive non pris en charge.
fi
# Copie les fichiers sources
sudo cp -a $(cat ../sources/source_dir)/. "$final_path"
# Copie les fichiers additionnels ou modifiés.
if test -e "../sources/ajouts"; then
sudo cp -a ../sources/ajouts/. "$final_path"
fi
}
ADD_SYS_USER () { # Créer un utilisateur système dédié à l'app
if ynh_system_user_exists "$app" # Test l'existence de l'utilisateur
then
sudo useradd -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin || (echo "Unable to create $app system account" >&2 && false)
fi
}
POOL_FPM () { # Créer le fichier de configuration du pool php-fpm et le configure.
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $finalphpconf
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
}
STORE_MD5_CONFIG () { # Enregistre la somme de contrôle du fichier de config
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
# $2 = Nom complet et chemin du fichier de conf.
ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1)
}
CHECK_MD5_CONFIG () { # Créé un backup du fichier de config si il a été modifié.
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
# $2 = Nom complet et chemin du fichier de conf.
if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then
sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup.
fi
}
FIND_PORT () { # Cherche un port libre.
# $1 = Numéro de port pour débuter la recherche.
port=$1
while ! sudo yunohost app checkport $port ; do
port=$((port+1))
done
CHECK_VAR "$port" "port empty"
}
### REMOVE SCRIPT
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
echo "Delete nginx config"
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo service nginx reload
fi
}
REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config
echo "Delete fpm config"
sudo rm "/etc/php5/fpm/pool.d/$app.conf"
fi
if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config
echo "Delete php config"
sudo rm "/etc/php5/fpm/conf.d/20-$app.ini"
fi
sudo service php5-fpm reload
}
REMOVE_LOGROTATE_CONF () { # Suppression de la configuration de logrotate
if [ -e "/etc/logrotate.d/$app" ]; then
echo "Delete logrotate config"
sudo rm "/etc/logrotate.d/$app"
fi
}
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
chaine="$1"
no_var=0
while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine
do
no_var=1
global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée.
only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse surtout du / et d'un éventuel chemin derrière.
real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable.
if test -z "$real_var" || [ "$real_var" = "/" ]; then
echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2
return 1
fi
chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine.
done
if [ "$no_var" -eq 1 ]
then
if [ -e "$chaine" ]; then
echo "Delete directory $chaine"
sudo rm -r "$chaine"
fi
return 0
else
echo "No detected variable." >&2
return 1
fi
}
REMOVE_BDD () { # Suppression de la base de donnée et de l'utilisateur associé.
# $1 = Nom de la base de donnée
# Utilise '$app' comme nom d'utilisateur et de base de donnée
db_user=$1
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then
echo "Delete db"
ynh_mysql_drop_db $db_user
ynh_mysql_drop_user $db_user
fi
}
REMOVE_SYS_USER () { # Supprime l'utilisateur système dédié à l'app
if ynh_system_user_exists "$app" # Test l'existence de l'utilisateur
then
sudo userdel $app
fi
}

25
scripts/backup Normal file
View file

@ -0,0 +1,25 @@
#!/bin/bash
# Récupère les infos de l'application.
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
# The parameter $1 is the backup directory location
# which will be compressed afterward
backup_dir=$1/apps/$app
sudo mkdir -p "$backup_dir"
# Backup sources & data
sudo cp -a $final_path/. $backup_dir/sources
# Copy Nginx and YunoHost parameters to make the script "standalone"
sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost
sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf $backup_dir/nginx.conf
# Copie de la configuration de démarrage de Jenkins
sudo cp -a /etc/default/$app $backup_dir/etc

View file

@ -1,57 +1,168 @@
#!/bin/bash #!/bin/bash
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
CLEAN_SETUP () {
# Nettoyage des résidus d'installation non pris en charge par le script remove.
if test -n "$PID_TAIL"
then
kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail.
sudo rm -f "$tempfile"
fi
# Clean hosts
sudo sed -i '/#jenkins/d' /etc/hosts
echo ""
}
TRAP_ON # Active trap pour arrêter le script si une erreur est détectée.
# Retrieve arguments # Retrieve arguments
domain=$1 domain=$YNH_APP_ARG_DOMAIN
path=$2 path=$YNH_APP_ARG_PATH
is_public=$3 is_public=$YNH_APP_ARG_IS_PUBLIC
port=$4
sudo yunohost app checkport $port app=$YNH_APP_INSTANCE_NAME
if [[ ! $? -eq 0 ]]; then
echo "Port $port is not available. Aborting..." # Source app helpers
exit 1 source /usr/share/yunohost/helpers
# Vérifie que les variables ne sont pas vides.
CHECK_VAR "$app" "app name not set"
CHECK_PATH # Vérifie et corrige la syntaxe du path.
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
# Vérifie que le dossier de destination n'est pas déjà utilisé.
final_path=/var/lib/$app
if [ -e "$final_path" ]
then
echo "This path already contains a folder" >&2
false
fi fi
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a jenkins FIND_PORT 8080 # Cherche un port libre.
if [[ ! $? -eq 0 ]]; then
exit 1
fi # Enregistre les infos dans la config YunoHost
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app port $port
ynh_app_setting_set $app final_path $final_path
echo "Install dependencies..." echo "Install dependencies..."
wget -q -O - "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key" | sudo apt-key add - wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo bash -c "cat > /etc/apt/sources.list.d/jenkins.list << EOF sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
deb http://pkg.jenkins-ci.org/debian binary/
EOF
"
sudo apt-get update sudo apt-get update
sudo apt-get install default-jre-headless -y
sudo apt-get install jenkins -y sudo apt-get install jenkins -y
if [[ "$path" != "/" ]]; # Renseigne le port
then sudo sed -i "s/^HTTP_PORT=.*/HTTP_PORT=$port/g" /etc/default/jenkins
# $ means 'process only the last line' # Ignore le Setup Wizard
sudo sed -i '$ s@--ajp13Port=$AJP_PORT@--ajp13Port=$AJP_PORT --prefix=$PREFIX@g' /etc/default/jenkins sudo sed -i "s/-Djava.awt.headless=true/& -Djenkins.install.runSetupWizard=false/g" /etc/default/jenkins
fi
sudo sed -i "s/HTTP_PORT=.*/HTTP_PORT=$port/g" /etc/default/jenkins
sudo service jenkins restart if [ "$path" != "/" ];
then # Ajoute le path en cas d'installation en sous-dossier dans les options de démarrage de Jenkins
sudo yunohost service add jenkins -l /var/log/jenkins/jenkins.log sudo sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path@g" /etc/default/jenkins
echo "Nginx configuration (sso disabled)..."
sed -i "s@YNH_LOCATION@$path@g" ../conf/nginx.conf
sed -i "s@YNH_PORT@$port@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/jenkins.conf
sudo yunohost app setting jenkins is_public -v $is_public
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting jenkins unprotected_uris -v "/"
fi fi
# restart 2 times for debug sudo service $app restart # Redémarre jenkins pour prendre en compte les modifications
sudo service jenkins restart tempfile="$(mktemp)"
tail -f -n1 /var/log/$app/$app.log > "$tempfile" & # Suit le démarrage dans le log
PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan.
# Copie le fichier de config nginx
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Et modifie les variables dans le fichier de configuration nginx
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__DOMAIN__@$domain@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
# Jenkins est public par défaut, au moins pour le téléchargement de jenkins-cli.jar
ynh_app_setting_set $app unprotected_uris "/"
sudo service nginx reload sudo service nginx reload
sudo yunohost app ssowatconf sudo yunohost app ssowatconf
# Ajoute le service au monitoring de Yunohost.
sudo yunohost service add $app -l /var/log/$app/$app.log
# Surveille le démarrage du service.
config_OK=0
echo "127.0.0.1 $domain #jenkins" | sudo tee -a /etc/hosts # Renseigne le domain dans le host, pour prévenir d'un dns pas encore propagé.
for i in `seq 1 60`
do # La boucle attend le démarrage de jenkins Ou 60 secondes.
if grep -q "INFOS: Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 0 ]; then
# Si le log annonce une première fois le démarrage de jenkins. Fait sauter la sécurité de la première connexion de l'admin. Qui bloque curl et demande une identification inexistante une fois sur deux...
sudo wget -nv --no-check-certificate https://$domain$path/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar
for i in `seq 1 60`
do # La boucle attend la mise à jour des dépôts de plugins. Ou 60 secondes.
if test -e /var/lib/jenkins/updates/default.json; then
break;
else
echo -n "." >&2
sleep 1
fi
done
# Installation du plugin pour l'authentification ldap et http auth
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin reverse-proxy-auth-plugin
# Installation des plugins recommandés (Lors de l'install avec le Setup Wizard)
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin cloudbees-folder # Folders Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin antisamy-markup-formatter # OWASP Markup Formatter Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin pam-auth # PAM Authentication plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin mailer # Mailer Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin ldap # LDAP Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin matrix-auth # Matrix Authorization Strategy Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin build-timeout # Build timeout plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin credentials-binding # Credentials Binding Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin timestamper # Timestamper
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin ws-cleanup # Workspace Cleanup Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin ant # Ant Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin gradle # Gradle Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin workflow-aggregator # Pipeline
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin pipeline-stage-view # Pipeline: Stage View Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin git # Git plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin github-organization-folder # GitHub Organization Folder Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin subversion # Subversion Plug-in
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin email-ext # Email Extension Plugin
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin ssh-slaves # SSH Slaves plugin
# Installation de plugins supplémentaires pour le confort
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin ansicolor # Prise en charge des couleurs pour la sortie console. Améliore la lisibilité de la console (par contre les couleurs ne passent pas...)
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin fstrigger # Monitoring sur le système de fichier local. Pour surveiller des dossiers de code et builder sur les changements.
# Configure la sécurité globale avec ldap par défaut.
sudo cp ../conf/config.xml /var/lib/jenkins/
sudo chown jenkins: /var/lib/jenkins/config.xml
sudo service $app restart # Puis redémarre à nouveau le service.
cat /dev/null > "$tempfile" # Purge le log de suivi du démarrage.
config_OK=1
i=1;
fi
if grep -q "INFOS: Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 1 ]; then
break # Si le log annonce une deuxième fois le démarrage de jenkins, sort de la boucle.
fi
echo -n "." >&2
sleep 1
done
kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail.
sudo rm "$tempfile"
# Si Jenkins est privé, retire l'autorisation publique.
if [ "$is_public" = "No" ];
then # Retire l'accès public
ynh_app_setting_delete $app unprotected_uris
ynh_app_setting_set $app skipped_uris "/github-webhook" # /path/github-webhook doit rester accessible pour les webhooks de github.
fi
# Clean hosts
sudo sed -i '/#jenkins/d' /etc/hosts

View file

@ -1,16 +1,36 @@
#!/bin/bash #!/bin/bash
domain=$(sudo yunohost app setting jenkins domain) source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
sudo rm /etc/nginx/conf.d/$domain.d/jenkins.conf # Récupère les infos de l'application.
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
domain=$(ynh_app_setting_get $app domain)
# Retire le service du monitoring de Yunohost.
if sudo yunohost service status | grep -q $app # Test l'existence du service dans Yunohost
then
echo "Remove $app service"
sudo yunohost service remove $app
fi
# Supprime Jenkins
sudo apt-get purge jenkins -y sudo apt-get purge jenkins -y
sudo rm /etc/apt/sources.list.d/jenkins.list sudo rm /etc/apt/sources.list.d/jenkins.list
# TODO remove repo key # Récupère l'id de la clé APT de jenkins
apt_key=$(sudo apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)
sudo apt-key del $apt_key # Supprime la clé APT
sudo apt-get update sudo apt-get update
sudo yunohost service remove jenkins # Régénère la configuration de SSOwat
sudo yunohost app ssowatconf sudo yunohost app ssowatconf
sudo service nginx reload
REMOVE_NGINX_CONF # Suppression de la configuration nginx
SECURE_REMOVE '/var/lib/$app' # Suppression du dossier de l'application, si il y a des résidus.
echo -e "\e[0m" # Restore normal color

65
scripts/restore Normal file
View file

@ -0,0 +1,65 @@
#!/bin/bash
# Récupère les infos de l'application.
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
if [ -d $final_path ]; then
ynh_die "There is already a directory: $final_path"
fi
# The parameter $1 is the uncompressed restore directory location
backup_dir=$1/apps/$app
# Restore Nginx
conf=/etc/nginx/conf.d/$domain.d/$app.conf
if [ -f $conf ]; then
ynh_die "There is already a nginx conf file at this path: $conf"
fi
sudo cp -a $backup_dir/nginx.conf $conf
# Restore YunoHost parameters
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app
echo "Reinstall dependencies..."
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install default-jre-headless -y
sudo apt-get install jenkins -y
# Restore sources & data
sudo cp -a "$backup_dir/sources/." $final_path
# Restauration de la configuration de démarrage de Jenkins
sudo cp -a $backup_dir/etc /etc/default/$app
sudo service $app restart # Redémarre jenkins pour prendre en compte les modifications
tempfile="$(mktemp)"
tail -f -n1 /var/log/$app/$app.log > "$tempfile" & # Suit le démarrage dans le log
PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan.
# Ajoute le service au monitoring de Yunohost.
sudo yunohost service add $app --log "/var/log/$app/$app.log"
# Reload webserver
sudo service nginx reload
# Surveille le démarrage du service.
for i in `seq 1 60`
do # La boucle attend le démarrage de jenkins Ou 60 secondes.
if grep -q "INFOS: Jenkins is fully up and running" "$tempfile"; then
break # Si le log annonce le démarrage de jenkins, sort de la boucle.
fi
echo -n "." >&2
sleep 1
done
kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail.
sudo rm "$tempfile"

View file

@ -1,25 +1,33 @@
#!/bin/bash #!/bin/bash
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
# Récupère les infos de l'application.
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
# Retrieve arguments # Retrieve arguments
domain=$(sudo yunohost app setting jenkins domain) domain=$(ynh_app_setting_get $app domain)
path=$(sudo yunohost app setting jenkins path) path=$(ynh_app_setting_get $app path)
path=${path%/} is_public=$(ynh_app_setting_get $app is_public)
is_public=$(sudo yunohost app setting jenkins is_public) port=$(ynh_app_setting_get $app port)
port=$(sudo yunohost app setting jenkins port)
sudo sed -i "s/HTTP_PORT=.*/HTTP_PORT=$port/g" /etc/default/jenkins
sed -i "s@YNH_LOCATION@$path@g" ../conf/nginx.conf # Copie le fichier de config nginx
sed -i "s@YNH_PORT@$port@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/jenkins.conf # Et modifie les variables dans le fichier de configuration nginx
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__DOMAIN__@$domain@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
if [ "$is_public" = "Yes" ]; if [ "$is_public" = "Yes" ];
then then
sudo yunohost app setting jenkins unprotected_uris -v "/" ynh_app_setting_set $app unprotected_uris "/"
else else
sudo yunohost app setting jenkins unprotected_uris -d ynh_app_setting_delete $app unprotected_uris
fi fi
sudo service nginx reload sudo service nginx reload
sudo yunohost app ssowatconf sudo yunohost app ssowatconf