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

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-30 22:49:52 +02:00 committed by Alexandre Aubin
parent 499ec6984f
commit dd7879d4f2
12 changed files with 160 additions and 274 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*~
*.sw[op]
/hooks/
.DS_Store

View file

@ -19,7 +19,8 @@ cpe = "cpe:2.3:a:domoticz:domoticz"
fund = "https://www.paypal.com/donate?token=rF_gUybGmQGia_jzLfu3vkeXRqYLRV-v-BxCTylrTsEN4mB-nDdSVQhg3a-I9LkiqORq70Gtxbo6rq3r&locale.x=US"
[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = [ "amd64", "armhf", "arm64" ]
multi_instance = false

View file

@ -1,21 +1,9 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,33 +1,24 @@
#!/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 /usr/share/yunohost/helpers
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/api_${app}.conf"
[[ "$domain" != "$mqtt_domain" ]] && ynh_backup --src_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_${app}.conf" --not_mandatory
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/api_${app}.conf"
[[ "$domain" != "$mqtt_domain" ]] && ynh_backup "/etc/nginx/conf.d/$mqtt_domain.d/mqtt_${app}.conf" || true
#=================================================
# SPECIFIC BACKUP
@ -35,31 +26,31 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/api_${app}.conf"
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
ynh_backup "/etc/fail2ban/jail.d/$app.conf"
ynh_backup "/etc/fail2ban/filter.d/$app.conf"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
[[ "$domain" != "$mqtt_domain" ]] && ynh_backup --src_path="/etc/mosquitto/conf.d" --not_mandatory
[[ "$domain" != "$mqtt_domain" ]] && ynh_backup "/etc/mosquitto/conf.d" || true
ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
ynh_backup "/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,20 +1,14 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression "Loading installation settings..."
old_api=$(ynh_app_setting_get --app=$app --key=api_path)
old_api=$(ynh_app_setting_get --key=api_path)
if [ "$new_path" == "/" ]; then
new_api=/api_/$app
else
@ -37,19 +31,17 @@ then
change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service=$app --action="stop"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..."
ynh_script_progression "Updating NGINX web server configuration..."
old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
old_nginx_api_conf_path=/etc/nginx/conf.d/$old_domain.d/api_$app.conf
@ -58,28 +50,28 @@ old_nginx_api_conf_path=/etc/nginx/conf.d/$old_domain.d/api_$app.conf
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$old_nginx_conf_path"
ynh_backup_if_checksum_is_different "$old_nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
path="$new_path"
api_path="$new_api"
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_config_add_nginx
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="$old_nginx_conf_path"
ynh_delete_file_checksum --file="$old_nginx_api_conf_path"
ynh_delete_file_checksum "$old_nginx_conf_path"
ynh_delete_file_checksum "$old_nginx_api_conf_path"
mv $old_nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
ynh_replace_string --match_string="/etc/nginx/conf.d/$old_domain.d/" --replace_string="/etc/nginx/conf.d/$new_domain.d/" --target_file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_replace --match="/etc/nginx/conf.d/$old_domain.d/" --replace="/etc/nginx/conf.d/$new_domain.d/" --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
mv $old_nginx_api_conf_path /etc/nginx/conf.d/$new_domain.d/api_$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"
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/api_$app.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/api_$app.conf"
fi
#=================================================
@ -87,32 +79,30 @@ fi
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..."
ynh_script_progression "Upgrading SSOwat configuration..."
# If the app is private, API should stays publicly accessible.
ynh_app_setting_delete --app=$app --key="api_path"
ynh_app_setting_set --app=$app --key="api_path" --value=$new_api
ynh_app_setting_delete --key="api_path"
ynh_app_setting_set --key="api_path" --value=$new_api
ynh_permission_url --permission api --url "$new_domain$new_api"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
ynh_systemctl --service=$app --action="start"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_script_progression "Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"

View file

@ -1,25 +1,19 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STORE SETTINGS
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_script_progression "Storing installation settings..."
#Will be used in restore script to check that we're restoring on the same OS/Board type
OS=`lowercase \`uname -s\``
mach=`uname -m`
ynh_app_setting_set --app="$app" --key=OS --value="$OS"
ynh_app_setting_set --app="$app" --key=mach --value="$mach"
ynh_app_setting_set --key=OS --value="$OS"
ynh_app_setting_set --key=mach --value="$mach"
#path used by api to read/update domoticz
#Set dedicated variables
@ -28,14 +22,12 @@ if [ "$path" == "/" ]; then
else
api_path=/api_"$path"
fi
ynh_app_setting_set --app="$app" --key=api_path --value="$api_path"
ynh_app_setting_set --key=api_path --value="$api_path"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
ynh_script_progression "Configuring system user..."
#allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus
if grep dialout -q < /etc/group; then
@ -51,7 +43,7 @@ fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=5
ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
@ -62,97 +54,90 @@ if [ ! -f "$install_dir"/domoticz.db ]; then
chmod 640 "$install_dir"/domoticz.db
fi
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app":"$app" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app":"$app" "$install_dir"
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
if [ "$domain" != "$mqtt_domain" ]; then
ynh_script_progression --message="Setting up mosquitto..." --weight=5
ynh_script_progression "Setting up mosquitto..."
#Setting up conf file for access
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/${app}_mosquitto.conf"
ynh_config_add --template="domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/${app}_mosquitto.conf"
chmod 644 /etc/mosquitto/conf.d/"$app"_mosquitto.conf
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app="$app" --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app="$app" --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app="$app" --key=mqtt_user):$(ynh_app_setting_get --app="$app" --key=mqtt_pwd) > "/etc/mosquitto/conf.d/${app}_credentials"
ynh_app_setting_set --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --key=mqtt_user):$(ynh_app_setting_get --key=mqtt_pwd) > "/etc/mosquitto/conf.d/${app}_credentials"
mosquitto_passwd -U "/etc/mosquitto/conf.d/${app}_credentials"
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
ynh_print_info "The credential to the mosquitto server has been saved in the settings of the app"
else
#If no MQTT have been set, we delete the mqtt permission.
ynh_permission_delete --permission="mqtt"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
ynh_script_progression "Configuring NGINX web server..."
[[ "$domain" != "$mqtt_domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/${mqtt_domain}.d/mqtt_${app}.conf"
[[ "$domain" != "$mqtt_domain" ]] && ynh_config_add --template="mqtt_nginx.conf" --destination="/etc/nginx/conf.d/${mqtt_domain}.d/mqtt_${app}.conf"
#Set Hook for nginx domain
cp -R ../sources/hooks/conf_regen/95-nginx_domoticz /usr/share/yunohost/hooks/conf_regen/
# Create a dedicated NGINX config
ynh_add_config --template="api_nginx.conf" --destination="/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
ynh_add_nginx_config
ynh_config_add --template="api_nginx.conf" --destination="/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
ynh_config_add_nginx
#=================================================
# SPECIFIC SETUP
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
ynh_script_progression "Configuring $app's systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
ynh_script_progression "Configuring log rotation..."
mkdir -p /var/log/"$app"
chown -R domoticz: /var/log/"$app"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R domoticz: /var/log/"$app"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
[[ "$domain" != "$mqtt_domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto"
ynh_config_add_logrotate
[[ "$domain" != "$mqtt_domain" ]] && ynh_config_add_logrotate "/var/log/mosquitto"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
[[ "$domain" != "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start"
ynh_systemctl --service="$app" --action="start"
#Restarting mosquitto to take changes into account
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart"
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemctl --service=mosquitto --action="restart"
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=8
ynh_script_progression "Configuring Fail2Ban..."
# Make sure a log file exists (mostly for CI tests)
log_file=/var/log/$app/$app.log
@ -162,10 +147,10 @@ if [ ! -f "$log_file" ]; then
fi
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="$log_file" --failregex="^.*Error: Failed login attempt from <HOST>.*$" --max_retry=5
ynh_config_add_fail2ban --logpath="$log_file" --failregex="^.*Error: Failed login attempt from <HOST>.*$"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -16,34 +10,33 @@ source /usr/share/yunohost/helpers
#=================================================
if [ "$domain" != "$mqtt_domain" ]; then
ynh_script_progression --message="Removing system configurations related to Mosquitto..." --weight=1
ynh_script_progression "Removing system configurations related to Mosquitto..."
yunohost service remove mosquitto
ynh_secure_remove --file="/etc/mosquitto/conf.d"
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
ynh_secure_remove --file="/etc/nginx/conf.d/${mqtt_domain}.d/mqtt_${app}.conf"
ynh_safe_rm "/etc/mosquitto/conf.d"
ynh_safe_rm "/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
ynh_safe_rm "/etc/nginx/conf.d/${mqtt_domain}.d/mqtt_${app}.conf"
yunohost tools regen-conf postfix
fi
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
if ynh_exec_warn_less yunohost service status "$app" >/dev/null
ynh_script_progression "Removing system configurations related to $app..."
if ynh_hide_warnings yunohost service status "$app" >/dev/null
then
ynh_script_progression --message="Removing $app service integration..."
ynh_script_progression "Removing $app service integration..."
yunohost service remove "$app"
fi
# Remove the dedicated systemd config
ynh_remove_systemd_config
ynh_config_remove_systemd
ynh_secure_remove --file="/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
ynh_remove_nginx_config
ynh_safe_rm "/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
ynh_config_remove_nginx
ynh_remove_logrotate
ynh_remove_fail2ban_config
ynh_config_remove_logrotate
ynh_config_remove_fail2ban
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/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 /usr/share/yunohost/helpers
@ -13,7 +7,6 @@ source /usr/share/yunohost/helpers
current_os=`lowercase \`uname -s\``
current_mach=`uname -m`
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
@ -21,23 +14,23 @@ current_mach=`uname -m`
#on the same system type. If we are restoring on another system type it won't work and in that
#case we must go through a reinstall process.
test "$OS" = "$current_os" \
|| ynh_die --message="Cannot restore : previous OS is $OS, current OS is $current_os, please reinstall"
|| ynh_die "Cannot restore : previous OS is $OS, current OS is $current_os, please reinstall"
test "$mach" = "$current_mach" \
|| ynh_die --message="Cannot restore : previous machine type is $mach, current machine type is $current_mach, please reinstall"
|| ynh_die "Cannot restore : previous machine type is $mach, current machine type is $current_mach, please reinstall"
ynh_app_setting_set --app="$app" --key=OS --value="$current_os"
ynh_app_setting_set --app="$app" --key=mach --value="$current_mach"
ynh_app_setting_set --key=OS --value="$current_os"
ynh_app_setting_set --key=mach --value="$current_mach"
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_script_progression "Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_${app}.conf" --not_mandatory
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
ynh_restore "/etc/nginx/conf.d/$mqtt_domain.d/mqtt_${app}.conf" || true
#=================================================
# RECREATE THE DEDICATED USER
@ -56,20 +49,19 @@ fi
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=5
ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app":"$app" "$install_dir"
ynh_restore "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app":"$app" "$install_dir"
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
if [ "$domain" != "$mqtt_domain" ]; then
ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5
ynh_restore_file --origin_path="/etc/mosquitto/conf.d" --not_mandatory
ynh_script_progression "Reinstalling up mosquitto..."
ynh_restore "/etc/mosquitto/conf.d" || true
else
#If no MQTT have been set, we delete the mqtt permission.
ynh_permission_delete --permission="mqtt"
@ -78,55 +70,54 @@ fi
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=3
ynh_script_progression "Restoring $app's systemd service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
ynh_restore "/etc/systemd/system/$app.service"
systemctl enable "$app".service --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
[[ "$domain" != "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"
#Restarting mosquitto to take changes into account
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart"
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemctl --service=mosquitto --action="restart"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
ynh_script_progression "Restoring the logrotate configuration..."
mkdir -p /var/log/"$app"
chown -R domoticz: /var/log/"$app"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R domoticz: /var/log/"$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore "/etc/logrotate.d/$app"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_script_progression "Restoring various files..."
ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
ynh_restore "/usr/share/yunohost/hooks/conf_regen/95-nginx_domoticz"
#yunohost tools regen-conf postfix
#=================================================
# RESTORE THE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=7
ynh_script_progression "Restoring the Fail2Ban configuration..."
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_restore "/etc/fail2ban/jail.d/$app.conf"
ynh_restore "/etc/fail2ban/filter.d/$app.conf"
log_file=/var/log/$app/$app.log
if [ ! -f "$log_file" ]; then
@ -134,19 +125,17 @@ if [ ! -f "$log_file" ]; then
chown $app: "$log_file"
fi
ynh_systemd_action --action=restart --service_name=fail2ban
ynh_systemctl --action=restart --service=fail2ban
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=3
ynh_script_progression "Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -1,42 +1,29 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
ynh_script_progression "Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
ynh_script_progression "Ensuring downward compatibility..."
#Store OS and machine (to be used in restore script)
if [ -z "${OS:+x}" ]; then
ynh_app_setting_-set --app="$app" --key=OS --value=`lowercase \`uname -s\``
ynh_app_setting_-set --key=OS --value=`lowercase \`uname -s\``
fi
if [ -z "${mach:+x}" ]; then
mach=`uname -m`
ynh_app_setting_set --app="$app" --key=mach --value="$mach"
ynh_app_setting_set --key=mach --value="$mach"
fi
#sudoer file for restarting is not required anymore (from 2023.1~ynh1) as upgrade is managed by the Yunohost Package
@ -51,26 +38,25 @@ if [ -z "$api_path" ]; then
else
api_path=/api_"$path"
fi
ynh_app_setting_set --app="$app" --key=api_path --value="$api_path"
ynh_app_setting_set --key=api_path --value="$api_path"
fi
#Previous version did not have settings stored and
#variable may not be bound.
if [[ -z "${mqtt_domain+x}" ]]; then
mqtt_domain="$domain"
ynh_app_setting_set --app="$app" --key=mqtt_domain --value="$mqtt_domain"
ynh_app_setting_set --key=mqtt_domain --value="$mqtt_domain"
fi
#remove unwanted log folder
if [ -d "/var/log/$app/$app" ]; then
ynh_secure_remove "/var/log/$app/$app"
ynh_safe_rm "/var/log/$app/$app"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Checking dedicated user permissions..."
ynh_script_progression "Checking dedicated user permissions..."
#allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus
if grep dialout -q < /etc/group; then
@ -87,9 +73,10 @@ fi
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
if ynh_app_upstream_version_changed
then
ynh_script_progression --message="Upgrading source files..." --weight=15
ynh_script_progression "Upgrading source files..."
ynh_setup_source --dest_dir="$install_dir"
#Create the database file
if [ ! -f "$install_dir"/domoticz.db ]; then
@ -98,29 +85,28 @@ then
fi
fi
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app":"$app" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app":"$app" "$install_dir"
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
if [ "$domain" != "$mqtt_domain" ]; then
ynh_script_progression --message="Setting up mosquitto..." --weight=5
ynh_script_progression "Setting up mosquitto..."
#Setting up conf file for access
if [ ! -f "/etc/mosquitto/conf.d/${app}_mosquitto.conf" ]
then
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/${app}_mosquitto.conf"
ynh_config_add --template="domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/${app}_mosquitto.conf"
chmod 644 /etc/mosquitto/conf.d/"$app"_mosquitto.conf
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app="$app" --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app="$app" --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app="$app" --key=mqtt_user):$(ynh_app_setting_get --app="$app" --key=mqtt_pwd) > "/etc/mosquitto/conf.d/${app}_credentials"
ynh_app_setting_set --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --key=mqtt_user):$(ynh_app_setting_get --key=mqtt_pwd) > "/etc/mosquitto/conf.d/${app}_credentials"
mosquitto_passwd -U "/etc/mosquitto/conf.d/${app}_credentials"
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
ynh_print_info "The credential to the mosquitto server has been saved in the settings of the app"
fi
else
#If no MQTT have been set, we delete the mqtt permission.
@ -130,50 +116,48 @@ fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
ynh_script_progression "Upgrading NGINX web server configuration..."
[[ "$domain" != "$mqtt_domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/${mqtt_domain}.d/mqtt_${app}.conf"
[[ "$domain" != "$mqtt_domain" ]] && ynh_config_add --template="mqtt_nginx.conf" --destination="/etc/nginx/conf.d/${mqtt_domain}.d/mqtt_${app}.conf"
#Set Hook for nginx domain
cp -R ../sources/hooks/conf_regen/95-nginx_domoticz /usr/share/yunohost/hooks/conf_regen/
# Create a dedicated NGINX config
if [[ ! -f "/etc/nginx/conf.d/${domain}.d/api_${app}.conf" ]]
then
ynh_print_warn --message="The nginx conf file will now be splitted between standard and api related path"
ynh_print_warn --message="Report any manual changes on the new /etc/nginx/conf.d/$domain.d/api_$app.conf file for json command to keep working"
ynh_add_config --template="api_nginx.conf" --destination="/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
fi
ynh_add_nginx_config
if [[ ! -f "/etc/nginx/conf.d/${domain}.d/api_${app}.conf" ]]
then
ynh_print_warn "The nginx conf file will now be splitted between standard and api related path"
ynh_print_warn "Report any manual changes on the new /etc/nginx/conf.d/$domain.d/api_$app.conf file for json command to keep working"
ynh_config_add --template="api_nginx.conf" --destination="/etc/nginx/conf.d/${domain}.d/api_${app}.conf"
fi
ynh_config_add_nginx
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
ynh_script_progression "Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
ynh_script_progression "Upgrading logrotate configuration..."
mkdir -p /var/log/"$app"
chown -R domoticz: /var/log/"$app"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R domoticz: /var/log/"$app"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --logfile="/var/log/$app" --non-append
[[ ! -z "$mqtt_domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto"
ynh_config_add_logrotate "/var/log/$app"
[[ ! -z "$mqtt_domain" ]] && ynh_config_add_logrotate "/var/log/mosquitto"
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=8
ynh_script_progression "Configuring Fail2Ban..."
# Make sure a log file exists (mostly for CI tests)
log_file=/var/log/$app/$app.log
@ -183,29 +167,28 @@ if [ ! -f "$log_file" ]; then
fi
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="$log_file" --failregex="^.*Error: Failed login attempt from <HOST>.*$" --max_retry=5
ynh_config_add_fail2ban --logpath="$log_file" --failregex="^.*Error: Failed login attempt from <HOST>.*$"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
[[ "$domain" != "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start"
ynh_systemctl --service="$app" --action="start"
#Restarting mosquitto to take changes from /etc/mosquitto/conf.d/*.conf into account
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart"
[[ "$domain" != "$mqtt_domain" ]] && ynh_systemctl --service=mosquitto --action="restart"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

View file

@ -1,31 +0,0 @@
--- a/www/index.html 2024-01-24 12:00:41.000000000 +0100
+++ b/www/index.html 2024-01-26 00:56:22.766868427 +0100
@@ -154,13 +154,14 @@
}
function ShowUpdateNotification(Revision, SystemName, DownloadURL) {
- var msgtxt=$.t('A new version of Domoticz is Available!...');
+ <!--var msgtxt=$.t('A new version of Domoticz is Available!...');-->
+ var msgtxt=$.t('A new version of Domoticz is Available, please wait for the YunoHost Package!...');
msgtxt+='<br>' + $.t('Version') + ': <b>' + Revision + '</b>, ' + $.t('Latest Changes') + ': <b><a class="norm-link" onclick="ShowLatestHistory();">' + $.t('Click Here') + '</a></b>';
if (SystemName=="windows") {
- msgtxt+='<br><center><a class="btn btn-danger" onclick="WindowsDownloadURL(\'' + DownloadURL + '\')">' + $.t('Update Now') + '</a></center>';
+<!-- msgtxt+='<br><center><a class="btn btn-danger" onclick="WindowsDownloadURL(\'' + DownloadURL + '\')">' + $.t('Update Now') + '</a></center>';-->
}
else {
- msgtxt+='<br><center><a class="btn btn-danger" onclick="SwitchLayout(\'Update\');">' + $.t('Update Now') + '</a></center>';
+<!-- msgtxt+='<br><center><a class="btn btn-danger" onclick="SwitchLayout(\'Update\');">' + $.t('Update Now') + '</a></center>';-->
}
generate_noty('success', msgtxt, false);
}
@@ -1264,8 +1265,8 @@
<li ng-class="{'current_page_item':getClass('/Users')}" id="mUsers"><a id="cUsers" href="#Users"><img src="images/users.png"> <span data-i18n="Users">Users</span></a></li>
<li ng-class="{'current_page_item':getClass('/Setup')}" id="mSetup"><a id="cSetup" href="#Setup"><img src="images/setup.png"> <span data-i18n="Settings">Settings</span></a></li>
<li id="dUpdate" class="divider"></li>
- <li ng-show="config.HaveUpdate && config.UseUpdate"><a href="#Update"><img src="images/update.png"> <span data-i18n="Update Domoticz">Update Domoticz</span></a></li>
- <li ng-show="!config.HaveUpdate && config.UseUpdate"><a class="lcursor" onclick="javascript:CheckForUpdate(true)"><img src="images/update.png"> <span data-i18n="Check for Update">Check for Update</span></a></li>
+<!-- <li ng-show="config.HaveUpdate && config.UseUpdate"><a href="#Update"><img src="images/update.png"> <span data-i18n="Update Domoticz">Update Domoticz</span></a></li>
+ <li ng-show="!config.HaveUpdate && config.UseUpdate"><a class="lcursor" onclick="javascript:CheckForUpdate(true)"><img src="images/update.png"> <span data-i18n="Check for Update">Check for Update</span></a></li>-->
<li class="dropdown-submenu">
<a id="cMoreOptions" tabindex="-1" data-i18n="More options">More options</a>
<ul class="dropdown-menu pull-left">