1
0
mirror of https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git synced 2023-10-10 13:37:40 +02:00

Implement addon update

This commit is contained in:
Jan Schneider 2018-01-21 01:47:07 +01:00
parent da1c9df9e4
commit fb7122669d
3 changed files with 174 additions and 87 deletions

View File

@ -29,7 +29,7 @@ namespace eval rmupdate {
variable install_log "/usr/local/addons/rmupdate/var/install.log" variable install_log "/usr/local/addons/rmupdate/var/install.log"
variable install_lock "/usr/local/addons/rmupdate/var/install.lock" variable install_lock "/usr/local/addons/rmupdate/var/install.lock"
variable log_file "/tmp/rmupdate-addon-log.txt" variable log_file "/tmp/rmupdate-addon-log.txt"
variable log_level 0 variable log_level 4
variable lock_start_port 12100 variable lock_start_port 12100
variable lock_socket variable lock_socket
variable lock_id_log_file 1 variable lock_id_log_file 1
@ -510,7 +510,6 @@ proc ::rmupdate::get_latest_firmware_version {} {
proc ::rmupdate::download_firmware {version} { proc ::rmupdate::download_firmware {version} {
variable img_dir variable img_dir
variable log_file
variable install_log variable install_log
set image_file "${img_dir}/RaspberryMatic-${version}.img" set image_file "${img_dir}/RaspberryMatic-${version}.img"
@ -529,7 +528,7 @@ proc ::rmupdate::download_firmware {version} {
regexp {/([^/]+)$} $download_url match archive_file regexp {/([^/]+)$} $download_url match archive_file
set archive_file "${img_dir}/${archive_file}" set archive_file "${img_dir}/${archive_file}"
file mkdir $img_dir file mkdir $img_dir
if {$log_file != ""} { if {$install_log != ""} {
exec /usr/bin/wget "${download_url}" --show-progress --progress=dot:giga --no-check-certificate --quiet --output-document=$archive_file 2>>${install_log} exec /usr/bin/wget "${download_url}" --show-progress --progress=dot:giga --no-check-certificate --quiet --output-document=$archive_file 2>>${install_log}
write_install_log "" write_install_log ""
} else { } else {
@ -733,7 +732,7 @@ proc ::rmupdate::is_firmware_up_to_date {} {
return 0 return 0
} }
proc ::rmupdate::get_addon_info {{fetch_available_versions 0} {fetch_download_url 0} {as_json 0}} { proc ::rmupdate::get_addon_info {{fetch_available_version 0} {fetch_download_url 0} {as_json 0} {addon_id ""}} {
variable rc_dir variable rc_dir
variable addons_www_dir variable addons_www_dir
array set addons {} array set addons {}
@ -741,6 +740,9 @@ proc ::rmupdate::get_addon_info {{fetch_available_versions 0} {fetch_download_ur
catch { catch {
set data [exec $f info] set data [exec $f info]
set id [file tail $f] set id [file tail $f]
if {$addon_id != "" && $addon_id != $id} {
continue
}
set addons(${id}::id) $id set addons(${id}::id) $id
set addons(${id}::name) "" set addons(${id}::name) ""
set addons(${id}::version) "" set addons(${id}::version) ""
@ -757,7 +759,7 @@ proc ::rmupdate::get_addon_info {{fetch_available_versions 0} {fetch_download_ur
set keyl "config_url" set keyl "config_url"
} }
set addons(${id}::${keyl}) $value set addons(${id}::${keyl}) $value
if {$keyl == "update" && $fetch_available_versions == 1} { if {$keyl == "update" && $fetch_available_version == 1} {
catch { catch {
set cgi "${addons_www_dir}/[string range $value 8 end]" set cgi "${addons_www_dir}/[string range $value 8 end]"
set available_version [exec tclsh "$cgi"] set available_version [exec tclsh "$cgi"]
@ -914,6 +916,59 @@ proc ::rmupdate::get_addon_info {{fetch_available_versions 0} {fetch_download_ur
} }
} }
proc ::rmupdate::install_addon {addon_id} {
variable rc_dir
if {[get_running_installation] != ""} {
error "Another install process is running."
}
set_running_installation "Addon ${addon_id}"
array set addon [get_addon_info 1 1 0 $addon_id]
set download_url $addon(${addon_id}::download_url)
write_log 3 "Downloading addon from ${download_url}."
regexp {/([^/]+)$} $download_url match archive_file
set archive_file "/tmp/${archive_file}"
if {[file exists $archive_file]} {
file delete $archive_file
}
exec /usr/bin/wget "${download_url}" --no-check-certificate --quiet --output-document=$archive_file
write_log 3 "Extracting archive ${archive_file}."
set tmp_dir "/tmp/rmupdate_addon_install_${addon_id}"
if {[file exists $tmp_dir]} {
file delete -force $tmp_dir
}
file mkdir $tmp_dir
cd $tmp_dir
exec /bin/tar xzvf "${archive_file}"
write_log 3 "Running update_script"
file attributes update_script -permissions 0755
exec ./update_script noreboot
cd /tmp
file delete -force $tmp_dir
file delete $archive_file
write_log 3 "Restarting addon"
if { [catch {
exec "${rc_dir}/${addon_id}" restart
} errormsg] } {
write_log 2 "Addon restart failed: ${errormsg}"
}
write_log 3 "Addon ${addon_id} successfully installed"
set_running_installation ""
return "Addon ${addon_id} successfully installed"
}
#puts [rmupdate::get_latest_firmware_version] #puts [rmupdate::get_latest_firmware_version]
#puts [rmupdate::get_firmware_info] #puts [rmupdate::get_firmware_info]

View File

@ -143,7 +143,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// We are not expecting a response // We are not expecting a response
}, },
function(xhr, ajaxOptions, thrownError) { function(xhr, ajaxOptions, thrownError) {
console.error("Firmware installation error.") console.error("Firmware installation error: " + thrownError + ": " + xhr.responseText);
$('[data-install-firmware-version="' + running_installation + '"]').removeClass('loading'); $('[data-install-firmware-version="' + running_installation + '"]').removeClass('loading');
//$('#modal-log').modal('hide'); //$('#modal-log').modal('hide');
if (running_installation) { if (running_installation) {
@ -164,8 +164,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} }
function get_firmware_info() { function get_firmware_info() {
$('#dimmer-firmware-info').addClass('active');
rest("GET", "/get_firmware_info", null, function(data) { rest("GET", "/get_firmware_info", null, function(data) {
$('#firmware_info tbody').empty(); $('#firmware-info tbody').empty();
data.forEach(function(fw) { data.forEach(function(fw) {
if (fw.latest) latest_firmware = fw.version; if (fw.latest) latest_firmware = fw.version;
if (fw.installed) current_firmware = fw.version; if (fw.installed) current_firmware = fw.version;
@ -190,7 +191,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var cls = ''; var cls = '';
if (fw.installed) cls = ' class="warning"'; if (fw.installed) cls = ' class="warning"';
if (fw.latest) cls = ' class="positive"'; if (fw.latest) cls = ' class="positive"';
$("#firmware_info tbody").append($('<tr' + cls + '>').append( $("#firmware-info tbody").append($('<tr' + cls + '>').append(
$('<td>').append($('<a>', {text: fw.version, title: 'Open release info', href: fw.info_url, target: "_blank"})), $('<td>').append($('<a>', {text: fw.version, title: 'Open release info', href: fw.info_url, target: "_blank"})),
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+available+'>'),$('<label></label>'))), $('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+available+'>'),$('<label></label>'))),
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+downloaded+'>'),$('<label></label>'))), $('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+downloaded+'>'),$('<label></label>'))),
@ -215,6 +216,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
rest("GET", "/get_running_installation", null, function(installation_info) { rest("GET", "/get_running_installation", null, function(installation_info) {
set_running_installation(installation_info); set_running_installation(installation_info);
}); });
$('#dimmer-firmware-info').removeClass('active');
}); });
} }
@ -227,55 +229,69 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}); });
} }
function install_addon(addon_id) {
if (!running_installation) {
display_message('info', 'Installing addon ' + addon_id + '.', 6000000);
$('[data-update-addon-id="' + addon_id + '"]').addClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').addClass('disabled');
rest("POST", "/install_addon", JSON.stringify({"addon_id":addon_id}),
function(data) {
//console.info(data);
$('[data-update-addon-id="' + addon_id + '"]').removeClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled');
$('#tr-' + addon_id).removeClass('warning');
$('#tr-' + addon_id).addClass('positive');
$('#button-update-' + addon_id).removeClass('green');
$('#button-update-' + addon_id).addClass('gray');
$('#label-version-' + addon_id).text($('#label-available-version-' + addon_id).text());
display_message('success', data, 6000000);
},
function(xhr, ajaxOptions, thrownError) {
console.error("Addon installation error: " + thrownError + ": " + xhr.responseText);
$('[data-update-addon-id="' + addon_id + '"]').removeClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled');
default_error_callback(xhr, ajaxOptions, thrownError);
}
);
}
}
function get_addon_info() { function get_addon_info() {
$('#dimmer-addon-info').addClass('active');
rest("GET", "/get_addon_info", null, function(data) { rest("GET", "/get_addon_info", null, function(data) {
$('#addon_info tbody').empty(); $('#addon-info tbody').empty();
data.forEach(function(addon) { data.forEach(function(addon) {
//if (fw.latest) latest_firmware = fw.version; var color = 'gray';
//if (fw.installed) current_firmware = fw.version; if (addon.available_version && (addon.version != addon.available_version)) color = 'green';
//var color = 'yellow';
//if (fw.latest) color = 'green'; var disabled = ((addon.available_version && addon.download_url) ? '' : 'disabled');
//if (fw.installed) color = 'gray'; var bupdate = $('<div class="ui '+ color +' basic '+ disabled +' button" id="button-update-' + addon.id + '">')
//var disabled = (fw.image || fw.url ? '' : 'disabled'); .attr('data-update-addon-id', addon.id)
//var binstall = $('<div class="ui '+ color +' basic '+ disabled +' button">').attr('data-install-firmware-version', fw.version).append($('<i class="sign in icon">'), 'install'); .attr('data-update-addon-available-version', addon.available_version)
//binstall.click(function() { .append($('<i class="sign in icon">'), 'update');
// install_firmware(this.getAttribute('data-install-firmware-version')); bupdate.click(function() {
//}); install_addon(this.getAttribute('data-update-addon-id'));
//var bcls = ''; });
//if (!fw.image) bcls = 'disabled';
//if (fw.version == running_installation) bcls = 'loading'; disabled = ((addon.config_url) ? '' : 'disabled');
//var bdelete = $('<div class="ui orange basic '+ bcls +' button">').attr('data-delete-version', fw.version).append($('<i class="delete icon">'), 'delete download'); var bconfig = $('<div class="ui blue basic '+ disabled +' button">')
//bdelete.click(function() { .attr('data-addon-config-url', addon.config_url)
// delete_firmware_image(this.getAttribute('data-delete-version')); .append($('<i class="setting icon">'), 'open config');
//}); bconfig.click(function() {
// var win = window.open(this.getAttribute('data-addon-config-url'), '_blank');
//var available = (fw.url ? 'checked=""' : '') win.focus();
//var downloaded = (fw.image ? 'checked=""' : '') });
//var cls = '';
//if (fw.installed) cls = ' class="warning"'; var cls = (((!addon.available_version) || (addon.version == addon.available_version)) ? "positive" : "warning");
//if (fw.latest) cls = ' class="positive"'; var available_version = ((addon.available_version) ? addon.available_version : "?");
var cls = ' class="positive"'; $("#addon-info tbody").append($('<tr class="' + cls + '" id="tr-' + addon.id + '">').append(
$("#addon_info tbody").append($('<tr' + cls + '>').append(
$('<td>').append($('<label>' + addon.name + '</label>')), $('<td>').append($('<label>' + addon.name + '</label>')),
$('<td>').append($('<label>' + addon.version + '</label>')), $('<td>').append($('<label id="label-version-' + addon.id + '">' + addon.version + '</label>')),
$('<td>').append($('<label>' + addon.available_version + '</label>')), $('<td>').append($('<label id="label-available-version-' + addon.id + '">' + available_version + '</label>')),
$('<td>').append($('<label>' + addon.download_url + '</label>')) $('<td class="center aligned">').append(bupdate, bconfig)
)); ));
}); });
//var color = "#d01919"; $('#dimmer-addon-info').removeClass('active');
//if (current_firmware == latest_firmware) {
// color = "#21BA45";
//}
//$("#firmware-summary").empty();
//$("#firmware-summary").append(
// $('<div class="sub header">').html('Current installed version: <span style="color:'+ color +'">' + current_firmware + '</span>'),
// $('<div class="sub header">').html('Latest available version: ' + latest_firmware)
//);
//if (current_firmware != latest_firmware) {
// $("#firmware-summary").append(
// $('<div class="ui green basic button" style="margin-top:20px; margin-bottom:20px;">').click(install_latest_firmware).append($('<i class="sign in icon">'), 'Install latest firmware')
// );
//}
}); });
} }
@ -292,7 +308,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}); });
get_system_info(); get_system_info();
get_firmware_info(); get_firmware_info();
//get_addon_info(); get_addon_info();
}); });
</script> </script>
</head> </head>
@ -308,7 +324,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<h2 class="ui dividing header">Firmwares</h2> <h2 class="ui dividing header">Firmwares</h2>
<div class="content" id="firmware-summary"> <div class="content" id="firmware-summary">
</div> </div>
<table id="firmware_info" class="ui celled stackable table">
<div class="dimmable">
<div id="dimmer-firmware-info" class="ui active inverted dimmer">
<div class="ui loader">Loading</div>
</div>
<table id="firmware-info" class="ui celled stackable table">
<thead> <thead>
<tr> <tr>
<th>Version</th> <th>Version</th>
@ -320,23 +341,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<tbody> <tbody>
</tbody> </tbody>
</table> </table>
<!--
<h2 class="ui dividing header">Addons</h2>
<table id="addon_info" class="ui celled stackable table">
<thead>
<tr>
<th>Name</th>
<th>Version</th>
<th class="center aligned">Available</th>
<th class="center aligned">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
-->
<div class="ui checkbox"> <div class="ui checkbox">
<input id="dryrun" type="checkbox"> <input id="dryrun" type="checkbox">
<label>Perform a trial run with no changes made</label> <label>Perform a trial run with no changes made</label>
@ -348,6 +352,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</div> </div>
</div> </div>
<h2 class="ui dividing header">Addons</h2>
<div class="dimmable">
<div id="dimmer-addon-info" class="ui active inverted dimmer">
<div class="ui loader">Loading</div>
</div>
<table id="addon-info" class="ui celled stackable table">
<thead>
<tr>
<th>Addon name</th>
<th>Installed version</th>
<th class="center aligned">Available version</th>
<th class="center aligned">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div style="height:80%" id="modal-log" class="ui modal"> <div style="height:80%" id="modal-log" class="ui modal">
<i class="close icon"></i> <i class="close icon"></i>
<div class="header"> <div class="header">

View File

@ -64,6 +64,13 @@ proc process {} {
} else { } else {
error "Invalid version: ${data}" error "Invalid version: ${data}"
} }
} elseif {[lindex $path 1] == "install_addon"} {
regexp {\"addon_id\"\s*:\s*\"([^\"]+)\"} $data match addon_id
if { [info exists addon_id] && $addon_id != "" } {
return "\"[rmupdate::install_addon $addon_id]\""
} else {
error "Invalid addon_id: ${addon_id}"
}
} elseif {[lindex $path 1] == "delete_firmware_image"} { } elseif {[lindex $path 1] == "delete_firmware_image"} {
regexp {\"version\"\s*:\s*\"([\d\.]+)\"} $data match version regexp {\"version\"\s*:\s*\"([\d\.]+)\"} $data match version
if { [info exists version] && $version != "" } { if { [info exists version] && $version != "" } {