mirror of
https://github.com/YunoHost-Apps/unattended_upgrades_ynh.git
synced 2024-10-01 13:35:00 +02:00
commit
fc538de7af
18 changed files with 1123 additions and 1032 deletions
52
CHANGELOG.md
Normal file
52
CHANGELOG.md
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
Changelog
|
||||||
|
=========
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
- Nothing for now...
|
||||||
|
|
||||||
|
## [1.0~ynh5](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13) - 2019-04-24
|
||||||
|
|
||||||
|
#### Added
|
||||||
|
* [Add a changelog](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/054a7f4e0c98e2ade70779a9f470ef1d0d50413e)
|
||||||
|
- [New badges](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/477f7f3f178336ec03882fe3ec4e718c745ecda2)
|
||||||
|
|
||||||
|
#### Fixed
|
||||||
|
- [Fix Buster](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/fa7afd13e1657948a07a3f05227e5b6d26bdd9de)
|
||||||
|
|
||||||
|
#### Changed
|
||||||
|
- [Update to last standard](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/f7ad5779f7074bfaafd1bf4653bfeaf2ddc0880d)
|
||||||
|
- [Update helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/02e6b338b17ddd468875865edc8bd9c5ad741381)
|
||||||
|
- [Update config-panel and actions](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/f37594eb5df701e70ce884354e4f5ad3371b3d8b)
|
||||||
|
- [Global upgrade](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/74210eea818d76a35f1f9872029b267300ff5c46)
|
||||||
|
|
||||||
|
|
||||||
|
## [1.0~ynh4](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9) - 2019-02-03
|
||||||
|
|
||||||
|
#### Added
|
||||||
|
- [Add progression bar](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9/commits/51a015f726f852bbb0dc8ceb4c463657803b1b8b)
|
||||||
|
- [Changelog & html email](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9/commits/f5c468947230dd2bcf8a82a0552548c6f6f61877)
|
||||||
|
|
||||||
|
|
||||||
|
## [1.0~ynh3](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8) - 2019-01-21
|
||||||
|
|
||||||
|
#### Changed
|
||||||
|
- [Update to last standart](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8/commits/2093bcf70e8527066eb8e0750c17cc361dd9a408)
|
||||||
|
- [Advertise config-panel and actions](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8/commits/53132454227b9b972357ee694f79748f6a6bab93)
|
||||||
|
|
||||||
|
|
||||||
|
## [1.0~ynh2](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6) - 2018-09-30
|
||||||
|
|
||||||
|
#### Added
|
||||||
|
- [Panel-config + actions fully tested](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6/commits/eb48bf36a6a792d80b553624f5a221495c0d29a5)
|
||||||
|
|
||||||
|
|
||||||
|
## [1.0~ynh2](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5) - 2018-07-16
|
||||||
|
|
||||||
|
#### Changed
|
||||||
|
- [Upgrade helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5/commits/d7d56c2d88aeb2817b509dbd9aa23434a1480148)
|
||||||
|
|
||||||
|
|
||||||
|
## [1.0~ynh1](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/1) - 2018-03-14
|
||||||
|
|
||||||
|
#### Changed
|
||||||
|
- [Update helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/1/commits/5a359c6833a5415932ab427a80dbbdc6ca3c8e23)
|
10
README.md
10
README.md
|
@ -1,6 +1,6 @@
|
||||||
# Unattended-upgrades for YunoHost
|
# Unattended-upgrades for YunoHost
|
||||||
|
|
||||||
[](https://dash.yunohost.org/appci/app/unattended_upgrades)
|
[](https://dash.yunohost.org/appci/app/unattended_upgrades)  [](https://github.com/YunoHost/Apps/#what-to-do-if-i-cant-maintain-my-app-anymore-)
|
||||||
[](https://install-app.yunohost.org/?app=unattended_upgrades)
|
[](https://install-app.yunohost.org/?app=unattended_upgrades)
|
||||||
|
|
||||||
*[Lire ce readme en français.](./README_fr.md)*
|
*[Lire ce readme en français.](./README_fr.md)*
|
||||||
|
@ -43,9 +43,9 @@ With its cron file
|
||||||
|
|
||||||
#### Supported architectures
|
#### Supported architectures
|
||||||
|
|
||||||
* x86-64b - [](https://ci-apps.yunohost.org/ci/apps/unattended_upgrades/)
|
* x86-64b - [](https://ci-apps.yunohost.org/ci/apps/unattended_upgrades/)
|
||||||
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/unattended_upgrades/)
|
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/unattended_upgrades/)
|
||||||
* Jessie x86-64b - [](https://ci-stretch.nohost.me/ci/apps/unattended_upgrades/)
|
* Buster x86-64b - [](https://ci-buster.nohost.me/ci/apps/unattended_upgrades/)
|
||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ Please do your pull request to the [testing branch](https://github.com/YunoHost-
|
||||||
|
|
||||||
To try the testing branch, please proceed like that.
|
To try the testing branch, please proceed like that.
|
||||||
```
|
```
|
||||||
sudo yunohost app install https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --debug
|
sudo yunohost app install https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --force --debug
|
||||||
or
|
or
|
||||||
sudo yunohost app upgrade unattended_upgrades -u https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --debug
|
sudo yunohost app upgrade unattended_upgrades -u https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --debug
|
||||||
```
|
```
|
||||||
|
|
10
README_fr.md
10
README_fr.md
|
@ -1,6 +1,6 @@
|
||||||
# Unattended-upgrades pour YunoHost
|
# Unattended-upgrades pour YunoHost
|
||||||
|
|
||||||
[](https://dash.yunohost.org/appci/app/unattended_upgrades)
|
[](https://dash.yunohost.org/appci/app/unattended_upgrades)  [](https://github.com/YunoHost/Apps/#what-to-do-if-i-cant-maintain-my-app-anymore-)
|
||||||
[](https://install-app.yunohost.org/?app=unattended_upgrades)
|
[](https://install-app.yunohost.org/?app=unattended_upgrades)
|
||||||
|
|
||||||
*[Read this readme in english.](./README.md)*
|
*[Read this readme in english.](./README.md)*
|
||||||
|
@ -43,9 +43,9 @@ Avec son cron
|
||||||
|
|
||||||
#### Architectures supportées.
|
#### Architectures supportées.
|
||||||
|
|
||||||
* x86-64b - [](https://ci-apps.yunohost.org/ci/apps/unattended_upgrades/)
|
* x86-64b - [](https://ci-apps.yunohost.org/ci/apps/unattended_upgrades/)
|
||||||
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/unattended_upgrades/)
|
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/unattended_upgrades/)
|
||||||
* Jessie x86-64b - [](https://ci-stretch.nohost.me/ci/apps/unattended_upgrades/)
|
* Buster x86-64b - [](https://ci-buster.nohost.me/ci/apps/unattended_upgrades/)
|
||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ Merci de faire vos pull request sur la [branche testing](https://github.com/Yuno
|
||||||
|
|
||||||
Pour tester la branche testing, merci de procéder ainsi.
|
Pour tester la branche testing, merci de procéder ainsi.
|
||||||
```
|
```
|
||||||
sudo yunohost app install https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --debug
|
sudo yunohost app install https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --force --debug
|
||||||
ou
|
ou
|
||||||
sudo yunohost app upgrade unattended_upgrades -u https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --debug
|
sudo yunohost app upgrade unattended_upgrades -u https://github.com/YunoHost-Apps/unattended_upgrades_ynh/tree/testing --debug
|
||||||
```
|
```
|
||||||
|
|
22
actions.json
22
actions.json
|
@ -1,22 +0,0 @@
|
||||||
[{
|
|
||||||
"id": "reset_default_unattended",
|
|
||||||
"name": "Reset the 50unattended-upgrades config file and restore a default one.",
|
|
||||||
"command": "/bin/bash scripts/actions/reset_default_config \"50unattended-upgrades\"",
|
|
||||||
"user": "root",
|
|
||||||
"accepted_return_codes": [0],
|
|
||||||
"description": {
|
|
||||||
"en": "Reset the unattended-upgrades config file 50unattended-upgrades.",
|
|
||||||
"fr": "Réinitialise le fichier de configuration unattended-upgrades 50unattended-upgrades."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "reset_default_periodic",
|
|
||||||
"name": "Reset the 02periodic apt config file and restore a default one.",
|
|
||||||
"command": "/bin/bash scripts/actions/reset_default_config \"02periodic\"",
|
|
||||||
"user": "root",
|
|
||||||
"accepted_return_codes": [0],
|
|
||||||
"description": {
|
|
||||||
"en": "Reset the config file 02periodic.",
|
|
||||||
"fr": "Réinitialise le fichier de configuration 02periodic."
|
|
||||||
}
|
|
||||||
}]
|
|
27
actions.toml
Normal file
27
actions.toml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
[reset_default_unattended]
|
||||||
|
name = "Reset the 50unattended-upgrades config file and restore a default one."
|
||||||
|
command = "/bin/bash scripts/actions/reset_default_config \"50unattended-upgrades\""
|
||||||
|
# user = "root" # optional
|
||||||
|
# cwd = "/" # optional
|
||||||
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
accepted_return_codes = [0]
|
||||||
|
description = "Reset the unattended-upgrades config file 50unattended-upgrades."
|
||||||
|
|
||||||
|
[reset_default_periodic]
|
||||||
|
name = "Reset the 02periodic apt config file and restore a default one."
|
||||||
|
command = "/bin/bash scripts/actions/reset_default_config \"02periodic\""
|
||||||
|
# user = "root" # optional
|
||||||
|
# cwd = "/" # optional
|
||||||
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
accepted_return_codes = [0]
|
||||||
|
description = "Reset the config file 02periodic."
|
||||||
|
|
||||||
|
|
||||||
|
[reset_default_app]
|
||||||
|
name = "Reset the app with a default configuration."
|
||||||
|
command = "/bin/bash scripts/actions/reset_default_app"
|
||||||
|
# user = "root" # optional
|
||||||
|
# cwd = "/" # optional
|
||||||
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
accepted_return_codes = [0]
|
||||||
|
description = "Reset the app to its default configuration to try to fix potential issues.<br>This action won't remove any data added to the app.<br>However, if you have modified any configuration, it will be overwritten."
|
|
@ -6,6 +6,18 @@
|
||||||
after_apticron=1
|
after_apticron=1
|
||||||
unattended_mail="If an upgrade has been done"
|
unattended_mail="If an upgrade has been done"
|
||||||
unattended_verbosity="1"
|
unattended_verbosity="1"
|
||||||
|
; Actions
|
||||||
|
; Config_panel
|
||||||
|
main.unattended_configuration.upgrade_level=Security only|Security and updates
|
||||||
|
main.unattended_configuration.ynh_update=0|1
|
||||||
|
main.unattended_configuration.unattended_mail=If an upgrade has been done|Only if there was an error|Never
|
||||||
|
main.apticron_configuration.previous_apticron=0|1
|
||||||
|
main.apticron_configuration.previous_apticron_hour=21
|
||||||
|
main.apticron_configuration.after_apticron=0|1
|
||||||
|
main.apticron_configuration.after_apticron_hour=5
|
||||||
|
main.periodic_configuration.unattended_verbosity=1|2|3
|
||||||
|
main.overwrite_files.overwrite_periodic=0|1
|
||||||
|
main.global_config.email_type=0|1
|
||||||
; Checks
|
; Checks
|
||||||
pkg_linter=1
|
pkg_linter=1
|
||||||
setup_sub_dir=0
|
setup_sub_dir=0
|
||||||
|
@ -14,11 +26,13 @@
|
||||||
setup_private=0
|
setup_private=0
|
||||||
setup_public=0
|
setup_public=0
|
||||||
upgrade=1
|
upgrade=1
|
||||||
|
upgrade=1 from_commit=5a359c6833a5415932ab427a80dbbdc6ca3c8e23
|
||||||
backup_restore=1
|
backup_restore=1
|
||||||
multi_instance=0
|
multi_instance=0
|
||||||
incorrect_path=0
|
|
||||||
port_already_use=0
|
port_already_use=0
|
||||||
change_url=0
|
change_url=0
|
||||||
|
actions=1
|
||||||
|
config_panel=1
|
||||||
;; Test complet 2/3
|
;; Test complet 2/3
|
||||||
; Manifest
|
; Manifest
|
||||||
upgrade_level="Security and updates"
|
upgrade_level="Security and updates"
|
||||||
|
@ -28,6 +42,8 @@
|
||||||
unattended_mail="Only if there was an error"
|
unattended_mail="Only if there was an error"
|
||||||
unattended_verbosity="2"
|
unattended_verbosity="2"
|
||||||
; Checks
|
; Checks
|
||||||
|
setup_sub_dir=0
|
||||||
|
setup_root=0
|
||||||
setup_nourl=1
|
setup_nourl=1
|
||||||
upgrade=1
|
upgrade=1
|
||||||
backup_restore=1
|
backup_restore=1
|
||||||
|
@ -40,20 +56,16 @@
|
||||||
unattended_mail="Never"
|
unattended_mail="Never"
|
||||||
unattended_verbosity="3"
|
unattended_verbosity="3"
|
||||||
; Checks
|
; Checks
|
||||||
|
setup_sub_dir=0
|
||||||
|
setup_root=0
|
||||||
setup_nourl=1
|
setup_nourl=1
|
||||||
upgrade=1
|
upgrade=1
|
||||||
backup_restore=1
|
backup_restore=1
|
||||||
;;; Levels
|
;;; Levels
|
||||||
Level 1=auto
|
|
||||||
Level 2=auto
|
|
||||||
Level 3=auto
|
|
||||||
Level 4=na
|
|
||||||
Level 5=auto
|
Level 5=auto
|
||||||
Level 6=auto
|
|
||||||
Level 7=auto
|
|
||||||
Level 8=0
|
|
||||||
Level 9=0
|
|
||||||
Level 10=0
|
|
||||||
;;; Options
|
;;; Options
|
||||||
Email=
|
Email=
|
||||||
Notification=down
|
Notification=change
|
||||||
|
;;; Upgrade options
|
||||||
|
; commit=b86b9d09ed97bf04b7e1afad72376d8d695b418b
|
||||||
|
name=Mar 14, 2018 Update helpers
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Unattended-upgrades configuration panel",
|
|
||||||
"version": "0.1",
|
|
||||||
"panel": [{
|
|
||||||
"name": "Unattended-upgrades configuration",
|
|
||||||
"id": "main",
|
|
||||||
"sections": [{
|
|
||||||
"name": "50unattended-upgrades configuration file",
|
|
||||||
"id": "unattended_configuration",
|
|
||||||
"options": [{
|
|
||||||
"name": "Choose the sources of packages to automatically upgrade.",
|
|
||||||
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>Security only, Security and updates.",
|
|
||||||
"id": "upgrade_level",
|
|
||||||
"type": "text",
|
|
||||||
"//": "\"choices\" : [\"Security only\", \"Security and updates\"]",
|
|
||||||
"default" : "Security only"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Would you like to update YunoHost packages automatically ?",
|
|
||||||
"id": "ynh_update",
|
|
||||||
"type": "bool",
|
|
||||||
"default": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Would you like to receive an email from Unattended-Upgrades ?",
|
|
||||||
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>If an upgrade has been done, Only if there was an error, Never.",
|
|
||||||
"id": "unattended_mail",
|
|
||||||
"type": "text",
|
|
||||||
"//": "\"choices\" : [\"If an upgrade has been done\", \"Only if there was an error\", \"Never\"]",
|
|
||||||
"default" : "If an upgrade has been done"
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "apticron cron file",
|
|
||||||
"id": "apticron_configuration",
|
|
||||||
"options": [{
|
|
||||||
"name": "Would you like to receive an email to inform which upgrades need to be done ?",
|
|
||||||
"id": "previous_apticron",
|
|
||||||
"type": "bool",
|
|
||||||
"default": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "When do you want to receive this email ?",
|
|
||||||
"help": "Choose an hour between 12 and 23.<br>",
|
|
||||||
"id": "previous_apticron_hour",
|
|
||||||
"type": "number",
|
|
||||||
"default": 20
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Would you like to receive an email to verify if there any upgrades left after each auto upgrade ?",
|
|
||||||
"id": "after_apticron",
|
|
||||||
"type": "bool",
|
|
||||||
"default": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "When do you want to receive this email ?",
|
|
||||||
"help": "Choose an hour between 0 and 10.",
|
|
||||||
"id": "after_apticron_hour",
|
|
||||||
"type": "number",
|
|
||||||
"default": 2
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "02periodic apt config file",
|
|
||||||
"id": "periodic_configuration",
|
|
||||||
"options": [{
|
|
||||||
"name": "Choose the level of verbosity of Unattended-Upgrades mail",
|
|
||||||
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>1, 2, 3.",
|
|
||||||
"help": "1: Progress report only.<br>2: Progress report and command outputs.<br>3: Progress report and command outputs and trace.",
|
|
||||||
"id": "unattended_verbosity",
|
|
||||||
"type": "text",
|
|
||||||
"//": "\"choices\" : [\"1\", \"2\", \"3\"]",
|
|
||||||
"default" : "1"
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Overwriting config files",
|
|
||||||
"id": "overwrite_files",
|
|
||||||
"options": [{
|
|
||||||
"name": "Overwrite the config file 02periodic ?",
|
|
||||||
"help": "If the file is overwritten, a backup will be created.",
|
|
||||||
"id": "overwrite_periodic",
|
|
||||||
"type": "bool",
|
|
||||||
"default": true
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Global configuration",
|
|
||||||
"id": "global_config",
|
|
||||||
"options": [{
|
|
||||||
"name": "Send HTML email to admin ?",
|
|
||||||
"help": "Allow app scripts to send HTML mails instead of plain text.",
|
|
||||||
"id": "email_type",
|
|
||||||
"type": "bool",
|
|
||||||
"default": true
|
|
||||||
}]
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
80
config_panel.toml
Normal file
80
config_panel.toml
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
version = "0.1"
|
||||||
|
name = "Unattended-upgrades configuration panel"
|
||||||
|
|
||||||
|
[main]
|
||||||
|
name = "Unattended-upgrades configuration"
|
||||||
|
|
||||||
|
|
||||||
|
[main.unattended_configuration]
|
||||||
|
name = "50unattended-upgrades configuration file"
|
||||||
|
|
||||||
|
[main.unattended_configuration.upgrade_level]
|
||||||
|
ask = "Choose the sources of packages to automatically upgrade."
|
||||||
|
choices = ["Security only", "Security and updates"]
|
||||||
|
default = "Security only"
|
||||||
|
|
||||||
|
[main.unattended_configuration.ynh_update]
|
||||||
|
ask = "Would you like to update YunoHost packages automatically ?"
|
||||||
|
type = "boolean"
|
||||||
|
default = true
|
||||||
|
|
||||||
|
[main.unattended_configuration.unattended_mail]
|
||||||
|
ask = "Would you like to receive an email from Unattended-Upgrades ?"
|
||||||
|
choices = ["If an upgrade has been done", "Only if there was an error", "Never"]
|
||||||
|
default = "If an upgrade has been done"
|
||||||
|
|
||||||
|
|
||||||
|
[main.apticron_configuration]
|
||||||
|
name = "apticron cron file"
|
||||||
|
|
||||||
|
[main.apticron_configuration.previous_apticron]
|
||||||
|
ask = "Would you like to receive an email to inform which upgrades need to be done ?"
|
||||||
|
type = "boolean"
|
||||||
|
default = true
|
||||||
|
|
||||||
|
[main.apticron_configuration.previous_apticron_hour]
|
||||||
|
ask = "When do you want to receive this email ?"
|
||||||
|
type = "number"
|
||||||
|
default = "20"
|
||||||
|
help = "Choose an hour between 12 and 23."
|
||||||
|
|
||||||
|
[main.apticron_configuration.after_apticron]
|
||||||
|
ask = "Would you like to receive an email to verify if there any upgrades left after each auto upgrade ?"
|
||||||
|
type = "boolean"
|
||||||
|
default = true
|
||||||
|
|
||||||
|
[main.apticron_configuration.after_apticron_hour]
|
||||||
|
ask = "When do you want to receive this email ?"
|
||||||
|
type = "number"
|
||||||
|
default = "2"
|
||||||
|
help = "Choose an hour between 0 and 10."
|
||||||
|
|
||||||
|
|
||||||
|
[main.periodic_configuration]
|
||||||
|
name = "02periodic apt config file"
|
||||||
|
|
||||||
|
[main.periodic_configuration.unattended_verbosity]
|
||||||
|
ask = "Choose the level of verbosity of Unattended-Upgrades mail."
|
||||||
|
choices = ["1", "2", "3"]
|
||||||
|
default = "1"
|
||||||
|
help = "1: Progress report only.<br>2: Progress report and command outputs.<br>3: Progress report and command outputs and trace."
|
||||||
|
|
||||||
|
|
||||||
|
[main.overwrite_files]
|
||||||
|
name = "Overwriting config files"
|
||||||
|
|
||||||
|
[main.overwrite_files.overwrite_periodic]
|
||||||
|
ask = "Overwrite the config file 02periodic ?"
|
||||||
|
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."
|
|
@ -6,7 +6,7 @@
|
||||||
"en": "Daily automatic upgrades",
|
"en": "Daily automatic upgrades",
|
||||||
"fr": "Mise à jour automatique quotidienne."
|
"fr": "Mise à jour automatique quotidienne."
|
||||||
},
|
},
|
||||||
"version": "1.0~ynh4",
|
"version": "1.0~ynh5",
|
||||||
"url": "https://wiki.debian.org/UnattendedUpgrades",
|
"url": "https://wiki.debian.org/UnattendedUpgrades",
|
||||||
"license": "GPL-2.0-or-later",
|
"license": "GPL-2.0-or-later",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
"email": "maniackc_dev@crudelis.fr"
|
"email": "maniackc_dev@crudelis.fr"
|
||||||
},
|
},
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">= 3.4"
|
"yunohost": ">= 3.6.0"
|
||||||
},
|
},
|
||||||
"multi_instance": false,
|
"multi_instance": false,
|
||||||
"services": [],
|
"services": [],
|
||||||
|
@ -22,6 +22,7 @@
|
||||||
"install" : [
|
"install" : [
|
||||||
{
|
{
|
||||||
"name": "upgrade_level",
|
"name": "upgrade_level",
|
||||||
|
"type": "string",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose the sources of packages to automatically upgrade",
|
"en": "Choose the sources of packages to automatically upgrade",
|
||||||
"fr": "Choisissez les sources des paquets à mettre à jour automatiquement"
|
"fr": "Choisissez les sources des paquets à mettre à jour automatiquement"
|
||||||
|
@ -58,6 +59,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "unattended_mail",
|
"name": "unattended_mail",
|
||||||
|
"type": "string",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Would you like to receive an email from Unattended-Upgrades ?",
|
"en": "Would you like to receive an email from Unattended-Upgrades ?",
|
||||||
"fr": "Souhaitez-vous recevoir un email de Unattended-Upgrades ?"
|
"fr": "Souhaitez-vous recevoir un email de Unattended-Upgrades ?"
|
||||||
|
@ -67,6 +69,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "unattended_verbosity",
|
"name": "unattended_verbosity",
|
||||||
|
"type": "string",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose the level of verbosity of Unattended-Upgrades mail",
|
"en": "Choose the level of verbosity of Unattended-Upgrades mail",
|
||||||
"fr": "Choisir le niveau de verbosité du mail de Unattended-Upgrades"
|
"fr": "Choisir le niveau de verbosité du mail de Unattended-Upgrades"
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PERSONAL HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP
|
# BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -27,25 +31,12 @@ CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
IS_PACKAGE_CHECK () {
|
IS_PACKAGE_CHECK () {
|
||||||
return $(env | grep -c container=lxc)
|
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]
|
||||||
}
|
then
|
||||||
|
return 0
|
||||||
#=================================================
|
else
|
||||||
# BOOLEAN CONVERTER
|
return 1
|
||||||
#=================================================
|
fi
|
||||||
|
|
||||||
bool_to_01 () {
|
|
||||||
local var="$1"
|
|
||||||
[ "$var" = "true" ] && var=1
|
|
||||||
[ "$var" = "false" ] && var=0
|
|
||||||
echo "$var"
|
|
||||||
}
|
|
||||||
|
|
||||||
bool_to_true_false () {
|
|
||||||
local var="$1"
|
|
||||||
[ "$var" = "1" ] && var=true
|
|
||||||
[ "$var" = "0" ] && var=false
|
|
||||||
echo "$var"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -129,359 +120,6 @@ ynh_multimedia_addaccess () {
|
||||||
usermod -a -G multimedia $user_name
|
usermod -a -G multimedia $user_name
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Create a dedicated fail2ban config (jail and filter conf files)
|
|
||||||
#
|
|
||||||
# usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]]
|
|
||||||
# | arg: -l, --logpath= - Log file to be checked by fail2ban
|
|
||||||
# | arg: -r, --failregex= - Failregex to be looked for by fail2ban
|
|
||||||
# | arg: -m, --max_retry= - Maximum number of retries allowed before banning IP address - default: 3
|
|
||||||
# | arg: -p, --ports= - Ports blocked for a banned IP address - default: http,https
|
|
||||||
ynh_add_fail2ban_config () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
declare -Ar args_array=( [l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= )
|
|
||||||
local logpath
|
|
||||||
local failregex
|
|
||||||
local max_retry
|
|
||||||
local ports
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
max_retry=${max_retry:-3}
|
|
||||||
ports=${ports:-http,https}
|
|
||||||
|
|
||||||
test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing."
|
|
||||||
test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing."
|
|
||||||
|
|
||||||
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
|
|
||||||
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
|
|
||||||
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
|
|
||||||
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
|
|
||||||
|
|
||||||
tee $finalfail2banjailconf <<EOF
|
|
||||||
[$app]
|
|
||||||
enabled = true
|
|
||||||
port = $ports
|
|
||||||
filter = $app
|
|
||||||
logpath = $logpath
|
|
||||||
maxretry = $max_retry
|
|
||||||
EOF
|
|
||||||
|
|
||||||
tee $finalfail2banfilterconf <<EOF
|
|
||||||
[INCLUDES]
|
|
||||||
before = common.conf
|
|
||||||
[Definition]
|
|
||||||
failregex = $failregex
|
|
||||||
ignoreregex =
|
|
||||||
EOF
|
|
||||||
|
|
||||||
ynh_store_file_checksum "$finalfail2banjailconf"
|
|
||||||
ynh_store_file_checksum "$finalfail2banfilterconf"
|
|
||||||
|
|
||||||
if [ "$(lsb_release --codename --short)" != "jessie" ]; then
|
|
||||||
systemctl reload fail2ban
|
|
||||||
else
|
|
||||||
systemctl restart fail2ban
|
|
||||||
fi
|
|
||||||
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
|
||||||
if [ -n "$fail2ban_error" ]
|
|
||||||
then
|
|
||||||
echo "[ERR] Fail2ban failed to load the jail for $app" >&2
|
|
||||||
echo "WARNING${fail2ban_error#*WARNING}" >&2
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove the dedicated fail2ban config (jail and filter conf files)
|
|
||||||
#
|
|
||||||
# usage: ynh_remove_fail2ban_config
|
|
||||||
ynh_remove_fail2ban_config () {
|
|
||||||
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
|
|
||||||
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
|
|
||||||
if [ "$(lsb_release --codename --short)" != "jessie" ]; then
|
|
||||||
systemctl reload fail2ban
|
|
||||||
else
|
|
||||||
systemctl restart fail2ban
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Read the value of a key in a ynh manifest file
|
|
||||||
#
|
|
||||||
# usage: ynh_read_manifest manifest key
|
|
||||||
# | arg: -m, --manifest= - Path of the manifest to read
|
|
||||||
# | arg: -k, --key= - Name of the key to find
|
|
||||||
ynh_read_manifest () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
declare -Ar args_array=( [m]=manifest= [k]=manifest_key= )
|
|
||||||
local manifest
|
|
||||||
local manifest_key
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$manifest_key'])"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read the upstream version from the manifest
|
|
||||||
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
|
|
||||||
# For example : 4.3-2~ynh3
|
|
||||||
# This include the number before ~ynh
|
|
||||||
# In the last example it return 4.3-2
|
|
||||||
#
|
|
||||||
# usage: ynh_app_upstream_version [-m manifest]
|
|
||||||
# | arg: -m, --manifest= - Path of the manifest to read
|
|
||||||
ynh_app_upstream_version () {
|
|
||||||
declare -Ar args_array=( [m]=manifest= )
|
|
||||||
local manifest
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
manifest="${manifest:-../manifest.json}"
|
|
||||||
if [ ! -e "$manifest" ]; then
|
|
||||||
manifest="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
|
||||||
fi
|
|
||||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
|
||||||
echo "${version_key/~ynh*/}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read package version from the manifest
|
|
||||||
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
|
|
||||||
# For example : 4.3-2~ynh3
|
|
||||||
# This include the number after ~ynh
|
|
||||||
# In the last example it return 3
|
|
||||||
#
|
|
||||||
# usage: ynh_app_package_version [-m manifest]
|
|
||||||
# | arg: -m, --manifest= - Path of the manifest to read
|
|
||||||
ynh_app_package_version () {
|
|
||||||
declare -Ar args_array=( [m]=manifest= )
|
|
||||||
local manifest
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
manifest="${manifest:-../manifest.json}"
|
|
||||||
if [ ! -e "$manifest" ]; then
|
|
||||||
manifest="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
|
||||||
fi
|
|
||||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
|
||||||
echo "${version_key/*~ynh/}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Checks the app version to upgrade with the existing app version and returns:
|
|
||||||
# - UPGRADE_APP if the upstream app version has changed
|
|
||||||
# - UPGRADE_PACKAGE if only the YunoHost package has changed
|
|
||||||
#
|
|
||||||
## It stops the current script without error if the package is up-to-date
|
|
||||||
#
|
|
||||||
# This helper should be used to avoid an upgrade of an app, or the upstream part
|
|
||||||
# of it, when it's not needed
|
|
||||||
#
|
|
||||||
# To force an upgrade, even if the package is up to date,
|
|
||||||
# you have to set the variable YNH_FORCE_UPGRADE before.
|
|
||||||
# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
|
|
||||||
#
|
|
||||||
# usage: ynh_check_app_version_changed
|
|
||||||
ynh_check_app_version_changed () {
|
|
||||||
local force_upgrade=${YNH_FORCE_UPGRADE:-0}
|
|
||||||
local package_check=${PACKAGE_CHECK_EXEC:-0}
|
|
||||||
|
|
||||||
# By default, upstream app version has changed
|
|
||||||
local return_value="UPGRADE_APP"
|
|
||||||
|
|
||||||
local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)
|
|
||||||
local current_upstream_version="$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json")"
|
|
||||||
local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0)
|
|
||||||
local update_upstream_version="$(ynh_app_upstream_version)"
|
|
||||||
|
|
||||||
if [ "$current_version" == "$update_version" ] ; then
|
|
||||||
# Complete versions are the same
|
|
||||||
if [ "$force_upgrade" != "0" ]
|
|
||||||
then
|
|
||||||
echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2
|
|
||||||
unset YNH_FORCE_UPGRADE
|
|
||||||
elif [ "$package_check" != "0" ]
|
|
||||||
then
|
|
||||||
echo "Upgrade forced for package check." >&2
|
|
||||||
else
|
|
||||||
ynh_die "Up-to-date, nothing to do" 0
|
|
||||||
fi
|
|
||||||
elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then
|
|
||||||
# Upstream versions are the same, only YunoHost package versions differ
|
|
||||||
return_value="UPGRADE_PACKAGE"
|
|
||||||
fi
|
|
||||||
echo $return_value
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
|
|
||||||
#
|
|
||||||
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
|
|
||||||
# | arg: -n, --service_name= - Name of the service to reload. Default : $app
|
|
||||||
# | arg: -a, --action= - Action to perform with systemctl. Default: start
|
|
||||||
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
|
|
||||||
# If not defined it don't wait until the service is completely started.
|
|
||||||
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
|
|
||||||
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
|
|
||||||
# | arg: -e, --length= - Length of the error log : Default : 20
|
|
||||||
ynh_systemd_action() {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
|
|
||||||
local service_name
|
|
||||||
local action
|
|
||||||
local line_match
|
|
||||||
local length
|
|
||||||
local log_path
|
|
||||||
local timeout
|
|
||||||
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
local service_name="${service_name:-$app}"
|
|
||||||
local action=${action:-start}
|
|
||||||
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
|
|
||||||
local length=${length:-20}
|
|
||||||
local timeout=${timeout:-300}
|
|
||||||
|
|
||||||
# Start to read the log
|
|
||||||
if [[ -n "${line_match:-}" ]]
|
|
||||||
then
|
|
||||||
local templog="$(mktemp)"
|
|
||||||
# Following the starting of the app in its log
|
|
||||||
if [ "$log_path" == "systemd" ] ; then
|
|
||||||
# Read the systemd journal
|
|
||||||
journalctl -u $service_name -f --since=-45 > "$templog" &
|
|
||||||
else
|
|
||||||
# Read the specified log file
|
|
||||||
tail -F -n0 "$log_path" > "$templog" &
|
|
||||||
fi
|
|
||||||
# Get the PID of the tail command
|
|
||||||
local pid_tail=$!
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${action^} the service $service_name" >&2
|
|
||||||
systemctl $action $service_name \
|
|
||||||
|| ( journalctl --lines=$length -u $service_name >&2 \
|
|
||||||
; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \
|
|
||||||
; false )
|
|
||||||
|
|
||||||
# Start the timeout and try to find line_match
|
|
||||||
if [[ -n "${line_match:-}" ]]
|
|
||||||
then
|
|
||||||
local i=0
|
|
||||||
for i in $(seq 1 $timeout)
|
|
||||||
do
|
|
||||||
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
|
|
||||||
if grep --quiet "$line_match" "$templog"
|
|
||||||
then
|
|
||||||
echo "The service $service_name has correctly started." >&2
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo -n "." >&2
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
if [ $i -eq $timeout ]
|
|
||||||
then
|
|
||||||
echo "The service $service_name didn't fully started before the timeout." >&2
|
|
||||||
echo "Please find here an extract of the end of the log of the service $service_name:"
|
|
||||||
journalctl --lines=$length -u $service_name >&2
|
|
||||||
test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
ynh_clean_check_starting
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clean temporary process and file used by ynh_check_starting
|
|
||||||
# (usually used in ynh_clean_setup scripts)
|
|
||||||
#
|
|
||||||
# usage: ynh_clean_check_starting
|
|
||||||
ynh_clean_check_starting () {
|
|
||||||
# Stop the execution of tail.
|
|
||||||
kill -s 15 $pid_tail 2>&1
|
|
||||||
ynh_secure_remove "$templog" 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Print a message as INFO and show progression during an app script
|
|
||||||
#
|
|
||||||
# usage: ynh_script_progression --message=message [--weight=weight] [--time]
|
|
||||||
# | arg: -m, --message= - The text to print
|
|
||||||
# | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script.
|
|
||||||
# | arg: -t, --time= - Print the execution time since the last call to this helper. Especially usefull to define weights.
|
|
||||||
# | arg: -l, --last= - Use for the last call of the helper, to fill te progression bar.
|
|
||||||
increment_progression=0
|
|
||||||
previous_weight=0
|
|
||||||
# Define base_time when the file is sourced
|
|
||||||
base_time=$(date +%s)
|
|
||||||
ynh_script_progression () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
declare -Ar args_array=( [m]=message= [w]=weight= [t]=time [l]=last )
|
|
||||||
local message
|
|
||||||
local weight
|
|
||||||
local time
|
|
||||||
local last
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
weight=${weight:-1}
|
|
||||||
time=${time:-0}
|
|
||||||
last=${last:-0}
|
|
||||||
|
|
||||||
# Get execution time since the last $base_time
|
|
||||||
local exec_time=$(( $(date +%s) - $base_time ))
|
|
||||||
base_time=$(date +%s)
|
|
||||||
|
|
||||||
# Get the number of occurrences of 'ynh_script_progression' in the script. Except those are commented.
|
|
||||||
local helper_calls="$(grep --count "^[^#]*ynh_script_progression" $0)"
|
|
||||||
# Get the number of call with a weight value
|
|
||||||
local weight_calls=$(grep --perl-regexp --count "^[^#]*ynh_script_progression.*(--weight|-w )" $0)
|
|
||||||
|
|
||||||
# Get the weight of each occurrences of 'ynh_script_progression' in the script using --weight
|
|
||||||
local weight_valuesA="$(grep --perl-regexp "^[^#]*ynh_script_progression.*--weight" $0 | sed 's/.*--weight[= ]\([[:digit:]].*\)/\1/g')"
|
|
||||||
# Get the weight of each occurrences of 'ynh_script_progression' in the script using -w
|
|
||||||
local weight_valuesB="$(grep --perl-regexp "^[^#]*ynh_script_progression.*-w " $0 | sed 's/.*-w[= ]\([[:digit:]].*\)/\1/g')"
|
|
||||||
# Each value will be on a different line.
|
|
||||||
# Remove each 'end of line' and replace it by a '+' to sum the values.
|
|
||||||
local weight_values=$(( $(echo "$weight_valuesA" | tr '\n' '+') + $(echo "$weight_valuesB" | tr '\n' '+') 0 ))
|
|
||||||
|
|
||||||
# max_progression is a total number of calls to this helper.
|
|
||||||
# Less the number of calls with a weight value.
|
|
||||||
# Plus the total of weight values
|
|
||||||
local max_progression=$(( $helper_calls - $weight_calls + $weight_values ))
|
|
||||||
|
|
||||||
# Increment each execution of ynh_script_progression in this script by the weight of the previous call.
|
|
||||||
increment_progression=$(( $increment_progression + $previous_weight ))
|
|
||||||
# Store the weight of the current call in $previous_weight for next call
|
|
||||||
previous_weight=$weight
|
|
||||||
|
|
||||||
# Set the scale of the progression bar
|
|
||||||
local scale=20
|
|
||||||
# progress_string(1,2) should have the size of the scale.
|
|
||||||
local progress_string1="####################"
|
|
||||||
local progress_string0="...................."
|
|
||||||
|
|
||||||
# Reduce $increment_progression to the size of the scale
|
|
||||||
if [ $last -eq 0 ]
|
|
||||||
then
|
|
||||||
local effective_progression=$(( $increment_progression * $scale / $max_progression ))
|
|
||||||
# If last is specified, fill immediately the progression_bar
|
|
||||||
else
|
|
||||||
local effective_progression=$scale
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build $progression_bar from progress_string(1,2) according to $effective_progression
|
|
||||||
local progression_bar="${progress_string1:0:$effective_progression}${progress_string0:0:$(( $scale - $effective_progression ))}"
|
|
||||||
|
|
||||||
local print_exec_time=""
|
|
||||||
if [ $time -eq 1 ]
|
|
||||||
then
|
|
||||||
print_exec_time=" [$(date +%Hh%Mm,%Ss --date="0 + $exec_time sec")]"
|
|
||||||
fi
|
|
||||||
|
|
||||||
ynh_print_info "[$progression_bar] > ${message}${print_exec_time}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# EXPERIMENTAL HELPERS
|
# EXPERIMENTAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -660,6 +298,8 @@ ynh_maintenance_mode_ON () {
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
mkdir -p /var/www/html/
|
||||||
|
|
||||||
# Create an html to serve as maintenance notice
|
# Create an html to serve as maintenance notice
|
||||||
echo "<!DOCTYPE html>
|
echo "<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
@ -730,128 +370,381 @@ ynh_maintenance_mode_OFF () {
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Download and check integrity of a file from app.src_file
|
# Create a changelog for an app after an upgrade from the file CHANGELOG.md.
|
||||||
#
|
#
|
||||||
# The file conf/app.src_file need to contains:
|
# usage: ynh_app_changelog [--format=markdown/html/plain] [--output=changelog_file] --changelog=changelog_source]
|
||||||
|
# | arg: -f --format= - Format in which the changelog will be printed
|
||||||
|
# markdown: Default format.
|
||||||
|
# html: Turn urls into html format.
|
||||||
|
# plain: Plain text changelog
|
||||||
|
# | arg: -o --output= - Output file for the changelog file (Default ./changelog)
|
||||||
|
# | arg: -c --changelog= - CHANGELOG.md source (Default ../CHANGELOG.md)
|
||||||
#
|
#
|
||||||
# FILE_URL=Address to download the file
|
# The changelog is printed into the file ./changelog and ./changelog_lite
|
||||||
# FILE_SUM=Control sum
|
ynh_app_changelog () {
|
||||||
# # (Optional) Program to check the integrity (sha256sum, md5sum...)
|
|
||||||
# # default: sha256
|
|
||||||
# FILE_SUM_PRG=sha256
|
|
||||||
# # (Optionnal) Name of the local archive (offline setup support)
|
|
||||||
# # default: Name of the downloaded file.
|
|
||||||
# FILENAME=example.deb
|
|
||||||
#
|
|
||||||
# usage: ynh_download_file --dest_dir="/destination/directory" [--source_id=myfile]
|
|
||||||
# | arg: -d, --dest_dir= - Directory where to download the file
|
|
||||||
# | arg: -s, --source_id= - Name of the source file 'app.src_file' if it isn't '$app'
|
|
||||||
ynh_download_file () {
|
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
declare -Ar args_array=( [d]=dest_dir= [s]=source_id= )
|
local legacy_args=foc
|
||||||
local dest_dir
|
declare -Ar args_array=( [f]=format= [o]=output= [c]=changelog= )
|
||||||
local source_id
|
local format
|
||||||
|
local output
|
||||||
|
local changelog
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
format=${format:-markdown}
|
||||||
|
output=${output:-changelog}
|
||||||
|
changelog=${changelog:-../CHANGELOG.md}
|
||||||
|
|
||||||
source_id=${source_id:-app} # If the argument is not given, source_id equals "$app"
|
local original_changelog="$changelog"
|
||||||
|
local temp_changelog="changelog_temp"
|
||||||
|
local final_changelog="$output"
|
||||||
|
|
||||||
# Load value from configuration file (see above for a small doc about this file
|
if [ ! -n "$original_changelog" ]
|
||||||
# format)
|
|
||||||
local src_file="$YNH_CWD/../conf/${source_id}.src_file"
|
|
||||||
# If the src_file doesn't exist, use the backup path instead, with a "settings" directory
|
|
||||||
if [ ! -e "$src_file" ]
|
|
||||||
then
|
then
|
||||||
src_file="$YNH_CWD/../settings/conf/${source_id}.src_file"
|
echo "No changelog available..." > "$final_changelog"
|
||||||
fi
|
echo "No changelog available..." > "${final_changelog}_lite"
|
||||||
local file_url=$(grep 'FILE_URL=' "$src_file" | cut -d= -f2-)
|
return 0
|
||||||
local file_sum=$(grep 'FILE_SUM=' "$src_file" | cut -d= -f2-)
|
|
||||||
local file_sumprg=$(grep 'FILE_SUM_PRG=' "$src_file" | cut -d= -f2-)
|
|
||||||
local filename=$(grep 'FILENAME=' "$src_file" | cut -d= -f2-)
|
|
||||||
|
|
||||||
# Default value
|
|
||||||
file_sumprg=${file_sumprg:-sha256sum}
|
|
||||||
if [ "$filename" = "" ] ; then
|
|
||||||
filename="$(basename "$file_url")"
|
|
||||||
fi
|
|
||||||
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${filename}"
|
|
||||||
|
|
||||||
if test -e "$local_src"
|
|
||||||
then # Use the local source file if it is present
|
|
||||||
cp $local_src $filename
|
|
||||||
else # If not, download the source
|
|
||||||
local out=`wget -nv -O $filename $file_url 2>&1` || ynh_print_err $out
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check the control sum
|
local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version")
|
||||||
echo "${file_sum} ${filename}" | ${file_sumprg} -c --status \
|
local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version")
|
||||||
|| ynh_die "Corrupt file"
|
|
||||||
|
|
||||||
# Create the destination directory, if it's not already.
|
# Get the line of the version to update to into the changelog
|
||||||
mkdir -p "$dest_dir"
|
local update_version_line=$(grep --max-count=1 --line-number "^## \[$update_version" "$original_changelog" | cut -d':' -f1)
|
||||||
|
# If there's no entry for this version yet into the changelog
|
||||||
|
# Get the first available version
|
||||||
|
if [ -z "$update_version_line" ]
|
||||||
|
then
|
||||||
|
update_version_line=$(grep --max-count=1 --line-number "^##" "$original_changelog" | cut -d':' -f1)
|
||||||
|
fi
|
||||||
|
|
||||||
# Move the file to its destination
|
# Get the length of the complete changelog.
|
||||||
mv $filename $dest_dir
|
local changelog_length=$(wc --lines "$original_changelog" | awk '{print $1}')
|
||||||
|
# Cut the file before the version to update to.
|
||||||
|
tail --lines=$(( $changelog_length - $update_version_line + 1 )) "$original_changelog" > "$temp_changelog"
|
||||||
|
|
||||||
|
# Get the length of the troncated changelog.
|
||||||
|
changelog_length=$(wc --lines "$temp_changelog" | awk '{print $1}')
|
||||||
|
# Get the line of the current version into the changelog
|
||||||
|
# Keep only the last line found
|
||||||
|
local current_version_line=$(grep --line-number "^## \[$current_version" "$temp_changelog" | cut -d':' -f1 | tail --lines=1)
|
||||||
|
# If there's no entry for this version into the changelog
|
||||||
|
# Get the last available version
|
||||||
|
if [ -z "$current_version_line" ]
|
||||||
|
then
|
||||||
|
current_version_line=$(grep --line-number "^##" "$original_changelog" | cut -d':' -f1 | tail --lines=1)
|
||||||
|
fi
|
||||||
|
# Cut the file before the current version.
|
||||||
|
# Then grep the previous version into the changelog to get the line number of the previous version
|
||||||
|
local previous_version_line=$(tail --lines=$(( $changelog_length - $current_version_line )) \
|
||||||
|
"$temp_changelog" | grep --max-count=1 --line-number "^## " | cut -d':' -f1)
|
||||||
|
# If there's no previous version into the changelog
|
||||||
|
# Go until the end of the changelog
|
||||||
|
if [ -z "$previous_version_line" ]
|
||||||
|
then
|
||||||
|
previous_version_line=$changelog_length
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cut the file after the previous version to keep only the changelog between the current version and the version to update to.
|
||||||
|
head --lines=$(( $current_version_line + $previous_version_line - 1 )) "$temp_changelog" | tee "$final_changelog"
|
||||||
|
|
||||||
|
if [ "$format" = "html" ]
|
||||||
|
then
|
||||||
|
# Replace markdown links by html links
|
||||||
|
ynh_replace_string --match_string="\[\(.*\)\](\(.*\)))" --replace_string="<a href=\"\2\">\1</a>)" --target_file="$final_changelog"
|
||||||
|
ynh_replace_string --match_string="\[\(.*\)\](\(.*\))" --replace_string="<a href=\"\2\">\1</a>" --target_file="$final_changelog"
|
||||||
|
elif [ "$format" = "plain" ]
|
||||||
|
then
|
||||||
|
# Change title format.
|
||||||
|
ynh_replace_string --match_string="^##.*\[\(.*\)\](\(.*\)) - \(.*\)$" --replace_string="## \1 (\3) - \2" --target_file="$final_changelog"
|
||||||
|
# Change modifications lines format.
|
||||||
|
ynh_replace_string --match_string="^\([-*]\).*\[\(.*\)\]\(.*\)" --replace_string="\1 \2 \3" --target_file="$final_changelog"
|
||||||
|
fi
|
||||||
|
# else markdown. As the file is already in markdown, nothing to do.
|
||||||
|
|
||||||
|
# Keep only important changes into the changelog
|
||||||
|
# Remove all minor changes
|
||||||
|
sed '/^-/d' "$final_changelog" > "${final_changelog}_lite"
|
||||||
|
# Remove all blank lines (to keep a clear workspace)
|
||||||
|
sed --in-place '/^$/d' "${final_changelog}_lite"
|
||||||
|
# Add a blank line at the end
|
||||||
|
echo "" >> "${final_changelog}_lite"
|
||||||
|
|
||||||
|
# Clean titles if there's no significative changes
|
||||||
|
local line
|
||||||
|
local previous_line=""
|
||||||
|
while read line <&3
|
||||||
|
do
|
||||||
|
if [ -n "$previous_line" ]
|
||||||
|
then
|
||||||
|
# Remove the line if it's a title or a blank line, and the previous one was a title as well.
|
||||||
|
if ( [ "${line:0:1}" = "#" ] || [ ${#line} -eq 0 ] ) && [ "${previous_line:0:1}" = "#" ]
|
||||||
|
then
|
||||||
|
ynh_replace_special_string --match_string="${previous_line//[/.}" --replace_string="" --target_file="${final_changelog}_lite"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
previous_line="$line"
|
||||||
|
done 3< "${final_changelog}_lite"
|
||||||
|
|
||||||
|
# Remove all blank lines again
|
||||||
|
sed --in-place '/^$/d' "${final_changelog}_lite"
|
||||||
|
|
||||||
|
# Restore changelog format with blank lines
|
||||||
|
ynh_replace_string --match_string="^##.*" --replace_string="\n\n&\n" --target_file="${final_changelog}_lite"
|
||||||
|
# Remove the 2 first blank lines
|
||||||
|
sed --in-place '1,2d' "${final_changelog}_lite"
|
||||||
|
# Add a blank line at the end
|
||||||
|
echo "" >> "${final_changelog}_lite"
|
||||||
|
|
||||||
|
# If changelog are empty, add an info
|
||||||
|
if [ $(wc --words "$final_changelog" | awk '{print $1}') -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "No changes from the changelog..." > "$final_changelog"
|
||||||
|
fi
|
||||||
|
if [ $(wc --words "${final_changelog}_lite" | awk '{print $1}') -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "No significative changes from the changelog..." > "${final_changelog}_lite"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Create a changelog for an app after an upgrade.
|
# Check the amount of available RAM
|
||||||
#
|
#
|
||||||
# The changelog is printed into the file ./changelog for the time of the upgrade.
|
# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram]
|
||||||
#
|
# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise.
|
||||||
# In order to create a changelog, ynh_app_changelog will get info from /etc/yunohost/apps/$app/status.json
|
# If --required isn't set, the helper will print the amount of RAM, in Mb.
|
||||||
# In order to find the current commit use by the app.
|
# | arg: -s, --no_swap - Ignore swap
|
||||||
# The remote repository, and the branch.
|
# | arg: -o, --only_swap - Ignore real RAM, consider only swap.
|
||||||
# The changelog will be only the commits since the current revision.
|
# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available.
|
||||||
#
|
ynh_check_ram () {
|
||||||
# Because of the need of those info, ynh_app_changelog works only
|
# Declare an array to define the options of this helper.
|
||||||
# with apps that have been installed from a list.
|
declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram )
|
||||||
#
|
local required
|
||||||
# usage: ynh_app_changelog
|
local no_swap
|
||||||
ynh_app_changelog () {
|
local only_swap
|
||||||
get_value_from_settings ()
|
# Manage arguments with getopts
|
||||||
{
|
ynh_handle_getopts_args "$@"
|
||||||
local value="$1"
|
required=${required:-}
|
||||||
# Extract a value from the status.json file of an installed app.
|
no_swap=${no_swap:-0}
|
||||||
|
only_swap=${only_swap:-0}
|
||||||
|
|
||||||
grep "$value\": \"" /etc/yunohost/apps/$app/status.json | sed "s/.*$value\": \"\([^\"]*\).*/\1/"
|
local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}')
|
||||||
}
|
local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}')
|
||||||
|
local total_ram_swap=$(( total_ram + total_swap ))
|
||||||
|
|
||||||
local current_revision="$(get_value_from_settings revision)"
|
local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}')
|
||||||
local repo="$(get_value_from_settings url)"
|
local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}')
|
||||||
local branch="$(get_value_from_settings branch)"
|
local free_ram_swap=$(( free_ram + free_swap ))
|
||||||
# ynh_app_changelog works only with an app installed from a list.
|
|
||||||
if [ -z "$current_revision" ] || [ -z "$repo" ] || [ -z "$branch" ]
|
# Use the total amount of ram
|
||||||
|
local ram=$total_ram_swap
|
||||||
|
if [ $free_ram -eq 1 ]
|
||||||
then
|
then
|
||||||
ynh_print_warn "Unable to build the changelog..."
|
# Use the total amount of free ram
|
||||||
touch changelog
|
ram=$free_ram_swap
|
||||||
|
if [ $no_swap -eq 1 ]
|
||||||
|
then
|
||||||
|
# Use only the amount of free ram
|
||||||
|
ram=$free_ram
|
||||||
|
elif [ $only_swap -eq 1 ]
|
||||||
|
then
|
||||||
|
# Use only the amount of free swap
|
||||||
|
ram=$free_swap
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ $no_swap -eq 1 ]
|
||||||
|
then
|
||||||
|
# Use only the amount of free ram
|
||||||
|
ram=$total_ram
|
||||||
|
elif [ $only_swap -eq 1 ]
|
||||||
|
then
|
||||||
|
# Use only the amount of free swap
|
||||||
|
ram=$total_swap
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$required" ]
|
||||||
|
then
|
||||||
|
# Return 1 if the amount of ram isn't enough.
|
||||||
|
if [ $ram -lt $required ]
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fetch the history of the repository, without cloning it
|
# If no RAM is required, return the amount of available ram.
|
||||||
mkdir git_history
|
else
|
||||||
(cd git_history
|
echo $ram
|
||||||
ynh_exec_warn_less git init
|
fi
|
||||||
ynh_exec_warn_less git remote add -f origin $repo
|
}
|
||||||
# Get the line of the current commit of the installed app in the history.
|
|
||||||
local line_to_head=$(git log origin/$branch --pretty=oneline | grep --line-number "$current_revision" | cut -d':' -f1)
|
#=================================================
|
||||||
# Cut the history before the current commit, to keep only newer commits.
|
|
||||||
# Then use sed to reorganise each lines and have a nice list of commits since the last upgrade.
|
# Define the values to configure php-fpm
|
||||||
# This list is redirected into the file changelog
|
#
|
||||||
git log origin/$branch --pretty=oneline | head --lines=$(($line_to_head-1)) | sed 's/^\([[:alnum:]]*\)\(.*\)/*(\1) -> \2/g' > ../changelog)
|
# usage: ynh_get_scalable_phpfpm --usage=usage --footprint=footprint [--print]
|
||||||
# Remove 'Merge pull request' commits
|
# | arg: -f, --footprint - Memory footprint of the service (low/medium/high).
|
||||||
sed -i '/Merge pull request #[[:digit:]]* from/d' changelog
|
# low - Less than 20Mb of ram by pool.
|
||||||
# As well as conflict resolving commits
|
# medium - Between 20Mb and 40Mb of ram by pool.
|
||||||
sed -i '/Merge branch .* into/d' changelog
|
# high - More than 40Mb of ram by pool.
|
||||||
|
# Or specify exactly the footprint, the load of the service as Mb by pool instead of having a standard value.
|
||||||
# Get the value of admin_mail_html
|
# To have this value, use the following command and stress the service.
|
||||||
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
|
# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
|
||||||
admin_mail_html="${admin_mail_html:-0}"
|
#
|
||||||
|
# | arg: -u, --usage - Expected usage of the service (low/medium/high).
|
||||||
# If a html email is required. Apply html to the changelog.
|
# low - Personal usage, behind the sso.
|
||||||
if [ "$admin_mail_html" -eq 1 ]
|
# medium - Low usage, few people or/and publicly accessible.
|
||||||
then
|
# high - High usage, frequently visited website.
|
||||||
sed -in-place "s@\*(\([[:alnum:]]*\)) -> \(.*\)@* __URL_TAG1__\2__URL_TAG2__${repo}/commit/\1__URL_TAG3__@g" changelog
|
#
|
||||||
|
# | arg: -p, --print - Print the result
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# The footprint of the service will be used to defined the maximum footprint we can allow, which is half the maximum RAM.
|
||||||
|
# So it will be used to defined 'pm.max_children'
|
||||||
|
# A lower value for the footprint will allow more children for 'pm.max_children'. And so for
|
||||||
|
# 'pm.start_servers', 'pm.min_spare_servers' and 'pm.max_spare_servers' which are defined from the
|
||||||
|
# value of 'pm.max_children'
|
||||||
|
# NOTE: 'pm.max_children' can't exceed 4 times the number of processor's cores.
|
||||||
|
#
|
||||||
|
# The usage value will defined the way php will handle the children for the pool.
|
||||||
|
# A value set as 'low' will set the process manager to 'ondemand'. Children will start only if the
|
||||||
|
# service is used, otherwise no child will stay alive. This config gives the lower footprint when the
|
||||||
|
# service is idle. But will use more proc since it has to start a child as soon it's used.
|
||||||
|
# Set as 'medium', the process manager will be at dynamic. If the service is idle, a number of children
|
||||||
|
# equal to pm.min_spare_servers will stay alive. So the service can be quick to answer to any request.
|
||||||
|
# The number of children can grow if needed. The footprint can stay low if the service is idle, but
|
||||||
|
# not null. The impact on the proc is a little bit less than 'ondemand' as there's always a few
|
||||||
|
# children already available.
|
||||||
|
# Set as 'high', the process manager will be set at 'static'. There will be always as many children as
|
||||||
|
# 'pm.max_children', the footprint is important (but will be set as maximum a quarter of the maximum
|
||||||
|
# RAM) but the impact on the proc is lower. The service will be quick to answer as there's always many
|
||||||
|
# children ready to answer.
|
||||||
|
ynh_get_scalable_phpfpm () {
|
||||||
|
local legacy_args=ufp
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
declare -Ar args_array=( [u]=usage= [f]=footprint= [p]=print )
|
||||||
|
local usage
|
||||||
|
local footprint
|
||||||
|
local print
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
# Set all characters as lowercase
|
||||||
|
footprint=${footprint,,}
|
||||||
|
usage=${usage,,}
|
||||||
|
print=${print:-0}
|
||||||
|
|
||||||
|
if [ "$footprint" = "low" ]
|
||||||
|
then
|
||||||
|
footprint=20
|
||||||
|
elif [ "$footprint" = "medium" ]
|
||||||
|
then
|
||||||
|
footprint=35
|
||||||
|
elif [ "$footprint" = "high" ]
|
||||||
|
then
|
||||||
|
footprint=50
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Define the way the process manager handle child processes.
|
||||||
|
if [ "$usage" = "low" ]
|
||||||
|
then
|
||||||
|
php_pm=ondemand
|
||||||
|
elif [ "$usage" = "medium" ]
|
||||||
|
then
|
||||||
|
php_pm=dynamic
|
||||||
|
elif [ "$usage" = "high" ]
|
||||||
|
then
|
||||||
|
php_pm=static
|
||||||
|
else
|
||||||
|
ynh_die --message="Does not recognize '$usage' as an usage value."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the total of RAM available, except swap.
|
||||||
|
local max_ram=$(ynh_check_ram --no_swap)
|
||||||
|
|
||||||
|
less0() {
|
||||||
|
# Do not allow value below 1
|
||||||
|
if [ $1 -le 0 ]
|
||||||
|
then
|
||||||
|
echo 1
|
||||||
|
else
|
||||||
|
echo $1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define pm.max_children
|
||||||
|
# The value of pm.max_children is the total amount of ram divide by 2 and divide again by the footprint of a pool for this app.
|
||||||
|
# So if php-fpm start the maximum of children, it won't exceed half of the ram.
|
||||||
|
php_max_children=$(( $max_ram / 2 / $footprint ))
|
||||||
|
# If process manager is set as static, use half less children.
|
||||||
|
# Used as static, there's always as many children as the value of pm.max_children
|
||||||
|
if [ "$php_pm" = "static" ]
|
||||||
|
then
|
||||||
|
php_max_children=$(( $php_max_children / 2 ))
|
||||||
|
fi
|
||||||
|
php_max_children=$(less0 $php_max_children)
|
||||||
|
|
||||||
|
# To not overload the proc, limit the number of children to 4 times the number of cores.
|
||||||
|
local core_number=$(nproc)
|
||||||
|
local max_proc=$(( $core_number * 4 ))
|
||||||
|
if [ $php_max_children -gt $max_proc ]
|
||||||
|
then
|
||||||
|
php_max_children=$max_proc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$php_pm" = "dynamic" ]
|
||||||
|
then
|
||||||
|
# Define pm.start_servers, pm.min_spare_servers and pm.max_spare_servers for a dynamic process manager
|
||||||
|
php_min_spare_servers=$(( $php_max_children / 8 ))
|
||||||
|
php_min_spare_servers=$(less0 $php_min_spare_servers)
|
||||||
|
|
||||||
|
php_max_spare_servers=$(( $php_max_children / 2 ))
|
||||||
|
php_max_spare_servers=$(less0 $php_max_spare_servers)
|
||||||
|
|
||||||
|
php_start_servers=$(( $php_min_spare_servers + ( $php_max_spare_servers - $php_min_spare_servers ) /2 ))
|
||||||
|
php_start_servers=$(less0 $php_start_servers)
|
||||||
|
else
|
||||||
|
php_min_spare_servers=0
|
||||||
|
php_max_spare_servers=0
|
||||||
|
php_start_servers=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $print -eq 1 ]
|
||||||
|
then
|
||||||
|
ynh_debug --message="Footprint=${footprint}Mb by pool."
|
||||||
|
ynh_debug --message="Process manager=$php_pm"
|
||||||
|
ynh_debug --message="Max RAM=${max_ram}Mb"
|
||||||
|
if [ "$php_pm" != "static" ]; then
|
||||||
|
ynh_debug --message="\nMax estimated footprint=$(( $php_max_children * $footprint ))"
|
||||||
|
ynh_debug --message="Min estimated footprint=$(( $php_min_spare_servers * $footprint ))"
|
||||||
|
fi
|
||||||
|
if [ "$php_pm" = "dynamic" ]; then
|
||||||
|
ynh_debug --message="Estimated average footprint=$(( $php_max_spare_servers * $footprint ))"
|
||||||
|
elif [ "$php_pm" = "static" ]; then
|
||||||
|
ynh_debug --message="Estimated footprint=$(( $php_max_children * $footprint ))"
|
||||||
|
fi
|
||||||
|
ynh_debug --message="\nRaw php-fpm values:"
|
||||||
|
ynh_debug --message="pm.max_children = $php_max_children"
|
||||||
|
if [ "$php_pm" = "dynamic" ]; then
|
||||||
|
ynh_debug --message="pm.start_servers = $php_start_servers"
|
||||||
|
ynh_debug --message="pm.min_spare_servers = $php_min_spare_servers"
|
||||||
|
ynh_debug --message="pm.max_spare_servers = $php_max_spare_servers"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Execute a command as another user
|
||||||
|
# usage: exec_as USER COMMAND [ARG ...]
|
||||||
|
exec_as() {
|
||||||
|
local USER=$1
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
if [[ $USER = $(whoami) ]]; then
|
||||||
|
eval "$@"
|
||||||
|
else
|
||||||
|
sudo -u "$USER" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
94
scripts/actions/reset_default_app
Executable file
94
scripts/actions/reset_default_app
Executable file
|
@ -0,0 +1,94 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Load common variables for all scripts.
|
||||||
|
source scripts/_variables
|
||||||
|
|
||||||
|
source scripts/_common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity)
|
||||||
|
upgrade_level="$(ynh_app_setting_get --app=$app --key=upgrade_level)"
|
||||||
|
ynh_update=$(ynh_app_setting_get --app=$app --key=ynh_update)
|
||||||
|
unattended_mail="$(ynh_app_setting_get --app=$app --key=unattended_mail)"
|
||||||
|
previous_apticron=$(ynh_app_setting_get --app=$app --key=previous_apticron)
|
||||||
|
after_apticron=$(ynh_app_setting_get --app=$app --key=after_apticron)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC ACTION
|
||||||
|
#=================================================
|
||||||
|
# RESET APTICRON CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Resetting Apticron..."
|
||||||
|
|
||||||
|
apticron_config="/etc/apticron/apticron.conf"
|
||||||
|
cp "conf/apticron.conf.backup" "$apticron_config"
|
||||||
|
ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \
|
||||||
|
--replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config"
|
||||||
|
ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \
|
||||||
|
--replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESET UNATTENDED-UPGRADES CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Resetting unattended-upgrades..."
|
||||||
|
|
||||||
|
yunohost app action run $app reset_default_unattended
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESET APT PERIODIC CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Resetting apt periodic..."
|
||||||
|
|
||||||
|
yunohost app action run $app reset_default_periodic
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESET APTICRON CRON FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Resetting apticron cron file..."
|
||||||
|
|
||||||
|
apticron_cron="/etc/cron.d/apticron"
|
||||||
|
cp "conf/apticron.crond.backup" "$apticron_cron"
|
||||||
|
|
||||||
|
# Copy and comment the current cron
|
||||||
|
ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron"
|
||||||
|
# Modify the time to set at 20:00 every day
|
||||||
|
ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron"
|
||||||
|
# Copy the new cron and set the time to 2:00 every night
|
||||||
|
ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron"
|
||||||
|
|
||||||
|
if [ $previous_apticron -eq 0 ]
|
||||||
|
then
|
||||||
|
# Comment the first cron
|
||||||
|
ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $after_apticron -eq 0 ]
|
||||||
|
then
|
||||||
|
# Comment the second cron
|
||||||
|
ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Execution completed" --last
|
|
@ -9,16 +9,24 @@
|
||||||
source scripts/_common.sh
|
source scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RETRIEVE ARGUMENTS
|
# RETRIEVE ARGUMENTS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Retrieve arguments from the manifest" --weight=2
|
ynh_script_progression --message="Loading installation settings..." --weight=2
|
||||||
|
|
||||||
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
upgrade_level="$(ynh_app_setting_get $app upgrade_level)"
|
|
||||||
ynh_update="$(ynh_app_setting_get $app ynh_update)"
|
upgrade_level="$(ynh_app_setting_get --app=$app --key=upgrade_level)"
|
||||||
unattended_mail="$(ynh_app_setting_get $app unattended_mail)"
|
ynh_update=$(ynh_app_setting_get --app=$app --key=ynh_update)
|
||||||
unattended_verbosity="$(ynh_app_setting_get $app unattended_verbosity)"
|
unattended_mail="$(ynh_app_setting_get --app=$app --key=unattended_mail)"
|
||||||
|
unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SORT OUT THE CONFIG FILE TO HANDLE
|
# SORT OUT THE CONFIG FILE TO HANDLE
|
||||||
|
@ -37,71 +45,72 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESET THE CONFIG FILE
|
# RESET THE CONFIG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Reset the config file $config_file" --weight=9
|
ynh_script_progression --message="Resetting the config file $config_file..." --weight=9
|
||||||
|
|
||||||
# Verify the checksum and backup the file if it's different
|
# Verify the checksum and backup the file if it's different
|
||||||
ynh_backup_if_checksum_is_different "$config_file"
|
ynh_backup_if_checksum_is_different --file="$config_file"
|
||||||
|
|
||||||
|
# Reset the config /etc/apt/apt.conf.d/50unattended-upgrades
|
||||||
if [ "$file" = "50unattended-upgrades" ]
|
if [ "$file" = "50unattended-upgrades" ]
|
||||||
then
|
then
|
||||||
# Get the default file and overwrite the current config
|
# Get the default file and overwrite the current config
|
||||||
cp /etc/apt/50unattended-upgrades.backup "$config_file"
|
cp /etc/apt/50unattended-upgrades.backup "$config_file"
|
||||||
|
|
||||||
# Recreate the default config
|
# Recreate the default config
|
||||||
distro_codename=$(lsb_release -cs)
|
|
||||||
# Allow security update
|
# Allow security update
|
||||||
ynh_replace_string "//\(.*\"o=Debian,n=${distro_codename},l=Debian-Security\";\)" "\1" "$config_file"
|
ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release),l=Debian-Security\";\)" --replace_string="\1" --target_file="$config_file"
|
||||||
# Allow other updates
|
# Allow other updates
|
||||||
if [ "$upgrade_level" = "Security and updates" ]
|
if [ "$upgrade_level" = "Security and updates" ]
|
||||||
then
|
then
|
||||||
ynh_replace_string "//\(.*\"o=Debian,n=$distro_codename\";\)" "\1" "$config_file"
|
ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release)\";\)" --replace_string="\1" --target_file="$config_file"
|
||||||
ynh_replace_string "//\(.*\"o=Debian,n=$distro_codename-updates\";\)" "\1" "$config_file"
|
ynh_replace_string --match_string="//\(.*\"o=Debian,n=$(ynh_get_debian_release)-updates\";\)" --replace_string="\1" --target_file="$config_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add YunoHost upgrade source
|
# Add YunoHost upgrade source
|
||||||
if [ $ynh_update -eq 1 ]
|
if [ $ynh_update -eq 1 ]
|
||||||
then
|
then
|
||||||
ynh_replace_string "origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
|
ynh_replace_string --match_string="origin=Debian,codename=\$(ynh_get_debian_release),label=Debian-Security\";" \
|
||||||
"&\n\n //YunoHost upgrade\n \"o=YunoHost,n=$distro_codename\";" "$config_file"
|
--replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,n=$(ynh_get_debian_release)\";" --target_file="$config_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Allow MinimalSteps upgrading to reduce risk in case of reboot
|
# Allow MinimalSteps upgrading to reduce risk in case of reboot
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::MinimalSteps\).*" "\1 \"true\";" "$config_file"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$config_file"
|
||||||
|
|
||||||
# Configure Unattended Upgrades mailing
|
# Configure Unattended Upgrades mailing
|
||||||
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
||||||
then
|
then
|
||||||
# Allow mail to root
|
# Allow mail to root
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$config_file"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$config_file"
|
||||||
|
|
||||||
# Send mail even if there's no errors
|
# Send mail even if there's no errors
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"false\";" "$config_file"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$config_file"
|
||||||
|
|
||||||
elif [ "$unattended_mail" = "Only if there was an error" ]
|
elif [ "$unattended_mail" = "Only if there was an error" ]
|
||||||
then
|
then
|
||||||
# Allow mail to root
|
# Allow mail to root
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$config_file"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$config_file"
|
||||||
|
|
||||||
# Send mail only if there's an error
|
# Send mail only if there's an error
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"true\";" "$config_file"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$config_file"
|
||||||
|
|
||||||
else # "Never"
|
else # "Never"
|
||||||
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
|
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
|
||||||
ynh_replace_string "^\(Unattended-Upgrade::Mail \)" "//\1" "$config_file"
|
ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$config_file"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Reset the config /etc/apt/apt.conf.d/02periodic
|
||||||
if [ "$file" = "02periodic" ]
|
if [ "$file" = "02periodic" ]
|
||||||
then
|
then
|
||||||
# Get the default file and overwrite the current config
|
# Get the default file and overwrite the current config
|
||||||
cp /etc/yunohost/apps/$app/conf/02periodic "$config_file"
|
cp /etc/yunohost/apps/$app/conf/02periodic "$config_file"
|
||||||
|
|
||||||
# Recreate the default config
|
# Recreate the default config
|
||||||
ynh_replace_string "__VERBOSITY__" "$unattended_verbosity" "/etc/apt/apt.conf.d/02periodic"
|
ynh_replace_string --match_string="__VERBOSITY__" --replace_string="$unattended_verbosity" --target_file="/etc/apt/apt.conf.d/02periodic"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Calculate and store the config file checksum into the app settings
|
# Calculate and store the config file checksum into the app settings
|
||||||
ynh_store_file_checksum "$config_file"
|
ynh_store_file_checksum --file="$config_file"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -19,7 +19,7 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Load settings"
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
@ -28,35 +28,35 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP UNATTENDED-UPGRADES CONFIG
|
# BACKUP UNATTENDED-UPGRADES CONFIG
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Backup unattended-upgrades config"
|
ynh_script_progression --message="Backing up unattended-upgrades config..."
|
||||||
|
|
||||||
ynh_backup "/etc/apt/apt.conf.d/50unattended-upgrades"
|
ynh_backup --src_path="/etc/apt/apt.conf.d/50unattended-upgrades"
|
||||||
# Backup also the backup of the config file
|
# Backup also the backup of the config file
|
||||||
ynh_backup "/etc/apt/50unattended-upgrades.backup"
|
ynh_backup --src_path="/etc/apt/50unattended-upgrades.backup"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP APT PERIODIC
|
# BACKUP APT PERIODIC
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Backup APT periodic"
|
ynh_script_progression --message="Backing up APT periodic..."
|
||||||
|
|
||||||
ynh_backup "/etc/apt/apt.conf.d/02periodic"
|
ynh_backup --src_path="/etc/apt/apt.conf.d/02periodic"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP APTICRON CONFIG
|
# BACKUP APTICRON CONFIG
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Backup Apticron config"
|
ynh_script_progression --message="Backing up Apticron config..."
|
||||||
|
|
||||||
ynh_backup "/etc/apticron/apticron.conf"
|
ynh_backup --src_path="/etc/apticron/apticron.conf"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE CRON FILE
|
# BACKUP THE CRON FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Backup cron file"
|
ynh_script_progression --message="Backing up cron file..."
|
||||||
|
|
||||||
ynh_backup "/etc/cron.d/apticron"
|
ynh_backup --src_path="/etc/cron.d/apticron"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Backup completed" --last
|
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last
|
||||||
|
|
127
scripts/config
127
scripts/config
|
@ -13,9 +13,9 @@ source /usr/share/yunohost/helpers
|
||||||
# RETRIEVE ARGUMENTS
|
# RETRIEVE ARGUMENTS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC CODE
|
# SPECIFIC CODE
|
||||||
|
@ -29,43 +29,47 @@ final_path=$(ynh_app_setting_get $app final_path)
|
||||||
# Otherwise, keep the value from the app config.
|
# Otherwise, keep the value from the app config.
|
||||||
|
|
||||||
# upgrade_level
|
# upgrade_level
|
||||||
old_upgrade_level="$(ynh_app_setting_get $app upgrade_level)"
|
old_upgrade_level="$(ynh_app_setting_get --app=$app --key=upgrade_level)"
|
||||||
upgrade_level="${YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UPGRADE_LEVEL:-$old_upgrade_level}"
|
upgrade_level="${YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UPGRADE_LEVEL:-$old_upgrade_level}"
|
||||||
|
|
||||||
# ynh_update
|
# ynh_update
|
||||||
old_ynh_update="$(ynh_app_setting_get $app ynh_update)"
|
old_ynh_update="$(ynh_app_setting_get --app=$app --key=ynh_update)"
|
||||||
old_ynh_update=$(bool_to_true_false $old_ynh_update)
|
|
||||||
ynh_update="${YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_YNH_UPDATE:-$old_ynh_update}"
|
ynh_update="${YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_YNH_UPDATE:-$old_ynh_update}"
|
||||||
|
|
||||||
# unattended_mail
|
# unattended_mail
|
||||||
old_unattended_mail="$(ynh_app_setting_get $app unattended_mail)"
|
old_unattended_mail="$(ynh_app_setting_get --app=$app --key=unattended_mail)"
|
||||||
unattended_mail="${YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UNATTENDED_MAIL:-$old_unattended_mail}"
|
unattended_mail="${YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UNATTENDED_MAIL:-$old_unattended_mail}"
|
||||||
|
|
||||||
|
|
||||||
# previous_apticron
|
# previous_apticron
|
||||||
old_previous_apticron="$(ynh_app_setting_get $app previous_apticron)"
|
old_previous_apticron="$(ynh_app_setting_get --app=$app --key=previous_apticron)"
|
||||||
old_previous_apticron=$(bool_to_true_false $old_previous_apticron)
|
|
||||||
previous_apticron="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON:-$old_previous_apticron}"
|
previous_apticron="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON:-$old_previous_apticron}"
|
||||||
|
|
||||||
# previous_apticron_hour
|
# previous_apticron_hour
|
||||||
old_previous_apticron_hour="$(cat /etc/cron.d/apticron | grep --max-count=1 "^#*0.*root if.*" | cut -d' ' -f2)"
|
old_previous_apticron_hour="$(cat /etc/cron.d/apticron | grep --max-count=1 "^#*0.*root if.*" | cut -d' ' -f2)"
|
||||||
previous_apticron_hour="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON_HOUR:-$old_previous_apticron_hour}"
|
previous_apticron_hour="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON_HOUR:-$old_previous_apticron_hour}"
|
||||||
|
|
||||||
# after_apticron
|
# after_apticron
|
||||||
old_after_apticron="$(ynh_app_setting_get $app after_apticron)"
|
old_after_apticron="$(ynh_app_setting_get --app=$app --key=after_apticron)"
|
||||||
old_after_apticron=$(bool_to_true_false $old_after_apticron)
|
|
||||||
after_apticron="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON:-$old_after_apticron}"
|
after_apticron="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON:-$old_after_apticron}"
|
||||||
|
|
||||||
# after_apticron_hour
|
# after_apticron_hour
|
||||||
old_after_apticron_hour="$(tac /etc/cron.d/apticron | grep --max-count=1 "^#*0.*root if.*" | cut -d' ' -f2)"
|
old_after_apticron_hour="$(tac /etc/cron.d/apticron | grep --max-count=1 "^#*0.*root if.*" | cut -d' ' -f2)"
|
||||||
after_apticron_hour="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON_HOUR:-$old_after_apticron_hour}"
|
after_apticron_hour="${YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON_HOUR:-$old_after_apticron_hour}"
|
||||||
|
|
||||||
|
|
||||||
# unattended_verbosity
|
# unattended_verbosity
|
||||||
old_unattended_verbosity="$(ynh_app_setting_get $app unattended_verbosity)"
|
old_unattended_verbosity="$(ynh_app_setting_get --app=$app --key=unattended_verbosity)"
|
||||||
unattended_verbosity="${YNH_CONFIG_MAIN_PERIODIC_CONFIGURATION_UNATTENDED_VERBOSITY:-$old_unattended_verbosity}"
|
unattended_verbosity="${YNH_CONFIG_MAIN_PERIODIC_CONFIGURATION_UNATTENDED_VERBOSITY:-$old_unattended_verbosity}"
|
||||||
|
|
||||||
|
|
||||||
# Overwrite 02periodic config file
|
# Overwrite 02periodic config file
|
||||||
old_overwrite_periodic="$(ynh_app_setting_get $app overwrite_periodic)"
|
old_overwrite_periodic="$(ynh_app_setting_get --app=$app --key=overwrite_periodic)"
|
||||||
old_overwrite_periodic=$(bool_to_true_false $old_overwrite_periodic)
|
|
||||||
overwrite_periodic="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PERIODIC:-$old_overwrite_periodic}"
|
overwrite_periodic="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PERIODIC:-$old_overwrite_periodic}"
|
||||||
|
|
||||||
|
|
||||||
# Type of admin mail configuration
|
# Type of admin mail configuration
|
||||||
old_admin_mail_html="$(ynh_app_setting_get $app admin_mail_html)"
|
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}"
|
admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -74,22 +78,22 @@ admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_htm
|
||||||
|
|
||||||
show_config() {
|
show_config() {
|
||||||
# here you are supposed to read some config file/database/other then print the values
|
# here you are supposed to read some config file/database/other then print the values
|
||||||
# echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
|
# ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
|
||||||
|
|
||||||
echo "YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UPGRADE_LEVEL=$upgrade_level"
|
ynh_return "YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UPGRADE_LEVEL=$upgrade_level"
|
||||||
echo "YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_YNH_UPDATE=$ynh_update"
|
ynh_return "YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_YNH_UPDATE=$ynh_update"
|
||||||
echo "YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UNATTENDED_MAIL=$unattended_mail"
|
ynh_return "YNH_CONFIG_MAIN_UNATTENDED_CONFIGURATION_UNATTENDED_MAIL=$unattended_mail"
|
||||||
|
|
||||||
echo "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON=$previous_apticron"
|
ynh_return "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON=$previous_apticron"
|
||||||
echo "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON_HOUR=$previous_apticron_hour"
|
ynh_return "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_PREVIOUS_APTICRON_HOUR=$previous_apticron_hour"
|
||||||
echo "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON=$after_apticron"
|
ynh_return "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON=$after_apticron"
|
||||||
echo "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON_HOUR=$after_apticron_hour"
|
ynh_return "YNH_CONFIG_MAIN_APTICRON_CONFIGURATION_AFTER_APTICRON_HOUR=$after_apticron_hour"
|
||||||
|
|
||||||
echo "YNH_CONFIG_MAIN_PERIODIC_CONFIGURATION_UNATTENDED_VERBOSITY=$unattended_verbosity"
|
ynh_return "YNH_CONFIG_MAIN_PERIODIC_CONFIGURATION_UNATTENDED_VERBOSITY=$unattended_verbosity"
|
||||||
|
|
||||||
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PERIODIC=$overwrite_periodic"
|
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PERIODIC=$overwrite_periodic"
|
||||||
|
|
||||||
echo "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
|
ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -97,7 +101,11 @@ show_config() {
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
apply_config() {
|
apply_config() {
|
||||||
# Change configuration if needed
|
|
||||||
|
#=================================================
|
||||||
|
# MODIFY 50UNATTENDED-UPGRADES CONFIG
|
||||||
|
#=================================================
|
||||||
|
|
||||||
unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades"
|
unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades"
|
||||||
# upgrade_level
|
# upgrade_level
|
||||||
if [ "$upgrade_level" != "$old_upgrade_level" ]
|
if [ "$upgrade_level" != "$old_upgrade_level" ]
|
||||||
|
@ -105,30 +113,29 @@ apply_config() {
|
||||||
if [ "$upgrade_level" = "Security and updates" ]
|
if [ "$upgrade_level" = "Security and updates" ]
|
||||||
then
|
then
|
||||||
# Uncomment lines in the config
|
# Uncomment lines in the config
|
||||||
ynh_replace_string "//\( *\"o=Debian,a=stable\)" " \1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\( *\"o=Debian,a=stable\)" --replace_string=" \1" --target_file="$unattended_upgrades_config"
|
||||||
ynh_replace_string "//\( *\"o=Debian,a=stable-updates\)" " \1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\( *\"o=Debian,a=stable-updates\)" --replace_string=" \1" --target_file="$unattended_upgrades_config"
|
||||||
else
|
else
|
||||||
# Comment lines in the config
|
# Comment lines in the config
|
||||||
ynh_replace_string "^ \( *\"o=Debian,a=stable\)" "//\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="^ \( *\"o=Debian,a=stable\)" --replace_string="//\1" --target_file="$unattended_upgrades_config"
|
||||||
ynh_replace_string "^ \( *\"o=Debian,a=stable-updates\)" "//\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="^ \( *\"o=Debian,a=stable-updates\)" --replace_string="//\1" --target_file="$unattended_upgrades_config"
|
||||||
fi
|
fi
|
||||||
ynh_app_setting_set $app upgrade_level "$upgrade_level"
|
ynh_app_setting_set --app=$app --key=upgrade_level --value="$upgrade_level"
|
||||||
fi
|
fi
|
||||||
# ynh_update
|
# ynh_update
|
||||||
if [ "$ynh_update" != "$old_ynh_update" ]
|
if [ "$ynh_update" != "$old_ynh_update" ]
|
||||||
then
|
then
|
||||||
ynh_update=$(bool_to_01 $ynh_update)
|
|
||||||
if [ "$ynh_update" -eq 1 ]
|
if [ "$ynh_update" -eq 1 ]
|
||||||
then
|
then
|
||||||
# Add YunoHost upgrade source
|
# Add YunoHost upgrade source
|
||||||
ynh_replace_string "origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
|
ynh_replace_string --match_string="origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
|
||||||
"&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" "$unattended_upgrades_config"
|
--replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" --target_file="$unattended_upgrades_config"
|
||||||
else
|
else
|
||||||
# Remove lines about YunoHost
|
# Remove lines about YunoHost
|
||||||
sed --in-place '/YunoHost upgrade/d' "$unattended_upgrades_config"
|
sed --in-place '/YunoHost upgrade/d' "$unattended_upgrades_config"
|
||||||
sed --in-place '/o=YunoHost/d' "$unattended_upgrades_config"
|
sed --in-place '/o=YunoHost/d' "$unattended_upgrades_config"
|
||||||
fi
|
fi
|
||||||
ynh_app_setting_set $app ynh_update "$ynh_update"
|
ynh_app_setting_set --app=$app --key=ynh_update --value="$ynh_update"
|
||||||
fi
|
fi
|
||||||
# unattended_mail
|
# unattended_mail
|
||||||
if [ "$unattended_mail" != "$old_unattended_mail" ]
|
if [ "$unattended_mail" != "$old_unattended_mail" ]
|
||||||
|
@ -136,88 +143,84 @@ apply_config() {
|
||||||
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
||||||
then
|
then
|
||||||
# Allow mail to root
|
# Allow mail to root
|
||||||
ynh_replace_string "/*\(Unattended-Upgrade::Mail \)" "\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="/*\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
# Send mail even if there's no errors
|
# Send mail even if there's no errors
|
||||||
ynh_replace_string "/*\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"false\";" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="/*\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
elif [ "$unattended_mail" = "Only if there was an error" ]
|
elif [ "$unattended_mail" = "Only if there was an error" ]
|
||||||
then
|
then
|
||||||
# Allow mail to root
|
# Allow mail to root
|
||||||
ynh_replace_string "/*\(Unattended-Upgrade::Mail \)" "\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="/*\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
# Send mail only if there's an error
|
# Send mail only if there's an error
|
||||||
ynh_replace_string "/*\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"true\";" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="/*\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
else # "Never"
|
else # "Never"
|
||||||
# Comment "Unattended-Upgrade::Mail"
|
# Comment "Unattended-Upgrade::Mail"
|
||||||
ynh_replace_string "^\(Unattended-Upgrade::Mail \)" "//\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config"
|
||||||
fi
|
fi
|
||||||
ynh_app_setting_set $app unattended_mail "$unattended_mail"
|
ynh_app_setting_set --app=$app --key=unattended_mail --value="$unattended_mail"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# previous_apticron
|
# previous_apticron
|
||||||
apticron_cron="/etc/cron.d/apticron"
|
apticron_cron="/etc/cron.d/apticron"
|
||||||
if [ "$previous_apticron" != "$old_previous_apticron" ]
|
if [ "$previous_apticron" != "$old_previous_apticron" ]
|
||||||
then
|
then
|
||||||
previous_apticron=$(bool_to_01 $previous_apticron)
|
|
||||||
if [ "$previous_apticron" = "1" ]
|
if [ "$previous_apticron" = "1" ]
|
||||||
then
|
then
|
||||||
# Uncomment the first cron line
|
# Uncomment the first cron line
|
||||||
ynh_replace_string "^#\(0 $old_previous_apticron_hour .*\)" "\1" "$apticron_cron"
|
ynh_replace_string --match_string="^#\(0 $old_previous_apticron_hour .*\)" --replace_string="\1" --target_file="$apticron_cron"
|
||||||
else
|
else
|
||||||
# Comment the first cron line
|
# Comment the first cron line
|
||||||
ynh_replace_string "^0 $old_previous_apticron_hour .*" "#&" "$apticron_cron"
|
ynh_replace_string --match_string="^0 $old_previous_apticron_hour .*" --replace_string="#&" --target_file="$apticron_cron"
|
||||||
fi
|
fi
|
||||||
ynh_app_setting_set $app previous_apticron "$previous_apticron"
|
ynh_app_setting_set --app=$app --key=previous_apticron --value="$previous_apticron"
|
||||||
fi
|
fi
|
||||||
# previous_apticron_hour
|
# previous_apticron_hour
|
||||||
if [ "$previous_apticron_hour" != "$old_previous_apticron_hour" ]
|
if [ "$previous_apticron_hour" != "$old_previous_apticron_hour" ]
|
||||||
then
|
then
|
||||||
# Use sed instead of ynh_replace_string to avoid the 'global' argument
|
# Use sed instead of ynh_replace_string to avoid the 'global' argument
|
||||||
sed --in-place "s/0 $old_previous_apticron_hour\( \* \* \* root if\)/0 $previous_apticron_hour\1/" "$apticron_cron"
|
sed --in-place "s/0 $old_previous_apticron_hour\( \* \* \* root if\)/0 $previous_apticron_hour\1/" "$apticron_cron"
|
||||||
ynh_app_setting_set $app previous_apticron_hour "$previous_apticron_hour"
|
ynh_app_setting_set --app=$app --key=previous_apticron_hour --value="$previous_apticron_hour"
|
||||||
fi
|
fi
|
||||||
# after_apticron
|
# after_apticron
|
||||||
if [ "$after_apticron" != "$old_after_apticron" ]
|
if [ "$after_apticron" != "$old_after_apticron" ]
|
||||||
then
|
then
|
||||||
after_apticron=$(bool_to_01 $after_apticron)
|
|
||||||
if [ "$after_apticron" = "1" ]
|
if [ "$after_apticron" = "1" ]
|
||||||
then
|
then
|
||||||
# Uncomment the second cron line
|
# Uncomment the second cron line
|
||||||
ynh_replace_string "^#\(0 $old_after_apticron_hour .*\)" "\1" "$apticron_cron"
|
ynh_replace_string --match_string="^#\(0 $old_after_apticron_hour .*\)" --replace_string="\1" --target_file="$apticron_cron"
|
||||||
else
|
else
|
||||||
# Comment the second cron line
|
# Comment the second cron line
|
||||||
ynh_replace_string "^0 $old_after_apticron_hour .*" "#&" "$apticron_cron"
|
ynh_replace_string --match_string="^0 $old_after_apticron_hour .*" --replace_string="#&" --target_file="$apticron_cron"
|
||||||
fi
|
fi
|
||||||
ynh_app_setting_set $app after_apticron "$after_apticron"
|
ynh_app_setting_set --app=$app --key=after_apticron --value="$after_apticron"
|
||||||
fi
|
fi
|
||||||
# after_apticron_hour
|
# after_apticron_hour
|
||||||
if [ "$after_apticron_hour" != "$old_after_apticron_hour" ]
|
if [ "$after_apticron_hour" != "$old_after_apticron_hour" ]
|
||||||
then
|
then
|
||||||
# Use sed instead of ynh_replace_string to avoid the 'global' argument
|
# Use sed instead of ynh_replace_string to avoid the 'global' argument
|
||||||
sed --in-place "s/0 $old_after_apticron_hour\( \* \* \* root if\)/0 $after_apticron_hour\1/" "$apticron_cron"
|
sed --in-place "s/0 $old_after_apticron_hour\( \* \* \* root if\)/0 $after_apticron_hour\1/" "$apticron_cron"
|
||||||
ynh_app_setting_set $app after_apticron_hour "$after_apticron_hour"
|
ynh_app_setting_set --app=$app --key=after_apticron_hour --value="$after_apticron_hour"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# unattended_verbosity
|
# unattended_verbosity
|
||||||
if [ "$unattended_verbosity" != "$old_unattended_verbosity" ]
|
if [ "$unattended_verbosity" != "$old_unattended_verbosity" ]
|
||||||
then
|
then
|
||||||
ynh_backup_if_checksum_is_different "/etc/apt/apt.conf.d/02periodic"
|
ynh_backup_if_checksum_is_different --file="/etc/apt/apt.conf.d/02periodic"
|
||||||
|
|
||||||
ynh_replace_string "^APT::Periodic::Verbose \".*" "APT::Periodic::Verbose \"$unattended_verbosity\";" "/etc/apt/apt.conf.d/02periodic"
|
ynh_replace_string --match_string="^APT::Periodic::Verbose \".*" --replace_string="APT::Periodic::Verbose \"$unattended_verbosity\";" --target_file="/etc/apt/apt.conf.d/02periodic"
|
||||||
ynh_app_setting_set $app unattended_verbosity "$unattended_verbosity"
|
ynh_app_setting_set --app=$app --key=unattended_verbosity --value="$unattended_verbosity"
|
||||||
|
|
||||||
ynh_store_file_checksum "/etc/apt/apt.conf.d/02periodic"
|
ynh_store_file_checksum --file="/etc/apt/apt.conf.d/02periodic"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set overwrite_periodic
|
# Set overwrite_periodic
|
||||||
overwrite_periodic=$(bool_to_01 $overwrite_periodic)
|
ynh_app_setting_set --app=$app --key=overwrite_periodic --value="$overwrite_periodic"
|
||||||
ynh_app_setting_set $app overwrite_periodic "$overwrite_periodic"
|
|
||||||
|
|
||||||
# Set admin_mail_html
|
# 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"
|
||||||
ynh_app_setting_set $app admin_mail_html "$admin_mail_html"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -227,6 +230,6 @@ apply_config() {
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
show) show_config;;
|
show) show_config;;
|
||||||
apply) apply_config;;
|
apply) apply_config;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
# Load common variables for all scripts.
|
# Load common variables for all scripts.
|
||||||
source _variables
|
source _variables
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE FAILURE OF THE SCRIPT
|
# MANAGE FAILURE OF THE SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -21,38 +22,37 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Retrieve arguments from the manifest"
|
|
||||||
|
|
||||||
upgrade_level="$YNH_APP_ARG_UPGRADE_LEVEL"
|
upgrade_level="$YNH_APP_ARG_UPGRADE_LEVEL"
|
||||||
ynh_update="$YNH_APP_ARG_YNH_UPDATE"
|
ynh_update=$YNH_APP_ARG_YNH_UPDATE
|
||||||
previous_apticron="$YNH_APP_ARG_PREVIOUS_APTICRON"
|
previous_apticron=$YNH_APP_ARG_PREVIOUS_APTICRON
|
||||||
after_apticron="$YNH_APP_ARG_AFTER_APTICRON"
|
after_apticron=$YNH_APP_ARG_AFTER_APTICRON
|
||||||
unattended_mail="$YNH_APP_ARG_UNATTENDED_MAIL"
|
unattended_mail="$YNH_APP_ARG_UNATTENDED_MAIL"
|
||||||
unattended_verbosity="$YNH_APP_ARG_UNATTENDED_VERBOSITY"
|
unattended_verbosity=$YNH_APP_ARG_UNATTENDED_VERBOSITY
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STORE SETTINGS FROM MANIFEST
|
# STORE SETTINGS FROM MANIFEST
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Store settings from manifest" --weight=3
|
ynh_script_progression --message="Storing installation settings..." --weight=3
|
||||||
|
|
||||||
ynh_app_setting_set $app upgrade_level "$upgrade_level"
|
ynh_app_setting_set --app=$app --key=upgrade_level --value="$upgrade_level"
|
||||||
ynh_app_setting_set $app ynh_update $ynh_update
|
ynh_app_setting_set --app=$app --key=ynh_update --value=$ynh_update
|
||||||
ynh_app_setting_set $app previous_apticron $previous_apticron
|
ynh_app_setting_set --app=$app --key=previous_apticron --value=$previous_apticron
|
||||||
ynh_app_setting_set $app after_apticron $after_apticron
|
ynh_app_setting_set --app=$app --key=after_apticron --value=$after_apticron
|
||||||
ynh_app_setting_set $app unattended_mail "$unattended_mail"
|
ynh_app_setting_set --app=$app --key=unattended_mail --value="$unattended_mail"
|
||||||
ynh_app_setting_set $app unattended_verbosity $unattended_verbosity
|
ynh_app_setting_set --app=$app --key=unattended_verbosity --value=$unattended_verbosity
|
||||||
|
|
||||||
ynh_app_setting_set $app overwrite_periodic "1"
|
ynh_app_setting_set --app=$app --key=overwrite_periodic --value=1
|
||||||
ynh_app_setting_set $app admin_mail_html "1"
|
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD MODIFICATIONS
|
# STANDARD MODIFICATIONS
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Install dependencies" --weight=10
|
ynh_script_progression --message="Installing dependencies..." --weight=10
|
||||||
|
|
||||||
ynh_install_app_dependencies $app_depencencies
|
ynh_install_app_dependencies $app_depencencies
|
||||||
|
|
||||||
|
@ -61,62 +61,70 @@ ynh_install_app_dependencies $app_depencencies
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURE APTICRON
|
# CONFIGURE APTICRON
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configure Apticron"
|
ynh_script_progression --message="Configuring Apticron..."
|
||||||
|
|
||||||
apticron_config="/etc/apticron/apticron.conf"
|
apticron_config="/etc/apticron/apticron.conf"
|
||||||
ynh_replace_string "# CUSTOM_SUBJECT=.*" \
|
# If the config file doesn't exist, copy the model
|
||||||
"&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" "$apticron_config"
|
if [ ! -e "$apticron_config" ]
|
||||||
ynh_replace_string "# CUSTOM_NO_UPDATES_SUBJECT=.*" \
|
then
|
||||||
"&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" "$apticron_config"
|
cp "/usr/lib/apticron/apticron.conf" "$apticron_config"
|
||||||
|
fi
|
||||||
|
# Create a backup of the config file for the reset action
|
||||||
|
cp "$apticron_config" "/etc/yunohost/apps/$app/conf/apticron.conf.backup"
|
||||||
|
|
||||||
|
ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \
|
||||||
|
--replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config"
|
||||||
|
ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \
|
||||||
|
--replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURE UNATTENDED-UPGRADES
|
# CONFIGURE UNATTENDED-UPGRADES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configure Unattended-Upgrades"
|
ynh_script_progression --message="Configuring Unattended-Upgrades..."
|
||||||
|
|
||||||
unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades"
|
unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades"
|
||||||
|
|
||||||
# Make a backup of 50unattended-upgrades
|
# Make a backup of 50unattended-upgrades
|
||||||
cp -a "$unattended_upgrades_config" "/etc/apt/50unattended-upgrades.backup"
|
cp "$unattended_upgrades_config" "/etc/apt/50unattended-upgrades.backup"
|
||||||
|
|
||||||
# Configure upgrade sources
|
# Configure upgrade sources
|
||||||
# Allow other updates
|
# Allow other updates
|
||||||
if [ "$upgrade_level" = "Security and updates" ]
|
if [ "$upgrade_level" = "Security and updates" ]
|
||||||
then
|
then
|
||||||
ynh_replace_string "//\(.*\"o=Debian,a=stable\)" "\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable\)" --replace_string="\1" --target_file="$unattended_upgrades_config"
|
||||||
ynh_replace_string "//\(.*\"o=Debian,a=stable-updates\)" "\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable-updates\)" --replace_string="\1" --target_file="$unattended_upgrades_config"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add YunoHost upgrade source
|
# Add YunoHost upgrade source
|
||||||
if [ $ynh_update -eq 1 ]
|
if [ $ynh_update -eq 1 ]
|
||||||
then
|
then
|
||||||
ynh_replace_string "origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
|
ynh_replace_string --match_string="origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
|
||||||
"&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" "$unattended_upgrades_config"
|
--replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" --target_file="$unattended_upgrades_config"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Allow MinimalSteps upgrading to reduce risk in case of reboot
|
# Allow MinimalSteps upgrading to reduce risk in case of reboot
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::MinimalSteps\).*" "\1 \"true\";" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
# Configure Unattended Upgrades mailing
|
# Configure Unattended Upgrades mailing
|
||||||
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
if [ "$unattended_mail" = "If an upgrade has been done" ]
|
||||||
then
|
then
|
||||||
# Allow mail to root
|
# Allow mail to root
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
# Send mail even if there's no errors
|
# Send mail even if there's no errors
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"false\";" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
elif [ "$unattended_mail" = "Only if there was an error" ]
|
elif [ "$unattended_mail" = "Only if there was an error" ]
|
||||||
then
|
then
|
||||||
# Allow mail to root
|
# Allow mail to root
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::Mail \)" "\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
# Send mail only if there's an error
|
# Send mail only if there's an error
|
||||||
ynh_replace_string "//\(Unattended-Upgrade::MailOnlyOnError \).*" "\1\"true\";" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config"
|
||||||
|
|
||||||
else # "Never"
|
else # "Never"
|
||||||
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
|
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
|
||||||
ynh_replace_string "^\(Unattended-Upgrade::Mail \)" "//\1" "$unattended_upgrades_config"
|
ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -125,7 +133,7 @@ fi
|
||||||
ynh_script_progression --message="Configure APT Periodic for Unattended" --weight=2
|
ynh_script_progression --message="Configure APT Periodic for Unattended" --weight=2
|
||||||
|
|
||||||
cp "../conf/02periodic" "/etc/apt/apt.conf.d/02periodic"
|
cp "../conf/02periodic" "/etc/apt/apt.conf.d/02periodic"
|
||||||
ynh_replace_string "__VERBOSITY__" "$unattended_verbosity" "/etc/apt/apt.conf.d/02periodic"
|
ynh_replace_string --match_string="__VERBOSITY__" --replace_string="$unattended_verbosity" --target_file="/etc/apt/apt.conf.d/02periodic"
|
||||||
# This config file is used by /etc/cron.daily/apt
|
# This config file is used by /etc/cron.daily/apt
|
||||||
|
|
||||||
ynh_store_file_checksum "/etc/apt/apt.conf.d/02periodic"
|
ynh_store_file_checksum "/etc/apt/apt.conf.d/02periodic"
|
||||||
|
@ -136,23 +144,26 @@ ynh_store_file_checksum "/etc/apt/apt.conf.d/02periodic"
|
||||||
ynh_script_progression --message="Modify original Apticron cron file" --weight=3
|
ynh_script_progression --message="Modify original Apticron cron file" --weight=3
|
||||||
|
|
||||||
apticron_cron="/etc/cron.d/apticron"
|
apticron_cron="/etc/cron.d/apticron"
|
||||||
|
# Create a backup of the cron file for the reset action
|
||||||
|
cp "$apticron_cron" "/etc/yunohost/apps/$app/conf/apticron.crond.backup"
|
||||||
|
|
||||||
# Copy and comment the current cron
|
# Copy and comment the current cron
|
||||||
ynh_replace_string "^.* root if.*" "#&\n&" "$apticron_cron"
|
ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron"
|
||||||
# Modify the time to set at 20:00 every day
|
# Modify the time to set at 20:00 every day
|
||||||
ynh_replace_string "^[[:digit:]].*\( root if.*\)" "0 20 * * *\1" "$apticron_cron"
|
ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron"
|
||||||
# Copy the new cron and set the time to 2:00 every night
|
# Copy the new cron and set the time to 2:00 every night
|
||||||
ynh_replace_string "^0 20\(.*\)" "&\n0 2\1" "$apticron_cron"
|
ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron"
|
||||||
|
|
||||||
if [ $previous_apticron -eq 0 ]
|
if [ $previous_apticron -eq 0 ]
|
||||||
then
|
then
|
||||||
# Comment the first cron
|
# Comment the first cron
|
||||||
ynh_replace_string "^0 20 .*" "#&" "$apticron_cron"
|
ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $after_apticron -eq 0 ]
|
if [ $after_apticron -eq 0 ]
|
||||||
then
|
then
|
||||||
# Comment the second cron
|
# Comment the second cron
|
||||||
ynh_replace_string "^0 2 .*" "#&" "$apticron_cron"
|
ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -176,10 +187,10 @@ You can also find some specific actions for this app by using the experimental _
|
||||||
|
|
||||||
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/unattended_upgrades_ynh__URL_TAG3__." > mail_to_send
|
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/unattended_upgrades_ynh__URL_TAG3__." > mail_to_send
|
||||||
|
|
||||||
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="install"
|
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=install
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Installation completed" --last
|
ynh_script_progression --message="Installation of $app completed" --last
|
||||||
|
|
|
@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Load settings"
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE DEPENDENCIES
|
# REMOVE DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Remove dependencies" --weight=5
|
ynh_script_progression --message="Removing dependencies..." --weight=5
|
||||||
|
|
||||||
ynh_remove_app_dependencies
|
ynh_remove_app_dependencies
|
||||||
|
|
||||||
|
@ -30,14 +30,14 @@ ynh_remove_app_dependencies
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE THE APT PERIODIC FILE
|
# REMOVE THE APT PERIODIC FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Remove the APT Periodic file"
|
ynh_script_progression --message="Removing the APT Periodic file..."
|
||||||
|
|
||||||
ynh_secure_remove "/etc/apt/apt.conf.d/02periodic"
|
ynh_secure_remove "/etc/apt/apt.conf.d/02periodic"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DECONFIGURE UNATTENDED-UPGRADES
|
# DECONFIGURE UNATTENDED-UPGRADES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Deconfigure unattended-upgrades"
|
ynh_script_progression --message="Deconfiguring unattended-upgrades..."
|
||||||
|
|
||||||
mv "/etc/apt/50unattended-upgrades.backup" "/etc/apt/apt.conf.d/50unattended-upgrades"
|
mv "/etc/apt/50unattended-upgrades.backup" "/etc/apt/apt.conf.d/50unattended-upgrades"
|
||||||
|
|
||||||
|
@ -45,4 +45,4 @@ mv "/etc/apt/50unattended-upgrades.backup" "/etc/apt/apt.conf.d/50unattended-upg
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Deletion completed" --last
|
ynh_script_progression --message="Removal of $app completed" --last
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source ../settings/scripts/_common.sh
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
# Load common variables for all scripts.
|
# Load common variables for all scripts.
|
||||||
source ../settings/scripts/_variables
|
source ../settings/scripts/_variables
|
||||||
|
|
||||||
|
source ../settings/scripts/_common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -21,7 +22,7 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Load settings"
|
ynh_script_progression --message="Loading settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
#=================================================
|
#=================================================
|
||||||
# REINSTALL DEPENDENCIES
|
# REINSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Reinstall dependencies" --weight=10
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=10
|
||||||
|
|
||||||
ynh_install_app_dependencies $app_depencencies
|
ynh_install_app_dependencies $app_depencencies
|
||||||
|
|
||||||
|
@ -38,27 +39,27 @@ ynh_install_app_dependencies $app_depencencies
|
||||||
# RESTORE UNATTENDED-UPGRADES CONFIG
|
# RESTORE UNATTENDED-UPGRADES CONFIG
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_restore_file "/etc/apt/apt.conf.d/50unattended-upgrades"
|
ynh_restore_file --origin_path="/etc/apt/apt.conf.d/50unattended-upgrades"
|
||||||
# Restore also the backup config file
|
# Restore also the backup config file
|
||||||
ynh_restore_file "/etc/apt/50unattended-upgrades.backup"
|
ynh_restore_file --origin_path="/etc/apt/50unattended-upgrades.backup"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE APT PERIODIC
|
# RESTORE APT PERIODIC
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_restore_file "/etc/apt/apt.conf.d/02periodic"
|
ynh_restore_file --origin_path="/etc/apt/apt.conf.d/02periodic"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE APTICRON CONFIG
|
# RESTORE APTICRON CONFIG
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_restore_file "/etc/apticron/apticron.conf"
|
ynh_restore_file --origin_path="/etc/apticron/apticron.conf"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE CRON FILE
|
# RESTORE CRON FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_restore_file "/etc/cron.d/apticron"
|
ynh_restore_file --origin_path="/etc/cron.d/apticron"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALISATION
|
# GENERIC FINALISATION
|
||||||
|
@ -81,10 +82,10 @@ You can also find some specific actions for this app by using the experimental _
|
||||||
|
|
||||||
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/unattended_upgrades_ynh__URL_TAG3__." > mail_to_send
|
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/unattended_upgrades_ynh__URL_TAG3__." > mail_to_send
|
||||||
|
|
||||||
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="restore"
|
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=restore
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Restoration completed" --last
|
ynh_script_progression --message="Restoration completed for $app" --last
|
||||||
|
|
|
@ -6,20 +6,21 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
# Load common variables for all scripts.
|
# Load common variables for all scripts.
|
||||||
source _variables
|
source _variables
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Load settings"
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
unattended_verbosity=$(ynh_app_setting_get $app unattended_verbosity)
|
unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity)
|
||||||
overwrite_periodic=$(ynh_app_setting_get $app overwrite_periodic)
|
overwrite_periodic=$(ynh_app_setting_get --app=$app --key=overwrite_periodic)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK VERSION
|
# CHECK VERSION
|
||||||
|
@ -30,18 +31,40 @@ upgrade_type=$(ynh_check_app_version_changed)
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENSURE DOWNWARD COMPATIBILITY
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Ensure downward compatibility"
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
||||||
|
|
||||||
# If overwrite_periodic doesn't exist, create it
|
# If overwrite_periodic doesn't exist, create it
|
||||||
if [ -z "$overwrite_periodic" ]; then
|
if [ -z "$overwrite_periodic" ]; then
|
||||||
overwrite_periodic=1
|
overwrite_periodic=1
|
||||||
ynh_app_setting_set $app overwrite_periodic $overwrite_periodic
|
ynh_app_setting_set --app=$app --key=overwrite_periodic --value=$overwrite_periodic
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If admin_mail_html doesn't exist, create it
|
||||||
|
if [ -z "$admin_mail_html" ]; then
|
||||||
|
admin_mail_html=1
|
||||||
|
ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make a non perfect backup for apticron.conf if non existent
|
||||||
|
if [ ! -e "../conf/apticron.conf.backup" ]; then
|
||||||
|
# Create a backup of the config file for the reset action
|
||||||
|
cp "/etc/apticron/apticron.conf" "../conf/apticron.conf.backup"
|
||||||
|
sed --in-place '/^CUSTOM_SUBJECT=/d' "../conf/apticron.conf.backup"
|
||||||
|
sed --in-place '/^CUSTOM_NO_UPDATES_SUBJECT=/d' "../conf/apticron.conf.backup"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make a non perfect backup for apticron cron file if non existent
|
||||||
|
if [ ! -e "../conf/apticron.crond.backup" ]; then
|
||||||
|
# Create a backup of the config file for the reset action
|
||||||
|
cp "/etc/cron.d/apticron" "../conf/apticron.crond.backup"
|
||||||
|
sed --in-place '/^[[:digit:]]/d' "../conf/apticron.crond.backup"
|
||||||
|
ynh_replace_string --match_string="^#\([[:digit:]].*\)" --replace_string="\1" --target_file="../conf/apticron.crond.backup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Backup the app before upgrading" --weight=3
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
|
||||||
|
|
||||||
# Backup the current version of the app
|
# Backup the current version of the app
|
||||||
ynh_backup_before_upgrade
|
ynh_backup_before_upgrade
|
||||||
|
@ -57,7 +80,7 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Upgrade dependencies" --weight=5
|
ynh_script_progression --message="Upgrading dependencies..." --weight=5
|
||||||
|
|
||||||
ynh_install_app_dependencies $app_depencencies
|
ynh_install_app_dependencies $app_depencencies
|
||||||
|
|
||||||
|
@ -82,14 +105,14 @@ ynh_install_app_dependencies $app_depencencies
|
||||||
# Overwrite 02periodic config file only if it's allowed
|
# Overwrite 02periodic config file only if it's allowed
|
||||||
if [ $overwrite_periodic -eq 1 ]
|
if [ $overwrite_periodic -eq 1 ]
|
||||||
then
|
then
|
||||||
ynh_script_progression --message="Upgrade APT Periodic for Unattended" --weight=3
|
ynh_script_progression --message="Upgrading APT Periodic for Unattended..." --weight=3
|
||||||
ynh_backup_if_checksum_is_different "/etc/apt/apt.conf.d/02periodic"
|
ynh_backup_if_checksum_is_different --file="/etc/apt/apt.conf.d/02periodic"
|
||||||
|
|
||||||
cp "../conf/02periodic" "/etc/apt/apt.conf.d/02periodic"
|
cp "../conf/02periodic" "/etc/apt/apt.conf.d/02periodic"
|
||||||
ynh_replace_string "__VERBOSITY__" "$unattended_verbosity" "/etc/apt/apt.conf.d/02periodic"
|
ynh_replace_string --match_string="__VERBOSITY__" --replace_string="$unattended_verbosity" --target_file="/etc/apt/apt.conf.d/02periodic"
|
||||||
# This config file is used by /etc/cron.daily/apt
|
# This config file is used by /etc/cron.daily/apt
|
||||||
|
|
||||||
ynh_store_file_checksum "/etc/apt/apt.conf.d/02periodic"
|
ynh_store_file_checksum --file="/etc/apt/apt.conf.d/02periodic"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -107,8 +130,13 @@ fi
|
||||||
# Get main domain and buid the url of the admin panel of the app.
|
# Get main domain and buid the url of the admin panel of the app.
|
||||||
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
|
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
|
||||||
|
|
||||||
# Build the changelog
|
# If a html email is required. Apply html to the changelog.
|
||||||
ynh_app_changelog || true
|
if [ "$admin_mail_html" -eq 1 ]; then
|
||||||
|
format=html
|
||||||
|
else
|
||||||
|
format=plain
|
||||||
|
fi
|
||||||
|
ynh_app_changelog --format=$format
|
||||||
|
|
||||||
echo "To modify any option of unattended-upgrades, please have a look to /etc/apt/apt.conf.d/50unattended-upgrades and
|
echo "To modify any option of unattended-upgrades, please have a look to /etc/apt/apt.conf.d/50unattended-upgrades and
|
||||||
/etc/apt/apt.conf.d/02periodic
|
/etc/apt/apt.conf.d/02periodic
|
||||||
|
@ -127,10 +155,10 @@ If you're facing an issue or want to improve this app, please open a new issue i
|
||||||
Changelog since your last upgrade:
|
Changelog since your last upgrade:
|
||||||
$(cat changelog)" > mail_to_send
|
$(cat changelog)" > mail_to_send
|
||||||
|
|
||||||
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="upgrade"
|
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=upgrade
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Upgrade completed" --last
|
ynh_script_progression --message="Upgrade of $app completed" --last
|
||||||
|
|
Loading…
Add table
Reference in a new issue