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 #############################################################################
31 use Getopt::Long 'GetOptions';
34 #============================ config =============================
35 my $rpm_root_dir = '/usr/src/redhat';
36 my $build_url_base = 'http://www.cipherdyne.org';
39 my $rpmbuildCmd = '/usr/bin/rpmbuild';
40 my $wgetCmd = '/usr/bin/wget';
41 #========================== end config ===========================
46 my $build_version = '';
47 my $print_version = 0;
64 Getopt::Long::Configure('no_ignore_case');
65 &usage() unless (GetOptions(
66 'project=s' => \$project,
67 'build-version=s' => \$build_version,
68 'rpm-build-dir=s' => \$rpm_root_dir,
69 'no-deps' => \$nodeps,
70 'verbose' => \$verbose,
71 'Version' => \$print_version,
77 print "[+] cd_rpmbuilder by Michael Rash <mbr\@cipherdyne.org>\n";
82 unless (defined $projects{$project}) {
83 print "[*] Unrecognized project: $project; must be one of:\n";
84 print $_, "\n" for keys %projects;
88 die "[*] Must specify a project with -p <project>\n";
91 die "[*] $wgetCmd is not a valid path to wget, update the config section."
93 die "[*] $rpmbuildCmd is not a valid path to rpmbuild, update the config " .
94 "section." unless -x $rpmbuildCmd;
96 chdir "$rpm_root_dir/SPECS" or die "[*] Could not chdir $rpm_root_dir/SPECS";
98 unless ($build_version) {
99 ### we need to get the latest version from cipherdyne.org
100 &get_latest_version();
103 my $spec_file = "$project-$build_version.spec";
104 my $tar_file = "$project-$build_version.tar.gz";
107 $spec_file = "$project-nodeps-$build_version.spec";
108 $tar_file = "$project-nodeps-$build_version.tar.gz";
114 ### get the remote spec file
115 &download_file($spec_file);
116 &md5_check($spec_file);
118 ### get the remote source tarball and md5 sum file
119 &download_file($tar_file);
120 &md5_check($tar_file);
123 move $tar_file, "../SOURCES/$project-$build_version.tar.gz" or die $!;
125 move $tar_file, '../SOURCES' or die $!;
131 ### print the paths to the new RPMS
135 #======================= end main ========================
140 find(\&get_rpms, "$rpm_root_dir/SRPMS");
141 find(\&get_rpms, "$rpm_root_dir/RPMS");
142 if ($action == $PRINT) {
144 print "[+] The following RPMS were successfully built:\n\n";
146 print "[-] No RPMS were successfully built; try running ",
150 for my $rpm_file (@rpm_paths) {
151 if ($action == $RM) {
152 unlink $rpm_file or die "[*] Could not unlink $rpm_file: $!";
153 } elsif ($action == $PRINT) {
154 if ($rpm_file =~ /\.src\.rpm/) {
155 print " $rpm_file (source RPM)\n";
157 print " $rpm_file\n";
161 print "\n" if $action == $PRINT;
166 my $file = $File::Find::name;
167 if ($file =~ /$project-$build_version-.*\.rpm$/) {
168 push @rpm_paths, $file;
173 sub download_file() {
175 unlink $file if -e $file;
176 print "[+] Downloading file:\n",
177 " $build_url_base/$project/download/$file\n";
178 my $cmd = "$wgetCmd $build_url_base/$project/download/$file";
180 $cmd .= ' > /dev/null 2>&1';
183 die "[*] Could not download $file, try running with -v"
191 &download_file("$file.md5");
193 open MD5, "md5sum -c $file.md5 |"
195 my $sum_line = <MD5>;
197 unless ($sum_line =~ m/$file:\s+OK/) {
198 die "[*] MD5 sum check failed for $file, ",
201 print "[+] Valid md5 sum check for $file\n";
208 "[+] Building RPM, this may take a little while (try -v if you want\n",
209 " to see all of the steps)...\n\n";
210 my $cmd = "$rpmbuildCmd -ba $spec_file";
212 $cmd .= ' > /dev/null 2>&1';
218 sub get_latest_version() {
219 unlink "$project-latest" if -e "$project-latest";
220 print "[+] Getting latest version file:\n",
221 " $build_url_base/$project/$project-latest\n";
222 my $cmd = "$wgetCmd $build_url_base/$project/$project-latest";
224 $cmd .= ' > /dev/null 2>&1';
227 open F, "< $project-latest" or
228 die "[*] Could not open $project-latest: $!";
232 $build_version = $line;
233 die "[*] Could not get build version" unless $build_version;
234 unlink "$project-latest" if -e "$project-latest";
241 cd_rpmbuilder; the CipherDyne RPM builder
242 [+] Version: $version
243 [+] By Michael Rash (mbr\@cipherdyne.org, http://www.cipherdyne.org)
245 Usage: cd_rpmbuilder -p <project> [options]
248 -p, --project <name> - This can be one of "psad", "fwknop",
249 "gpgdir", or "fwsnort".
250 -b, --build-version <ver> - Build a specific project version.
251 -r, --rpm-build-dir <dir> - Change the RPM build directory from the
252 default of $rpm_root_dir.
253 -n, --no-deps - Build the specified project without any
254 dependencies (such as perl modules).
255 -v, --verbose - Run in verbose mode.
256 -V, --Version - Print version and exit.
257 -h, --help - Display usage information.