aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/remove-boot-splash
blob: ee973a24ddb8c5f640d06eb20e3856ad436b4e96 (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
#!/usr/bin/perl

@ARGV == 1 or die "usage: remove-splash <initrd>\n";

my $magic = 'BOOTSPL3';
my $buffer_size = 15;

my ($initrd) = @ARGV;

# FIXME it must have a clear way to do that in perl
if (!system("/bin/zcat $initrd 2> /dev/null | /bin/cpio -t &> /dev/null")) {
    print STDERR "remove-boot-splash: initrd in initramfs format\n";
    chomp(my $tmp_dir = `mktemp -d`);
    chdir $tmp_dir;
    system("/bin/zcat $initrd 2>/dev/null | /bin/cpio -id 2>/dev/null");
    if (-d "$tmp_dir/usr/share/plymouth") {
	system("rm -fr $tmp_dir/usr/share/plymouth $tmp_dir/usr/lib/plymouth $tmp_dir/usr/lib/libply* $tmp_dir/lib/libply* $tmp_dir/bin/plymouthd $tmp_dir/bin/plymouth $tmp_dir/etc/splashy $tmp_dir/usr/share/splashy");
	print STDERR "remove-boot-splash: removing plymouth from initrd\n";
	system("/bin/find . -print | /bin/cpio --quiet -c -o 2> /dev/null | gzip -c > $initrd")
    } else {
	print STDERR "ERROR remove-boot-splash: plymouth not found in $initrd\n"
    }
    system("rm -rf $tmp_dir");
    exit
}

open(my $F, "+< $initrd") or die "can't open $initrd: $!\n";

while (1) {
    my $got = read($F, my $buffer, $buffer_size);
    $got > length($magic) or last;

    my $index = index($buffer, $magic);
    if ($index >= 0) {
	my $offset = $index + tell($F) - $got;

	seek($F, $offset + 12, 0) && read($F, my $tmp, 4) or last;
	my $splash_size = unpack("V", $tmp) + 38;

	my $initrd_size = seek($F, 0, 2) && tell($F);
	
	if ($offset + $splash_size == $initrd_size) {
	    truncate($F, $offset);
	    exit 0;
	} else {
	    warn "bootsplash found at offset $offset, but it is not at the end ($offset + $splash_size != $initrd_size)\n";
	}
    }
    seek($F, -length($magic), 1); # handle the case BOOTSPL3 when overlaps between buffers
}

warn "bootsplash not found in $initrd\n";