Show current user device in system info

This commit is contained in:
Jan Schneider 2018-02-25 19:20:27 +01:00
parent 50038c37fa
commit 507314f45e
3 changed files with 79 additions and 41 deletions

View File

@ -391,6 +391,20 @@ proc ::rmupdate::get_system_device {} {
return "/dev/mmcblk0"
}
proc ::rmupdate::get_mounted_device {mountpoint} {
set fd [open /etc/mtab r]
set data [read $fd]
close $fd
foreach d [split $data "\n"] {
if { [regexp {^(\S+)\s+(\S+)\s+} $d match device mp] } {
if {$mp == $mountpoint} {
return $device
}
}
}
return ""
}
proc ::rmupdate::get_current_root_partition_number {} {
set cmdline "/proc/cmdline"
set fd [open $cmdline r]
@ -575,11 +589,11 @@ proc ::rmupdate::update_filesystems {image {dryrun 0}} {
if [catch {
set out ""
if {$dryrun} {
write_log 4 "rsync --dry-run --progress --archive --delete ${mnt_img}/ ${mnt_s}"
set out [exec rsync --dry-run --progress --archive --delete ${mnt_img} ${mnt_s}]
write_log 4 "rsync --dry-run --progress --archive --one-file-system --delete ${mnt_img}/ ${mnt_s}"
set out [exec rsync --dry-run --progress --archive --one-file-system --delete ${mnt_img} ${mnt_s}]
} else {
write_log 4 "rsync --progress --archive --delete ${mnt_img}/ ${mnt_s}"
set out [exec rsync --progress --archive --delete ${mnt_img}/ ${mnt_s}]
write_log 4 "rsync --progress --archive --one-file-system --delete ${mnt_img}/ ${mnt_s}"
set out [exec rsync --progress --archive --one-file-system --delete ${mnt_img}/ ${mnt_s}]
}
write_log 4 $out
} err] {
@ -621,50 +635,69 @@ proc ::rmupdate::move_userfs_to_device {target_device {sync_data 0} {repartition
error [i18n "Target device does not exist."]
}
set source_device [get_system_device]
set source_partition_device [get_mounted_device "/usr/local"]
set source_device [string range $source_partition_device 0 end-1]
if { [regexp {mmcblk} $source_partition_device match] } {
set source_device [string range $source_partition_device 0 end-2]
}
if { $source_device == ""} {
error [i18n "Failed to find source device for /usr/local."]
}
if { $source_device == $target_device} {
error [i18n "Source and target are the same device."]
}
set partition 0
set partition_number 0
if {$repartition == 1} {
set exitcode [catch {
exec /usr/sbin/parted --script ${target_device} \
mklabel msdos \
mkpart primary ext4 0% 100%
} output]
if { $exitcode != 0 && $exitcode != 1 } {
error $output
}
set partition_number 1
} else {
for {set p 1} {$p <= 4} {incr p} {
set filesystem_label [get_filesystem_label $target_device $p]
if {[regexp "^.*userfs$" $filesystem_label match]} {
set partition $p
array set partitions [get_partitions $target_device]
set keys [array names partitions]
foreach key $keys {
regexp {^(.+)::([^:]+)$} $key match id opt
if {$opt == "filesystem_label"} {
if {[regexp "^.*userfs$" $partitions($key) match]} {
set partition_number $partitions(${id}::partition)
}
}
}
if {$partition_number == 0} {
error [format [i18n "Failed to find userfs partition on %s, and repartition is not desired."] $target_device]
}
}
set target_partition_device [get_partition_device $target_device $partition_number]
if {$sync_data == 1} {
set exitcode [catch { exec /sbin/mkfs.ext4 -F -L userfs $target_partition_device } output]
if { $exitcode != 0 && $exitcode != 1 } {
error $output
}
# Write ReGaHSS state to disk
load tclrega.so
rega system.Save()
file mkdir $mnt_sys
exec /bin/mount $target_partition_device $mnt_sys
#set shell_script "cd /usr/local; tar -c . | (cd $mnt_sys; tar -xv)"
#set exitcode [catch { exec /bin/sh -c $shell_script } output]
set out [exec rsync --progress --archive --one-file-system --delete /usr/local/ ${mnt_sys}]
exec /bin/umount $mnt_sys
if { $exitcode != 0 && $exitcode != 1 } {
error $output
}
}
set exitcode [catch {
exec /usr/sbin/parted --script ${target_device} \
mklabel msdos \
mkpart primary ext4 ${start1}B 100%
} output]
if { $exitcode != 0 && $exitcode != 1 } {
error $output
}
set exitcode [catch { exec /sbin/mkfs.ext4 -F -L userfs [get_partition_device $target_device 1] } output]
if { $exitcode != 0 && $exitcode != 1 } {
error $output
}
# Write ReGaHSS state to disk
load tclrega.so
rega system.Save()
exec /bin/mount [get_partition_device $target_device 1] $mnt_sys
set shell_script "cd /usr/local; tar -c . | (cd $mnt_sys; tar -xv)"
set exitcode [catch { exec /bin/sh -c $shell_script } output]
exec /bin/umount $mnt_sys
if { $exitcode != 0 && $exitcode != 1 } {
error $output
}
catch { exec tune2fs -L 0userfs [get_partition_device $source_device 4] }
catch { exec tune2fs -L 0userfs $source_partition_device }
catch { exec tune2fs -L userfs $target_partition_device }
}
proc ::rmupdate::clone_system {target_device {activate_clone 0}} {
@ -898,7 +931,7 @@ 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}"
#puts "${img_file} ${image_file}"
if {$img_file != $image_file} {
file rename $img_file $image_file
}
@ -1416,3 +1449,4 @@ proc ::rmupdate::wlan_disconnect {} {
#rmupdate::clone_system /dev/sda 1
#puts [rmupdate::get_partitions]
#puts [array_to_json [rmupdate::get_partitions]]
#puts [rmupdate::move_userfs_to_device /dev/sda 1 0]

View File

@ -298,7 +298,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
$("#system-info").empty();
$("#system-info").append(
$('<div class="item">').html(i18next.t('system_type', {'system_type': data.system_type})),
$('<div class="item">').html(i18next.t('current_root_partiton', {'root_partition': data.root_partition}))
$('<div class="item">').html(i18next.t('current_root_partiton', {'root_partition': data.root_partition})),
$('<div class="item">').html(i18next.t('current_user_partiton', {'user_partition': data.user_partition}))
);
});
}
@ -491,6 +492,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
title: 'System update',
system_info: 'System information',
current_root_partiton: 'Current root partition: {{root_partition}}',
current_user_partiton: 'Current user partition: {{user_partition}}',
system_type: 'System type: {{system_type}}',
reboot_system: 'Reboot system',
shutdown_system: 'Shutdown system',
@ -552,6 +554,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
title: 'System-Aktualisierung',
system_info: 'System-Informationen',
current_root_partiton: 'Aktuelle Root-Partition: {{root_partition}}',
current_user_partiton: 'Aktuelle User-Partition: {{user_partition}}',
system_type: 'System-Typ: {{system_type}}',
reboot_system: 'System neu starten',
shutdown_system: 'System herunterfahren',

View File

@ -55,7 +55,8 @@ proc process {} {
} elseif {[lindex $path 1] == "get_system_info"} {
set system_type [rmupdate::get_rpi_version]
set root_partition [rmupdate::get_partition_device [rmupdate::get_system_device] [rmupdate::get_current_root_partition_number]]
return "\{\"system_type\":\"${system_type}\",\"root_partition\":\"${root_partition}\"\}"
set user_partition [rmupdate::get_mounted_device "/usr/local"]
return "\{\"system_type\":\"${system_type}\",\"root_partition\":\"${root_partition}\",\"user_partition\":\"${user_partition}\"\}"
} elseif {[lindex $path 1] == "system_reboot"} {
exec /sbin/reboot
return "\"reboot initiated\""