summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmove/tree/mdk_move_loop46
1 files changed, 46 insertions, 0 deletions
diff --git a/move/tree/mdk_move_loop b/move/tree/mdk_move_loop
new file mode 100755
index 000000000..6b239316b
--- /dev/null
+++ b/move/tree/mdk_move_loop
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+
+my %loop = (boot => 'loop0', always => 'loop1', totem => 'loop2');
+
+sub check {
+ my ($loop, $file) = @_;
+ `sudo losetup /dev/$loop 2>/dev/null` =~ m!/$file!;
+}
+
+sub name2file {
+ my ($name) = @_;
+ "live_tree_$name.clp";
+}
+
+sub to_memory {
+ my ($loop, $file) = @_;
+
+ return if -e "/tmp/$file";
+
+ if (-e "/$file") {
+ system("sudo mv /$file /tmp");
+ } else {
+ system("sudo cp /image_raw/$file /tmp");
+ }
+ system("sudo losetup /dev/$loop /tmp/$file");
+}
+
+sub to_cdrom {
+ my ($loop, $file) = @_;
+ my $f = -e "/$file" ? "/$file" : -e "/tmp/$file" ? "/tmp/$file" : return;
+ system("sudo losetup /dev/$loop /image_raw/$file");
+ system("sudo rm $f");
+}
+
+sub usage() { die "usage: mdk_move_loop <to_cdrom | to_memory> [names ...]\n" }
+
+my ($direction, @names) = @ARGV;
+my $f = $direction eq 'to_memory' && \&to_memory || $direction eq 'to_cdrom' && \&to_cdrom;
+$f && @names or usage();
+
+foreach my $name (@names) {
+ my $loop = $loop{$name} or die "unknown name $name\n";
+ my $file = name2file($name);
+ check($loop, $file) or next;
+ $f->($loop, $file);
+}