1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ntfy_ynh.git synced 2024-09-03 19:46:27 +02:00

Switch to packaging version v2

(cherry picked from commit 1a7fde7c120fea7872ec909141a7e7824dbff376)
Signed-off-by: Alexander Wühr <awuehr@pnyhf.eu>
This commit is contained in:
Alexander Wühr 2023-02-24 14:01:24 +01:00
parent b0f30c05cf
commit 1fa0147e21
No known key found for this signature in database
19 changed files with 138 additions and 773 deletions

View file

@ -19,7 +19,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
ntfy (pronounce: *notify*) is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, entirely without signup, cost or setup. It's also open source if you want to run your own. ntfy (pronounce: *notify*) is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, entirely without signup, cost or setup. It's also open source if you want to run your own.
**Shipped version:** 2.0.1~ynh1 **Shipped version:** 2.0.1~ynh2
**Demo:** https://ntfy.sh/app **Demo:** https://ntfy.sh/app
## Disclaimers / important information ## Disclaimers / important information

View file

@ -19,7 +19,7 @@ Si vous navez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po
ntfy (pronounce: *notify*) is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, entirely without signup, cost or setup. It's also open source if you want to run your own. ntfy (pronounce: *notify*) is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, entirely without signup, cost or setup. It's also open source if you want to run your own.
**Version incluse :** 2.0.1~ynh1 **Version incluse :** 2.0.1~ynh2
**Démo :** https://ntfy.sh/app **Démo :** https://ntfy.sh/app
## Avertissements / informations importantes ## Avertissements / informations importantes

View file

@ -1,18 +0,0 @@
;; Default test serie
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=1
setup_nourl=0
setup_private=0
upgrade=1
upgrade=1 from_commit=2.0.0-ynh1
upgrade=1 from_commit=1.31.0-ynh1
# 1.30.1~ynh1
upgrade=1 from_commit=6d7d7082971be2626d082a117cdd613a21716f61
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
actions=0
config_panel=0

2
conf/ntfy.sh Normal file → Executable file
View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
HOME=__FINALPATH__ HOME=__INSTALL_DIR__
NTFY_CONFIG_FILE="$HOME/server.yml" $HOME/ntfy $@ NTFY_CONFIG_FILE="$HOME/server.yml" $HOME/ntfy $@

View file

@ -3,7 +3,7 @@
# Please refer to the documentation at https://ntfy.sh/docs/config/ for details. # Please refer to the documentation at https://ntfy.sh/docs/config/ for details.
# All options also support underscores (_) instead of dashes (-) to comply with the YAML spec. # All options also support underscores (_) instead of dashes (-) to comply with the YAML spec.
cache-file: __FINALPATH__/data/cache.db cache-file: __INSTALL_DIR__/data/cache.db
cache-startup-queries: | cache-startup-queries: |
pragma journal_mode = WAL; pragma journal_mode = WAL;
pragma synchronous = normal; pragma synchronous = normal;
@ -11,10 +11,10 @@ cache-startup-queries: |
pragma busy_timeout = 15000; pragma busy_timeout = 15000;
vacuum; vacuum;
auth-file: __FINALPATH__/data/user.db auth-file: __INSTALL_DIR__/data/user.db
auth-default-access: "deny-all" auth-default-access: "deny-all"
enable-login: true enable-login: true
attachment-cache-dir: __FINALPATH__/data/attachments attachment-cache-dir: __INSTALL_DIR__/data/attachments
upstream-base-url: "https://ntfy.sh" upstream-base-url: "https://ntfy.sh"

View file

@ -6,13 +6,13 @@ After=network.target
Environment="NTFY_LISTEN_HTTP=localhost:__PORT__" Environment="NTFY_LISTEN_HTTP=localhost:__PORT__"
Environment="NTFY_BASE_URL=https://__DOMAIN__" Environment="NTFY_BASE_URL=https://__DOMAIN__"
Environment="NTFY_BEHIND_PROXY=1" Environment="NTFY_BEHIND_PROXY=1"
Environment="NTFY_CONFIG_FILE=__FINALPATH__/server.yml" Environment="NTFY_CONFIG_FILE=__INSTALL_DIR__/server.yml"
Type=simple Type=simple
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
WorkingDirectory=__FINALPATH__/ WorkingDirectory=__INSTALL_DIR__/
ExecStart=__FINALPATH__/ntfy serve ExecStart=__INSTALL_DIR__/ntfy serve
ExecReload=/bin/kill --signal HUP $MAINPID ExecReload=/bin/kill --signal HUP $MAINPID
Restart=on-failure Restart=on-failure

