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

Localization

This commit is contained in:
Jan Schneider 2018-01-23 00:34:09 +01:00
parent 6bb72481c3
commit c350b05664
4 changed files with 206 additions and 77 deletions

View File

@ -33,6 +33,7 @@ namespace eval rmupdate {
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
variable language "de"
} }
proc json_string {str} { proc json_string {str} {
@ -48,6 +49,29 @@ proc json_string {str} {
return "[string map $replace_map $str]" return "[string map $replace_map $str]"
} }
proc ::rmupdate::i18n {str} {
variable language
if {$language == "de"} {
if {$str == "Checking size of filesystems."} { return "Überprüfe Größe der Dateisysteme." }
if {$str == "Current filesystem of partition %d (%d bytes) not big enough (new usage: %d bytes)."} { return "Aktuelles Dateisystem der Partition %d (%d Bytes) nicht groß genug (neue Belegung: %d bytes)." }
if {$str == "Updating filesystems."} { return "Aktualisiere Dateisysteme." }
if {$str == "Updating system partition %s."} { return "Aktualisiere System-Partition %s." }
if {$str == "Updating boot configuration."} { return "Aktualisiere Boot-Konfiguration." }
if {$str == "Downloading firmware from %s."} { return "Lade Firmware von %s herunter." }
if {$str == "Download completed."} { return "Download abgeschlossen." }
if {$str == "Extracting firmware %s.\nThis process takes some minutes, please be patient..."} { return "Entpacke Firmware %s.\nBitte haben Sie ein wenig Geduld, dieser Vorgang benötigt einige Minuten..." }
if {$str == "Failed to find download link for firmware %s."} { return "Download-Link für Firmware %s nicht gefunden." }
if {$str == "Failed to extract firmware image from archive."} { return "Firmware-Image konnte nicht entpackt werden." }
if {$str == "Another install process is running."} { return "Es läuft bereits ein andere Installationsvorgang." }
if {$str == "System not upgradeable."} { return "Dieses System ist nicht aktualisierbar." }
if {$str == "Rebooting system."} { return "Das System wird neu gestartet." }
if {$str == "Latest firmware version: %s"} { return "Aktuellste Firmware-Version: %s" }
if {$str == "Current firmware version: %s"} { return "Installierte Firmware-Version: %s" }
return $str
}
}
proc ::rmupdate::get_rpi_version {} { proc ::rmupdate::get_rpi_version {} {
# Revison list from http://elinux.org/RPi_HardwareHistory # Revison list from http://elinux.org/RPi_HardwareHistory
set revision_map(0002) "rpi0" set revision_map(0002) "rpi0"
@ -130,12 +154,12 @@ proc ::rmupdate::read_log {} {
return $data return $data
} }
proc ::rmupdate::write_install_log {str} { proc ::rmupdate::write_install_log {str args} {
variable install_log variable install_log
write_log 4 $str write_log 4 [format $str $args]
puts stderr $str puts stderr $str
set fd [open $install_log "a"] set fd [open $install_log "a"]
puts $fd $str puts $fd [format [i18n $str] $args]
close $fd close $fd
} }
@ -291,7 +315,7 @@ proc ::rmupdate::update_fstab {fstab {boot ""} {root ""} {user ""}} {
proc ::rmupdate::mount_image_partition {image partition mountpoint} { proc ::rmupdate::mount_image_partition {image partition mountpoint} {
variable loop_dev variable loop_dev
write_install_log "Mounting parition ${partition} of image ${image}." write_log 3 "Mounting parition ${partition} of image ${image}."
set p [get_partion_start_and_size $image $partition] set p [get_partion_start_and_size $image $partition]
write_log 4 "Partiton start=[lindex $p 0], size=[lindex $p 1]." write_log 4 "Partiton start=[lindex $p 0], size=[lindex $p 1]."
@ -322,9 +346,9 @@ proc ::rmupdate::mount_system_partition {partition mountpoint} {
} }
if {$remount} { if {$remount} {
write_install_log "Remounting filesystem ${partition} (rw)." write_log 3 "Remounting filesystem ${partition} (rw)."
} else { } else {
write_install_log "Mounting device ${partition} (rw)." write_log 3 "Mounting device ${partition} (rw)."
} }
if {![file exists $mountpoint]} { if {![file exists $mountpoint]} {
@ -381,16 +405,17 @@ proc ::rmupdate::check_sizes {image} {
set su_cur [get_filesystem_size_and_usage $mnt_sys] set su_cur [get_filesystem_size_and_usage $mnt_sys]
set cur_size [lindex $su_cur 0] set cur_size [lindex $su_cur 0]
write_install_log "Current filesystem (${partition}) size: ${cur_size}, new filesystem used bytes: ${new_used}." write_log 4 "Current filesystem (${partition}) size: ${cur_size}, new filesystem used bytes: ${new_used}."
umount $mnt_img umount $mnt_img
umount $mnt_sys umount $mnt_sys
if { [expr {$new_used*1.05}] > $cur_size && [expr {$new_used+50*1024*1024}] >= $cur_size } { if { [expr {$new_used*1.05}] > $cur_size && [expr {$new_used+50*1024*1024}] >= $cur_size } {
error "Current filesystem of partition $partition (${cur_size} bytes) not big enough (new usage: ${new_used} bytes)." #error "Current filesystem of partition $partition (${cur_size} bytes) not big enough (new usage: ${new_used} bytes)."
error [format [i18n "Current filesystem of partition %d (%d bytes) not big enough (new usage: %d bytes)."] $partition $cur_size $new_used]
} }
} }
write_install_log "Sizes of filesystems checked successfully." write_log 3 "Sizes of filesystems checked successfully."
} }
proc ::rmupdate::update_filesystems {image {dryrun 0}} { proc ::rmupdate::update_filesystems {image {dryrun 0}} {
@ -415,7 +440,7 @@ proc ::rmupdate::update_filesystems {image {dryrun 0}} {
if {$sys_partition == 1} { if {$sys_partition == 1} {
set mnt_s "/boot" set mnt_s "/boot"
} }
write_install_log "Updating system partition ${sys_partition}." write_install_log "Updating system partition %s." $sys_partition
mount_image_partition $image $img_partition $mnt_img mount_image_partition $image $img_partition $mnt_img
mount_system_partition $sys_partition $mnt_s mount_system_partition $sys_partition $mnt_s
@ -426,7 +451,7 @@ proc ::rmupdate::update_filesystems {image {dryrun 0}} {
write_log 4 "ls -la ${mnt_s}" write_log 4 "ls -la ${mnt_s}"
write_log 4 [exec ls -la ${mnt_s}] write_log 4 [exec ls -la ${mnt_s}]
} }
write_install_log "Rsyncing filesystem of partition ${sys_partition}." write_log 3 "Rsyncing filesystem of partition ${sys_partition}."
if [catch { if [catch {
set out "" set out ""
if {$dryrun} { if {$dryrun} {
@ -440,7 +465,7 @@ proc ::rmupdate::update_filesystems {image {dryrun 0}} {
} err] { } err] {
write_log 4 $err write_log 4 $err
} }
write_install_log "Rsync finished." write_log 3 "Rsync finished."
if {$log_level >= 4} { if {$log_level >= 4} {
write_log 4 "ls -la ${mnt_img}" write_log 4 "ls -la ${mnt_img}"
write_log 4 [exec ls -la ${mnt_img}] write_log 4 [exec ls -la ${mnt_img}]
@ -449,7 +474,7 @@ proc ::rmupdate::update_filesystems {image {dryrun 0}} {
} }
if {$img_partition == 1} { if {$img_partition == 1} {
write_install_log "Update cmdline." write_install_log "Updating boot configuration."
if {!$dryrun} { if {!$dryrun} {
set new_root_partition 2 set new_root_partition 2
if {$root_partition == 2} { if {$root_partition == 2} {
@ -522,9 +547,9 @@ proc ::rmupdate::download_firmware {version} {
} }
} }
if {$download_url == ""} { if {$download_url == ""} {
error "Failed to get url for firmware ${version}" error [format [i18n "Failed to find download link for firmware %s."] $version]
} }
write_install_log "Downloading firmware from ${download_url}." write_install_log "Downloading firmware from %s." $download_url
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
@ -534,9 +559,11 @@ proc ::rmupdate::download_firmware {version} {
} else { } else {
exec /usr/bin/wget "${download_url}" --no-check-certificate --quiet --output-document=$archive_file exec /usr/bin/wget "${download_url}" --no-check-certificate --quiet --output-document=$archive_file
} }
write_install_log ""
write_install_log "Download completed." write_install_log "Download completed."
write_install_log "Extracting firmware ${archive_file}." write_install_log "Extracting firmware %s.\nThis process takes some minutes, please be patient..." [file tail $archive_file]
set data [exec /usr/bin/unzip -ql "${archive_file}" 2>/dev/null] set data [exec /usr/bin/unzip -ql "${archive_file}" 2>/dev/null]
set img_file "" set img_file ""
foreach d [split $data "\n"] { foreach d [split $data "\n"] {
@ -546,7 +573,7 @@ proc ::rmupdate::download_firmware {version} {
} }
} }
if { $img_file == "" } { if { $img_file == "" } {
error "Failed to extract image from archive." error [i18n "Failed to extract firmware image from archive."]
} }
exec /usr/bin/unzip "${archive_file}" "${img_file}" -o -d "${img_dir}" 2>/dev/null exec /usr/bin/unzip "${archive_file}" "${img_file}" -o -d "${img_dir}" 2>/dev/null
set img_file "${img_dir}/${img_file}" set img_file "${img_dir}/${img_file}"
@ -675,12 +702,14 @@ proc ::rmupdate::delete_firmware_image {version} {
catch { eval {file delete [glob "${img_dir}/*${version}*.zip"]} } catch { eval {file delete [glob "${img_dir}/*${version}*.zip"]} }
} }
proc ::rmupdate::install_firmware_version {version {reboot 1} {dryrun 0}} { proc ::rmupdate::install_firmware_version {version lang {reboot 1} {dryrun 0}} {
variable language
set language $lang
if {[get_running_installation] != ""} { if {[get_running_installation] != ""} {
error "Another install process is running." error [i18n "Another install process is running."]
} }
if {! [is_system_upgradeable]} { if {! [is_system_upgradeable]} {
error "System not upgradeable." error [i18n "System not upgradeable."]
} }
set_running_installation "Firmware ${version}" set_running_installation "Firmware ${version}"
@ -721,10 +750,10 @@ proc ::rmupdate::install_latest_version {{reboot 1} {dryrun 0}} {
proc ::rmupdate::is_firmware_up_to_date {} { proc ::rmupdate::is_firmware_up_to_date {} {
set latest_version [get_latest_firmware_version] set latest_version [get_latest_firmware_version]
write_install_log "Latest firmware version: ${latest_version}" write_install_log "Latest firmware version: %s" $latest_version
set current_version [get_current_firmware_version] set current_version [get_current_firmware_version]
write_install_log "Current firmware version: ${current_version}" write_install_log "Installed firmware version: ${current_version}"
if {[compare_versions $current_version $latest_version] >= 0} { if {[compare_versions $current_version $latest_version] >= 0} {
return 1 return 1
@ -892,7 +921,7 @@ proc ::rmupdate::install_addon {addon_id} {
variable rc_dir variable rc_dir
if {[get_running_installation] != ""} { if {[get_running_installation] != ""} {
error "Another install process is running." error [i18n "Another install process is running."]
} }
set_running_installation "Addon ${addon_id}" set_running_installation "Addon ${addon_id}"

View File

@ -23,13 +23,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/8.1.0/i18next.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.2.0/jquery-i18next.min.js" ></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.css" integrity="sha256-wT6CFc7EKRuf7uyVfi+MQNHUzojuHN2pSw0YWFt2K5E=" crossorigin="anonymous" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.css" integrity="sha256-wT6CFc7EKRuf7uyVfi+MQNHUzojuHN2pSw0YWFt2K5E=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.js" integrity="sha256-flVaeawsBV96vCHiLmXn03IRJym7+ZfcLVvUWONCas8=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.js" integrity="sha256-flVaeawsBV96vCHiLmXn03IRJym7+ZfcLVvUWONCas8=" crossorigin="anonymous"></script>
<style> <style>
</style> </style>
<title>RaspberryMatic Update Addon</title> <title data-i18n="title">RaspberryMatic Update Addon</title>
<script> <script>
var language = navigator.language || navigator.userLanguage;
var message_timer_id = null; var message_timer_id = null;
var running_installation = ""; var running_installation = "";
var current_firmware = '?'; var current_firmware = '?';
@ -66,7 +69,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} }
catch(e) { catch(e) {
} }
display_message('error', 'An error occurred: ' + err, 6000000); display_message('error', i18next.t('error_occurred', {'error': err}), 6000000);
} }
function rest(method, path, data, success_callback, error_callback) { function rest(method, path, data, success_callback, error_callback) {
@ -83,7 +86,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}); });
} }
function set_running_installation(installation_info) { function set_running_installation(installation_info, error) {
//console.info("set_running_installation: |" + installation_info + "|" + running_installation + "|" + error);
var firmware_regex = /firmware\s+(.*)/i; var firmware_regex = /firmware\s+(.*)/i;
if (running_installation && (!installation_info)) { if (running_installation && (!installation_info)) {
// Running installation finished // Running installation finished
@ -92,8 +96,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var version = match[1]; var version = match[1];
$('[data-install-firmware-version="' + version + '"]').removeClass('loading'); $('[data-install-firmware-version="' + version + '"]').removeClass('loading');
} }
msg = running_installation + ' successfully installed.' if (error) {
display_message('success', msg, 6000000); display_message('error', i18next.t('installation_failed', {'what': running_installation, 'error': error}), 6000000);
}
else {
display_message('success', i18next.t('installation_success', {'what': running_installation}), 6000000);
}
$('#modal-log').modal('refresh');
$('#log-content').scrollTop($('#log-content').prop("scrollHeight"));
} }
running_installation = installation_info; running_installation = installation_info;
@ -109,11 +119,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
function update_install_log() { function update_install_log() {
rest("GET", "/get_running_installation", null, function(installation_info) { rest("GET", "/get_running_installation", null, function(installation_info) {
if (running_installation && (installation_info != running_installation)) {
if (installation_info == "") {
// Wait a while to handle potential errors
setTimeout(function() {
set_running_installation(installation_info); set_running_installation(installation_info);
}, 3000);
}
else {
set_running_installation(installation_info);
}
}
}); });
rest("GET", "/read_install_log", null, function(data) { rest("GET", "/read_install_log", null, function(data) {
$('#log-content').html(data.replace(/\n/g, '<br />')); $('#log-content').html(data.replace(/\n/g, '<br />'));
$('#modal-log').modal('refresh'); //$('#modal-log').modal('refresh');
$('#log-content').scrollTop($('#log-content').prop("scrollHeight")); $('#log-content').scrollTop($('#log-content').prop("scrollHeight"));
if (running_installation) { if (running_installation) {
setTimeout(update_install_log, 1000); setTimeout(update_install_log, 1000);
@ -124,7 +144,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
function delete_firmware_image(version) { function delete_firmware_image(version) {
rest("POST", "/delete_firmware_image", JSON.stringify({"version":version}), rest("POST", "/delete_firmware_image", JSON.stringify({"version":version}),
function(data) { function(data) {
display_message('success', 'Firmware image ' + version + ' successfully deleted.', 5000); display_message('success', i18next.t('delete_firmware_img_success', {'version': version}), 5000);
get_firmware_info(); get_firmware_info();
} }
); );
@ -136,21 +156,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if (!running_installation) { if (!running_installation) {
var reboot = $('#reboot-after-install').is(':checked'); var reboot = $('#reboot-after-install').is(':checked');
var dryrun = $('#dryrun').is(':checked'); var dryrun = $('#dryrun').is(':checked');
display_message('info', 'Installing firmware ' + version + '.', 6000000); display_message('info', i18next.t('installing_firmware', {'version': version}), 6000000);
clear_message(); clear_message();
rest("POST", "/start_install_firmware", JSON.stringify({"version":version, "reboot":reboot, "dryrun":dryrun}), set_running_installation("Firmware " + version);
rest("POST", "/start_install_firmware", JSON.stringify({"language": language, "version":version, "reboot":reboot, "dryrun":dryrun}),
function(data) { function(data) {
// 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: " + thrownError + ": " + xhr.responseText); console.error("Firmware installation error: " + thrownError + ": " + xhr.responseText);
$('[data-install-firmware-version="' + running_installation + '"]').removeClass('loading');
//$('#modal-log').modal('hide'); //$('#modal-log').modal('hide');
if (running_installation) { set_running_installation("", thrownError + ": " + xhr.responseText);
//get_firmware_info();
default_error_callback(xhr, ajaxOptions, thrownError);
}
set_running_installation("");
} }
); );
} }
@ -174,14 +190,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if (fw.latest) color = 'green'; if (fw.latest) color = 'green';
if (fw.installed) color = 'gray'; if (fw.installed) color = 'gray';
var disabled = (fw.image || fw.url ? '' : 'disabled'); var disabled = (fw.image || fw.url ? '' : 'disabled');
var binstall = $('<div class="ui '+ color +' basic '+ disabled +' button">').attr('data-install-firmware-version', fw.version).append($('<i class="sign in icon">'), 'install'); 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() { binstall.click(function() {
install_firmware(this.getAttribute('data-install-firmware-version')); install_firmware(this.getAttribute('data-install-firmware-version'));
}); });
var bcls = ''; var bcls = '';
if (!fw.image) bcls = 'disabled'; if (!fw.image) bcls = 'disabled';
if (fw.version == running_installation) bcls = 'loading'; if (fw.version == running_installation) bcls = 'loading';
var bdelete = $('<div class="ui orange basic '+ bcls +' button">').attr('data-delete-version', fw.version).append($('<i class="delete icon">'), 'delete download'); var bdelete = $('<div class="ui orange basic '+ bcls +' button">').attr('data-delete-version', fw.version).append($('<i class="delete icon">'), i18next.t('delete_download'));
bdelete.click(function() { bdelete.click(function() {
delete_firmware_image(this.getAttribute('data-delete-version')); delete_firmware_image(this.getAttribute('data-delete-version'));
}); });
@ -192,7 +208,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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: i18next.t('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>'))),
$('<td class="center aligned">').append(bdelete, binstall) $('<td class="center aligned">').append(bdelete, binstall)
@ -204,12 +220,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} }
$("#firmware-summary").empty(); $("#firmware-summary").empty();
$("#firmware-summary").append( $("#firmware-summary").append(
$('<div class="sub header">').html('Current installed version: <span style="color:'+ color +'">' + current_firmware + '</span>'), $('<div class="sub header">').html(i18next.t('current_installed_version') + ': <span style="color:'+ color +'">' + current_firmware + '</span>'),
$('<div class="sub header">').html('Latest available version: ' + latest_firmware) $('<div class="sub header">').html(i18next.t('latest_available_version') + ': ' + latest_firmware)
); );
if (current_firmware != latest_firmware) { if (current_firmware != latest_firmware) {
$("#firmware-summary").append( $("#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') $('<div class="ui green basic button" style="margin-top:20px; margin-bottom:20px;">').click(install_latest_firmware).append($('<i class="sign in icon">'), i18next.t('install_latest_firmware'))
); );
} }
@ -224,7 +240,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
rest("GET", "/get_system_info", null, function(data) { rest("GET", "/get_system_info", null, function(data) {
$("#system-info").empty(); $("#system-info").empty();
$("#system-info").append( $("#system-info").append(
$('<div class="sub header">').html('Current root partition: ' + data.root_partition) $('<div class="sub header">').html(i18next.t('current_root_partiton', {'root_partition': data.root_partition}))
); );
}); });
} }
@ -268,7 +284,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var bupdate = $('<div class="ui '+ color +' basic '+ disabled +' button" id="button-update-' + addon.id + '">') var bupdate = $('<div class="ui '+ color +' basic '+ disabled +' button" id="button-update-' + addon.id + '">')
.attr('data-update-addon-id', addon.id) .attr('data-update-addon-id', addon.id)
.attr('data-update-addon-available-version', addon.available_version) .attr('data-update-addon-available-version', addon.available_version)
.append($('<i class="sign in icon">'), (addon.version == addon.available_version) ? "reinstall" : "update"); .append($('<i class="sign in icon">'), (addon.version == addon.available_version) ? i18next.t('reinstall') : i18next.t('update'));
bupdate.click(function() { bupdate.click(function() {
install_addon(this.getAttribute('data-update-addon-id')); install_addon(this.getAttribute('data-update-addon-id'));
}); });
@ -276,7 +292,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
disabled = ((addon.config_url) ? '' : 'disabled'); disabled = ((addon.config_url) ? '' : 'disabled');
var bconfig = $('<div class="ui blue basic '+ disabled +' button">') var bconfig = $('<div class="ui blue basic '+ disabled +' button">')
.attr('data-addon-config-url', addon.config_url) .attr('data-addon-config-url', addon.config_url)
.append($('<i class="setting icon">'), 'open config'); .append($('<i class="setting icon">'), i18next.t('open_config'));
bconfig.click(function() { bconfig.click(function() {
var win = window.open(this.getAttribute('data-addon-config-url'), '_blank'); var win = window.open(this.getAttribute('data-addon-config-url'), '_blank');
win.focus(); win.focus();
@ -296,14 +312,97 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} }
$(document).ready(function() { $(document).ready(function() {
i18next.init({
lng: language,
fallbackLng: 'en',
resources: {
en: {
translation: {
title: 'System update',
system_info: 'System information',
current_root_partiton: 'Current root partition: {{root_partition}}',
firmwares: 'Firmwares',
current_installed_version: 'Current installed version',
latest_available_version: 'Latest available version',
loading: 'Loading',
version: 'Version',
available: 'Available',
downloaded: 'Downloaded',
action: 'Action',
delete_download: 'Delete download',
install: 'Install',
installation_log: 'Installation log',
open_release_info: 'Open release info',
perform_trial_run: 'Perform a trial run with no changes made',
reboot_after_install: 'Reboot system after installation',
addons: 'Addons',
addon_name: 'Addon name',
installed_version: 'Installed version',
available_version: 'Available version',
reinstall: 'Reinstall',
update: 'Update',
open_config: 'Open config',
error_occurred: 'An error occurred: {{error}}',
installation_failed: 'Failed to install {{what}}: {{error}}',
installation_success: '{{what}} successfully installed.',
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!'
}
},
de: {
translation: {
title: 'System-Aktualisierung',
system_info: 'System-Informationen',
current_root_partiton: 'Aktuelle Root-Partition: {{root_partition}}',
firmwares: 'Firmwares',
current_installed_version: 'Momentan installierte Version',
latest_available_version: 'Aktuellste verfügbare Version',
loading: 'Lade',
version: 'Version',
available: 'Verfügbar',
downloaded: 'Heruntergeladen',
action: 'Aktion',
delete_download: 'Download löschen',
install: 'Installieren',
installation_log: 'Installations-Protokoll',
open_release_info: 'Release-Informationen öffnen',
perform_trial_run: 'Testlauf durchführen ohne Änderungen durchzuführen',
reboot_after_install: 'System nach Installation neu starten',
addons: 'Zusatzsoftware',
addon_name: 'Name des Addons',
installed_version: 'Installierte Version',
available_version: 'Verfügbare Version',
reinstall: 'Neu installieren',
update: 'Aktualisieren',
open_config: 'Konfiguration öffnen',
error_occurred: 'Ein Fehler ist aufgetreten: {{error}}',
installation_failed: 'Fehler beim Installieren von {{what}}: {{error}}',
installation_success: '{{what}} erfolgreich installiert.',
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!'
}
}
}
}, function(err, t) {
jqueryI18next.init(i18next, $);
$('title').localize();
$('h1').localize();
$('h2').localize();
$('div').localize();
$('th').localize();
$('label').localize();
});
rest("GET", "/version", null, function(version) { rest("GET", "/version", null, function(version) {
document.title = document.title + " " + version; document.title = document.title + " " + version;
}); });
rest("GET", "/is_system_upgradeable", null, function(upgradeable) { rest("GET", "/is_system_upgradeable", null, function(upgradeable) {
if (!upgradeable) { if (!upgradeable) {
var message = 'System not upgradeable or filesystem to small!<br />'; display_message('error', i18next.t('system_not_upgradeable'), 6000000);
message += 'Please download and install adjusted RaspMatic image from <a href="https://github.com/j-a-n/raspberrymatic-addon-rmupdate">RaspMatic image</a> first.';
display_message('error', message, 6000000);
} }
}); });
get_system_info(); get_system_info();
@ -314,28 +413,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</head> </head>
<body> <body>
<div style="padding-top: 5vw; padding-bottom: 5vw" class="ui container"> <div style="padding-top: 5vw; padding-bottom: 5vw" class="ui container">
<h1 class="ui header">RaspberryMatic Update</h1> <h1 class="ui header" data-i18n="title"></h1>
<div id="message" class="ui message hidden"> <div id="message" class="ui message hidden">
</div> </div>
<h2 class="ui dividing header">System info</h2> <h2 class="ui dividing header" data-i18n="system_info"></h2>
<div class="content" id="system-info"> <div class="content" id="system-info">
</div> </div>
<h2 class="ui dividing header">Firmwares</h2> <h2 class="ui dividing header" data-i18n="firmwares"></h2>
<div class="content" id="firmware-summary"> <div class="content" id="firmware-summary">
</div> </div>
<div class="dimmable"> <div class="dimmable">
<div id="dimmer-firmware-info" class="ui active inverted dimmer"> <div id="dimmer-firmware-info" class="ui active inverted dimmer">
<div class="ui loader">Loading</div> <div class="ui loader" data-i18n="loading"></div>
</div> </div>
<table id="firmware-info" class="ui celled stackable table"> <table id="firmware-info" class="ui celled stackable table">
<thead> <thead>
<tr> <tr>
<th>Version</th> <th data-i18n="version"></th>
<th class="center aligned">Available</th> <th class="center aligned" data-i18n="available"></th>
<th class="center aligned">Downloaded</th> <th class="center aligned" data-i18n="downloaded"></th>
<th class="center aligned">Action</th> <th class="center aligned" data-i18n="action"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -343,27 +442,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</table> </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 data-i18n="perform_trial_run"></label>
</div> </div>
<br /> <br />
<div class="ui checkbox"> <div class="ui checkbox">
<input id="reboot-after-install" type="checkbox" checked="checked"> <input id="reboot-after-install" type="checkbox" checked="checked">
<label>Reboot system after installation</label> <label data-i18n="reboot_after_install"></label>
</div> </div>
</div> </div>
<h2 class="ui dividing header">Addons</h2> <h2 class="ui dividing header" data-i18n="addons"></h2>
<div class="dimmable"> <div class="dimmable">
<div id="dimmer-addon-info" class="ui active inverted dimmer"> <div id="dimmer-addon-info" class="ui active inverted dimmer">
<div class="ui loader">Loading</div> <div class="ui loader" data-i18n="loading"></div>
</div> </div>
<table id="addon-info" class="ui celled stackable table"> <table id="addon-info" class="ui celled stackable table">
<thead> <thead>
<tr> <tr>
<th>Addon name</th> <th data-i18n="addon_name"></th>
<th>Installed version</th> <th data-i18n="installed_version"></th>
<th>Available version</th> <th data-i18n="available_version"></th>
<th class="center aligned">Action</th> <th class="center aligned" data-i18n="action"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -373,15 +472,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</div> </div>
<div style="height:80%" id="modal-log" class="ui modal"> <div style="height:60vh;" id="modal-log" class="ui modal">
<i class="close icon"></i> <i class="close icon"></i>
<div class="header"> <div class="header" data-i18n="installation_log">
Installation log
</div> </div>
<div class="content"> <div class="content">
<div id="message-log" class="ui message hidden"> <div id="message-log" class="ui message hidden">
</div> </div>
<pre style="max-height:80%; overflow-x:hidden; overflow-y:auto; white-space: pre-wrap;" id="log-content" class="content"> <pre style="height:25vh; overflow-x:hidden; overflow-y:auto; white-space: pre-wrap;" id="log-content">
</pre> </pre>
</div> </div>
</div> </div>

View File

@ -41,6 +41,7 @@ proc process {} {
return [rmupdate::get_addon_info 1 1 1] return [rmupdate::get_addon_info 1 1 1]
} elseif {[lindex $path 1] == "start_install_firmware"} { } elseif {[lindex $path 1] == "start_install_firmware"} {
regexp {\"version\"\s*:\s*\"([\d\.]+)\"} $data match version 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 {\"reboot\"\s*:\s*(true|false)} $data match reboot
regexp {\"dryrun\"\s*:\s*(true|false)} $data match dryrun regexp {\"dryrun\"\s*:\s*(true|false)} $data match dryrun
if { [info exists version] && $version != "" } { if { [info exists version] && $version != "" } {
@ -60,7 +61,7 @@ proc process {} {
} else { } else {
set dryrun 0 set dryrun 0
} }
return "\"[rmupdate::install_firmware_version $version $reboot $dryrun]\"" return "\"[rmupdate::install_firmware_version $version $lang $reboot $dryrun]\""
} else { } else {
error "Invalid version: ${data}" error "Invalid version: ${data}"
} }

View File

@ -2,6 +2,7 @@
LOOP_DEV=7 LOOP_DEV=7
BOOT_SIZE=$((100*1024*1024)) BOOT_SIZE=$((100*1024*1024))
GAP_SIZE=$((900*1024*1024)) # Free space for future use
ROOT_SIZE=$((1000*1024*1024)) ROOT_SIZE=$((1000*1024*1024))
USR_LOCAL_SIZE=$((2*1024*1024)) USR_LOCAL_SIZE=$((2*1024*1024))
@ -23,14 +24,14 @@ echo "image: ${image_file}"
echo "adjusted image: ${new_image_file}" echo "adjusted image: ${new_image_file}"
echo "*** Creating new image file and partitions ***" echo "*** Creating new image file and partitions ***"
dd if=/dev/zero of=$new_image_file bs=1M count=$((((${BOOT_SIZE}+${ROOT_SIZE}+${ROOT_SIZE}+${USR_LOCAL_SIZE})/1024/1024)+1)) dd if=/dev/zero of=$new_image_file bs=1M count=$((((${BOOT_SIZE}+${GAP_SIZE}+${ROOT_SIZE}+${ROOT_SIZE}+${USR_LOCAL_SIZE})/1024/1024)+1))
parted --script $new_image_file \ parted --script $new_image_file \
mklabel msdos \ mklabel msdos \
mkpart primary fat32 512B ${BOOT_SIZE}B \ mkpart primary fat32 512B ${BOOT_SIZE}B \
set 1 boot on \ set 1 boot on \
mkpart primary ext4 $((512+${BOOT_SIZE}))B $((${BOOT_SIZE}+${ROOT_SIZE}))B \ mkpart primary ext4 $((512+${BOOT_SIZE}))B $((${BOOT_SIZE}+${ROOT_SIZE}))B \
mkpart primary ext4 $((512+${BOOT_SIZE}+${ROOT_SIZE}))B $((${BOOT_SIZE}+${ROOT_SIZE}+${ROOT_SIZE}))B \ mkpart primary ext4 $((512+${BOOT_SIZE}+${GAP_SIZE}+${ROOT_SIZE}))B $((${BOOT_SIZE}+${GAP_SIZE}+${ROOT_SIZE}+${ROOT_SIZE}))B \
mkpart primary ext4 $((512+${BOOT_SIZE}+${ROOT_SIZE}+${ROOT_SIZE}))B 100% mkpart primary ext4 $((512+${BOOT_SIZE}+${GAP_SIZE}+${ROOT_SIZE}+${ROOT_SIZE}))B 100%
echo "*** Copying original partitons ***" echo "*** Copying original partitons ***"
oIFS="$IFS" oIFS="$IFS"
@ -44,8 +45,8 @@ for line in $(parted $image_file unit B print | grep primary); do
echo $num - $start - $size echo $num - $start - $size
seek=0 seek=0
[ "$num" = "1" ] && seek=$start [ "$num" = "1" ] && seek=$start
[ "$num" = "2" ] && seek=$(((512+${BOOT_SIZE})/512)) [ "$num" = "2" ] && seek=$(((512+${BOOT_SIZE}+${GAP_SIZE})/512))
[ "$num" = "3" ] && seek=$(((512+${BOOT_SIZE}+${ROOT_SIZE}+${ROOT_SIZE})/512)) [ "$num" = "3" ] && seek=$(((512+${BOOT_SIZE}+${GAP_SIZE}+${ROOT_SIZE}+${ROOT_SIZE})/512))
dd if=$image_file of=$new_image_file bs=512 skip=$start count=$size seek=$seek conv=notrunc dd if=$image_file of=$new_image_file bs=512 skip=$start count=$size seek=$seek conv=notrunc
done done