#! /usr/bin/perl -w
#                              -*- Mode: Perl -*- 
# cvs-pkginit --- 
# Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com ) 
# Created On       : Wed May 28 11:38:18 1997
# Created On Node  : tiamat.datasync.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Fri Feb 20 15:16:40 1998
# Last Machine Used: tiamat.datasync.com
# Update Count     : 45
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# 
# 

use strict;
use diagnostics;
use Carp;
require 5.001;

package main;

=head1 NAME

cvs-pkginit - A tool to print out steps to enter a package into cvs

=cut


=head1 SYNOPSIS

 usage: cvs-pkginit <Package Name> <Upstream Version> [<Debian revision>]

 This assumes that there is an old, non-cvs source tree, in say
 $exportdir. The printed out steps asumme the following:
 $exportdir/<Package>/<Package>-<Version>/     #debianized tree
 $exportdir/<Package>/<Package>_<Version>.orig.tar.gz

=over 2

=back

=cut

=head1 DESCRIPTION

This is a basic tutorial script, and probably needs a lot of
polishing. Suppose you want to enter package <Package Name> into CVS,
which happens to be at version <Upstream Version> and you are at
Debian Revision <Debian revision>. (For Debian only packages, the
Debian revision should be ignored). Just say
cvs-pkginit <Package Name> <Upstream Version> [<Debian revision>]
and this script will come back with a recipe to enter your package
into CVS.

=cut 

sub main {
  my $exportdir = '/usr/local/src/Packages';
  my $workdir = '/usr/local/src/Workdir';
  my $usage = '';
  my $MYNAME = '';
  my $version= '';
  my $tversion = '';
  my $deb = '';
  my $ko = '';
  my $package = '';
  
  ($MYNAME     = $0) =~ s|.*/||;

  $usage = <<EOUSAGE;
 usage: $MYNAME <Package Name> <Package Version> [<Debian revision>]

   Note: this script has been superceded by cvs-inject, that takes a
   .dsc file and does this all for you.

 This assumes that there is an old, non-cvs source tree, in say
 $exportdir. The printed out steps asumme the following:
 $exportdir/<Package>/<Package>-<Version>/     #debianized tree
 $exportdir/<Package>/<Package>_<Version>.orig.tar.gz

   This is not automated since human intervention is still required.
EOUSAGE

  # We need three arguments
  die "$usage\n" unless $#ARGV >= 1;
  
  $package = shift @ARGV;
  $version = shift @ARGV;
  $deb     =shift @ARGV;

  ($tversion = $version) =~ tr/\./_/;
  $ko = "-ko" if $deb;
  
  my $import_msg = "Initial Import";
  my $vendor_tag='source-dist';
  my $import_tag="upstream_version_$tversion";

  my $add_msg="Initial revision";
  my $commit_msg='Added all debian changes';
  my $final_tag="debian_version_$tversion";
  
  if ($deb) {
    $final_tag="debian_version_$tversion-$deb";
  }
  
  
  print <<"EOINPUT";
Note: this script has been superceded by cvs-inject, that takes a.dsc
  file and does this all for you. 
#
# The CVS working directory is  $workdir
# Old package tree is           $exportdir
# We expect to see
#     $exportdir/$package/$package-$version/
#     $exportdir/$package/$package\_$version.orig.tar.gz
#
# Change to the work directory, create the original sources
#
cd $workdir
tar zvvfx $exportdir/$package/$package\_$version.orig.tar.gz
cp -a $package\_$version.orig $package\_$version
mv -f $package\_$version.orig $package
# Now for the cvs import process.
cd $package
cvs import $ko -m '$import_msg' debian/$package $vendor_tag $import_tag
cd ..
rm -rf $package
cvs co $package
# There should be no changes below
diff -qBbwr $package-$version $package | grep -v CVS
#
# Now, change directory to where the debianized version exists 
# $exportdir.  
cd $exportdir/$package/$package-$version
sudo ./debian/rules clean
diff -qBbwr . $workdir/$package | grep -v CVS
#
# Add to the following definition based on the diff output above
#
FILES_DIFFERENT=debian
tar cf - \$FILES_DIFFERENT | ( cd $workdir/$package; tar xvvpf -)
cd ..
rm -rf $package-$version $package\_$version-$deb*
cd $workdir/$package
cvs add debian
cd debian
cvs add -m '$add_msg' `cvs update 2>/dev/null | egrep '^\?' |sed 's/\?//'`
cd ..
cvs update 2>/dev/null  | egrep '^M' | sed 's/^M//'
cvs commit -m '$commit_msg'
# Check to see if the tags match
cvs-buildpackage -d -n
cvs tag $final_tag
cd ..
rm -rf $package-$version

Note: this script has been superceded by cvs-inject, that takes a.dsc
  file and does this all for you. 

EOINPUT
}





=head1 CAVEATS

This is very inchoate, at the moment, and needs testing. This script
has been superceded by cvs-inject, that takes a.dsc and does this all
for you.

=cut

=head1 BUGS

None Known so far.

=cut

=head1 AUTHOR

Manoj Srivastava <srivasta@debian.org>

=cut

&main::main();

__END__    
