« lib/Tapper/Installer/Precondition/Kernelbuild.pm
↑ Summary
lib/Tapper/Installer/Precondition/PRC.pm »
| 1 | package Tapper::Installer::Precondition::Rawimage; | ||||||||||||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||
| 3 | 5 | $Tapper::Installer::Precondition::Rawimage::VERSION = '5.0.3'; | |||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 5 | ▶ | use File::Path; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 5 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | extends 'Tapper::Installer::Precondition'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 0 | ▶ | sub install { | ||||||||||||||||||
|
Subroutine
install: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||
| 15 | 0 | my ($self, $img) = @_; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 0 | ▶ | return "not filename given for rawimage" if not $img->{name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | my $img_size = 2048*1024; # 2GByte - size of standard rawimage in kbyte | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | my $filename = $img->{name}; | |||||||||||||||||||
| 22 | 0 | my $path = $self->cfg->{paths}{base_dir}.$img->{path}; | |||||||||||||||||||
| 23 | 0 | ▶ | my $size = $img->{size} || $img_size; | ||||||||||||||||||
|
Condition0%0/3
$img->{'size'} || $img_size
MC/DC0%0/2
$img->{'size'} || $img_size
$img->{'size'}
$img_size
Truth table0%0/3
A || B
A= $img->{'size'}B= $img_size
| |||||||||||||||||||||
| 24 | 0 | my ($error, $retval); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | if (not -d $path) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 0 | mkpath($path, {error => \$error}); | |||||||||||||||||||
| 28 | 0 | foreach my $diag (@$error) { | |||||||||||||||||||
| 29 | 0 | my ($file, $message) = each %$diag; | |||||||||||||||||||
| 30 | 0 | ▶ | return "general error: $message\n" if $file eq ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 0 | return "Can't create $file: $message"; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | $filename = $path."/".$filename; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ($error, $retval) = $self->log_and_exec("dd if=/dev/zero of=$filename bs=1024 count=$size"); | |||||||||||||||||||
| 38 | 0 | ▶ | return $retval if $error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ($error, $retval) = $self->log_and_exec("/sbin/mkfs.ext3 -F -L tapper $filename"); | |||||||||||||||||||
| 41 | 0 | ▶ | return $retval if $error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | $self->makedir($self->cfg->{paths}{guest_mount_dir}) if not -d $self->cfg->{paths}{guest_mount_dir}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | ($error, $retval) = $self->log_and_exec("mount -o loop $filename ".$self->cfg->{paths}{guest_mount_dir}); | |||||||||||||||||||
| 45 | 0 | ▶ | return $retval if $error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | my $mountdir = $self->cfg->{paths}{guest_mount_dir}; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | mkdir ("$mountdir/etc") or return ("Can't create /etc in raw image $filename: $!"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | ▶ | open(my $FH,">","$mountdir/etc/tapper-release") or return "Can't open /etc/tapper-release in raw image $filename: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | print $FH "Tapper"; | |||||||||||||||||||
| 51 | 0 | close $FH; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ($error, $retval) = $self->log_and_exec("umount $mountdir"); | |||||||||||||||||||
| 54 | 0 | ▶ | return $retval if $error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 0 | return 0; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | ; | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 5 | 1; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||