gBootRoot pronounced "bOOtrOOt"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

219 lines
6.1 KiB

#!/usr/bin/perl
use File::Basename;
use File::Find;
# The Lazy Guy's packaging tool for gBootRoot.
# This program sets-up the archive which will be turned into a package and
# needs to be run as root. The advantage of this program is that the
# archive will always represent the Makefile which is being tested
# when development isn't being done with perl -I . ./gbootroot.
# This program uses dh-make, and copies your own defaults to
# $packaging_place/debian from your $packaging_defaults, and updates
# to the proper date/times in changelog and copyright. After this you will
# want to run debuild from devscripts (this uses lintian) as a non-root user.
# And finish stuff off with dpkg-scanpackages.
# User defined variables for directories and package
my $user_home = "/home/mttrader";
my $prog = "gbootroot";
my $revision = 1;
my $dist = "unstable";
my $urgency = "low";
my $gbootroot_cvs = "$user_home/gbootroot/gbootroot";
my $packaging_place = "$user_home/gbootroot/PACKAGING";
my $packaging_defaults = "$gbootroot_cvs/pkg/dpkg";
my $email = "freesource\@users.sourceforge.net";
my $name = "Jonathan Rosenbaum";
# Other vars
my ($real_uid, $real_gid) = (stat($user_home))[4,5];
# Find the version
my $version;
open(CVS, "$gbootroot_cvs/$prog") or
die "Couldn't find $prog in $gbootroot_cvs: $!\n";
while (<CVS>) {
if (/\my \$version/) {
$version = (split(/=/,$_))[1];
chomp $version;
$version =~ s/ //;
$version =~ s/"//g;
$version =~ s/;//;
}
}
close(CVS);
$packaging_place = "$packaging_place/$prog-$version";
# Make sure the directory exists.
home_builder($packaging_place);
# Because I am too lazy to clean out CVS, I only want the stuff copied over
# which is in the Makefile, I'll also have to clean out any CVS directories.
$/ = "";
my @make_paragraph;
open(CVS, "$gbootroot_cvs/Makefile") or
die "Couldn't find Makefile in $gbootroot_cvs: $!\n";
while (<CVS>) {
push(@make_paragraph,$_);
}
close(CVS);
$/ = "\n";
chomp $make_paragraph[1];
my @make_lines = split(/\n/,$make_paragraph[1]);
shift(@make_lines);
chdir($gbootroot_cvs) or die "Couldn't change to $gbootroot_cvs: $?\n";
# Basically we are just concerned with the first part of cp and will
# use home_builder to make sure the directory exists.
foreach (@make_lines) {
s/\t//;
if (/cp/) {
my $dir = ((split))[2];
my $base;
if ($dir =~ m,/,) {
$base = dirname($dir);
home_builder("$packaging_place/$base");
}
system "cp -fa $dir $packaging_place/$base";
}
else {
system "$_";
}
}
system "cp -fa Makefile.pkg $packaging_place/Makefile";
# Now we get to clean out any CVS directories and make sure that the
# permissions are all for the user who will be creating the package.
if (-d $packaging_place) {
finddepth sub {
my($uid,$gid) = (stat($File::Find::name))[4,5];
if ($real_uid != $uid) {
system "chown $real_uid $File::Find::name";
}
if ($real_gid != $gid) {
system "chgrp $real_gid $File::Find::name";
}
if (/CVS/) {
chdir(dirname($File::Find::name));
system "rm -rf CVS";
}
} , $packaging_place ;
}
# Now we to the dh_make thing, and setup the time, version, and defaults.
chdir($packaging_place) or die "Can't change to $packaging_place: $?\n";
system "dh_make -e $email";
# Here we ask the user what changes to add to the changelog and set the proper
# time using 822-date. If it is the initial release we don't do anything.
open(CHANGELOG,"$packaging_defaults/changelog")
or die "Couldn't open $packagaging_place/changelog: $?\n";
my @changelog = <CHANGELOG>;
close (CHANGELOG);
my $stop;
foreach (@changelog) {
if (/$version-$revision/) {
print "\nThe changelog for $version-$revision already exists, this may mean\n" .
"that this is the first invocation or that you haven't changed the\n" .
"version in the $prog program.\n";
$stop = 1;
}
}
# Ask some questions first.
if (!$stop) {
print "\nWrite what you want to be put in the changelog, and I'll\n" .
"prettify everything. End with a newline and .\n";
print " * ";
my $save_doc;
$save_doc = " * ";
$count = 0;
while (<STDIN>) {
my $doc_reply = $_;
if ($doc_reply) {
print " ";
$doc_reply = " $doc_reply" if $count != 0;
}
last if $doc_reply =~ /^\s*\.\s*$/;
if ($doc_reply) {
$save_doc = $save_doc . $doc_reply;
}
$count++;
}
open(CHANGELOG,">$packaging_defaults/changelog")
or die "Couldn't open check: $?\n";
for my $ct (0 .. ($#changelog - 3)) {
print CHANGELOG $changelog[$ct];
}
print CHANGELOG "$prog ($version-$revision) $dist; urgency=$urgency\n\n";
print CHANGELOG "$save_doc\n";
print CHANGELOG " -- $name <$email> " . `822-date`;
for my $ct (($#changelog - 3) .. $#changelog) {
print CHANGELOG $changelog[$ct];
}
close(CHANGELOG);
print "\n";
} # end if !$stop
system "rm $packaging_place/debian/*";
system "cp -fa $packaging_defaults/* $packaging_place/debian";
# Set-up the copyright
open(COPYRIGHT,">$packaging_defaults/copyright")
or die "Couldn't open up $packaging_defaults/copyright: $?\n";
print COPYRIGHT "This package was debianized by $name\n";
print COPYRIGHT "$email on " , `822-date`, ".\n";
print COPYRIGHT "Author: \n$name <$email>\n\n";
print COPYRIGHT "Copyright:\n\n" .
"On Debian GNU/Linux systems, the complete text of the GNU General Public\n" .
"License can be found in /usr/share/common-licenses/GPL\n";
sub home_builder {
my ($home_builder) = @_;
if (!-d $home_builder) {
if (-e $home_builder) {
print "ERROR: A file exists where $home_builder should be.\n";
}
else {
my @directory_parts = split(m,/,,$home_builder);
my $placement = "/";
for (1 .. $#directory_parts) {
$_ == 1 ? ($placement = "/$directory_parts[$_]")
: ($placement = $placement . "/" . $directory_parts[$_]);
-d $placement or mkdir $placement;
system "chown $real_uid $placement";
system "chgrp $real_gid $placement";
}
}
}
} # end home_builder