1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#!/usr/bin/perl -w
use strict;
use File::Copy;
my $PART = "hda7";
print "START: knx-install.pl\n";
my @lines;
#---------------------------------------------------------------------------------
# Copy /KNOPPIX
#---------------------------------------------------------------------------------
#
# ATTENTION grub etch ne fonctionne pas avec mkfs.ext3 lenny
#
system("mkfs.ext3 /dev/$PART") && die "ERROR: $!";
system("mount -t ext3 /dev/$PART /media/$PART") && die "ERROR: $!";
system("cp -Rpv /KNOPPIX/* /media/$PART") && die "ERROR: $!";
copy("/mnt-system/boot/isolinux/linux", "/media/$PART/boot/vmlinuz-2.6.28") || die "ERROR: $!";
copy("/etc/X11/xorg.conf", "/media/$PART/etc/X11") || die "ERROR: $!";
copy("/usr/share/keymaps/i386/azerty/fr.kmap.gz", "/media/$PART/etc/console/boottime.kmap.gz") || die "ERROR: $!";
chdir "/media";
@lines = glob("*");
foreach my $d (@lines) {
if ( ! -d "/media/$PART/media/$d" ) {
mkdir "/media/$PART/media/$d";
}
}
#---------------------------------------------------------------------------------
# Update /etc/fstab
#---------------------------------------------------------------------------------
open(FD, "</etc/fstab") || die "ERROR: $!";
@lines = <FD>;
close FD;
@lines = grep(!/$PART/, @lines);
push @lines, "\n/dev/$PART / ext3 errors=remount-ro 0 0\n";
open(FD, ">/media/$PART/etc/fstab") || die "ERROR: $!";
print FD join("", @lines);
close FS;
#---------------------------------------------------------------------------------
# Create /boot/initrd.img-2.6.28
#---------------------------------------------------------------------------------
copy("/mnt-system/boot/isolinux/linux", "/boot/vmlinuz-2.6.28") || die "ERROR: $!";
chdir "/boot";
system("mkinitramfs -o initrd.img-2.6.28 2.6.28") && die "ERROR: $!";
copy("initrd.img-2.6.28", "/media/$PART/boot") || die "ERROR: $!";
#---------------------------------------------------------------------------------
# Update /etc/inittab
#---------------------------------------------------------------------------------
open(FD, "</etc/inittab") || die "ERROR: $!";
@lines = <FD>;
close FD;
@lines = map { if (/^si/) { $_ = "si::sysinit:/etc/init.d/rcS"; }
elsif (/^# [2-6].*getty.*/) { m/^# (.*)/;
my $l = $1 . "\n";
substr($l, 4, 0) = "5";
$_= $l
}
elsif (/^# l[0-6]:/) { m/^# (.*)/;
$_ = $1 . "\n";
}
elsif (/^z/) { $_ = "## $_"; }
elsif (/^[1-4]:/) { $_ = "## $_"; }
elsif (/^x1:5/) { $_ = "x1:5:once:/bin/su -l -c \"/usr/bin/startx -- -br -noreset -nolisten tcp\" knoppix >/dev/console 2>&1\n"; }
else { $_ ;}
} @lines;
open(FD, ">/media/$PART/etc/inittab") || die "ERROR: $!";
print FD join("", @lines);
close FS;
#---------------------------------------------------------------------------------
# knoppix password
#---------------------------------------------------------------------------------
print "knoppix user account:\n";
system("chroot /media/$PART passwd knoppix") && die "ERROR: $!";
#---------------------------------------------------------------------------------
# Update /etc/network
#---------------------------------------------------------------------------------
open(FD, "</etc/network/interfaces") || die "ERROR: $!";
@lines = <FD>;
close FD;
@lines = map { if(/^iface eth0/) { $_ = "iface eth0 inet static"; }
else { $_ ;}
} @lines;
open(FD, ">/media/$PART/etc/network/interfaces") || die "ERROR: $!";
print FD join("", @lines);
close FS;
#---------------------------------------------------------------------------------
# GRUB
#---------------------------------------------------------------------------------
system("grub-install --root-directory=/media/$PART /dev/$PART") && die "ERROR: $!";
# hda2 -> hd0,1
my $n1 = index(join("", @{["a".."z"]}), substr($PART, 2, 1));
my $n2 = substr($PART, 3, 1) - 1;
open(FD, ">/media/$PART/boot/grub/menu.lst") || die "ERROR: $!";
print FD <<EOS;
default 0
timeout 5
color cyan/blue white/blue
title Knoppix 6.0 ($PART)
root (hd$n1,$n2)
kernel /boot/vmlinuz-2.6.28 root=/dev/$PART ro ramdisk_size=100000 lang=fr apm=power-off nomce vga=258
initrd /boot/initrd.img-2.6.28
savedefault
boot
EOS
close FD;
open(FD, "| grub --batch") || die "ERROR: $!";
print FD <<EOS;
root (hd$n1,$n2)
setup (hd$n1)
quit
EOS
close FD;
#---------------------------------------------------------------------------------
print "END: knx-install.pl\n"; |
Partager