Implement userfs move

This commit is contained in:
Jan Schneider 2018-02-28 00:11:00 +01:00
parent 638b8ced7e
commit 469efb9ee1
3 changed files with 100 additions and 31 deletions

View File

@ -354,6 +354,16 @@ proc ::rmupdate::get_partitions {{device ""}} {
return [array get partitions]
}
proc ::rmupdate::get_disk_device {partition_device} {
if { [regexp {^(\S+mmcblk\d)p\d$} $partition_device match disk_device] } {
return $disk_device
}
if { [regexp {^(\S+)\d$} $partition_device match disk_device] } {
return $disk_device
}
return $partition_device
}
proc ::rmupdate::get_partition_device {device partition} {
if { [regexp {mmcblk} $device match] } {
return "${device}p${partition}"
@ -692,6 +702,13 @@ proc ::rmupdate::move_userfs_to_device {target_device {sync_data 0} {repartition
error [i18n "Target device does not exist."]
}
set target_partition_device ""
if {[get_disk_device $target_device] != $target_device} {
set target_partition_device $target_device
set target_device [get_disk_device $target_partition_device]
set repartition 0
}
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] } {
@ -705,35 +722,39 @@ proc ::rmupdate::move_userfs_to_device {target_device {sync_data 0} {repartition
error [i18n "Source and target are the same device."]
}
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 {
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 {$target_partition_device == ""} {
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 {
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]
}
}
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]
}
set target_partition_device [get_partition_device $target_device $partition_number]
if {$sync_data == 1} {
catch { exec /bin/umount $target_partition_device }
set exitcode [catch { exec /sbin/mkfs.ext4 -F -L userfs $target_partition_device } output]
if { $exitcode != 0 && $exitcode != 1 } {
error $output
@ -1508,6 +1529,7 @@ proc ::rmupdate::wlan_disconnect {} {
#puts [rmupdate::get_system_device]
#puts $rmupdate::sys_dev
#rmupdate::clone_system /dev/sda 1
#puts [rmupdate::get_disk_device /dev/mmcblk0p3]
#puts [rmupdate::get_partitions]
#puts [array_to_json [rmupdate::get_partitions]]
#puts [rmupdate::move_userfs_to_device /dev/sda 1 0]
#rmupdate::move_userfs_to_device /dev/sda1 1 0

View File

@ -301,7 +301,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
rest("GET", "/get_system_info", null, function(data) {
$("#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('system_type', {'system_type': data.system_type})),
$('<div class="item">').html(i18next.t('uptime', {'uptime': data.uptime}))
);
});
}
@ -344,13 +345,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var partition = disks[disk_device].partitions[part];
var menu_items = [];
if ((partition.partition == 0) && (! disks[disk_device].usr_local_on_disk)) {
menu_items.push($('<a class="item">').append(i18next.t('use_disk_for_userfs')).attr('data-disk-device', partition.disk_device).click(function() {
alert("test: " + this.getAttribute('data-disk-device'));
if (! disks[disk_device].usr_local_on_disk) {
var device = partition.disk_device;
var label = i18next.t('use_disk_for_userfs');
if (partition.partition > 0) {
device = partition.partition_device;
var label = i18next.t('use_partition_for_userfs');
}
menu_items.push($('<a class="item">').append(label).attr('data-device', device).click(function() {
var target_device = this.getAttribute('data-device');
$('#modal-move-userfs').modal({
onDeny: function(){
return true;
},
onApprove: function() {
rest('POST', '/move_userfs_to_device', JSON.stringify({"target_device":target_device}), function(data) {
display_message('success', i18next.t('userfs_moved'), 120000);
rest('POST', '/system_reboot');
});
return true;
}
})
.modal('show');
}));
}
var menu = null;
/*
if (menu_items.length > 0) {
menu = $('<div class="ui compact menu" style="min-height:30px; max-height: 30px;">').append(
$('<div class="ui dropdown item">').append(
@ -360,7 +379,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
)
)
}
*/
if (partition.partition == 0) {
var st = "border:none; border-top: 2px solid #aaafaf";
@ -581,6 +599,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
title: 'System update',
system_info: 'System information',
system_type: 'System type: {{system_type}}',
uptime: 'Uptime: {{uptime}}',
reboot_system: 'Reboot system',
shutdown_system: 'Shutdown system',
reboot: 'Reboot',
@ -598,6 +617,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
size: 'Size',
usage: 'Usage',
use_disk_for_userfs: 'Use whole disk for userfs.',
use_partition_for_userfs: 'Use partition for userfs.',
move_userfs: 'Move userfs to another device',
sure_to_move_userfs: 'Are you sure you want to move userfs?',
move: 'Move',
userfs_moved: 'Userfs moved, system will reboot now.',
firmwares: 'Firmwares',
current_installed_version: 'Current installed version',
latest_available_version: 'Latest available version',
@ -651,6 +675,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
title: 'System-Aktualisierung',
system_info: 'System-Informationen',
system_type: 'System-Typ: {{system_type}}',
uptime: 'Betriebszeit: {{uptime}}',
reboot_system: 'System neu starten',
shutdown_system: 'System herunterfahren',
reboot: 'Neu starten',
@ -668,6 +693,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
size: 'Größe',
usage: 'Belegt',
use_disk_for_userfs: 'Den gesamten Datenträger für das userfs verwenden.',
use_partition_for_userfs: 'Die Partition als userfs verwenden.',
move_userfs: 'Userfs auf anderen Datenträger verschieben',
sure_to_move_userfs: 'Soll das userfs wirklich verschoben werden?',
move: 'Verschieben',
userfs_moved: 'Userfs wurde verschoben, das System wird neu gestartet.',
firmwares: 'Firmwares',
current_installed_version: 'Momentan installierte Version',
latest_available_version: 'Aktuellste verfügbare Version',
@ -981,6 +1011,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</div>
</div>
<div id="modal-move-userfs" class="ui small basic modal transition scrolling">
<div data-i18n="move_userfs" class="header"></div>
<div class="content">
<p data-i18n="sure_to_move_userfs"></p>
</div>
<div class="actions">
<div data-i18n="cancel" class="ui gray basic cancel inverted button">
</div>
<div data-i18n="move" class="ui red approve inverted button">
</div>
</div>
</div>
<div id="modal-connect-wlan" class="ui modal">
<i class="close icon"></i>
<div class="header" data-i18n="connect_to_wlan">

View File

@ -54,9 +54,13 @@ proc process {} {
return [rmupdate::get_firmware_info]
} elseif {[lindex $path 1] == "get_system_info"} {
set system_type [rmupdate::get_rpi_version]
return "\{\"system_type\":\"${system_type}\"\}"
set uptime [exec /usr/bin/uptime]
return "\{\"system_type\":\"${system_type}\",\"uptime\":\"${uptime}\"\}"
} elseif {[lindex $path 1] == "get_partitions"} {
return [array_to_json [rmupdate::get_partitions]]
} elseif {[lindex $path 1] == "move_userfs_to_device"} {
regexp {\"target_device\"\s*:\s*\"([^\"]+)\"} $data match target_device
return [rmupdate::move_userfs_to_device $target_device 1 1]
} elseif {[lindex $path 1] == "system_reboot"} {
exec /sbin/reboot
return "\"reboot initiated\""