diff --git a/addon/lib/rmupdate.tcl b/addon/lib/rmupdate.tcl index a532683..5542e7b 100644 --- a/addon/lib/rmupdate.tcl +++ b/addon/lib/rmupdate.tcl @@ -67,6 +67,9 @@ proc ::rmupdate::i18n {str} { if {$str == "System will reboot now."} { return "Das System wird jetzt neu gestartet." } if {$str == "Latest firmware version: %s"} { return "Aktuellste Firmware-Version: %s" } if {$str == "Current firmware version: %s"} { return "Installierte Firmware-Version: %s" } + if {$str == "Download url missing."} { return "Download-URL fehlt." } + if {$str == "Addon %s successfully installed."} { return "Addon %s erfolgreich installiert." } + if {$str == "Addon %s successfully uninstalled."} { return "Addon %s erfolgreich deinstalliert." } } return $str } @@ -924,7 +927,7 @@ proc ::rmupdate::get_addon_info {{fetch_available_version 0} {fetch_download_url } } -proc ::rmupdate::install_addon {addon_id} { +proc ::rmupdate::uninstall_addon {addon_id} { variable rc_dir if {[get_running_installation] != ""} { @@ -933,12 +936,43 @@ proc ::rmupdate::install_addon {addon_id} { 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 "Uninstalling addon" + if { [catch { + exec "${rc_dir}/${addon_id}" uninstall + } errormsg] } { + write_log 2 "${rc_dir}/${addon_id} uninstall failed: ${errormsg}" + } + + write_log 3 "Addon ${addon_id} successfully uninstalled" + + set_running_installation "" + + return [format [i18n "Addon %s successfully uninstalled."] $addon_id] +} + +proc ::rmupdate::install_addon {{addon_id ""} {download_url ""}} { + variable rc_dir + + if {[get_running_installation] != ""} { + error [i18n "Another install process is running."] + } + + if {$addon_id != ""} { + array set addon [get_addon_info 1 1 0 $addon_id] + set download_url $addon(${addon_id}::download_url) + } + + if {$download_url == ""} { + error [i18n "Download url missing."] + } + if {$addon_id == ""} { + set addon_id "unknown" + } + + set_running_installation "Addon ${addon_id}" write_log 3 "Downloading addon from ${download_url}." - regexp {/([^/]+)$} $download_url match archive_file - set archive_file "/tmp/${archive_file}" + set archive_file "/tmp/${addon_id}.tar.gz" if {[file exists $archive_file]} { file delete $archive_file } @@ -957,7 +991,11 @@ proc ::rmupdate::install_addon {addon_id} { write_log 3 "Running update_script" file attributes update_script -permissions 0755 - exec ./update_script noreboot + if { [catch { + exec ./update_script noreboot + } errormsg] } { + write_log 2 "Addon update_script failed: ${errormsg}" + } cd /tmp @@ -975,7 +1013,7 @@ proc ::rmupdate::install_addon {addon_id} { set_running_installation "" - return "Addon ${addon_id} successfully installed" + return [format [i18n "Addon %s successfully installed."] $addon_id] } #puts [rmupdate::get_latest_firmware_version] diff --git a/addon/www/index.html b/addon/www/index.html index 54595a0..60cda5c 100644 --- a/addon/www/index.html +++ b/addon/www/index.html @@ -231,8 +231,8 @@ along with this program. If not, see . } $("#firmware-summary").empty(); $("#firmware-summary").append( - $('
').html(i18next.t('current_installed_version') + ': ' + current_firmware + ''), - $('
').html(i18next.t('latest_available_version') + ': ' + latest_firmware) + $('
').html(i18next.t('current_installed_version') + ': ' + current_firmware + ''), + $('
').html(i18next.t('latest_available_version') + ': ' + latest_firmware) ); if (current_firmware != latest_firmware) { $("#firmware-summary").append( @@ -251,33 +251,65 @@ along with this program. If not, see . rest("GET", "/get_system_info", null, function(data) { $("#system-info").empty(); $("#system-info").append( - $('
').html(i18next.t('system_type', {'system_type': data.system_type})), - $('
').html(i18next.t('current_root_partiton', {'root_partition': data.root_partition})) + $('
').html(i18next.t('system_type', {'system_type': data.system_type})), + $('
').html(i18next.t('current_root_partiton', {'root_partition': data.root_partition})) ); }); } - function install_addon(addon_id) { + function install_addon(addon_id, download_url) { if (!running_installation) { - display_message('info', 'Installing addon ' + addon_id + '.', 6000000); + display_message('info', i18next.t('installing_addon', {'addon_id': 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}), + $('[data-uninstall-addon-id="' + addon_id + '"]').addClass('disabled'); + $('#install-addon-url-button').addClass('disabled'); + rest("POST", "/install_addon", JSON.stringify({"addon_id":addon_id, "download_url":download_url}), function(data) { //console.info(data); $('[data-update-addon-id="' + addon_id + '"]').removeClass('loading'); $('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled'); + $('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('disabled'); + $('#install-addon-url-button').removeClass('disabled'); + $('#install-addon-url-input').val(''); $('#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); + get_addon_info(); }, 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'); + $('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('disabled'); + $('#install-addon-url-input').val(''); + $('#install-addon-url-button').removeClass('disabled'); + default_error_callback(xhr, ajaxOptions, thrownError); + } + ); + } + } + + function uninstall_addon(addon_id) { + if (!running_installation) { + display_message('info', i18next.t('uninstalling_addon', {'addon_id': addon_id}), 6000000); + $('[data-uninstall-addon-id="' + addon_id + '"]').addClass('loading'); + $('[data-uninstall-addon-id="' + addon_id + '"]').addClass('disabled'); + $('[data-update-addon-id="' + addon_id + '"]').addClass('disabled'); + rest("POST", "/uninstall_addon", JSON.stringify({"addon_id":addon_id}), + function(data) { + //console.info(data); + display_message('success', data, 6000000); + $('#tr-' + addon_id).remove(); + }, + function(xhr, ajaxOptions, thrownError) { + console.error("Addon installation error: " + thrownError + ": " + xhr.responseText); + $('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('loading'); + $('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('disabled'); + $('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled'); default_error_callback(xhr, ajaxOptions, thrownError); } ); @@ -310,13 +342,30 @@ along with this program. If not, see . win.focus(); }); + var buninstall = $('
') + .attr('data-uninstall-addon-id', addon.id) + .append($(''), i18next.t('uninstall')); + buninstall.click(function() { + var addon_id = this.getAttribute('data-uninstall-addon-id'); + $('#modal-uninstall-addon').modal({ + onDeny: function(){ + return true; + }, + onApprove: function() { + uninstall_addon(addon_id); + return true; + } + }) + .modal('show'); + }); + var cls = (((!addon.available_version) || (addon.version == addon.available_version)) ? "positive" : "warning"); var available_version = ((addon.available_version) ? addon.available_version : "?"); $("#addon-info tbody").append($('').append( $('').append($('')), $('').append($('')), $('').append($('')), - $('').append(bupdate, bconfig) + $('').append(bupdate, bconfig, buninstall) )); }); $('#dimmer-addon-info').removeClass('active'); @@ -361,7 +410,14 @@ along with this program. If not, see . delete_firmware_img_success: 'Firmware image {{version}} successfully deleted.', installing_firmware: 'Installing firmware {{version}}.', install_latest_firmware: 'Install latest firmware', - system_not_upgradeable: 'System not upgradeable or filesystem to small!' + system_not_upgradeable: 'System not upgradeable or filesystem to small!', + uninstall: 'Uninstall', + cancel: 'Canel', + uninstall_addon: 'Uninstall addon', + sure_to_uninstall_addon: 'Are you sure you want to uninstall this addon?', + installing_addon: 'Installing addon {{addon_id}}.', + uninstalling_addon: 'Uninstalling addon {{addon_id}}.', + install_addon_from_url: 'Install addon from url', } }, de: { @@ -397,7 +453,14 @@ along with this program. If not, see . delete_firmware_img_success: 'Firmware-Image {{version}} erfolgreich gelöscht.', installing_firmware: 'Installiere Firmware {{version}}.', install_latest_firmware: 'Aktuellste Firmware installieren', - system_not_upgradeable: 'System nicht aktualisierbar oder Dateisystem zu klein!' + system_not_upgradeable: 'System nicht aktualisierbar oder Dateisystem zu klein!', + uninstall: 'Deinstallieren', + cancel: 'Abbrechen', + uninstall_addon: 'Addon deinstallieren', + sure_to_uninstall_addon: 'Sind sie sicher, dass sie dieses Addon deinstallieren wollen?', + installing_addon: 'Installiere Addon {{addon_id}}.', + uninstalling_addon: 'Deinstalliere Addon {{addon_id}}.', + install_addon_from_url: 'Addon von URL installieren', } } } @@ -427,15 +490,25 @@ along with this program. If not, see .
-

+

+ -

-
+ +

+ +
+
+

+
-

-
+

+ +
+
+

+
@@ -465,7 +538,11 @@ along with this program. If not, see .
-

+

+ +
+
+

@@ -483,7 +560,18 @@ along with this program. If not, see .
- +

+ +
+
+

+
+ + +
+ + + diff --git a/addon/www/rest.cgi b/addon/www/rest.cgi index 3c06109..3c7283d 100644 --- a/addon/www/rest.cgi +++ b/addon/www/rest.cgi @@ -67,9 +67,19 @@ proc process {} { error "Invalid version: ${data}" } } elseif {[lindex $path 1] == "install_addon"} { + regexp {\"addon_id\"\s*:\s*\"([^\"]+)\"} $data match addon_id + if { ![info exists addon_id] } { + set addon_id "" + } + regexp {\"download_url\"\s*:\s*\"([^\"]+)\"} $data match download_url + if { ![info exists download_url] } { + set download_url "" + } + return "\"[rmupdate::install_addon $addon_id $download_url]\"" + } elseif {[lindex $path 1] == "uninstall_addon"} { regexp {\"addon_id\"\s*:\s*\"([^\"]+)\"} $data match addon_id if { [info exists addon_id] && $addon_id != "" } { - return "\"[rmupdate::install_addon $addon_id]\"" + return "\"[rmupdate::uninstall_addon $addon_id]\"" } else { error "Invalid addon_id: ${addon_id}" } diff --git a/rmupdate.tar.gz b/rmupdate.tar.gz index 25174d7..b03cfa6 100644 Binary files a/rmupdate.tar.gz and b/rmupdate.tar.gz differ