3
#############################################################################
5
# File: cd_rpmbuilder "CipherDyne Rpm Builder"
7
# Purpose: Provides a consistent way to build RPMs of CipherDyne open source
8
# projects (psad, fwsnort, fwsknop, and gpgdir).
10
# Author: Michael Rash
12
# Copyright (C) 2006-2008 Michael Rash (mbr@cipherdyne.org)
14
# License (GNU Public License - GPLv2):
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program; if not, write to the Free Software
23
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26
#############################################################################
28
# $Id: cd_rpmbuilder 1864 2008-08-22 03:16:19Z mbr $
33
use Getopt::Long 'GetOptions';
36
#============================ config =============================
37
my $rpm_root_dir = '/usr/src/redhat';
38
my $build_url_base = 'http://www.cipherdyne.org';
41
my $rpmbuildCmd = '/usr/bin/rpmbuild';
42
my $wgetCmd = '/usr/bin/wget';
43
#========================== end config ===========================
48
my $build_version = '';
49
my $print_version = 0;
66
Getopt::Long::Configure('no_ignore_case');
67
&usage() unless (GetOptions(
68
'project=s' => \$project,
69
'build-version=s' => \$build_version,
70
'rpm-build-dir=s' => \$rpm_root_dir,
71
'no-deps' => \$nodeps,
72
'verbose' => \$verbose,
73
'Version' => \$print_version,
79
print "[+] cd_rpmbuilder by Michael Rash <mbr\@cipherdyne.org>\n";
84
unless (defined $projects{$project}) {
85
print "[*] Unrecognized project: $project; must be one of:\n";
86
print $_, "\n" for keys %projects;
90
die "[*] Must specify a project with -p <project>\n";
93
die "[*] $wgetCmd is not a valid path to wget, update the config section."
95
die "[*] $rpmbuildCmd is not a valid path to rpmbuild, update the config " .
96
"section." unless -x $rpmbuildCmd;
98
chdir "$rpm_root_dir/SPECS" or die "[*] Could not chdir $rpm_root_dir/SPECS";
100
unless ($build_version) {
101
### we need to get the latest version from cipherdyne.org
102
&get_latest_version();
105
my $spec_file = "$project-$build_version.spec";
106
my $tar_file = "$project-$build_version.tar.gz";
109
$spec_file = "$project-nodeps-$build_version.spec";
110
$tar_file = "$project-nodeps-$build_version.tar.gz";
116
### get the remote spec file
117
&download_file($spec_file);
118
&md5_check($spec_file);
120
### get the remote source tarball and md5 sum file
121
&download_file($tar_file);
122
&md5_check($tar_file);
125
move $tar_file, "../SOURCES/$project-$build_version.tar.gz" or die $!;
127
move $tar_file, '../SOURCES' or die $!;
133
### print the paths to the new RPMS
137
#======================= end main ========================
142
find(\&get_rpms, "$rpm_root_dir/SRPMS");
143
find(\&get_rpms, "$rpm_root_dir/RPMS");
144
if ($action == $PRINT) {
146
print "[+] The following RPMS were successfully built:\n\n";
148
print "[-] No RPMS were successfully built; try running ",
152
for my $rpm_file (@rpm_paths) {
153
if ($action == $RM) {
154
unlink $rpm_file or die "[*] Could not unlink $rpm_file: $!";
155
} elsif ($action == $PRINT) {
156
if ($rpm_file =~ /\.src\.rpm/) {
157
print " $rpm_file (source RPM)\n";
159
print " $rpm_file\n";
163
print "\n" if $action == $PRINT;
168
my $file = $File::Find::name;
169
if ($file =~ /$project-$build_version-.*\.rpm$/) {
170
push @rpm_paths, $file;
175
sub download_file() {
177
unlink $file if -e $file;
178
print "[+] Downloading file:\n",
179
" $build_url_base/$project/download/$file\n";
180
my $cmd = "$wgetCmd $build_url_base/$project/download/$file";
182
$cmd .= ' > /dev/null 2>&1';
185
die "[*] Could not download $file, try running with -v"
193
&download_file("$file.md5");
195
open MD5, "md5sum -c $file.md5 |"
197
my $sum_line = <MD5>;
199
unless ($sum_line =~ m/$file:\s+OK/) {
200
die "[*] MD5 sum check failed for $file, ",
203
print "[+] Valid md5 sum check for $file\n";
210
"[+] Building RPM, this may take a little while (try -v if you want\n",
211
" to see all of the steps)...\n\n";
212
my $cmd = "$rpmbuildCmd -ba $spec_file";
214
$cmd .= ' > /dev/null 2>&1';
220
sub get_latest_version() {
221
unlink "$project-latest" if -e "$project-latest";
222
print "[+] Getting latest version file:\n",
223
" $build_url_base/$project/$project-latest\n";
224
my $cmd = "$wgetCmd $build_url_base/$project/$project-latest";
226
$cmd .= ' > /dev/null 2>&1';
229
open F, "< $project-latest" or
230
die "[*] Could not open $project-latest: $!";
234
$build_version = $line;
235
die "[*] Could not get build version" unless $build_version;
236
unlink "$project-latest" if -e "$project-latest";
243
cd_rpmbuilder; the CipherDyne RPM builder
244
[+] Version: $version
245
[+] By Michael Rash (mbr\@cipherdyne.org, http://www.cipherdyne.org)
247
Usage: cd_rpmbuilder -p <project> [options]
250
-p, --project <name> - This can be one of "psad", "fwknop",
251
"gpgdir", or "fwsnort".
252
-b, --build-version <ver> - Build a specific project version.
253
-r, --rpm-build-dir <dir> - Change the RPM build directory from the
254
default of $rpm_root_dir.
255
-n, --no-deps - Build the specified project without any
256
dependencies (such as perl modules).
257
-v, --verbose - Run in verbose mode.
258
-V, --Version - Print version and exit.
259
-h, --help - Display usage information.