Update of /cvsroot/fink/fink/perlmod/Fink/SelfUpdate
In directory
sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv12055/perlmod/Fink/SelfUpdate
Modified Files:
Tag: selfupdate_classes
CVS.pm rsync.pm
Log Message:
Offload all CVS-method stuff into its own class. Yay complete modularity!
Index: rsync.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/SelfUpdate/Attic/rsync.pm,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -d -r1.1.2.7 -r1.1.2.8
--- rsync.pm 8 Mar 2007 08:02:09 -0000 1.1.2.7
+++ rsync.pm 8 Mar 2007 17:21:57 -0000 1.1.2.8
@@ -29,6 +29,7 @@
use Fink::CLI qw(&print_breaking);
use Fink::Config qw($basepath $config $distribution);
use Fink::Mirror;
+use Fink::Package;
use Fink::Command qw(chowname rm_f mkdir_p touch);
use strict;
Index: CVS.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/SelfUpdate/Attic/CVS.pm,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -d -r1.1.2.4 -r1.1.2.5
--- CVS.pm 8 Mar 2007 08:02:09 -0000 1.1.2.4
+++ CVS.pm 8 Mar 2007 17:21:57 -0000 1.1.2.5
@@ -26,9 +26,12 @@
use base qw(Fink::SelfUpdate::Base);
-use Fink::Services qw(&execute);
-use Fink::Config qw($basepath);
-use Fink::Command qw(rm_f touch);
+use Fink::CLI qw(&print_breaking &prompt);
+use Fink::Config qw($basepath $config $distribution);
+use Fink::Package;
+use Fink::Command qw(cat chowname mkdir_p mv rm_f rm_rf touch);
+
+use File::Find;
use strict;
use warnings;
@@ -84,9 +87,267 @@
return (-f "$finkdir/stamp-cvs-live" || -f
"$finkdir/dists/stamp-cvs-live");
}
+sub do_direct {
+ my $class = shift; # class method for now
+
+ if (-d "$basepath/fink/dists/CVS") {
+ # already have a cvs checkout
+ $class->do_direct_cvs();
+ } else {
+ $class->setup_direct_cvs();
+ }
+}
+
=head2 Private Methods
-None yet.
+=cut
+
+### set up direct cvs
+
+sub setup_direct_cvs {
+ my ($finkdir, $tempdir, $tempfinkdir);
+ my ($username, $cvsuser, @testlist);
+ my ($use_hardlinks, $cutoff, $cmd);
+ my ($cmdd);
+
+ $username = "root";
+ if (exists $ENV{SUDO_USER}) {
+ $username = $ENV{SUDO_USER};
+ }
+
+ print "\n";
+ $username =
+ &prompt("Fink has the capability to run the CVS commands as a ".
+ "normal user. That has some advantages - it
uses that ".
+ "user's CVS settings files and allows the
package ".
+ "descriptions to be edited and updated without
becoming ".
+ "root. Please specify the user login name that
should be ".
+ "used:",
+ default => $username);
+
+ # sanity check
+ @testlist = getpwnam($username);
+ if (scalar(@testlist) <= 0) {
+ die "The user \"$username\" does not exist on the system.\n";
+ }
+
+ print "\n";
+ $cvsuser =
+ &prompt("For Fink developers only: ".
+ "Enter your SourceForge login name to set up
full CVS access. ".
+ "Other users, just press return to set up
anonymous ".
+ "read-only access.",
+ default => "anonymous");
+ print "\n";
+
+ # start by creating a temporary directory with the right permissions
+ $finkdir = "$basepath/fink";
+ $tempdir = "$finkdir.tmp";
+ $tempfinkdir = "$tempdir/fink";
+
+ if (-d $tempdir) {
+ rm_rf $tempdir or
+ die "Can't remove left-over temporary directory
'$tempdir'\n";
+ }
+ mkdir_p $tempdir or
+ die "Can't create temporary directory '$tempdir'\n";
+ if ($username ne "root") {
+ chowname $username, $tempdir or
+ die "Can't set ownership of temporary directory
'$tempdir'\n";
+ }
+
+ # check if hardlinks from the old directory work
+ &print_breaking("Checking to see if we can use hard links to merge ".
+ "the existing tree. Please ignore
errors on the next ".
+ "few lines.");
+ unless (touch "$finkdir/README" and link "$finkdir/README",
"$tempdir/README") {
+ $use_hardlinks = 0;
+ } else {
+ $use_hardlinks = 1;
+ }
+ unlink "$tempdir/README";
+
+ # start the CVS fun
+ chdir $tempdir or die "Can't cd to $tempdir: $!\n";
+
+ # add cvs quiet flag if verbosity level permits
+ my $verbosity = "-q";
+ if ($config->verbosity_level() > 1) {
+ $verbosity = "";
+ }
+ my $cvsrepository = "fink.cvs.sourceforge.net:/cvsroot/fink";
+ if (-f "$basepath/lib/fink/URL/cvs-repository") {
+ $cvsrepository = cat "$basepath/lib/fink/URL/cvs-repository";
+ chomp($cvsrepository);
+ $cvsrepository .= ':/cvsroot/fink';
+ }
+ if ($cvsuser eq "anonymous") {
+ if (-f "$basepath/lib/fink/URL/anonymous-cvs") {
+ $cvsrepository = cat
"$basepath/lib/fink/URL/anonymous-cvs";
+ chomp($cvsrepository);
+ }
+ &print_breaking("Now logging into the CVS server. When CVS asks
you ".
+ "for a password, just press
return (i.e. the password ".
+ "is empty).");
+ $cmd = "cvs -d:pserver:[EMAIL PROTECTED] login";
+ if ($username ne "root") {
+ $cmd = "/usr/bin/su $username -c '$cmd'";
+ }
+ if (&execute($cmd)) {
+ die "Logging into the CVS server for anonymous
read-only access failed.\n";
+ }
+
+ $cmd = "cvs ${verbosity} -z3 -d:pserver:[EMAIL PROTECTED]";
+ } else {
+ if (-f "$basepath/lib/fink/URL/developer-cvs") {
+ $cvsrepository = cat
"$basepath/lib/fink/URL/developer-cvs";
+ chomp($cvsrepository);
+ }
+ $cmd = "cvs ${verbosity} -z3 -d:ext:[EMAIL PROTECTED]";
+ $ENV{CVS_RSH} = "ssh";
+ }
+ $cmdd = "$cmd checkout -l -d fink dists";
+ if ($username ne "root") {
+ $cmdd = "/usr/bin/su $username -c '$cmdd'";
+ }
+ &print_breaking("Setting up base Fink directory...");
+ if (&execute($cmdd)) {
+ die "Downloading package descriptions from CVS failed.\n";
+ }
+
+ my @trees = split(/\s+/, $config->param_default("SelfUpdateCVSTrees",
$distribution));
+ chdir "fink" or die "Can't cd to fink\n";
+
+ for my $tree (@trees) {
+ &print_breaking("Checking out $tree tree...");
+
+ my $cvsdir = "dists/$tree";
+ $cvsdir = "packages/dists" if ($tree eq "10.1");
+ $cmdd = "$cmd checkout -d $tree $cvsdir";
+
+ if ($username ne "root") {
+ $cmdd = "/usr/bin/su $username -c '$cmdd'";
+ }
+ if (&execute($cmdd)) {
+ die "Downloading package descriptions from CVS
failed.\n";
+ }
+ }
+ chdir $tempdir or die "Can't cd to $tempdir: $!\n";
+
+ if (not -d $tempfinkdir) {
+ die "The CVS didn't report an error, but the directory
'$tempfinkdir' ".
+ "doesn't exist as expected. Strange.\n";
+ }
+
+ # merge the old tree
+ $cutoff = length($finkdir)+1;
+ find(sub {
+ if ($_ eq "CVS") {
+ $File::Find::prune = 1;
+ return;
+ }
+ return if (length($File::Find::name) <=
$cutoff);
+ my $rel = substr($File::Find::name, $cutoff);
+ if (-l and not -e "$tempfinkdir/$rel") {
+ my $linkto;
+ $linkto = readlink($_)
+ or die "Can't read target of
symlink $File::Find::name: $!\n";
+ symlink $linkto, "$tempfinkdir/$rel" or
+ die "Can't create symlink
\"$tempfinkdir/$rel\"\n";
+ } elsif (-d and not -d "$tempfinkdir/$rel") {
+ mkdir_p "$tempfinkdir/$rel" or
+ die "Can't create directory
\"$tempfinkdir/$rel\"\n";
+ } elsif (-f and not -f "$tempfinkdir/$rel") {
+ my $cmd;
+ if ($use_hardlinks) {
+ $cmd = "ln";
+ } else {
+ $cmd = "cp -p"
+ }
+ $cmd .= " '$_' '$tempfinkdir/$rel'";
+ if (&execute($cmd)) {
+ die "Can't copy file
\"$tempfinkdir/$rel\"\n";
+ }
+ }
+ }, $finkdir);
+
+ # switch $tempfinkdir to $finkdir
+ chdir $basepath or die "Can't cd to $basepath: $!\n";
+ mv $finkdir, "$finkdir.old" or
+ die "Can't move \"$finkdir\" out of the way\n";
+ mv $tempfinkdir, $finkdir or
+ die "Can't move new tree \"$tempfinkdir\" into place at
\"$finkdir\". ".
+ "Warning: Your Fink installation is in an inconsistent
state now.\n";
+ rm_rf $tempdir;
+
+ print "\n";
+ &print_breaking("Your Fink installation was successfully set up for ".
+ "direct CVS updating. The directory
\"$finkdir.old\" ".
+ "contains your old package description
tree. Its ".
+ "contents were merged into the new one,
but the old ".
+ "tree was left intact for safety
reasons. If you no ".
+ "longer need it, remove it manually.");
+ print "\n";
+}
+
+### call cvs update
+
+sub do_direct_cvs {
+ my ($descdir, @sb, $cmd, $cmd_recursive, $username, $msg);
+
+ # add cvs quiet flag if verbosity level permits
+ my $verbosity = "-q";
+ if ($config->verbosity_level() > 1) {
+ $verbosity = "";
+ }
+
+ $descdir = "$basepath/fink";
+ chdir $descdir or die "Can't cd to $descdir: $!\n";
+
+ @sb = stat("$descdir/CVS");
+
+ $cmd = "cvs ${verbosity} -z3 update -d -P -l";
+
+ $msg = "I will now run the cvs command to retrieve the latest package
descriptions. ";
+
+ if ($sb[4] != 0 and $> != $sb[4]) {
+ ($username) = getpwuid($sb[4]);
+ $msg .= "The 'su' command will be used to run the cvs command
as the ".
+ "user '$username'. ";
+ }
+
+ $msg .= "After that, the core packages will be updated right away; ".
+ "you should then update the other packages using
commands like ".
+ "'fink update-all'.";
+
+ print "\n";
+ &print_breaking($msg);
+ print "\n";
+
+ $ENV{CVS_RSH} = "ssh";
+
+ # first, update the top-level stuff
+
+ my $errors = 0;
+
+ $cmd = "/usr/bin/su $username -c '$cmd'" if ($username);
+ if (&execute($cmd)) {
+ $errors++;
+ }
+
+ # then, update the trees
+
+ my @trees = split(/\s+/, $config->param_default("SelfUpdateCVSTrees",
$distribution));
+ for my $tree (@trees) {
+ $cmd = "cvs ${verbosity} -z3 update -d -P ${tree}";
+ $cmd = "/usr/bin/su $username -c '$cmd'" if ($username);
+ if (&execute($cmd)) {
+ $errors++;
+ }
+ }
+
+ die "Updating using CVS failed. Check the error messages above.\n" if
($errors);
+}
=over 4
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Fink-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits