summaryrefslogtreecommitdiffstats
path: root/globetrotter/make_live
diff options
context:
space:
mode:
Diffstat (limited to 'globetrotter/make_live')
-rwxr-xr-xglobetrotter/make_live65
1 files changed, 54 insertions, 11 deletions
diff --git a/globetrotter/make_live b/globetrotter/make_live
index e06960d3f..0752165e7 100755
--- a/globetrotter/make_live
+++ b/globetrotter/make_live
@@ -59,7 +59,7 @@ sub get_hds() {
my $all_hds = fsedit::get_hds();
my $other;
($all_hds->{hds}, $other) = partition { $_->{usb_description} eq 'LaCie|LaCie Hard Drive USB' } @{$all_hds->{hds}};
- die "I did not found any LaCie disk\n" if !$all_hds->{hds}[0];
+ my_exit("Your disk cannot be restored because it cannot be found!") if !$all_hds->{hds}[0];
$all_hds, $all_hds->{hds}[0]; # $other
}
@@ -103,6 +103,21 @@ sub formatdisk {
run_program::get_stdout('service', 'usb', 'start');
}
+sub my_exit {
+ my ($msg) = @_;
+ print "\n\n==============================================================\n\n";
+ print $msg;
+ print "\n\nPress <RETURN> to return back to menu\n\n";
+ print "==============================================================\n\n";
+ <STDIN>;
+ exit(0);
+}
+
+sub find_partition {
+ my ($label, @parts) = @_;
+ find { member(fs::type2fs($_), qw(ext2 ext3)) && chomp_(`e2label /dev/$_->{device} 2>/dev/root`) eq $label } @parts;
+}
+
my $pkg_dev;
if ($rescue) {
system("mount -t tmpfs none /tmp");
@@ -116,15 +131,23 @@ if ($rescue) {
my ($all_hds, $hd, $other) = get_hds();
print "Looking for the package partition\n";
my @parts = partition_table::get_normal_parts($hd);
- my $pkg_dev = find { member(fs::type2fs($_), qw(ext2 ext3)) && chomp_(`e2label /dev/$_->{device} 2>/dev/root`) eq "MDK-PKGS" } @parts;
- die "I cannot find the package partition which is needed in order to restore the system!" if is_empty_hash_ref($pkg_dev) || !$pkg_dev->{device};
- my $root = find { member(fs::type2fs($_), qw(ext2 ext3)) && chomp_(`e2label /dev/$_->{device} 2>/dev/root`) eq "MDK-ROOT" } @parts;
+ $pkg_dev = find_partition("MDK-PKGS", @parts);
+ #die "I cannot find the package partition which is needed in order to restore the system!"
+ my_exit("Your disk cannot be restored because there is no more a restore partition!") if is_empty_hash_ref($pkg_dev) || !$pkg_dev->{device};
+ print "Packages partition was found on $pkg_dev->{device}\n";
+ my $root = find_partition("MDK-ROOT", @parts);
$root = find { $_->{device} eq "sda1" } @parts if is_empty_hash_ref($root);
- die "I cannot find any hard disk to restore!" if is_empty_hash_ref($root) || !$root->{device};
+ #my_exit("I cannot find any hard disk to restore!") if is_empty_hash_ref($root) || !$root->{device};
+ my_exit("Your disk cannot be restored because there is no more a root partition!") if is_empty_hash_ref($root) || !$root->{device};
+ print "\nPlease wait, disk is being checked, this can take quite some time\n\n";
+ run_program::run("e2fsck -C0 -y $_") foreach map {
+ my $p = find_partition($_, @parts);
+ if_($p, $p->{device}); # handle lost labels
+ } "MDK-PKGS", "MDK-HOME"; # MDK-ROOT"
print "Please wait, disk reinstallation is in progress, this can take quite some time\n";
print "Formating $root->{device}\n";
system("mkfs.ext2 -j /dev/$root->{device} > /dev/null\n");
-
+ run_program::run('tune2fs', '-L', "MDK-ROOT", "/dev/$root->{device}"); # prevent lost label if restore aborts before the end
}
sub installPackages() {
@@ -166,8 +189,8 @@ sub installPackages() {
#my @l = glob_('/export/Mandrake/RPMS/kernel-enterprise-2.6*');
my @l = glob_('/export/Mandrake/RPMS/kernel-2.6*');
@l >= 1 or die "can't find kernel";
- @l <= 1 or die "too many kernels";
- first(`rpm -qp --qf '%{name}' $l[0]` =~ /kernel-(.*)/);
+ @l <= 1 or warn "too many kernels";
+ first(`rpm -qp --qf '%{name}' $l[-1]` =~ /kernel-(.*)/);
};
my $kernel_version = c::kernel_version();
@@ -275,6 +298,27 @@ sub config_X_proprietary_drivers() {
substInFile { $_ = '' if $_ eq 'nvidia' } "$::prefix/etc/modules";
}
+my $fstab;
+
+my $cleaner = before_leaving {
+ if (my $err = $@) {
+ print "\n>> an error happened: $err\n";
+ }
+ print "Cleaning on exiting\n";
+ print "- Umounting partitions:\n";
+ print "\tumounting /proc\n";
+ eval { fs::umount("$::prefix/proc") };
+ # fs::umount("$::prefix/$_") foreach 'mnt/packages', 'mnt/share', 'home', '';
+ if ($fstab) {
+ print "\tumounting everything else\n";
+ eval { fs::umount_all($fstab, $::prefix) } or system("umount $::prefix");
+ }
+ print "\tumounting /tmp\n";
+ eval { fs::umount("/tmp") } if $rescue;
+ print "Cleaning done\n";
+};
+
+
$::prefix = $ARGV[0] || '/tmp/live_tree';
-d $::prefix or mkdir $::prefix;
@@ -299,7 +343,7 @@ my ($root) = grep { $_->{mntpoint} eq "/" } @parts;
print "Root is $root->{device}\n";
run_program::run('tune2fs', '-L', "MDK-ROOT", "/dev/$root->{device}");
# fs::mount_part($root, $::prefix);
-my $fstab = [ fsedit::get_all_fstab($all_hds) ];
+$fstab = [ fsedit::get_all_fstab($all_hds) ];
# we need to mount every fs we want to see into /etc/fstab !!!
fs::mount_part($_, $::prefix) foreach sort { $a->{mntpoint} cmp $b->{mntpoint} } @$fstab;
@@ -457,5 +501,4 @@ run_program::rooted($::prefix, 'urpmi.addmedia', '-h', 'contrib', 'file:///mnt/p
# for fast test replaying:
run_program::rooted($::prefix, 'tar', 'cfj', '/root/etc.tar.bz2', '/etc');
-system("umount $::prefix/proc");
-eval { fs::umount_all($fstab, $::prefix) } or system("umount $::prefix");
+my_exit("Your disk was succesfully restored!\nYou can now reboot your machine.");