mirror of
https://github.com/YunoHost-Apps/domoticz_ynh.git
synced 2024-09-03 18:26:17 +02:00
rationnalize variable management & mqtt settings
This commit is contained in:
parent
5f9a9d213b
commit
c6d7084421
4 changed files with 47 additions and 35 deletions
|
@ -15,7 +15,7 @@ lowercase(){
|
|||
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
|
||||
}
|
||||
|
||||
os=`lowercase \`uname -s\``
|
||||
OS=`lowercase \`uname -s\``
|
||||
mach=`uname -m`
|
||||
if [ ${mach} = "armv6l" ]
|
||||
then
|
||||
|
|
|
@ -10,32 +10,30 @@ source _common.sh
|
|||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
# STORE SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Storing installation settings..."
|
||||
|
||||
#Will be used in restore script to check that we're restoring on the same OS/Board type
|
||||
ynh_app_setting_set --app="$app" --key=OS --value="$OS"
|
||||
ynh_app_setting_set --app="$app" --key=mach --value="$mach"
|
||||
|
||||
#Settings for mosquitto. We store empty values so that they may be automatically retrieved and bound in other scripts.
|
||||
if [ "$domain" == "$mqtt_domain" ]; then
|
||||
mqtt_domain=""
|
||||
#packaging v2 : settings are automatically stored. We overide the values
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_domain --value="$mqtt_domain"
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_port --value=""
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value=""
|
||||
fi
|
||||
|
||||
#path used by api to read/update domoticz
|
||||
#Set dedicated variables
|
||||
if [ "$path" == "/" ]; then
|
||||
api_path=/api_/"$app"
|
||||
else
|
||||
api_path=/api_"$path"
|
||||
fi
|
||||
|
||||
if [ "$domain" == "$mqtt_domain" ]; then
|
||||
mqtt_domain=""
|
||||
#pacakging v2 : settings are automatically stored. We don't want mqtt_domain in this case
|
||||
ynh_app_setting_delete --app="$app" --key=mqtt_domain
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Storing installation settings..."
|
||||
|
||||
#Will be used in restore script to check that we're restoring on the same OS/Board type
|
||||
ynh_app_setting_set --app="$app" --key=OS --value="$os"
|
||||
ynh_app_setting_set --app="$app" --key=mach --value="$mach"
|
||||
|
||||
#path used by api to read/update domoticz
|
||||
ynh_app_setting_set --app="$app" --key=api_path --value="$api_path"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -11,8 +11,8 @@ source ../settings/scripts/_common.sh
|
|||
source /usr/share/yunohost/helpers
|
||||
|
||||
#Have to reload them as otherwise they are all the same
|
||||
backup_OS=$(ynh_app_setting_get --app="$app" --key=OS)
|
||||
backup_mach=$(ynh_app_setting_get --app="$app" --key=mach)
|
||||
#backup_OS=$(ynh_app_setting_get --app="$app" --key=OS)
|
||||
#backup_mach=$(ynh_app_setting_get --app="$app" --key=mach)
|
||||
current_os=`lowercase \`uname -s\``
|
||||
current_mach=`uname -m`
|
||||
|
||||
|
@ -22,11 +22,14 @@ current_mach=`uname -m`
|
|||
#As we are downloading compiled binaries for each system, we have to check if the restore occurs
|
||||
#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 "$backup_OS" = "$current_os" \
|
||||
test "$OS" = "$current_os" \
|
||||
|| ynh_die --message="Cannot restore : previous OS is $backup_OS, current OS is $current_os, please reinstall"
|
||||
test "$backup_mach" = "$current_mach" \
|
||||
test "$mach" = "$current_mach" \
|
||||
|| ynh_die --message="Cannot restore : previous machine type is $backup_mach, current machine type is $current_mach, please reinstall"
|
||||
|
||||
ynh_app_setting_set --app="$app" --key=OS --value="$OS"
|
||||
ynh_app_setting_set --app="$app" --key=mach --value="$mach"
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
|
|
|
@ -13,12 +13,6 @@ version_gt() {
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
current_OS=$(ynh_app_setting_get --app="$app" --key=OS)
|
||||
current_mach=$(ynh_app_setting_get --app="$app" --key=mach)
|
||||
mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain)
|
||||
mqtt_port=$(ynh_app_setting_get --app="$app" --key=mqtt_port)
|
||||
mqtt_websocket_port=$(ynh_app_setting_get --app="$app" --key=mqtt_websocket_port)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
#=================================================
|
||||
|
@ -41,10 +35,10 @@ ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$a
|
|||
ynh_script_progression --message="Ensuring downward compatibility..."
|
||||
|
||||
#Store OS and machine (to be used in restore script)
|
||||
if [ -z "$current_OS" ]; then
|
||||
if [ -z "$OS" ]; then
|
||||
ynh_app_setting_set --app="$app" --key=OS --value="$OS"
|
||||
fi
|
||||
if [ -z "$current_mach" ]; then
|
||||
if [ -z "$mach" ]; then
|
||||
ynh_app_setting_set --app="$app" --key=mach --value="$MACH"
|
||||
fi
|
||||
|
||||
|
@ -63,24 +57,41 @@ if [ -z "$api_path" ]; then
|
|||
ynh_app_setting_set --app="$app" --key=api_path --value="$api_path"
|
||||
fi
|
||||
|
||||
#Need to be kept for backward compatibility : previous version did not have settings stored and
|
||||
#variable may not be bound.
|
||||
mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain)
|
||||
if [[ -z "$mqtt_domain" ]]; then
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_domain --value="$mqtt_domain"
|
||||
fi
|
||||
|
||||
#Port to listen for MQTT internal
|
||||
#first we read from manifest to ensure variable is bound
|
||||
mqtt_port=$(ynh_app_setting_get --app="$app" --key=mqtt_port)
|
||||
#then we store the setting in the manifest so it is automatically loaded for other scritps
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_port --value="$mqtt_port"
|
||||
#then if a domain has been provided (manually for example to install mosquitto afterward), we assign a port in case it is empty.
|
||||
if [[ -z "$mqtt_port" && ! -z "$mqtt_domain" ]]; then
|
||||
mqtt_port=$(ynh_find_port --port="$default_mqtt_port")
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_port --value="$mqtt_port"
|
||||
fi
|
||||
|
||||
#Port to listen for MQTT websocket
|
||||
#first we read from manifest to ensure variable is bound
|
||||
mqtt_websocket_port=$(ynh_app_setting_get --app="$app" --key=mqtt_websocket_port)
|
||||
#then we store the setting in the manifest so it is automatically loaded for other scritps
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port"
|
||||
#then if a domain has been provided (manually for example to install mosquitto afterward), we assign a port in case it is empty.
|
||||
if [[ -z "$mqtt_websocket_port" && ! -z "$mqtt_domain" ]]; then
|
||||
mqtt_websocket_port=$(ynh_find_port --port="$default_mqtt_websocket_port")
|
||||
ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port"
|
||||
fi
|
||||
|
||||
# Create the permission "domoticz_API" only if it doesn't exist.
|
||||
if ! ynh_permission_exists --permission="domoticz_API"
|
||||
then
|
||||
#if ! ynh_permission_exists --permission="domoticz_API"
|
||||
#then
|
||||
# API Authorization with dedicated URL
|
||||
ynh_permission_create --permission="domoticz_API" --label="api" --url="$domain$api_path" --allowed="visitors" --show_tile="false" --protected="true"
|
||||
fi
|
||||
# ynh_permission_create --permission="domoticz_API" --label="api" --url="$domain$api_path" --allowed="visitors" --show_tile="false" --protected="true"
|
||||
#fi
|
||||
|
||||
# Create the permission "domoticz_MQTT" only if it doesn't exist.
|
||||
if [ ! -z "$mqtt_domain" ]; then
|
||||
|
|
Loading…
Add table
Reference in a new issue