aboutsummaryrefslogtreecommitdiffstats
path: root/BCD/Isolinux.pm
blob: 6b0d8dfa1bfe1956572a38ecab117135dc1251e6 (plain)
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
package BCD::Isolinux;

use File::Copy::Recursive qw(dircopy pathrm);
use BCD::Common qw(:DEFAULT $isoconf $wd $name $arch $version $based_on $repo $builddir);

our @ISA = qw(Exporter);
our @EXPORT = qw(main_isolinux);

my $LOG="ISOLINUX -";
my $color = "yellow";

my $repo_isolinux;
if (!defined($isoconf->{isolinux}{fullpath})) {
	$repo_isolinux = "$repo/$based_on/$arch/$isoconf->{isolinux}{defaultpath}/";
} else {
	$repo_isolinux = $isoconf->{isolinux}{fullpath};
}
my $build_isolinux_dir = "$builddir/isolinux";

sub switch_theme {
    my $theme = $isoconf->{theme}{bootsplash};
    print_color("$LOG switch to theme $theme", $color);
    -d "$isoconf->{theme}{bootsplash_path}/themes/$theme" or die "$LOG cant find the gfxboot theme: $isoconf->{theme}{bootsplash_path}/themes/$theme";
    opendir my $DIR, $build_isolinux_dir or die "$LOG FATAL switch_theme: unable to open $build_isolinux_dir\n";
    foreach my $f (readdir $DIR) {
        $f =~ /^\.{1,2}$/ and next;
        -d "$build_isolinux_dir/$f" or next;
        opendir my $ALT, "$build_isolinux_dir/$f" or die "LOG FATAL switch_theme: unable to open $dir/$f\n";
        foreach my $all (readdir $ALT) {
            $all =~ /all.rdz/ or next;
            my $initrd = "$build_isolinux_dir/$f/$all";
            my $binary = "/usr/share/bootsplash/scripts/make-boot-splash-raw";
            -x $binary or die "$LOG you need $binary which is available in bootsplash >= 3.2.3\n";
	    my $cmd;
	    if ($isoconf->{based_on} gt "2009.1" && $isoconf->{based_on} ne "mes5") {
            	$cmd = "$binary $initrd $theme";
    		} else {
		# old script use a resolution parameter
	    	$cmd = "$binary $initrd 800x600 $theme";
	    }
	    print_color("$LOG using $f", $color);
            system($cmd) == 0 or die "$LOG FATAL switch_theme: config file for $theme may not exist\n";
        }
        closedir $ALT;
    }
    closedir $DIR;
    # syslinux
    my $lilo_sys = "$isoconf->{theme}{bootsplash_path}/themes/$theme/lilo/syslinux";
    -f $lilo_sys and system("cp -vf $lilo_sys", "$build_isolinux_dir/boot.msg");
    print_color("$LOG copy $isoconf->{theme}{gfxboot_path}/themes/*.jpg to $build_isolinux_dir/",, $color);
    system("cp -vf $isoconf->{theme}{gfxboot_path}/themes/$theme/welcome.jpg $build_isolinux_dir/");
    system("cp -vf $isoconf->{theme}{gfxboot_path}/themes/$theme/back.jpg $build_isolinux_dir/");
}

sub add_entry {
    my $syslinuxcfg = "$build_isolinux_dir/isolinux.cfg";
    -f $syslinuxcfg or die "$LOG can't path $syslinuxcfg";
    foreach my $syslinux (@{$isoconf->{isolinux}{entry}}) {
	$syslinux->{name} or next;
	print_color("$LOG add $syslinux->{name} in $syslinuxcfg", $color);
	open my $SYS, ">> $syslinuxcfg";
	print $SYS "label $syslinux->{label}\n";
	print $SYS "    kernel $syslinux->{kernel}\n";
	print $SYS "    append $syslinux->{append}\n";
	close $SYS;
	if (-f $syslinux->{bin}) {
	       	system("cp -vf $syslinux->{bin} $build_isolinux_dir/");
	} else {
		die "$LOG $syslinux->{bin} is not present on the system !\n";
	}
    }
}

sub use_firmware {
    print_color("$LOG copy fw.gz to $build_isolinux_dir/alt0/", $color);
    my $syslinuxcfg = "$build_isolinux_dir/isolinux.cfg";
    open (IN, "+<$syslinuxcfg");
    @file = <IN>;
    seek IN,0,0;
    foreach (@file){
	$_ =~ s|alt0/all.rdz|alt0/all.rdz,alt0/fw.gz|g;
        print IN $_;
    }
    close IN;
    system("cp -v /usr/lib*/drakx-installer-images/isolinux/alt0/fw.gz $build_isolinux_dir/alt0/")
}

sub copy_files {
	foreach my $file (@{$isoconf->{isolinux}{tocopy}}) {
		$file->{name} or next;
		if (-f $file->{file}) {
			print_color("$LOG copy $file->{file} in $build_isolinux_dir", $color);
			system("cp -avf $file->{file} $build_isolinux_dir/");
		} else {
			die "$LOG $file->{file} is not present on the system !\n";
		}
	}
}

sub main_isolinux {
    if (! -d $repo_isolinux) { 
	print_color("$LOG I can't find the isolinux dir $repo_isolinux !", $color);
	exit;
    }
    print_color("$LOG Remove old copy of isolinux", $color);
    pathrm("$build_isolinux_dir/isolinux") or die $!;
    print_color("$LOG copy $repo_isolinux to $build_isolinux_dir", $color);
    dircopy($repo_isolinux, $build_isolinux_dir) or die $!;
    add_entry;
    if ($isoconf->{isolinux}{firmware} eq "yes") {
	    use_firmware;
    }
    copy_files;
    switch_theme;
}

1;