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

Merge pull request #46 from YunoHost-Apps/testing

Testing
This commit is contained in:
Maniack Crudelis 2020-04-25 13:22:12 +02:00 committed by GitHub
commit 629d279c7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 747 additions and 437 deletions

View file

@ -4,6 +4,20 @@ Changelog
## Unreleased
- Nothing for now...
## [0.11.6~ynh4](https://github.com/YunoHost-Apps/lutim_ynh/pull/46) - 2020-04-25
#### Added
- [Add new badges](https://github.com/YunoHost-Apps/lutim_ynh/pull/46/commits/4e28257f0550378297789c77a5354b004100f5ae)
* [New reset actions](https://github.com/YunoHost-Apps/lutim_ynh/pull/46/commits/e1c90a7c1b2c0c66c4d7bfc8a8e2a221d5c817ab)
#### Fixed
- [Fix potential error on install](https://github.com/YunoHost-Apps/lutim_ynh/pull/46/commits/e481e03e0511787f297e10f85d6a54b3fedb5470)
#### Changed
- [Indentation](https://github.com/YunoHost-Apps/lutim_ynh/pull/46/commits/a934b7369842dfbdc45e7c1dfdf3483276d4c755)
- [Misc upgrade](https://github.com/YunoHost-Apps/lutim_ynh/pull/46/commits/750ea401950f4e8b3facfa7caa5bc2388b6a4272)
## [0.11.6~ynh3](https://github.com/YunoHost-Apps/lutim_ynh/pull/45) - 2020-03-12
#### Changed

View file

@ -1,6 +1,6 @@
# Lutim for YunoHost
[![Integration level](https://dash.yunohost.org/integration/lutim.svg)](https://dash.yunohost.org/appci/app/lutim)
[![Integration level](https://dash.yunohost.org/integration/lutim.svg)](https://dash.yunohost.org/appci/app/lutim) ![](https://ci-apps.yunohost.org/ci/badges/lutim.status.svg) [![](https://ci-apps.yunohost.org/ci/badges/lutim.maintain.svg)](https://github.com/YunoHost/Apps/#what-to-do-if-i-cant-maintain-my-app-anymore-)
[![Install Lutim with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=lutim)
*[Lire ce readme en français.](./README_fr.md)*
@ -41,7 +41,7 @@ Not relevant.
* x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/lutim%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/lutim/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/lutim%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/lutim/)
* Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/lutim%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/lutim/)
* Buster x86-64b - [![](https://ci-buster.nohost.me/ci/logs/lutim%20%28Apps%29.svg)](https://ci-buster.nohost.me/ci/apps/lutim/)
## Limitations
@ -63,7 +63,7 @@ Please do your pull request to the [testing branch](https://github.com/YunoHost-
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/lutim_ynh/tree/testing --debug
sudo yunohost app install https://github.com/YunoHost-Apps/lutim_ynh/tree/testing --force --debug
or
sudo yunohost app upgrade lutim -u https://github.com/YunoHost-Apps/lutim_ynh/tree/testing --debug
```

View file

@ -1,6 +1,6 @@
# Lutim pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/lutim.svg)](https://dash.yunohost.org/appci/app/lutim)
[![Niveau d'intégration](https://dash.yunohost.org/integration/lutim.svg)](https://dash.yunohost.org/appci/app/lutim) ![](https://ci-apps.yunohost.org/ci/badges/lutim.status.svg) [![](https://ci-apps.yunohost.org/ci/badges/lutim.maintain.svg)](https://github.com/YunoHost/Apps/#what-to-do-if-i-cant-maintain-my-app-anymore-)
[![Installer Lutim avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=lutim)
*[Read this readme in english.](./README.md)*
@ -41,7 +41,7 @@ Non applicable.
* x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/lutim%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/lutim/)
* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/lutim%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/lutim/)
* Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/lutim%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/lutim/)
* Buster x86-64b - [![](https://ci-buster.nohost.me/ci/logs/lutim%20%28Apps%29.svg)](https://ci-buster.nohost.me/ci/apps/lutim/)
## Limitations
@ -63,7 +63,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.
```
sudo yunohost app install https://github.com/YunoHost-Apps/lutim_ynh/tree/testing --debug
sudo yunohost app install https://github.com/YunoHost-Apps/lutim_ynh/tree/testing --force --debug
ou
sudo yunohost app upgrade lutim -u https://github.com/YunoHost-Apps/lutim_ynh/tree/testing --debug
```

View file

@ -22,14 +22,31 @@ command = "/bin/bash scripts/actions/reset_default_config \"lutim.conf\""
accepted_return_codes = [0]
description = "Reset the config file lutim.conf."
[public_private]
name = "Move to public or private"
command = "/bin/bash scripts/actions/public_private"
accepted_return_codes = [0]
description = "Change the public access of the app."
[public_private.arguments]
[public_private.arguments.is_public]
type = "boolean"
ask = "Is it a public app ?"
default = true
[reset_default_nginx]
name = "Reset the nginx config for this app."
command = "/bin/bash scripts/actions/reset_default_system nginx"
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Reset the nginx config for this app."
[reset_default_systemd]
name = "Reset the systemd config for this app."
command = "/bin/bash scripts/actions/reset_default_system systemd"
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Reset the systemd config for this app."
[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."

View file

@ -1,29 +1,39 @@
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
always_encrypt=1
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=4c29aa94f9d9048411c6e165e122e03574fb9b8d
backup_restore=1
multi_instance=0
port_already_use=1 (8095)
change_url=1
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
always_encrypt=1
; Actions
; Config_panel
main.configuration.always_encrypt=0|1
main.configuration.antiflood=10
main.configuration.delay=None|Day|Week|Month|Year
main.overwrite_files.overwrite_settings=0|1
main.overwrite_files.overwrite_nginx=0|1
main.overwrite_files.overwrite_systemd=0|1
main.global_config.email_type=0|1
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=4c29aa94f9d9048411c6e165e122e03574fb9b8d
backup_restore=1
multi_instance=0
port_already_use=1 (8095)
change_url=1
actions=1
config_panel=1
;;; Levels
# Level 5: https://github.com/YunoHost/package_linter/issues/36
Level 5=1
Level 5=auto
;;; Options
Email=
Notification=down
Notification=change
;;; Upgrade options
; commit=4c29aa94f9d9048411c6e165e122e03574fb9b8d
name=08 Sep 2017 4c29aa94f9d9048411c6e165e122e03574fb9b8d
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1&always_encrypt=1&
; commit=4c29aa94f9d9048411c6e165e122e03574fb9b8d
name=08 Sep 2017 4c29aa94f9d9048411c6e165e122e03574fb9b8d
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1&always_encrypt=1&

View file

@ -1,30 +1,30 @@
location __PATH__ {
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
# This is important for user's privacy !
access_log off;
error_log /var/log/nginx/lutim.error.log;
# This is important for user's privacy !
access_log off;
error_log /var/log/nginx/lutim.error.log;
# This is important ! Make it OK with your Lutim configuration
client_max_body_size 40M;
# This is important ! Make it OK with your Lutim configuration
client_max_body_size 40M;
proxy_pass http://127.0.0.1:__PORT__;
proxy_pass http://127.0.0.1:__PORT__;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Lutim reads this header and understands that the current session is actually HTTPS.
# Enable it if you run a HTTPS server (in this case, don't forgot to change the listen port
proxy_set_header X-Forwarded-Proto https;
# Lutim reads this header and understands that the current session is actually HTTPS.
# Enable it if you run a HTTPS server (in this case, don't forgot to change the listen port
proxy_set_header X-Forwarded-Proto https;
# We expect the downsteam servers to redirect to the right hostname, so don't do any rewrite
proxy_redirect off;
# We expect the downsteam servers to redirect to the right hostname, so don't do any rewrite
proxy_redirect off;
}

View file

@ -24,14 +24,6 @@ name = "Lutim configuration"
default = "Year"
help = "Users won't be able to ask Lutim to download images more than one per anti_flood_delay seconds."
[main.is_public]
name = "Public access"
[main.is_public.is_public]
ask = "Is it a public website?"
type = "boolean"
default = true
[main.overwrite_files]
name = "Overwriting config files"

26
hooks/post_app_addaccess Normal file
View file

@ -0,0 +1,26 @@
#!/bin/bash
# Source app helpers
source /usr/share/yunohost/helpers
app=$1
added_users=$2
permission=$3
added_groups=$4
if [ "$app" == __APP__ ]; then
if [ "$permission" = "upload images" ]; then # The fake permission "upload images" is modifed.
if [ "$added_groups" = "visitors" ]; then # As is it a fake permission we can only grant/remove the "visitors" group.
# We remove the regex, no more protection is needed.
ynh_app_setting_delete --app=$app --key=protected_regex
# Sync the is_public variable according to the permission
ynh_app_setting_set --app=$app --key=is_public --value=1
yunohost app ssowatconf
else
ynh_print_warn --message="This app doesn't support this authorisation, you can only add or remove visitors group."
fi
fi
fi

View file

@ -0,0 +1,34 @@
#!/bin/bash
# Source app helpers
source /usr/share/yunohost/helpers
app=$1
removed_users=$2
permission=$3
removed_groups=$4
if [ "$app" == __APP__ ]; then
if [ "$permission" = "upload images" ]; then # The fake permission "upload images" is modifed.
if [ "$removed_groups" = "visitors" ]; then # As is it a fake permission we can only grant/remove the "visitors" group.
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
# If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
# Sync the is_public variable according to the permission
ynh_app_setting_set --app=$app --key=is_public --value=0
yunohost app ssowatconf
else
ynh_print_warn --message="This app doesn't support this authorisation, you can only add or remove visitors group."
fi
fi
fi

View file

@ -1,64 +1,67 @@
{
"name": "Lutim",
"id": "lutim",
"packaging_format": 1,
"description": {
"en": "Self hosting images and sharing anonymous application",
"fr": "Application d'hébergement et de partage d'images anonyme"
},
"version": "0.11.6~ynh3",
"url": "https://lut.im",
"license": "AGPL-3.0",
"maintainer": {
"name": "Maniack Crudelis et matlink",
"email": "maniackc_dev@crudelis.fr"
},
"requirements": {
"yunohost": ">= 3.5"
},
"multi_instance": false,
"services": [
"nginx"
],
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for Lutim",
"fr": "Choisissez un domaine pour Lutim"
},
"example": "domain.org"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for Lutim",
"fr": "Choisissez un chemin pour Lutim"
},
"example": "/lutim",
"default": "/lutim"
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Uploading images is it public?",
"fr": "L'upload des images est-il public ?"
},
"default": false
},
{
"name": "always_encrypt",
"type": "boolean",
"ask": {
"en": "Force the encryption of images?",
"fr": "Forcer le chiffrement des images ?"
},
"default": true
}
]
}
"name": "Lutim",
"id": "lutim",
"packaging_format": 1,
"description": {
"en": "Self hosting images and sharing anonymous application",
"fr": "Application d'hébergement et de partage d'images anonyme"
},
"version": "0.11.6~ynh4",
"url": "https://lut.im",
"license": "AGPL-3.0",
"maintainer": {
"name": "Maniack Crudelis et matlink",
"email": "maniackc_dev@crudelis.fr"
},
"requirements": {
"yunohost": ">= 3.7"
},
"multi_instance": false,
"services": [
"nginx"
],
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for Lutim",
"fr": "Choisissez un domaine pour Lutim"
},
"example": "domain.org"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for Lutim",
"fr": "Choisissez un chemin pour Lutim"
},
"example": "/lutim",
"default": "/lutim"
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Uploading images is it public?",
"fr": "L'upload des images est-il public ?"
},
"default": false,
"help": {
"en": "If you set Lutim as public, everyone will be able to upload images and share them.<br>But even if not public, everyone can see an image from a link shared with your Lutim."
}
},
{
"name": "always_encrypt",
"type": "boolean",
"ask": {
"en": "Force the encryption of images?",
"fr": "Forcer le chiffrement des images ?"
},
"default": true
}
]
}
}

View file

@ -9,11 +9,18 @@
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:-$YNH_APP_ID}
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)

View file

@ -9,11 +9,18 @@
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:-$YNH_APP_ID}
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)

View file

@ -9,11 +9,18 @@
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:-$YNH_APP_ID}
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)

View file

@ -1,83 +0,0 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
# Get is_public
is_public=${YNH_ACTION_IS_PUBLIC}
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
is_public_old=$(ynh_app_setting_get --app=$app --key=is_public)
if [ $is_public -eq $is_public_old ]
then
ynh_die --message="is_public is already set as $is_public." --ret_code=0
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================
if [ $is_public -eq 0 ]; then
public_private="private"
else
public_private="public"
fi
ynh_script_progression --message="Moving the application to $public_private..." --weight=3
if [ $is_public -eq 0 ]
then
# If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
else
ynh_app_setting_delete --app=$app --key=protected_regex
fi
ynh_script_progression --message="Upgrading SSOwat configuration..."
# Regen ssowat configuration
yunohost app ssowatconf
# Update the config of the app
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

158
scripts/actions/reset_default_app Executable file
View file

@ -0,0 +1,158 @@
#!/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
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
port=$(ynh_app_setting_get --app=$app --key=port)
always_encrypt=$(ynh_app_setting_get --app=$app --key=always_encrypt)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
secret=$(ynh_app_setting_get --app=$app --key=secret)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set --app=$app --key=overwrite_settings --value=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
#=================================================
# SPECIFIC ACTION
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activating maintenance mode..."
ynh_maintenance_mode_ON
#=================================================
# STOP LUTIM
#=================================================
ynh_systemd_action --action=stop
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Resetting source files..." --weight=2
# Download, check integrity, uncompress and patch the source from app.src
(cd scripts; YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path")
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Resetting nginx web server configuration..." --weight=4
# Create a dedicated nginx config
yunohost app action run $app reset_default_nginx
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# RECONFIGURE APP
#=================================================
ynh_script_progression --message="Reconfiguring Lutim..." --weight=2
# Configure Lutim
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
(cd scripts; cp ../conf/lutim.conf.template "$final_path/lutim.conf")
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/lutim.conf"
#=================================================
# SETUP CRON
#=================================================
(cd scripts; cp ../conf/cron_lutim /etc/cron.d/$app)
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path/" --target_file=/etc/cron.d/$app
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file=/etc/cron.d/$app
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R $app: $final_path
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Resetting systemd configuration..."
yunohost app action run $app reset_default_systemd
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Resetting logrotate configuration..."
ynh_use_logrotate --non-append
chown $app -R /var/log/$app
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Disabling maintenance mode..."
ynh_maintenance_mode_OFF
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -9,11 +9,23 @@
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
@ -28,7 +40,7 @@ secret=$(ynh_app_setting_get --app=$app --key=secret)
file="$1"
if [ "$file" = "lutim.conf" ]; then
config_file="$final_path/lutim.conf"
config_file="$final_path/lutim.conf"
fi
#=================================================
@ -43,15 +55,15 @@ ynh_backup_if_checksum_is_different --file="$config_file"
if [ "$file" = "lutim.conf" ]
then
# Get the default file and overwrite the current config
cp /etc/yunohost/apps/$app/conf/lutim.conf.template "$config_file"
# Get the default file and overwrite the current config
cp /etc/yunohost/apps/$app/conf/lutim.conf.template "$config_file"
# Recreate the default config
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config_file"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config_file"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$config_file"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config_file"
# Recreate the default config
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config_file"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config_file"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$config_file"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config_file"
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
fi

View file

@ -0,0 +1,67 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
type=$1
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# SPECIFIC ACTION
#=================================================
# RESET THE CONFIG FILE
#=================================================
if [ $type == nginx ]; then
name=Nginx
elif [ $type == systemd ]; then
name=systemd
else
ynh_die --message="The type $type is not recognized"
fi
ynh_script_progression --message="Resetting the specific configuration of $name for the app $app..." --weight=3
if [ $type == nginx ]
then
(cd scripts; ynh_add_nginx_config)
elif [ $type == systemd ]
then
ynh_systemd_action --action=stop
(cd scripts; ynh_add_systemd_config)
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="300"
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -38,11 +38,13 @@ ynh_script_progression --message="Backing up the app before changing its url (ma
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_clean_check_starting
# restore it if the upgrade fails
ynh_restore_upgradebackup
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -63,26 +65,15 @@ ynh_maintenance_mode_ON
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
change_path=1
fi
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD MODIFICATIONS
#=================================================
@ -95,26 +86,26 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
ynh_add_nginx_config
# Create a dedicated nginx config
ynh_add_nginx_config
fi
# Change the domain for nginx
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
@ -122,16 +113,16 @@ fi
#=================================================
ynh_script_progression --message="Reconfiguring SSOwat..."
if [ $is_public -eq 0 ]
if [ $is_public -eq 0 ] # Only user with a yunohost account can upload an image
then
# If the app is private, viewing images stays publicly accessible.
if [ "$new_path" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
new_path=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$new_domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$new_path/stats/?$","$domain_regex$new_path/manifest.webapp/?$","$domain_regex$new_path/?$","$domain_regex$new_path/[d-m]/.*$"
# If the app is private, viewing images stays publicly accessible.
if [ "$new_path" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
new_path=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$new_domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$new_path/stats/?$","$domain_regex$new_path/manifest.webapp/?$","$domain_regex$new_path/?$","$domain_regex$new_path/[d-m]/.*$"
fi
#=================================================

View file

@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers
# RETRIEVE ARGUMENTS
#=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
@ -26,9 +26,9 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_file="$final_path/lutim.conf"
get_config_value() {
option_name="$1"
# Get the value of this option in the config file
grep "$option_name *=>" "$config_file" | cut -d'>' -f2 | sed s'/ //g' | cut -d',' -f1
option_name="$1"
# Get the value of this option in the config file
grep "$option_name *=>" "$config_file" | cut -d'>' -f2 | sed s'/ //g' | cut -d',' -f1
}
#=================================================
@ -43,28 +43,26 @@ get_config_value() {
# always_encrypt
old_always_encrypt="$(get_config_value always_encrypt)"
always_encrypt="${YNH_CONFIG_MAIN_CONFIGURATION_ALWAYS_ENCRYPT:-$old_always_encrypt}"
# antiflood
old_antiflood="$(get_config_value anti_flood_delay)"
antiflood="${YNH_CONFIG_MAIN_CONFIGURATION_ANTIFLOOD:-$old_antiflood}"
# delay
old_delay="$(get_config_value default_delay)"
if [ $old_delay -eq 0 ]; then
old_delay=None
old_delay=None
elif [ $old_delay -eq 1 ]; then
old_delay=Day
old_delay=Day
elif [ $old_delay -eq 7 ]; then
old_delay=Week
old_delay=Week
elif [ $old_delay -eq 30 ]; then
old_delay=Month
old_delay=Month
else
old_delay=Year
old_delay=Year
fi
delay="${YNH_CONFIG_MAIN_CONFIGURATION_DELAY:-$old_delay}"
# is_public
old_is_public="$(ynh_app_setting_get --app=$app --key=is_public)"
is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}"
# Overwrite settings.json file
old_overwrite_settings="$(ynh_app_setting_get --app=$app --key=overwrite_settings)"
overwrite_settings="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS:-$old_overwrite_settings}"
@ -86,20 +84,18 @@ admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_htm
#=================================================
show_config() {
# here you are supposed to read some config file/database/other then print the values
# ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
# here you are supposed to read some config file/database/other then print the values
# ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_ALWAYS_ENCRYPT=$always_encrypt"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_ANTIFLOOD=$antiflood"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_DELAY=$delay"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_ALWAYS_ENCRYPT=$always_encrypt"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_ANTIFLOOD=$antiflood"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_DELAY=$delay"
ynh_return "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD=$overwrite_systemd"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD=$overwrite_systemd"
ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
}
#=================================================
@ -107,70 +103,75 @@ show_config() {
#=================================================
apply_config() {
restart_lutim=0
# Change configuration if needed
# always_encrypt
if [ "$always_encrypt" != "$old_always_encrypt" ]
then
ynh_replace_string --match_string=".*always_encrypt *=>.*" --replace_string=" always_encrypt => $always_encrypt," --target_file="$config_file"
restart_lutim=1
fi
#=================================================
# MODIFY LUTIM CONFIGURATION
#=================================================
# antiflood
if [ "$antiflood" != "$old_antiflood" ]
then
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$config_file"
# Disable anti_flood_delay if the delay is 0
if [ $antiflood = 0 ]; then
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$config_file"
fi
ynh_app_setting_set --app=$app --key=antiflood --value="$antiflood"
restart_lutim=1
fi
restart_lutim=0
# delay
if [ "$delay" != "$old_delay" ]
then
if [ $delay = None ]; then
delay=0
elif [ $delay = Day ]; then
delay=1
elif [ $delay = Week ]; then
delay=7
elif [ $delay = Month ]; then
delay=30
else
delay=360
fi
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$config_file"
ynh_app_setting_set --app=$app --key=delay --value="$delay"
restart_lutim=1
fi
# Change configuration if needed
# always_encrypt
if [ "$always_encrypt" != "$old_always_encrypt" ]
then
ynh_replace_string --match_string=".*always_encrypt *=>.*" --replace_string=" always_encrypt => $always_encrypt," --target_file="$config_file"
restart_lutim=1
fi
if [ $restart_lutim -eq 1 ]
then
# Wait for lutim to be fully started
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
fi
# antiflood
if [ "$antiflood" != "$old_antiflood" ]
then
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$config_file"
# Disable anti_flood_delay if the delay is 0
if [ $antiflood = 0 ]; then
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$config_file"
fi
ynh_app_setting_set --app=$app --key=antiflood --value="$antiflood"
restart_lutim=1
fi
# Change public accessibility
if [ "$is_public" = "true" ]
then
yunohost app action run $app public_private --args is_public=1
else
yunohost app action run $app public_private --args is_public=0
fi
# delay
if [ "$delay" != "$old_delay" ]
then
if [ $delay = None ]; then
delay=0
elif [ $delay = Day ]; then
delay=1
elif [ $delay = Week ]; then
delay=7
elif [ $delay = Month ]; then
delay=30
else
delay=360
fi
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$config_file"
ynh_app_setting_set --app=$app --key=delay --value="$delay"
restart_lutim=1
fi
# Set overwrite_settings
ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings"
# Set overwrite_nginx
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
# Set overwrite_systemd
ynh_app_setting_set --app=$app --key=overwrite_systemd --value="$overwrite_systemd"
if [ $restart_lutim -eq 1 ]
then
# Wait for lutim to be fully started
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
fi
# Set admin_mail_html
ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
#=================================================
# MODIFY OVERWRITTING SETTINGS
#=================================================
# Set overwrite_settings
ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings"
# Set overwrite_nginx
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
# Set overwrite_systemd
ynh_app_setting_set --app=$app --key=overwrite_systemd --value="$overwrite_systemd"
#=================================================
# MODIFY EMAIL SETTING
#=================================================
# Set admin_mail_html
ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
}
#=================================================
@ -180,6 +181,6 @@ apply_config() {
#=================================================
case $1 in
show) show_config;;
apply) apply_config;;
show) show_config;;
apply) apply_config;;
esac

View file

@ -6,18 +6,19 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source _variables
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
ynh_clean_check_starting
}
ynh_abort_if_errors
@ -121,6 +122,13 @@ ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) *
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$final_path/lutim.conf"
#=================================================
# SETUP HOOKS FILE
#=================================================
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_addaccess"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_removeaccess"
#=================================================
# SETUP SYSTEMD
#=================================================
@ -151,7 +159,7 @@ carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu)
if [ "$?" -ne 0 ]
then
ynh_die --message="Unable to find the perl directory for your architecture."
ynh_die --message="Unable to find the perl directory for your architecture."
fi
ynh_replace_string --match_string="__ARCHDIR__" --replace_string="$arch_dir" --target_file="$final_path/script/lutim"
@ -192,17 +200,26 @@ yunohost service add $app --log $final_path/log/production.log
#=================================================
ynh_script_progression --message="Configuring SSOwat..."
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
ynh_permission_update --permission="main" --add="visitors"
# This is a fake permission without any URL.
# The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified.
# We can't use a real permission for now because the actual permision system doesn't support regex.
ynh_permission_create --permission="upload images" --allowed="visitors"
if [ $is_public -eq 0 ]
then
# If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
# If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
# If the app is not public, then the "visitors" group doesn't have this permission
ynh_permission_update --permission="upload images" --remove="visitors"
fi
#=================================================
@ -219,10 +236,14 @@ ynh_script_progression --message="Restarting Lutim..." --weight=6
# Wait for lutim to be fully started
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
ynh_systemd_action --action=stop
# Set right permissions on new files created at first start
chown -R $app: $final_path
# Wait for lutim to be fully started
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
@ -243,4 +264,4 @@ ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --time --last
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -94,4 +94,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --time --last
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -6,18 +6,19 @@
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source ../settings/scripts/_variables
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -39,9 +40,9 @@ path_url=$(ynh_app_setting_get --app=$app --key=path)
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# ACTIVATE MAINTENANCE MODE

View file

@ -6,11 +6,12 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source _variables
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
@ -48,56 +49,87 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
# Fix is_public as a boolean
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
skipped_uris=$(ynh_app_setting_get --app=$app --key=skipped_uris)
# Unused with the permission system
if [ ! -z "$skipped_uris" ]; then
ynh_app_setting_delete --app=$app --key=skipped_uris
fi
# Create the permission "upload images" only if it doesn't exist.
if ! ynh_permission_exists --permission="upload images"
then
# This is a fake permission without any URL.
# The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified.
# We can't use a real permission for now because the actual permision system doesn't support regex.
ynh_permission_create --permission="upload images" --allowed="visitors"
if [ $is_public -eq 0 ]
then
# If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
# If the app is not public, then the "visitors" group doesn't have this permission
ynh_permission_update --permission="upload images" --remove="visitors"
fi
fi
# if final_path isn't set, which can happens with old scripts, set final_path.
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
# Fix always_encrypt as a boolean
if [ "$always_encrypt" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=always_encrypt --value=1
always_encrypt=1
ynh_app_setting_set --app=$app --key=always_encrypt --value=1
always_encrypt=1
elif [ "$always_encrypt" = "No" ]; then
ynh_app_setting_set --app=$app --key=always_encrypt --value=0
always_encrypt=0
ynh_app_setting_set --app=$app --key=always_encrypt --value=0
always_encrypt=0
fi
# If overwrite_settings doesn't exist, create it
if [ -z "$overwrite_settings" ]; then
overwrite_settings=1
ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings
overwrite_settings=1
ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings
fi
# If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then
overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
fi
# If overwrite_systemd doesn't exist, create it
if [ -z "$overwrite_systemd" ]; then
overwrite_systemd=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=$overwrite_systemd
overwrite_systemd=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=$overwrite_systemd
fi
# If secret doesn't exist, create it
if [ -z "$secret" ]; then
secret=$(grep "secrets *=>" "$final_path/lutim.conf" | cut -d\' -f2)
ynh_app_setting_set --app=$app --key=secret --value=$secret
secret=$(grep "secrets *=>" "$final_path/lutim.conf" | cut -d\' -f2)
ynh_app_setting_set --app=$app --key=secret --value=$secret
fi
# Close opened port
if yunohost firewall list | grep -q "\- $port$"
then
ynh_exec_quiet yunohost firewall disallow TCP $port
ynh_exec_quiet yunohost firewall disallow TCP $port
fi
# Replace skipped_uris by unprotected_uris for the migration to the new permission system.
@ -113,9 +145,9 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
ynh_backup_before_upgrade
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
# restore it if the upgrade fails
ynh_restore_upgradebackup
ynh_clean_check_starting
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -142,9 +174,9 @@ ynh_maintenance_mode_ON
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
#=================================================
@ -161,8 +193,8 @@ ynh_install_app_dependencies $app_depencencies
# Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ]
then
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2
ynh_add_nginx_config
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2
ynh_add_nginx_config
fi
#=================================================
@ -178,38 +210,45 @@ ynh_system_user_create --username=$app
#=================================================
# SETUP LUTIM
#=================================================
ynh_script_progression --message="Reconfigure Lutim"
ynh_script_progression --message="Reconfiguring Lutim..."
# Overwrite the settings config file only if it's allowed
if [ $overwrite_settings -eq 1 ]
then
# Configure Lutim
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
# Configure Lutim
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/lutim.conf"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/lutim.conf"
# Optional parameters from config-panel feature
if [ -n "$antiflood" ]; then
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$final_path/lutim.conf"
# Disable anti_flood_delay if the delay is 0
if [ $antiflood = 0 ]; then
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$final_path/lutim.conf"
fi
fi
if [ -n "$delay" ]; then
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$final_path/lutim.conf"
fi
# Optional parameters from config-panel feature
if [ -n "$antiflood" ]; then
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$final_path/lutim.conf"
# Disable anti_flood_delay if the delay is 0
if [ $antiflood = 0 ]; then
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$final_path/lutim.conf"
fi
fi
if [ -n "$delay" ]; then
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$final_path/lutim.conf"
fi
fi
#=================================================
# SETUP HOOKS FILE
#=================================================
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_addaccess"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_removeaccess"
#=================================================
# SETUP SYSTEMD
#=================================================
@ -217,8 +256,8 @@ fi
# Overwrite the systemd configuration only if it's allowed
if [ $overwrite_systemd -eq 1 ]
then
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
ynh_add_systemd_config
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
ynh_add_systemd_config
fi
#=================================================
@ -235,9 +274,9 @@ ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_fil
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading Lutim with carton..." --weight=4
(cd $final_path
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
ynh_script_progression --message="Upgrading Lutim with carton..." --weight=4
(cd $final_path
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
fi
#=================================================
@ -257,20 +296,6 @@ ynh_script_progression --message="Upgrading logrotate configuration..."
ynh_use_logrotate --non-append
chown $app -R /var/log/$app
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..."
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
if [ $is_public -eq 0 ]
then
# If the app is private, viewing images stays publicly accessible.
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
fi
#=================================================
# RELOAD NGINX
#=================================================