From 98c23ccba0e933dc5c3e1fca46659c02d9d81783 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 21 Mar 2018 00:14:13 +0100 Subject: [PATCH] Install firmware from url --- addon/lib/rmupdate.tcl | 55 +++++++++++++++++++++++++++--------------- addon/www/index.html | 28 +++++++++++++++++---- addon/www/rest.cgi | 55 ++++++++++++++++++++---------------------- 3 files changed, 84 insertions(+), 54 deletions(-) diff --git a/addon/lib/rmupdate.tcl b/addon/lib/rmupdate.tcl index 09534a2..5a3e455 100644 --- a/addon/lib/rmupdate.tcl +++ b/addon/lib/rmupdate.tcl @@ -993,17 +993,22 @@ proc ::rmupdate::get_latest_firmware_version {} { return [lindex $versions 0] } -proc ::rmupdate::download_firmware {version} { +proc ::rmupdate::download_firmware {{download_url ""} {version ""}} { variable img_dir variable install_log - set image_file "${img_dir}/RaspberryMatic-${version}.img" - set download_url "" - foreach e [get_available_firmware_downloads] { - set v [get_version_from_filename $e] - if {$v == $version} { - set download_url $e - break + if {$version == ""} { + set image_file "${img_dir}/RaspberryMatic-${version}.img" + } else { + set image_file "${img_dir}/RaspberryMatic-unknown.img" + } + if {$download_url == ""} { + foreach e [get_available_firmware_downloads] { + set v [get_version_from_filename $e] + if {$v == $version} { + set download_url $e + break + } } } if {$download_url == ""} { @@ -1038,6 +1043,9 @@ proc ::rmupdate::download_firmware {version} { exec /usr/bin/unzip "${archive_file}" "${img_file}" -o -d "${img_dir}" 2>/dev/null set img_file "${img_dir}/${img_file}" #puts "${img_file} ${image_file}" + if {$version == ""} { + set image_file $img_file + } if {$img_file != $image_file} { file rename $img_file $image_file } @@ -1174,9 +1182,11 @@ proc ::rmupdate::delete_firmware_image {version} { catch { eval {file delete [glob "${img_dir}/*${version}*.zip"]} } } -proc ::rmupdate::install_firmware_version {version lang {reboot 1} {keep_download 0} {dryrun 0}} { +proc ::rmupdate::install_firmware {{download_url ""} {version ""} {lang ""} {reboot 1} {keep_download 0} {dryrun 0}} { variable language - set language $lang + if {$lang != ""} { + set language $lang + } if {[get_running_installation] != ""} { error [i18n "Another install process is running."] } @@ -1184,19 +1194,23 @@ proc ::rmupdate::install_firmware_version {version lang {reboot 1} {keep_downloa error [i18n "System not upgradeable."] } - set_running_installation "Firmware ${version}" - set firmware_image "" - - foreach e [get_available_firmware_images] { - set v [get_version_from_filename $e] - if {$v == $version} { - set firmware_image $e - break + if {$version == ""} { + set_running_installation "Firmware unknown" + set keep_download 0 + } else { + set_running_installation "Firmware ${version}" + foreach e [get_available_firmware_images] { + set v [get_version_from_filename $e] + if {$v == $version} { + set firmware_image $e + break + } } } + if {$firmware_image == ""} { - set firmware_image [download_firmware $version] + set firmware_image [download_firmware $download_url $version] } get_system_device @@ -1221,8 +1235,9 @@ proc ::rmupdate::install_firmware_version {version lang {reboot 1} {keep_downloa } proc ::rmupdate::install_latest_version {{reboot 1} {dryrun 0}} { + variable language set latest_version [get_latest_firmware_version] - return install_firmware_version $latest_version $reboot $dryrun + return install_firmware "" $latest_version $language $reboot $dryrun } proc ::rmupdate::is_firmware_up_to_date {} { diff --git a/addon/www/index.html b/addon/www/index.html index cd2b248..a88abfe 100644 --- a/addon/www/index.html +++ b/addon/www/index.html @@ -116,6 +116,7 @@ along with this program. If not, see . function disable_buttons() { $('#install-latest-firmware-button').addClass('disabled'); + $('#install-firmware-url-button').addClass('disabled'); $('[data-install-firmware-version]').addClass('disabled'); $('[data-delete-firmware-version]').addClass('disabled'); $('[data-update-addon-id]').addClass('disabled'); @@ -127,6 +128,8 @@ along with this program. If not, see . function reset_buttons() { $('#install-latest-firmware-button').removeClass('loading'); $('#install-latest-firmware-button').removeClass('disabled'); + $('#install-firmware-url-button').removeClass('loading'); + $('#install-firmware-url-button').removeClass('disabled'); $('[data-install-firmware-version]').removeClass('loading'); $('[data-install-firmware-version]').removeClass('disabled'); $('[data-delete-firmware-version]').removeClass('disabled'); @@ -212,7 +215,7 @@ along with this program. If not, see . ); } - function install_firmware(version) { + function install_firmware(download_url, version) { $('#log-content').html(''); $('#install-progress').progress("reset"); $('#modal-log').modal('show'); @@ -220,8 +223,15 @@ along with this program. If not, see . var reboot = $('#reboot-after-install').is(':checked'); var keep_download = ! $('#delete-download-after-install').is(':checked'); var dryrun = $('#dryrun').is(':checked'); - set_running_installation("Firmware " + version); - rest("POST", "/start_install_firmware", JSON.stringify({"language": language, "version":version, "reboot":reboot, "dryrun":dryrun, "keep_download": keep_download}), + if (version) { + set_running_installation("Firmware " + version); + } + else { + set_running_installation("Firmware unknown"); + } + if (!download_url) download_url = ""; + if (!version) version = ""; + rest("POST", "/start_install_firmware", JSON.stringify({"download_url": download_url, "version":version, "language": language, "reboot":reboot, "dryrun":dryrun, "keep_download": keep_download}), function(data) { // We are not expecting a response }, @@ -237,7 +247,7 @@ along with this program. If not, see . function install_latest_firmware() { if (latest_firmware && latest_firmware != '?') { - install_firmware(latest_firmware); + install_firmware(null, latest_firmware); } } @@ -258,7 +268,7 @@ along with this program. If not, see . var disabled = ((fw.image || fw.url) && fw.supported ? '' : 'disabled'); var binstall = $('
').attr('data-install-firmware-version', fw.version).append($(''), i18next.t('install')); binstall.click(function() { - install_firmware(this.getAttribute('data-install-firmware-version')); + install_firmware(null, this.getAttribute('data-install-firmware-version')); }); var bcls = ''; if (!fw.image) bcls = 'disabled'; @@ -808,6 +818,7 @@ along with this program. If not, see . $('th').localize(); $('label').localize(); $('#install-addon-url-button').contents().last()[0].textContent = i18next.t('install'); + $('#install-firmware-url-button').contents().last()[0].textContent = i18next.t('install'); $('#install-addon-file-button').contents().last()[0].textContent = i18next.t('choose_addon_file'); }); var form_config = { @@ -914,6 +925,13 @@ along with this program. If not, see .
+
+ + +
diff --git a/addon/www/rest.cgi b/addon/www/rest.cgi index ac8f30f..574c488 100644 --- a/addon/www/rest.cgi +++ b/addon/www/rest.cgi @@ -70,40 +70,37 @@ proc process {} { } elseif {[lindex $path 1] == "get_addon_info"} { return [rmupdate::get_addon_info 1 1 1] } elseif {[lindex $path 1] == "start_install_firmware"} { - regexp {\"version\"\s*:\s*\"([\d\.]+)\"} $data match version + regexp {\"download_url\"\s*:\s*\"([^\"]*)\"} $data match download_url + regexp {\"version\"\s*:\s*\"([\d\.]*)\"} $data match version regexp {\"language\"\s*:\s*\"([^\"]+)\"} $data match lang regexp {\"reboot\"\s*:\s*(true|false)} $data match reboot regexp {\"dryrun\"\s*:\s*(true|false)} $data match dryrun regexp {\"keep_download\"\s*:\s*(true|false)} $data match keep_download - if { [info exists version] && $version != "" } { - if { ![info exists reboot] } { - set reboot "true" - } - if {$reboot == "true"} { - set reboot 1 - } else { - set reboot 0 - } - if { ![info exists dryrun] } { - set dryrun "false" - } - if {$dryrun == "true"} { - set dryrun 1 - } else { - set dryrun 0 - } - if { ![info exists keep_download] } { - set keep_download "false" - } - if {$keep_download == "true"} { - set keep_download 1 - } else { - set keep_download 0 - } - return "\"[rmupdate::install_firmware_version $version $lang $reboot $keep_download $dryrun]\"" - } else { - error "Invalid version: ${data}" + if { ![info exists reboot] } { + set reboot "true" } + if {$reboot == "true"} { + set reboot 1 + } else { + set reboot 0 + } + if { ![info exists dryrun] } { + set dryrun "false" + } + if {$dryrun == "true"} { + set dryrun 1 + } else { + set dryrun 0 + } + if { ![info exists keep_download] } { + set keep_download "false" + } + if {$keep_download == "true"} { + set keep_download 1 + } else { + set keep_download 0 + } + return "\"[rmupdate::install_firmware $download_url $version $lang $reboot $keep_download $dryrun]\"" } elseif {[lindex $path 1] == "install_addon"} { regexp {\"addon_id\"\s*:\s*\"([^\"]+)\"} $data match addon_id if { ![info exists addon_id] } {