summaryrefslogtreecommitdiff
path: root/scripts/cpanflute
blob: a95f5978955e21859d808cd74edccd291310bdd4 (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
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
166
167
168
169
170
171
172
173
#!/usr/bin/perl

# need this for hostname()
use File::Basename;
use Sys::Hostname;
use Getopt::Long;
use strict;

my $MainDir = '/tmp/cpan';

# set default options, then get options
my %options=();
$options{'email'}=(getpwuid($<))[0] . "\@redhat.com" ;
GetOptions(\%options, "email=s", "n=s", "create") || exit 1;

my $InputFile = $ARGV[0];
my $create = '';

if ($options{'create'}) {
  $create = '-c';
}

my $tarball = basename($InputFile);
$tarball =~ /(\S+)\-(\S+)\.tar\.gz/;
my $clm_name=$1;
my $clm_version=$2;

my $class = dirname($InputFile);
$class =~ s/^\.\/[0-9][0-9]_//;
if ($class ne '.') {
  $class = "($class)";
} else {
  $class = "";
}

# Change ::'s to -'s
$clm_name =~ s/::/-/g;

my $clm_changelog = get_changelog();

# complain if either parameter is missing
($clm_name eq "") && die "Module name not specified\n";
($clm_version eq "") && die "Module version not specified\n";

# Create and Open file to create SPEC files.
mkdir($MainDir, 0755);
system("cp $InputFile $MainDir");
my $filename = $clm_name . '.spec'; 
open (FILE, "> $MainDir/$filename");

# Print the spec file. Lots of substitutions here.
print FILE "Summary: $clm_name module for perl $class
Name: perl-$clm_name
Version: $clm_version
Release: 7
Copyright: distributable
Group: Applications/CPAN
Source0: $clm_name-$clm_version.tar.gz
Url: http://www.cpan.org
BuildRoot: %{_tmppath}/perl-$clm_name-buildroot/
BuildRequires: perl >= 0:5.00503
Requires: perl >= 0:5.00503

%description
$clm_name module for perl

# Provide perl-specific find-{provides,requires}.
%define __find_provides /usr/lib/rpm/find-provides.perl
%define __find_requires /usr/lib/rpm/find-requires.perl

%prep
%setup -q -n $clm_name-%{version} $create

%build
CFLAGS=\"\$RPM_OPT_FLAGS\" perl Makefile.PL
make

%clean 
rm -rf \$RPM_BUILD_ROOT

%install
rm -rf \$RPM_BUILD_ROOT
eval `perl '-V:installarchlib'`
mkdir -p \$RPM_BUILD_ROOT/\$installarchlib
make PREFIX=\$RPM_BUILD_ROOT/usr install

[ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress

find \$RPM_BUILD_ROOT/usr -type f -print | \
	sed \"s\@^\$RPM_BUILD_ROOT\@\@g\" | \
	grep -v perllocal.pod | \
	grep -v \"\\.packlist\" > $clm_name-$clm_version-filelist
if [ \"\$(cat $clm_name-$clm_version-filelist)X\" = \"X\" ] ; then
    echo \"ERROR: EMPTY FILE LIST\"
    exit -1
fi

%files -f $clm_name-$clm_version-filelist
%defattr(-,root,root)

%changelog
* $clm_changelog
- Spec file was autogenerated. 
";
close(FILE);

# Now build the rpm
create_rcfiles();

open (LOG, "> $MainDir/LogFile");
build_rpm();
close LOG;

sub cleanup {
  unlink "$MainDir/$filename";
  unlink "$MainDir/$tarball";
}

sub build_rpm {
  my $retval;

  # First, make sure it unpacks cleanely
  system("rpm --rcfile $MainDir/rpmrc -bp $MainDir/$filename");
  $retval = $? >> 8;
  if ($retval != 0) {
    print "RPM test unpacking failed!\n";
    print LOG "PREP failed: $filename\n";
    return;
  }

  system("rpm --rcfile $MainDir/rpmrc -bs --rmsource --rmspec --clean $MainDir/$filename");
  $retval = $? >> 8;
  if ($retval != 0) {
    print "RPM building failed!\n";
    print LOG "SOURCE failed: $filename\n";
    return;
  }
  cleanup();
}

sub create_rcfiles {
    open(MACROS, "> $MainDir/macros");
    print MACROS qq{
%_topdir        $MainDir
%_builddir      %{_topdir}/junk
%_rpmdir        %{_topdir}
%_sourcedir     %{_topdir}
%_specdir       %{_topdir}
%_srcrpmdir     %{_topdir}/temp
};
    close(MACROS);
  
    open(RPMRC, "> $MainDir/rpmrc");
    print RPMRC qq{
include: /usr/lib/rpm/rpmrc
macrofiles: /usr/lib/rpm/macros:$MainDir/macros
};
    close(RPMRC);
}

sub get_changelog {
  # generate the changelog entry from available system info
	my ($name);

	$name = (getpwuid($<))[6];
	$name = (split(",", $name))[0];
  return ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")[(localtime)[6]] . " " .
    ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[(localtime)[4]] . " " .
    (localtime)[3] . " " . (1900+(localtime)[5]) . " " .
		$name . " <" . $options{'email'} . ">";
}