-
Notifications
You must be signed in to change notification settings - Fork 1
/
addRTpatch.pl
executable file
·166 lines (149 loc) · 3.49 KB
/
addRTpatch.pl
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
160
161
162
163
164
165
#!/usr/bin/perl
## Howto
##
## addRTpatch.pl -n patch_tarball out_xml_file : creates a new XML file with the list of patches contained in the tarball
## addRTpatch.pl -a patch_tarball out_xml_file : appends the list of patches contained in the tarball to an existing list
##
## The XML file helps to manage the Xenomai and RTAI linux patches. It lists for each of them the set of patches it contains and for
## which architecture and kernel version they can be used
##
#########
use Data::Dumper;
use XML::Simple;
## Retrieving the work directory
my $WORKING_DIR = `readlink -f $0`;
$WORKING_DIR = `dirname $WORKING_DIR`;
chomp $WORKING_DIR;
my $rt_patches;
my $xml_file;
if($#ARGV == 2)
{
if($ARGV[0] eq '-n')
{
$rt_patches = {
'RTextension_version' => []
};
$xml_file = $ARGV[2];
}
elsif($ARGV[0] eq '-a')
{
my $xml_reader = new XML::Simple(ForceArray => 1);
$xml_file=$ARGV[2];
$rt_patches = $xml_reader->XMLin($xml_file);
}
else
{
die 'Wrong command';
}
}
else
{
die 'Wrong number of parameters';
}
## Determine the type of compression
my $tarball = `readlink -f $ARGV[1]`;
if($tarball =~ m/.*\.tar.gz$/)
{
open(FILE_LIST,"tar -tzf $tarball |");
}
elsif($tarball =~ m/.*\.tar.bz2/)
{
open(FILE_LIST,"tar -tjf $tarball |");
}
else
{
die 'This archive is not supported. Please provide a .gz or .bz2 tarball';
}
my @file_list = <FILE_LIST>;
close(FILE_LIST);
## Determine the type of the RT extension
my $extension_type;
if($file_list[0] =~ m/xenomai.*/)
{
$extension_type = 'Xenomai';
}
elsif($file_list[0] =~ m/rtai.*/)
{
$extension_type = 'RTAI';
}
else
{
die 'Please give a valid RT patch';
}
my $rt_extension = {
'version' => '', 'patch' => []
};
if($file_list[0] =~ m/.*-(.*)\//)
{
$rt_extension->{version} = $1;
}
## Checking whether the version already exists
if($ARGV[0] eq '-a')
{
foreach $rt_version (@{$rt_patches->{RTextension_version}})
{
if($rt_version->{version}->[0] eq $rt_extension->{version})
{
die 'This version already exists';
}
}
}
## Retrieving the patches according to each RT linux extension
if($extension_type eq 'Xenomai')
{
foreach my $file (@file_list)
{
my $patch = {
'name' => '', 'arch' => '', 'kernel' => ''
};
if($file =~ m/.*\/ksrc\/arch\/(\w+)\/patches\/(.*)\.patch/)
{
$arch = $1;
if($1 eq 'ppc'){$arch = 'powerpc';}
if($1 eq 'i386'){$arch = 'x86';}
$patch->{arch} = $arch;
$patch->{name} = $file;
$patch->{kernel} = $2;
if($patch->{kernel} =~ s/.*-(\d+\.\d+\.\d+).*/$1/)
{
push @{$rt_extension->{patch}},$patch;
}
}
}
}
elsif($extension_type eq 'RTAI')
{
foreach my $file (@file_list)
{
my $patch = {
'name' => '', 'arch' => '', 'kernel' => ''
};
if($file =~ m/.*\/base\/arch\/(\w+)\/patches\/(.*)\.patch/)
{
$arch = $1;
if($1 eq 'ppc'){$arch = 'powerpc';}
if($1 eq 'i386'){$arch = 'x86';}
$patch->{arch} = $arch;
$patch->{name} = $file;
$patch->{kernel} = $2;
if($patch->{kernel} =~ s/.*-(\d+\.\d+\.\d+).*/$1/)
{
push @{$rt_extension->{patch}},$patch;
}
}
}
}
push @{$rt_patches->{RTextension_version}},$rt_extension;
my $xml_writer = new XML::Simple (NoAttr=>1, XMLDecl=>0, RootName=>"$extension_type".'Patches');
my $data = $xml_writer->XMLout($rt_patches);
#print Dumper($data);
#exit;
## Writing XML
if (! open (XML_FILE, ">$xml_file"))
{
die "Ensure that the path to the file is correct or that write permission is granted.";
}
$xml_header = "<?xml version='1.0'?>\n";
printf(XML_FILE $xml_header);
printf(XML_FILE $data);
close(XML_FILE);