mirror of
https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git
synced 2023-10-10 13:37:40 +02:00
Install firmware from url
This commit is contained in:
parent
9a9457ee95
commit
98c23ccba0
@ -993,12 +993,16 @@ 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
|
||||
|
||||
if {$version == ""} {
|
||||
set image_file "${img_dir}/RaspberryMatic-${version}.img"
|
||||
set download_url ""
|
||||
} 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} {
|
||||
@ -1006,6 +1010,7 @@ proc ::rmupdate::download_firmware {version} {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if {$download_url == ""} {
|
||||
error [format [i18n "Failed to find download link for firmware %s."] $version]
|
||||
}
|
||||
@ -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
|
||||
if {$lang != ""} {
|
||||
set language $lang
|
||||
}
|
||||
if {[get_running_installation] != ""} {
|
||||
error [i18n "Another install process is running."]
|
||||
}
|
||||
@ -1184,10 +1194,12 @@ proc ::rmupdate::install_firmware_version {version lang {reboot 1} {keep_downloa
|
||||
error [i18n "System not upgradeable."]
|
||||
}
|
||||
|
||||
set_running_installation "Firmware ${version}"
|
||||
|
||||
set firmware_image ""
|
||||
|
||||
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} {
|
||||
@ -1195,8 +1207,10 @@ proc ::rmupdate::install_firmware_version {version lang {reboot 1} {keep_downloa
|
||||
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 {} {
|
||||
|
@ -116,6 +116,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
);
|
||||
}
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
var reboot = $('#reboot-after-install').is(':checked');
|
||||
var keep_download = ! $('#delete-download-after-install').is(':checked');
|
||||
var dryrun = $('#dryrun').is(':checked');
|
||||
if (version) {
|
||||
set_running_installation("Firmware " + version);
|
||||
rest("POST", "/start_install_firmware", JSON.stringify({"language": language, "version":version, "reboot":reboot, "dryrun":dryrun, "keep_download": keep_download}),
|
||||
}
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
var disabled = ((fw.image || fw.url) && fw.supported ? '' : 'disabled');
|
||||
var binstall = $('<div class="ui '+ color +' basic '+ disabled +' button">').attr('data-install-firmware-version', fw.version).append($('<i class="sign in icon">'), 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 <http://www.gnu.org/licenses/>.
|
||||
$('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 <http://www.gnu.org/licenses/>.
|
||||
<div id="dimmer-firmware-info" class="ui active inverted dimmer">
|
||||
<div class="ui loader" data-i18n="loading"></div>
|
||||
</div>
|
||||
<div style="width: 100%" class="ui action input">
|
||||
<input id="install-firmware-url-input" type="text" placeholder="http://.../RaspberryMatic.zip"/>
|
||||
<button id="install-firmware-url-button" class="ui green right labeled icon button" onclick="install_firmware($('#install-firmware-url-input').val());">
|
||||
<i class="sign in icon"></i>
|
||||
install
|
||||
</button>
|
||||
</div>
|
||||
<table id="firmware-info" class="ui celled stackable table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -70,12 +70,12 @@ 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"
|
||||
}
|
||||
@ -100,10 +100,7 @@ proc process {} {
|
||||
} else {
|
||||
set keep_download 0
|
||||
}
|
||||
return "\"[rmupdate::install_firmware_version $version $lang $reboot $keep_download $dryrun]\""
|
||||
} else {
|
||||
error "Invalid version: ${data}"
|
||||
}
|
||||
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] } {
|
||||
|
Loading…
Reference in New Issue
Block a user