1 #!/usr/bin/perl
 2 # sophoscdcreate Copyright Michael Howe 2005
 3 # Released under the GNU GPL (a copy of which is available from
 4 # http://www.gnu.org/copyleft/gpl.html )
 5 #
 6 # Purpose:
 7 #   Creates a cd image for command-line sophos scanning with the latest IDE
 8 #   files from ftp://micros.oucs.ox.ac.uk.  They are saved to the ides/ dir of
 9 #   the CD.
10 # Prerequisites:
11 #   - A base directory containing the appropriate executable files for sophos.
12 #   - Internet access to ftp://micros.oucs.ox.ac.uk
13 
14 use warnings;
15 use strict;
16 use Net::FTP;
17 use File::Path;
18 
19 # Change these appropriately:
20 #  Source of the image (directory with ide files, exe files, etc):
21 my $img_src = '/home/michael/computing/antivirus/sophos/cd/';
22 #  Destination iso file to create:
23 my $img_dst = '/home/michael/disk_images/isos/sophos_cli.iso';
24 
25 # These probably should be ok as the defaults.
26 #  FTP site to get IDE files from:
27 my $ide_srchost = 'micros.oucs.ox.ac.uk';
28 #  Directory on the FTP server where thi IDE files live:
29 my $ide_srcdir = '/antivirus/sophos/idefiles/';
30 #  Directory to store the downloaded IDE files in:
31 my $ide_dstdir = "${img_src}ides/";
32 #  A place to backup the old IDE files to:
33 my $ide_backupdir = "${img_src}ide-backup/";
34 
35 # This shouldn't need changing.
36 #
37 # Do some cleanup and check IDE dirs exist.
38 chdir( $ide_dstdir )
39 	or die "Couldn't change to $ide_dstdir\n";
40 if ( -d $ide_backupdir ) {
41 	rmtree( $ide_backupdir )
42 		or die "Couldn't remove backup dir $ide_backupdir\n";
43 }
44 
45 # Backup current IDEs
46 rename( $ide_dstdir, $ide_backupdir )
47 	or die "Couldn't backup ide dir ($ide_dstdir -> $ide_backupdir)\n";
48 mkdir( $ide_dstdir )
49 	or die "Can't make ide dir $ide_dstdir\n";
50 
51 
52 # FTP magic:
53 my $ftp = Net::FTP->new( $ide_srchost )
54 	or die "Couldn't connect: $@\n";
55 $ftp->login()
56 	or die "Couldn't login\n";
57 $ftp->cwd( $ide_srcdir )
58 	or die "Couldn't change directory\n";
59 my @ides = $ftp->ls();
60 foreach my $ide ( @ides ) {
61 	$ftp->get( $ide ) or warn "Couldn't get ide $ide.\n";
62 }
63 # we're done
64 $ftp->quit;
65 
66 system( "mkisofs -o $img_dst $img_src" )
67 	or warn "Error - cannot make iso $img_src: $!\n";
68 
69 
70 # vim: tw=80
71 


syntax highlighted by Code2HTML, v. 0.9.1