View file

@ -1,10 +0,0 @@
### Configuration
By default, only user selected at installation can read from and write to topics. To change this refer to the upstream project's documentation: https://docs.ntfy.sh/config/#access-control
The configuration file is located at `/var/www/<app>/server.yml`.
### Limitations
- requires a dedicated (sub-)domain
- no LDAP support by upstream application

12
doc/admin.md Normal file
View file

@ -0,0 +1,12 @@
### Configuration
By default, only user selected at installation can read from and write to topics. To change this refer to the upstream project's documentation: https://docs.ntfy.sh/config/#access-control
The configuration file is located at `__INSTALL_DIR__/server.yml` and can be edited directly.
To configure users, tokens, acls and tiers, you'll find a small wrapper script at `__INSTALL_DIR__/ntfy.sh`.
```sh
sudo ~__APP__/ntfy.sh user add your_new_username
```
for example will add a new user.

View file

@ -1,47 +0,0 @@
{
"name": "ntfy",
"id": "ntfy",
"packaging_format": 1,
"description": {
"en": "Open Source Push Notification Server",
"fr": "Serveur open source de notification"
},
"upstream": {
"license": "GPL-2.0-only",
"website": "https://ntfy.sh/",
"demo": "https://ntfy.sh/app",
"admindoc": "https://docs.ntfy.sh/",
"userdoc": "https://docs.ntfy.sh/",
"code": "https://github.com/binwiederhier/ntfy"
},
"url": "https://ntfy.sh/",
"version": "2.0.1~ynh1",
"license": "GPL-2.0-only",
"maintainer": {
"name": "Alexander Wühr",
"email": "alex@pnyhf.eu"
},
"requirements": {
"yunohost": ">= 11"
},
"multi_instance": true,
"services": [
"nginx"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain"
},
{
"name": "admin",
"type": "user"
},
{
"name": "password",
"type": "password"
}
]
}
}

52
manifest.toml Normal file
View file

@ -0,0 +1,52 @@
packaging_format = 2
id = "ntfy"
name = "ntfy"
description.en = "Open Source Push Notification Server"
description.fr = "Serveur open source de notification"
version = "2.0.1~ynh2"
maintainers = ["Alexander Wühr"]
[upstream]
license = "GPL-2.0-only"
website = "https://ntfy.sh/"
demo = "https://ntfy.sh/app"
admindoc = "https://docs.ntfy.sh/"
userdoc = "https://docs.ntfy.sh/"
code = "https://github.com/binwiederhier/ntfy"
fund = "https://liberapay.com/ntfy"
[integration]
yunohost = ">= 11"
architectures = ["amd64", "arm64", "armhf"]
multi_instance = true
ldap = false
sso = false
disk = "50M"
ram.build = "50M"
ram.runtime = "50M"
[install]
[install.domain]
type = "domain"
full_domain = true
[install.admin]
type = "user"
[install.password]
type = "password"
[resources]
[resources.system_user]
[resources.install_dir]
[resources.permissions]
main.url = "/"
main.auth_header = false
[resources.ports]
main.default = 8080

View file

