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 #136 from YunoHost-Apps/testing

Testing - Packaging v2
This commit is contained in:
Salamandar 2024-03-20 11:25:09 +01:00 committed by GitHub
commit 17b1c0eceb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 278 additions and 1090 deletions

View file

@ -1,100 +0,0 @@
#!/bin/bash
#=================================================
# PACKAGE UPDATING HELPER
#=================================================
# This script is meant to be run by GitHub Actions
# The YunoHost-Apps organisation offers a template Action to run this script periodically
# Since each app is different, maintainers can adapt its contents so as to perform
# automatic actions when a new upstream release is detected.
#=================================================
# FETCHING LATEST RELEASE AND ITS ASSETS
#=================================================
# Fetching information
current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions)
version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | select( .target_commitish | contains("refs/heads/master") | not ) | .tag_name' | sort -V | tail -1 | cut -d"-" -f2)
assets="https://pkg.jenkins.io/debian-stable/binary/jenkins_${version}_all.deb"
# Setting up the environment variables
echo "Current version: $current_version"
echo "Latest release from upstream: $version"
echo "VERSION=$version" >> $GITHUB_ENV
echo "REPO=$repo" >> $GITHUB_ENV
# For the time being, let's assume the script will fail
echo "PROCEED=false" >> $GITHUB_ENV
# Proceed only if the retrieved version is greater than the current one
if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then
echo "::warning ::No new version available"
exit 0
# Proceed only if a PR for this new version does not already exist
elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then
echo "::warning ::A branch already exists for this update"
exit 0
fi
#=================================================
# UPDATE SOURCE FILES
#=================================================
# Let's download source
asset_url=$assets
echo "Handling asset at $asset_url"
src="app"
# Create the temporary directory
tempdir="$(mktemp -d)"
# Download sources and calculate checksum
filename=${asset_url##*/}
curl --silent -4 -L $asset_url -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
# Delete temporary directory
rm -rf $tempdir
# Get extension
if [[ $filename == *.tar.gz ]]; then
extension=tar.gz
else
extension=${filename##*.}
fi
# Rewrite source file
cat <<EOT > conf/$src.src
SOURCE_URL=$asset_url
SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=$extension
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=jenkins.deb
SOURCE_EXTRACT=false
EOT
echo "... conf/$src.src updated"
#=================================================
# SPECIFIC UPDATE STEPS
#=================================================
# Any action on the app's source code can be done.
# The GitHub Action workflow takes care of committing all changes after this script ends.
#=================================================
# GENERIC FINALIZATION
#=================================================
# Replace new version in manifest
echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json
# No need to update the README, yunohost-bot takes care of it
# The Action will proceed only if the PROCEED environment variable is set to true
echo "PROCEED=true" >> $GITHUB_ENV
exit 0

View file

@ -1,49 +0,0 @@
# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected.
# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization.
# This file should be enough by itself, but feel free to tune it to your needs.
# It calls updater.sh, which is where you should put the app-specific update steps.
name: Check for new upstream releases
on:
# Allow to manually trigger the workflow
workflow_dispatch:
# Run it every day at 6:00 UTC
schedule:
- cron: '0 6 * * *'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
id: run_updater
run: |
# Setting up Git user
git config --global user.name 'yunohost-bot'
git config --global user.email 'yunohost-bot@users.noreply.github.com'
# Run the updater script
/bin/bash .github/workflows/updater.sh
- name: Commit changes
id: commit
if: ${{ env.PROCEED == 'true' }}
run: |
git commit -am "Upgrade to v$VERSION"
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update to version ${{ env.VERSION }}
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
signoff: false
base: testing
branch: ci-auto-update-v${{ env.VERSION }}
delete-branch: true
title: 'Upgrade to version ${{ env.VERSION }}'
body: |
Upgrade to v${{ env.VERSION }}
draft: false

View file

@ -1,5 +1,5 @@
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/readme_generator
It shall NOT be edited by hand.
-->
@ -16,25 +16,21 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
## Overview
Extendable continuous integration server
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
**Shipped version:** 2.426.1~ynh1
**Shipped version:** 2.426.3~ynh2
## Screenshots
![Screenshot of Jenkins](./doc/screenshots/screenshot1.png)
## Disclaimers / important information
* Use the admin panel of your Jenkins to configure this app.
## Documentation and resources
* Official app website: <https://jenkins.io>
* Official user documentation: <https://www.jenkins.io/doc/book/>
* Upstream app code repository: <https://github.com/jenkinsci/jenkins>
* YunoHost Store: <https://apps.yunohost.org/app/jenkins>
* Report a bug: <https://github.com/YunoHost-Apps/jenkins_ynh/issues>
- Official app website: <https://jenkins.io>
- Official user documentation: <https://www.jenkins.io/doc/book/>
- Upstream app code repository: <https://github.com/jenkinsci/jenkins>
- YunoHost Store: <https://apps.yunohost.org/app/jenkins>
- Report a bug: <https://github.com/YunoHost-Apps/jenkins_ynh/issues>
## Developer info
@ -42,7 +38,7 @@ Please send your pull request to the [testing branch](https://github.com/YunoHos
To try the testing branch, please proceed like that.
``` bash
```bash
sudo yunohost app install https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing --debug
or
sudo yunohost app upgrade jenkins -u https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing --debug

View file

@ -1,5 +1,5 @@
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/readme_generator
It shall NOT be edited by hand.
-->
@ -16,25 +16,21 @@ Si vous navez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po
## Vue densemble
Serveur d'intégration continue extensible
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
**Version incluse :** 2.426.1~ynh1
**Version incluse :** 2.426.3~ynh2
## Captures décran
![Capture décran de Jenkins](./doc/screenshots/screenshot1.png)
## Avertissements / informations importantes
* Utiliser le panneau d'administration Jenkins pour configurer l'application.
## Documentations et ressources
* Site officiel de lapp : <https://jenkins.io>
* Documentation officielle utilisateur : <https://www.jenkins.io/doc/book/>
* Dépôt de code officiel de lapp : <https://github.com/jenkinsci/jenkins>
* YunoHost Store: <https://apps.yunohost.org/app/jenkins>
* Signaler un bug : <https://github.com/YunoHost-Apps/jenkins_ynh/issues>
- Site officiel de lapp : <https://jenkins.io>
- Documentation officielle utilisateur : <https://www.jenkins.io/doc/book/>
- Dépôt de code officiel de lapp : <https://github.com/jenkinsci/jenkins>
- YunoHost Store : <https://apps.yunohost.org/app/jenkins>
- Signaler un bug : <https://github.com/YunoHost-Apps/jenkins_ynh/issues>
## Informations pour les développeurs
@ -42,7 +38,7 @@ Merci de faire vos pull request sur la [branche testing](https://github.com/Yuno
Pour essayer la branche testing, procédez comme suit.
``` bash
```bash
sudo yunohost app install https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing --debug
ou
sudo yunohost app upgrade jenkins -u https://github.com/YunoHost-Apps/jenkins_ynh/tree/testing --debug

View file

@ -1,49 +0,0 @@
;; Test complet
; Manifest
domain="domain.tld"
path="/path"
is_public=1
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
# 2.150.2~ynh2
#upgrade=1 from_commit=29141b702f2954e0f72925121aea82a7fa3fc118
# 2.263.1~ynh1
#upgrade=1 from_commit=0e1aae7be82034650e2c1f6c1ad6d68a41b80176
# 2.263.4~ynh1
#upgrade=1 from_commit=72656bca2e144ef9a92cfec2af6cd13cb8e8aee3
# 2.277.2~ynh1
#upgrade=1 from_commit=e6cf48fdbcc7cac5c5147d4a7cc1ebfd9055bfef
# 2.277.3~ynh1
#upgrade=1 from_commit=3f0f52e24273e9da86ac2fa7000953b7734196a5
# 2.277.4~ynh1
#upgrade=1 from_commit=36fdba9bbd201832f5707083b878ae967052ad6a
# 2.289.1~ynh1
#upgrade=1 from_commit=abf516d8a4dd721af8b9a2560a2a1dbd7ea79fb8
# 2.289.2~ynh1
#upgrade=1 from_commit=c7a3a24e56e9be3b5991a175d08be116392b5a19
# 2.289.3~ynh1
#upgrade=1 from_commit=f165327adcc291a479ab73050bcaa1b84784e763
# 2.303.1~ynh1
#upgrade=1 from_commit=0bb8a4ca3a90693c5594a72379704f7e08519c92
# 2.319.1~ynh1
#upgrade=1 from_commit=449a3d43180316d6b1bdb693354bd7cdbe8ef987
# 2.319.2~ynh1
#upgrade=1 from_commit=7e40418b50b5c25d80f3bc521f9627cdd22c4201
# 2.319.3~ynh1
#upgrade=1 from_commit=ceac884c4d82f8164ec7ce391d354d794948bb72
# 2.332.3~ynh1
#upgrade=1 from_commit=5ff1883636f649c7e32d6b520fd54621f83097ba
# 2.375.2~ynh1
upgrade=1 from_commit=4733662adabc01ea1e29ca0bf55c45f204bb1857
backup_restore=1
multi_instance=0
change_url=1
;;; Options
Email=
Notification=none

View file

@ -1,7 +0,0 @@
SOURCE_URL=https://pkg.jenkins.io/debian-stable/binary/jenkins_2.426.1_all.deb
SOURCE_SUM=a30fd080820c88e13801b80fd3d7434757b331a9fe7728b59493faaca3402949
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=deb
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=jenkins.deb
SOURCE_EXTRACT=false

View file

@ -1,7 +0,0 @@
SOURCE_URL=https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.8/jenkins-plugin-manager-2.12.8.jar
SOURCE_SUM=e5b22868c498c311ea1b776e9087af199b795ddbf0bc0474b0b4ca9e67837f26
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=jar
SOURCE_IN_SUBDIR=false
SOURCE_FILENAME=jenkins-plugin-manager.jar
SOURCE_EXTRACT=false

View file

@ -6,19 +6,8 @@ name = "Jenkins configuration"
[main.overwrite_files]
name = "Overwriting config files"
[main.overwrite_files.overwrite_nginx]
[main.overwrite_files.overwrite_nginx]
ask = "Overwrite the NGINX config file?"
type = "boolean"
default = true
help = "If the file is overwritten, a backup will be created."
[main.global_config]
name = "Global configuration"
[main.global_config.email_type]
ask = "Send HTML email to admin?"
type = "boolean"
default = true
help = "Allow app scripts to send HTML mails instead of plain text."

1
doc/ADMIN.md Normal file
View file

@ -0,0 +1 @@
Use the admin panel of your Jenkins to configure this app.

1
doc/ADMIN_fr.md Normal file
View file

@ -0,0 +1 @@
Utilisez le panneau d'administration Jenkins pour configurer l'application.

1
doc/DESCRIPTION.md Normal file
View file

@ -0,0 +1 @@
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

View file

@ -1 +0,0 @@
* Use the admin panel of your Jenkins to configure this app.

View file

@ -1 +0,0 @@
* Utiliser le panneau d'administration Jenkins pour configurer l'application.

4
doc/POST_INSTALL.md Normal file
View file

@ -0,0 +1,4 @@
You can configure this app easily by using the experimental [config-panel feature](https://__DOMAIN__/yunohost/apps/__APP__/config-panel).
You can also find some specific actions for this app by using the experimental [action feature](https://__DOMAIN__/yunohost/apps/__APP__/actions).
If you're facing an issue or want to improve this app, please open a new issue in this [project](https://github.com/YunoHost-Apps/jenkins_ynh).

4
doc/POST_UPGRADE.md Normal file
View file

@ -0,0 +1,4 @@
You can configure this app easily by using the experimental [config-panel feature](https://__DOMAIN__/yunohost/apps/__APP__/config-panel).
You can also find some specific actions for this app by using the experimental [action feature](https://__DOMAIN__/yunohost/apps/__APP__/actions).
If you're facing an issue or want to improve this app, please open a new issue in this [project](https://github.com/YunoHost-Apps/jenkins_ynh).

View file

@ -1,54 +0,0 @@
{
"name": "Jenkins",
"id": "jenkins",
"packaging_format": 1,
"description": {
"en": "Extendable continuous integration server",
"fr": "Serveur d'intégration continue extensible"
},
"version": "2.426.1~ynh1",
"url": "https://jenkins.io/index.html",
"upstream": {
"license": "MIT",
"website": "https://jenkins.io",
"userdoc": "https://www.jenkins.io/doc/book/",
"code": "https://github.com/jenkinsci/jenkins",
"cpe": "cpe:2.3:a:jenkins:jenkins"
},
"license": "MIT",
"maintainer": {
"name": "yalh76"
},
"previous_maintainers": [
{
"name": "Julien Malik et Maniack Crudelis",
"email": "maniackc_dev@crudelis.fr"
}
],
"requirements": {
"yunohost": ">= 4.3.0"
},
"multi_instance": false,
"services": [
"nginx"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain"
},
{
"name": "path",
"type": "path",
"example": "/jenkins",
"default": "/jenkins"
},
{
"name": "is_public",
"type": "boolean",
"default": true
}
]
}
}

81
manifest.toml Normal file
View file

@ -0,0 +1,81 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
packaging_format = 2
id = "jenkins"
name = "Jenkins"
description.en = "Extendable continuous integration server"
description.fr = "Serveur d'intégration continue extensible"
version = "2.426.3~ynh2"
maintainers = ["yalh76"]
[upstream]
license = "MIT"
website = "https://jenkins.io"
userdoc = "https://www.jenkins.io/doc/book/"
code = "https://github.com/jenkinsci/jenkins"
cpe = "cpe:2.3:a:cloudbees:jenkins"
fund = "https://www.jenkins.io/donate"
[integration]
yunohost = ">= 11.2"
architectures = "all"
multi_instance = false
ldap = true
sso = false
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install]
[install.domain]
type = "domain"
[install.path]
type = "path"
default = "/jenkins"
[install.init_main_permission]
type = "group"
default = "visitors"
[resources]
[resources.sources]
[resources.sources.jenkins-plugin-manager]
url = "https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.8/jenkins-plugin-manager-2.12.8.jar"
sha256 = "e5b22868c498c311ea1b776e9087af199b795ddbf0bc0474b0b4ca9e67837f26"
format = "whatever"
extract = false
rename = "jenkins-plugin-manager.jar"
[resources.sources.main]
url = "https://pkg.jenkins.io/debian-stable/binary/jenkins_2.426.3_all.deb"
sha256 = "7a453125a0194deba5a6464220e8beab3d0cd6a83f84f85a096babfaf5e752b5"
format = "whatever"
extract = false
rename = "jenkins.deb"
[resources.system_user]
home = "/var/lib/jenkins"
[resources.install_dir]
dir = "/var/lib/jenkins"
[resources.permissions]
main.url = "/"
github_webhook.url = "/github-webhook"
github_webhook.allowed = "visitors"
github_webhook.protected = false
github_webhook.show_tile = false
[resources.ports]
main.default = 8095
[resources.apt]
packages = [
"openjdk-11-jdk\\|openjdk-17-jdk\\|openjdk-21-jdk",
"daemon",
"net-tools"
]

View file

@ -4,11 +4,6 @@
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="openjdk-11-jdk|openjdk-17-jdk daemon net-tools"
PLUGIN_CLI_VERSION=2.9.3
#=================================================
# PERSONAL HELPERS
#=================================================
@ -17,18 +12,14 @@ PLUGIN_CLI_VERSION=2.9.3
# BOOLEAN CONVERTER
#=================================================
bool_to_01 () {
local var="$1"
[ "$var" = "true" ] && var=1
[ "$var" = "false" ] && var=0
echo "$var"
bool_to_01() {
declare -A bool01=([false]=0 [true]=1)
echo "${bool01[$1]}"
}
bool_to_true_false () {
local var="$1"
[ "$var" = "1" ] && var=true
[ "$var" = "0" ] && var=false
echo "$var"
b01_to_bool() {
declare -A b01bool=([0]=false [1]=true)
echo "${b01bool[$1]}"
}
#=================================================

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,32 +8,6 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd"
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
@ -45,22 +17,14 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path" --not_mandatory
ynh_backup --src_path="$install_dir" --not_mandatory
#=================================================
# BACKUP THE NGINX CONFIGURATION
# BACKUP THE SYSTEM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -9,126 +7,38 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
# 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)
#=================================================
# BACKUP BEFORE CHANGE URL 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 () {
ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd"
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..."
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_change_url_nginx_config
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# MODIFY JENKINS SETUP
#=================================================
ynh_script_progression --message="Updating Jenkins setup..."
ynh_replace_string --match_string="Environment=\"JENKINS_PREFIX=$old_path\"" --replace_string="Environment=\"JENKINS_PREFIX=$new_path\"" --target_file="/lib/systemd/system/jenkins.service"
ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PREFIX=$old_path\"" \
--replace_string="Environment=\"JENKINS_PREFIX=$new_path\""
systemctl daemon-reload --quiet
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --line_match="Started" --log_path="systemd"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -9,16 +7,6 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# SPECIFIC CODE
#=================================================
# LOAD VALUES
#=================================================
@ -29,15 +17,10 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Otherwise, keep the value from the app config.
# Overwrite nginx configuration
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
old_overwrite_nginx="$(ynh_app_setting_get --app="$app" --key="overwrite_nginx")"
old_overwrite_nginx=$(b01_to_bool "$old_overwrite_nginx")
overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
# Type of admin mail configuration
old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)"
old_admin_mail_html=$(bool_to_true_false $old_admin_mail_html)
admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
#=================================================
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
#=================================================
@ -47,8 +30,6 @@ show_config() {
# echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
echo "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
}
#=================================================
@ -56,17 +37,12 @@ show_config() {
#=================================================
apply_config() {
# Set overwrite_nginx
overwrite_nginx=$(bool_to_01 $overwrite_nginx)
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
# Set admin_mail_html
admin_mail_html=$(bool_to_01 $admin_mail_html)
ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
overwrite_nginx=$(bool_to_01 "$overwrite_nginx")
ynh_app_setting_set --app="$app" --key=overwrite_nginx --value="$overwrite_nginx"
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1
ynh_app_config_run "$1"

View file

@ -1,206 +1,122 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
# Stop change_port()
ynh_exec_warn_less kill -s 15 $pid_change_port
# Clean hosts
sed -i '/#jenkins/d' /etc/hosts
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
jenkins_version=$(ynh_app_upstream_version)
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
final_path=/var/lib/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
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=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
ynh_app_setting_set --app="$app" --key="overwrite_nginx" --value="1"
#=================================================
# 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"
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$final_path"
ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL JENKINS
#=================================================
ynh_script_progression --message="Installing Jenkins..."
# Download jenkins deb file and install it.
dpkg --install --force-confnew ../conf/jenkins.deb || true
dpkg --install --force-confnew "$install_dir/jenkins.deb" || true
dpkg_install_failed=$(dpkg-query -f '${status} ${package}\n' -W | awk '$4 ~ /^jenkins.*/ && $3 != "installed" {print $4}' | wc -l)
if [[ $dpkg_install_failed -ge 1 ]]; then
ynh_print_warn --message="The service jenkins cannot be started for now."
ynh_print_warn --message="The service jenkins cannot be started for now."
fi
#=================================================
# SETUP APPLICATION
#=================================================
ynh_script_progression --message="Setuping application on port $port..."
ynh_script_progression --message="Setting up application on port $port..."
cat >> "$final_path/jenkins.install.InstallUtil.lastExecVersion" <<EOF
$jenkins_version
EOF
chown $app:$app "$final_path/jenkins.install.InstallUtil.lastExecVersion"
cat >> "$final_path/jenkins.install.UpgradeWizard.state" <<EOF
$jenkins_version
EOF
chown $app:$app "$final_path/jenkins.install.UpgradeWizard.state"
ynh_replace_string --match_string="Environment=\"JENKINS_PORT=8080\"" --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path_url\"" --target_file="/lib/systemd/system/jenkins.service"
echo "$jenkins_version" >> "$install_dir/jenkins.install.InstallUtil.lastExecVersion"
echo "$jenkins_version" >> "$install_dir/jenkins.install.UpgradeWizard.state"
chown "$app:$app" "$install_dir/jenkins.install.InstallUtil.lastExecVersion"
chown "$app:$app" "$install_dir/jenkins.install.UpgradeWizard.state"
ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PORT=8080\"" \
--replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\""
systemctl daemon-reload --quiet
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
if [[ $dpkg_install_failed -ge 1 ]]; then
dpkg --configure -a
dpkg --configure -a
fi
#=================================================
# INSTALL PLUGINS
#=================================================
ynh_script_progression --message="Installing plugins..."
jenkins_plugin_manager="ynh_exec_warn_less java -jar $final_path/jenkins-plugin-manager.jar --war /usr/share/java/jenkins.war --plugin-download-directory=$final_path/plugins"
# Install plugins for http authentication and ldap.
$jenkins_plugin_manager --plugins reverse-proxy-auth-plugin
# Install recommended plugins (those from Setup Wizard)
$jenkins_plugin_manager --plugins cloudbees-folder # Folders Plugin
$jenkins_plugin_manager --plugins antisamy-markup-formatter # OWASP Markup Formatter Plugin
$jenkins_plugin_manager --plugins pam-auth # PAM Authentication plugin
$jenkins_plugin_manager --plugins mailer # Mailer Plugin
$jenkins_plugin_manager --plugins ldap # LDAP Plugin
$jenkins_plugin_manager --plugins matrix-auth # Matrix Authorization Strategy Plugin
$jenkins_plugin_manager --plugins build-timeout # Build timeout plugin
$jenkins_plugin_manager --plugins credentials-binding # Credentials Binding Plugin
$jenkins_plugin_manager --plugins timestamper # Timestamper
$jenkins_plugin_manager --plugins ws-cleanup # Workspace Cleanup Plugin
$jenkins_plugin_manager --plugins ant # Ant Plugin
$jenkins_plugin_manager --plugins gradle # Gradle Plugin
$jenkins_plugin_manager --plugins workflow-aggregator # Pipeline
$jenkins_plugin_manager --plugins pipeline-stage-view # Pipeline: Stage View Plugin
$jenkins_plugin_manager --plugins git # Git plugin
$jenkins_plugin_manager --plugins github-branch-source # GitHub Branch Source Plugin
$jenkins_plugin_manager --plugins subversion # Subversion Plug-in
$jenkins_plugin_manager --plugins email-ext # Email Extension Plugin
$jenkins_plugin_manager --plugins ssh-slaves # SSH Slaves plugin
# Install extra comfort plugins
# Handle terminal colours. Enhance the readability of the terminal.
$jenkins_plugin_manager --plugins ansicolor
# Monitoring of the local file system. Allow to monitor a directory and trig a job if a file has been modified.
$jenkins_plugin_manager --plugins fstrigger
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="../conf/config.xml" --destination="$final_path/config.xml"
chown $app:$app "$final_path/config.xml"
ynh_add_config --template="config.xml" --destination="$install_dir/config.xml"
chown "$app:$app" "$install_dir/config.xml"
#=================================================
# GENERIC FINALIZATION
# INSTALL PLUGINS
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression --message="Installing plugins..."
yunohost service add $app --description="Jenkins Continuous Integration Server"
jenkins_plugin_manager=(
ynh_exec_warn_less java -jar "$install_dir/jenkins-plugin-manager.jar" --war /usr/share/java/jenkins.war --plugin-download-directory="$install_dir/plugins"
)
# Install plugins for http authentication and ldap.
"${jenkins_plugin_manager[@]}" --plugins reverse-proxy-auth-plugin
# Install recommended plugins (those from Setup Wizard)
"${jenkins_plugin_manager[@]}" --plugins cloudbees-folder # Folders Plugin
"${jenkins_plugin_manager[@]}" --plugins antisamy-markup-formatter # OWASP Markup Formatter Plugin
"${jenkins_plugin_manager[@]}" --plugins pam-auth # PAM Authentication plugin
"${jenkins_plugin_manager[@]}" --plugins mailer # Mailer Plugin
"${jenkins_plugin_manager[@]}" --plugins ldap # LDAP Plugin
"${jenkins_plugin_manager[@]}" --plugins matrix-auth # Matrix Authorization Strategy Plugin
"${jenkins_plugin_manager[@]}" --plugins build-timeout # Build timeout plugin
"${jenkins_plugin_manager[@]}" --plugins credentials-binding # Credentials Binding Plugin
"${jenkins_plugin_manager[@]}" --plugins timestamper # Timestamper
"${jenkins_plugin_manager[@]}" --plugins ws-cleanup # Workspace Cleanup Plugin
"${jenkins_plugin_manager[@]}" --plugins ant # Ant Plugin
"${jenkins_plugin_manager[@]}" --plugins gradle # Gradle Plugin
"${jenkins_plugin_manager[@]}" --plugins workflow-aggregator # Pipeline
"${jenkins_plugin_manager[@]}" --plugins pipeline-stage-view # Pipeline: Stage View Plugin
"${jenkins_plugin_manager[@]}" --plugins git # Git plugin
"${jenkins_plugin_manager[@]}" --plugins github-branch-source # GitHub Branch Source Plugin
"${jenkins_plugin_manager[@]}" --plugins subversion # Subversion Plug-in
"${jenkins_plugin_manager[@]}" --plugins email-ext # Email Extension Plugin
"${jenkins_plugin_manager[@]}" --plugins ssh-slaves # SSH Slaves plugin
# Install extra comfort plugins
# Handle terminal colours. Enhance the readability of the terminal.
"${jenkins_plugin_manager[@]}" --plugins ansicolor
# Monitoring of the local file system. Allow to monitor a directory and trig a job if a file has been modified.
"${jenkins_plugin_manager[@]}" --plugins fstrigger
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Service is provided by the deb package
yunohost service add "$app" --description="Jenkins Continuous Integration Server"
#=================================================
# START SYSTEMD SERVICE
@ -208,44 +124,7 @@ yunohost service add $app --description="Jenkins Continuous Integration Server"
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
# /path/github-webhook has to be accessible for github's webhooks
ynh_permission_create --permission="github-webhook" --url="/github-webhook" --allowed="visitors" --show_tile="false" --protected="true"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# 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"
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__.
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
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,59 +8,27 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then
yunohost service remove "$app"
fi
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd"
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd"
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
ynh_script_progression --message="Removing Jenkins deb packages..."
# Remove metapackage and its dependencies
ynh_package_autopurge $app
ynh_remove_app_dependencies
#=================================================
# 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..."
# Remove the dedicated NGINX config
ynh_remove_nginx_config
ynh_package_autopurge "$app"
#=================================================
# SPECIFIC REMOVE

View file

@ -1,75 +1,21 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
# Stop change_port()
ynh_exec_warn_less kill -s 15 $pid_change_port
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_restore_file --origin_path="$install_dir" --not_mandatory
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
chown -R "$app:www-data" "$install_dir"
#=================================================
# INSTALL JENKINS
@ -83,55 +29,29 @@ dpkg --install --force-confnew ../conf/jenkins.deb
#=================================================
# SETUP APPLICATION
#=================================================
ynh_script_progression --message="Setuping application..."
ynh_script_progression --message="Setting up $app's service..."
ynh_replace_string --match_string="Environment=\"JENKINS_PORT=8080\"" --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path_url\"" --target_file="/lib/systemd/system/jenkins.service"
ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PORT=8080\"" \
--replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\""
systemctl daemon-reload --quiet
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
yunohost service add "$app" --description="Jenkins Continuous Integration Server"
#=================================================
# RESTORE THE APP MAIN DIR
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_restore_file --origin_path="$final_path" --not_mandatory
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Jenkins Continuous Integration Server"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# 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"
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__.
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
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="$app" --action="restart" --log_path="systemd"
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -1,58 +1,18 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_script_progression --message="Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd"
ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
@ -60,32 +20,17 @@ ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --
ynh_script_progression --message="Ensuring downward compatibility..."
# If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then
overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
if [ -z "${overwrite_nginx:-}" ]; then
overwrite_nginx=1
ynh_app_setting_set --app="$app" --key="overwrite_nginx" --value="$overwrite_nginx"
fi
# Remove the apt list entry for jenkins
if [ -e "/etc/apt/sources.list.d/jenkins.list" ]
then
ynh_secure_remove --file=/etc/apt/sources.list.d/jenkins.list
# Get APT key id for jenkins
apt_key=$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)
# Delete the APT key
apt-key del $apt_key
apt-get update
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"
if [ -e "/etc/apt/sources.list.d/jenkins.list" ]; then
ynh_secure_remove --file=/etc/apt/sources.list.d/jenkins.list
# Delete the APT key
apt-key del "$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)"
apt-get update
fi
# Remove the log files
@ -94,120 +39,64 @@ ynh_secure_remove --file="/var/log/$app"
# No more needed since systemd
ynh_delete_file_checksum --file="/etc/default/jenkins"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..."
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download jenkins deb file and install it.
ynh_setup_source --dest_dir="../conf"
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
# Download jenkins deb file and install it.
ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir"
dpkg --install --force-confnew ../conf/jenkins.deb
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# SETUP APPLICATION
#=================================================
ynh_script_progression --message="Setuping application..."
ynh_replace_string --match_string="Environment=\"JENKINS_PORT=8080\"" --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path_url\"" --target_file="/lib/systemd/system/jenkins.service"
systemctl daemon-reload --quiet
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
fi
dpkg --install --force-confnew "$install_dir/jenkins.deb"
#=================================================
# UPGRADE DEPENDENCIES
# SETUP APPLICATION
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_script_progression --message="Setting up application..."
ynh_install_app_dependencies $pkg_dependencies
ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PORT=8080\"" \
--replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\""
systemctl daemon-reload --quiet
#=================================================
# NGINX CONFIGURATION
#=================================================
# Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ]
then
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
#=================================================
# SPECIFIC UPGRADE
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
#=================================================
# UPGRADE PLUGINS
#=================================================
ynh_script_progression --message="Upgrading plugins..."
jenkins_plugin_manager="ynh_exec_warn_less java -jar $final_path/jenkins-plugin-manager.jar --war /usr/share/java/jenkins.war --plugin-download-directory=$final_path/plugins"
UPDATE_LIST=$($jenkins_plugin_manager --list | grep -o '.*\..*' | grep -oP '^(.*?) ')
jenkins_plugin_manager=(
ynh_exec_warn_less java -jar "$install_dir/jenkins-plugin-manager.jar" --war /usr/share/java/jenkins.war --plugin-download-directory="$install_dir/plugins"
)
mapfile -t UPDATE_LIST < <("${jenkins_plugin_manager[@]}" --list | grep -o '.*\..*' | grep -oP '^(.*?) ')
for plugin in ${UPDATE_LIST}
do
$jenkins_plugin_manager --plugins "$plugin" || true
for plugin in "${UPDATE_LIST[@]}"; do
"${jenkins_plugin_manager[@]}" --plugins "$plugin" || true
done
#=================================================
# GENERIC FINALIZATION
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
yunohost service add $app --description="Jenkins Continuous Integration Server"
# Overwrite the nginx configuration only if it's allowed
if [ "$overwrite_nginx" -eq 1 ]; then
ynh_add_nginx_config
fi
yunohost service add "$app" --description="Jenkins Continuous Integration Server"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# 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"
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__.
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
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
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
#=================================================
# END OF SCRIPT

View file

@ -1,123 +0,0 @@
#!/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.
$(cat "$app_message")"
# 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 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
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"
}

11
tests.toml Normal file
View file

@ -0,0 +1,11 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json
test_format = 1.0
[default]
# ------------
# Tests to run
# ------------
test_upgrade_from.4733662adabc01ea1e29ca0bf55c45f204bb1857.name = "2.375.2~ynh1"