diff --git a/scripts/install b/scripts/install
index 9b756f1..4f01c0d 100755
--- a/scripts/install
+++ b/scripts/install
@@ -47,9 +47,13 @@ ynh_script_progression --message="Storing installation settings..." --weight=1
 
 ynh_app_setting_set --app=$app --key=domain --value=$domain
 ynh_app_setting_set --app=$app --key=path --value=$path_url
-#ynh_app_setting_set --app=$app --key=admin --value=$admin
 ynh_app_setting_set --app=$app --key=is_public --value=$is_public
 
+#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
+
+
 #=================================================
 # STANDARD MODIFICATIONS
 #=================================================
@@ -176,7 +180,7 @@ ynh_script_progression --message="Configuring SSOwat..." --weight=1
 if [ $is_public -eq 1 ]
 then
 	# unprotected_uris allows SSO credentials to be passed anyway.
-	ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
+	ynh_permission_update --permission "main" --add visitors
 fi
 
 #=================================================
diff --git a/scripts/restore b/scripts/restore
index f02199d..bc8cfdc 100755
--- a/scripts/restore
+++ b/scripts/restore
@@ -31,6 +31,8 @@ app=$YNH_APP_INSTANCE_NAME
 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)
+backup_OS=$(ynh_app_setting_get --app=$app --key=OS)
+backup_mach=$(ynh_app_setting_get --app=$app --key=mach)
 
 #=================================================
 # CHECK IF THE APP CAN BE RESTORED
@@ -41,6 +43,10 @@ ynh_webpath_available --domain=$domain --path_url=$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 "
+test "$backup_OS" = "$OS" \
+	|| ynh_die --message="Cannot restore : previous OS is $backup_OS, current OS is $OS, please reinstall"
+test "$backup_mach" = "$MACH" \
+	|| ynh_die --message="Cannot restore : previous machine type is $backup_mach, current machine type is $MACH, please reinstall"
 
 #=================================================
 # STANDARD RESTORATION STEPS
diff --git a/scripts/upgrade b/scripts/upgrade
index 1b6a6e1..6c6a227 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -1,5 +1,9 @@
 #!/bin/bash
 
+version_gt() { 
+	test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
+}
+
 #=================================================
 # GENERIC START
 #=================================================
@@ -40,6 +44,7 @@ upgrade_type=$(ynh_check_app_version_changed)
 #=================================================
 ynh_script_progression --message="Ensuring downward compatibility..."
 
+
 # Fix is_public as a boolean value
 if [ "$is_public" = "Yes" ]; then
 	ynh_app_setting_set --app=$app --key=is_public --value=1
@@ -47,6 +52,11 @@ if [ "$is_public" = "Yes" ]; then
 elif [ "$is_public" = "No" ]; then
 	ynh_app_setting_set --app=$app --key=is_public --value=0
 	is_public=0
+#Previous domoticz version did not have public/private settings 
+elif [ -z "is_public" ]; then
+	ynh_app_setting_set --app=$app --key=is_public --value=1
+	is_public=1
+	ynh_print_warn --message="Application is set as public, if you require to set it as private, please use the authorization config panel in Users/Manage Groups and permissions"
 fi
 
 
@@ -61,12 +71,25 @@ fi
 #=================================================
 ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10
 
+#ugly hack so that existing backup for previous version work
+current_upstream_version=$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$app/manifest.json")
+current_package_version=$(ynh_app_package_version --manifest="/etc/yunohost/apps/$app/manifest.json")
+if version_gt "4.9701" "$current_upstream_version" && version_gt "2" $current_package_version ; then
+	touch /etc/cron.d/$app
+fi
+
 # Backup the current version of the app
 ynh_backup_before_upgrade
 ynh_clean_setup () {
 	# restore it if the upgrade fails
 	ynh_restore_upgradebackup
 }
+
+#remove ugly hack
+if [ -f /etc/cron.d/$app ]; then
+	rm /etc/cron.d/$app
+fi
+
 # Exit if an error occurs during the execution of the script
 ynh_abort_if_errors
 
@@ -74,6 +97,7 @@ ynh_abort_if_errors
 # CHECK THE PATH
 #=================================================
 
+
 # Normalize the URL path syntax
 # N.B. : this is for app installations before YunoHost 2.7
 # where this value might be something like /foo/ or foo/
@@ -217,7 +241,7 @@ ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
 if [ $is_public -eq 1 ]
 then
 	# unprotected_uris allows SSO credentials to be passed anyway
-	ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
+	ynh_permission_update --permission "main" --add visitors
 fi
 
 #=================================================
@@ -227,8 +251,13 @@ 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="Upgrade of $app completed" --last