@ -7,6 +7,15 @@
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS
#================================================= #=================================================
ntfy_setup_source() {
ynh_setup_source -d "$install_dir" -s "$YNH_ARCH"
mkdir -p "$install_dir/data"
chown -R $app:$app "$install_dir"
chmod -R 750 "$install_dir/data"
ynh_secure_remove "$install_dir/client"
ynh_secure_remove "$install_dir/server"
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS

View file

@ -1,60 +1,10 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_backup -s "$install_dir"
# MANAGE SCRIPT FAILURE ynh_backup -s "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= ynh_backup -s "/etc/systemd/system/$app.service"
ynh_clean_setup () { ynh_print_info --message="Backup script completed. (YunoHost will then actually copy those files to the archive)"
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,109 +1,15 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_script_progression --message="Updating systemd service..." --weight=1
# RETRIEVE ARGUMENTS ynh_add_systemd_config
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN ynh_script_progression --message="Updating webserver configuration..." --weight=1
domain=$YNH_APP_NEW_DOMAIN ynh_change_url_nginx_config
app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Restarting systemd service..." --weight=1
ynh_systemd_action --action=restart
#================================================= ynh_script_progression --message="URL change completed" --last
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
# 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/$domain.d/$app.conf"
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$domain" ]
then
change_domain=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# 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/$domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
# Re-install the systemd unit
ynh_add_systemd_config
fi
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -1,102 +0,0 @@
#!/bin/bash
# In simple cases, you don't need a config script.
# With a simple config_panel.toml, you can write in the app settings, in the
# upstream config file or replace complete files (logo ...) and restart services.
# The config scripts allows you to go further, to handle specific cases
# (validation of several interdependent fields, specific getter/setter for a value,
# display dynamic informations or choices, pre-loading of config type .cube... ).
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__amount() {
# Here we can imagine to have an API call to stripe to know the amount of donation during a month
local amount = 200
# It's possible to change some properties of the question by overriding it:
if [ $amount -gt 100 ]
then
cat << EOF
style: success
value: $amount
ask:
en: A lot of donation this month: **$amount €**
EOF
else
cat << EOF
style: danger
value: $amount
ask:
en: Not so much donation this month: $amount €
EOF
fi
}
get__prices() {
local prices = "$(grep "DONATION\['" "$final_path/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')"
if [ "$prices" == "," ];
then
# Return YNH_NULL if you prefer to not return a value at all.
echo YNH_NULL
else
echo $prices
fi
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
validate__publishable_key() {
# We can imagine here we test if the key is really a publisheable key
(is_secret_key $publishable_key) &&
echo 'This key seems to be a secret key'
}
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__prices() {
#---------------------------------------------
# IMPORTANT: setter are trigger only if a change is detected
#---------------------------------------------
for price in $(echo $prices | sed "s/,/ /"); do
frequency=$(echo $price | cut -d/ -f1)
currency=$(echo $price | cut -d/ -f2)
price_id=$(echo $price | cut -d/ -f3)
sed "d/DONATION\['$frequency'\]\['$currency'\]" "$final_path/settings.py"
echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py"
done
#---------------------------------------------
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
#---------------------------------------------
ynh_app_setting_set $app prices $prices
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1

View file

@ -1,168 +1,32 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
app=$YNH_APP_INSTANCE_NAME
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=/
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port=$(ynh_find_port --port=8080)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=6 ynh_script_progression --message="Setting up source files..." --weight=6
ntfy_setup_source
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_script_progression --message="Adding configuration file..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src ynh_add_config -t "server.yml" -d "$install_dir/server.yml"
ynh_setup_source --dest_dir="$final_path" --source_id="$YNH_ARCH"
ynh_secure_remove --file=$final_path/client ynh_script_progression --message="Configuring systemd service..." --weight=1
ynh_secure_remove --file=$final_path/server
mkdir -p "$final_path/data"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="server.yml" --destination="$final_path/server.yml"
chmod 400 "$final_path/server.yml"
chown $app:$app "$final_path/server.yml"
#=================================================
# ADD A SIMPLE WRAPPER SCRIPT
#=================================================
ynh_script_progression --message="Adding a command wrapper..." --weight=1
ynh_add_config --template="ntfy.sh" --destination="$final_path/ntfy.sh"
chmod +x "$final_path/ntfy.sh"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#================================================= ynh_script_progression --message="Starting systemd service..." --weight=1
# GENERIC FINALIZATION ynh_systemd_action --action=start
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app yunohost service add $app
#================================================= ynh_script_progression --message="Adding a command wrapper..." --weight=1
# START SYSTEMD SERVICE ynh_add_config -t "ntfy.sh" -d "$install_dir/ntfy.sh"
#================================================= chown $app:$app "$install_dir/ntfy.sh"
ynh_script_progression --message="Starting a systemd service..." --weight=1 chmod u+x "$install_dir/ntfy.sh"
# Start a systemd service ynh_script_progression --message="Configuring web server..." --weight=2
ynh_systemd_action --service_name=$app --action="start" ynh_add_nginx_config
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
ynh_permission_url --permission="main" --auth_header=false
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# ADD APP ADMIN USER
#=================================================
ynh_script_progression --message="Adding admin user..." --weight=1 ynh_script_progression --message="Adding admin user..." --weight=1
ynh_exec_as $app NTFY_PASSWORD="$password" $install_dir/ntfy.sh user add --role=admin $admin
ynh_exec_as $app NTFY_PASSWORD="$password" $final_path/ntfy user --config=$final_path/server.yml add --role=admin $admin ynh_script_progression --message="Installation completed" --last
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -1,74 +1,15 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_script_progression --message="Removing service in YunoHost..." --weight=1
# LOAD SETTINGS yunohost service remove $app
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Removing the systemd service..." --weight=1
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
#================================================= ynh_script_progression --message="Removing the web server configuration..." --weight=2
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=10
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=2
# Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= ynh_script_progression --message="Removal completed" --last
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -1,107 +1,25 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_script_progression --message="Restoring the main directory..." --weight=1
# MANAGE SCRIPT FAILURE ynh_restore_file -o "$install_dir"
#=================================================
ynh_clean_setup () { ynh_script_progression --message="Restoring the web server configuration..." --weight=1
true ynh_restore_file -o "/etc/nginx/conf.d/$domain.d/$app.conf"
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet ynh_systemd_action --action=enable
#=================================================
# SPECIFIC RESTORATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app yunohost service add $app
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --action=start
ynh_systemd_action --service_name=$app --action="start" ynh_script_progression --message="Reloading the web server..." --weight=1
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
#================================================= ynh_script_progression --message="Restoration completed" --last
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -1,149 +1,35 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..." --weight=1 ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=30
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_script_progression --message="Upgrading source files..." --weight=6
ntfy_setup_source
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --source_id="$YNH_ARCH"
ynh_secure_remove --file=$final_path/client
ynh_secure_remove --file=$final_path/server
fi fi
chmod 750 "$final_path" ynh_script_progression --message="Updating configuration file..." --weight=1
chmod -R o-rwx "$final_path" ynh_add_config -t "server.yml" -d "$install_dir/server.yml"
chown -R $app:$app "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_add_config --template="server.yml" --destination="$final_path/server.yml"
chmod 400 "$final_path/server.yml"
chown $app:$app "$final_path/server.yml"
#=================================================
# UPDATE A SIMPLE WRAPPER SCRIPT
#=================================================
ynh_script_progression --message="Updating a command wrapper..." --weight=1
ynh_add_config --template="ntfy.sh" --destination="$final_path/ntfy.sh"
chmod +x "$final_path/ntfy.sh"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app yunohost service add $app
#================================================= ynh_script_progression --message="Updating simple command wrapper..." --weight=1
# START SYSTEMD SERVICE ynh_add_config -t "ntfy.sh" -d "$install_dir/ntfy.sh"
#================================================= chown $app:$app "$install_dir/ntfy.sh"
ynh_script_progression --message="Starting a systemd service..." --weight=1 chmod u+x "$install_dir/ntfy.sh"
ynh_systemd_action --service_name=$app --action="start" ynh_script_progression --message="Upgrading web server configuration..." --weight=2
ynh_add_nginx_config
#================================================= ynh_script_progression --message="Restarting systemd service..." --weight=1
# RELOAD NGINX ynh_systemd_action --action=restart
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload ynh_script_progression --message="Upgrade completed" --last
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last

4
tests.toml Normal file
View file

@ -0,0 +1,4 @@
test_format = 1.0
[default]
test_upgrade_from.b0f30c0.name = "Upgrade from 2.0.1~ynh1"