use strict; use warnings; use utf8; use bigint; use Array::Utils qw(:all); my $cpanPath = "/cygdrive/d/Softwares/cpanmirror"; my $remoteMirror = "http://mirrors.neusoft.edu.cn/cpan"; ##Get package file `cd /home/Gurpreet && rm -rf 01mailrc.txt*`; `cd /home/Gurpreet && rm -rf 02packages.details.txt*`; `cd /home/Gurpreet && rm -rf 03modlist.data*`; print "Deleted old package files\n"; print "=" x 30, "\n"; `cd /home/Gurpreet/ && wget $remoteMirror/authors/01mailrc.txt.gz`; `cp -f /home/Gurpreet/01mailrc.txt.gz $cpanPath/authors/`; `cd /home/Gurpreet/ && wget $remoteMirror/modules/02packages.details.txt.gz`; `cp -f /home/Gurpreet/02packages.details.txt.gz $cpanPath/modules/`; `cd /home/Gurpreet/ && wget $remoteMirror/modules/03modlist.data.gz`; `cp -f /home/Gurpreet/03modlist.data.gz $cpanPath/modules/`; print "Updated package files \n"; print "=" x 30, "\n"; #`cd /home/Gurpreet && gunzip 02packages.details.txt.gz`; print "Extracted package file \n"; print "=" x 30, "\n"; #Get total files excluding top lines in package file my $totalFiles = `cat 02packages.details.txt|wc -l`; chomp($totalFiles); $totalFiles = $totalFiles - 9; print "Total files = $totalFiles\n"; print "=" x 30, "\n"; #Get all packages names my @packageNames = `cat 02packages.details.txt|tail -$totalFiles|rev|cut -d " " -f1|rev|sort|un iq`; chomp($_) foreach (@packageNames); print "Total unique packages = ", scalar(@packageNames), "\n"; print "=" x 30, "\n"; #Start with numbers print "Enter starting point of download\n"; chomp( my $startPoint = ); print "Enter ending point of download\n"; chomp( my $endPoint = ); #Start getting package files print "Starting update of cpanmirror. Press enter\n"; print "=" x 30, "\n"; ; my $ctr = $startPoint; foreach my $val ( @packageNames[ $startPoint .. $endPoint ] ) { my @vals = split /\//, $val; my $packageName = $vals[ scalar(@vals) - 1 ]; my $dirName = join "/", @vals[ 0 .. scalar(@vals) - 2 ]; print "$ctr)Dir=$dirName Package=$packageName\n"; `mkdir -p $cpanPath/authors/id/$dirName` unless -d $dirName; `cd $cpanPath/authors/id/$dirName && wget $remoteMirror/authors/id/$dirName /$packageName` unless -e "$cpanPath/authors/id/$dirName/$packageName"; $ctr++; } #Now get the list of old files and delete them print "Print Y to delete all extra files\n"; chomp( my $todo = ); my @allFileNames = `cd $cpanPath/authors/id && find -type f|grep -v CHECKSUMS`; foreach my $existingFile (@allFileNames) { chomp($existingFile); my $exactName = substr $existingFile, 2; unless ( $exactName ~~ @packageNames ) { print "Deleting $cpanPath/authors/id/$exactName\n"; ` rm -rf $cpanPath/authors/id/$exactName` if $todo eq "Y" || $todo eq "y "; } }