4 use Spreadsheet::ParseExcel;
6 my $xls_file = shift @ARGV || die "usage: $0 file.xls\n";
8 my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($xls_file);
16 foreach my $sheet (@{$oBook->{Worksheet}}) {
17 if ($sheet->{Name} !~ m/(Instruments|sheet1)/i) {
18 print "# skipped sheet ",$sheet->{Name},"\n";
21 for(my $i = $sheet->{MinRow} ; defined $sheet->{MaxRow} && $i <= $sheet->{MaxRow} ; $i++) {
23 my $id = $sheet->{Cells}[$i][3]->{Val} || next;
24 my $ime = $sheet->{Cells}[$i][4]->{Val} || next;
26 my $conf_name = lc($ime . '_' . $id);
27 $conf_name =~ s/\s+/_/g;
29 my $ip = $sheet->{Cells}[$i][16]->{Val} || next;
30 my $hostname = $sheet->{Cells}[$i][17]->Value || next;
31 my $os = $sheet->{Cells}[$i][19]->Value || next;
32 my $path = $sheet->{Cells}[$i][23]->Value || next;
33 my $share = $sheet->{Cells}[$i][24]->Value || next;
35 if ($ip !~ /\d+\.\d+\.\d+\.\d+/) {
36 print "# skipped $ip, $hostname, $os, $path, $share\n";
40 print "$ip hostname[$hostname] os[$os] path[$path] share[$share]\n";
42 my $drive = lc(substr($path,0,1));
46 $rsync_share = 'cDrive';
47 } elsif ($drive eq 'd') {
48 $rsync_share = 'dDrive';
50 die "unknown drive '$drive' from path '$path'";
53 $path =~ s#^[cd]:\\#/#gi;
56 open(O, "> conf/${conf_name}.pl") || die "can't open conf/${conf_name}.pl: $!";
58 if ($os =~ m#(98|95|9x)#i) {
60 print "$ip\tsmb://${share}\n";
62 push @{$smb_share_name{$hostname}}, $share;
66 \$Conf{XferMethod} = 'smb';
67 \$Conf{SmbHostName} = '$hostname';
68 \$Conf{SmbShareName} = [ '`,join("','", @{$smb_share_name{$hostname}}),qq`' ];
72 $hosts{$ip} .= "\t$hostname" unless ($hosts{$ip} =~ m/$hostname/i);
74 $hosts{$ip} = "$ip\t$hostname";
79 my $t = shift || return;
80 return '[' . lc($t) . uc($t) . ']';
83 $path =~ s/([a-zA-z])/case_insesitive($1)/ge;
85 print "$ip\trsync://${share}::${path}\n";
87 $path =~ s/([ '])/\\$1/g;
88 push @{$rsync_share_name{$hostname}}, $path;
92 \$Conf{XferMethod} = 'rsyncd';
93 \$Conf{RsyncShareName} = [ '$rsync_share' ];
94 \$Conf{BackupFilesOnly} = [ '$rsync_share' => '`, join("','$rsync_share' => '", @{$rsync_share_name{$hostname}}), qq`' ];
101 $bpc_hosts{$conf_name} = "$conf_name\t0\tasa";
103 $hosts{$ip} .= "\t$conf_name" unless ($hosts{$ip} =~ m/$conf_name/i);
104 $hosts{$ip} .= "\t$hostname" unless ($hosts{$ip} =~ m/$hostname/i);
106 $hosts{$ip} = "$ip\t$conf_name\t$hostname";
112 open(H, "> conf/hosts.backuppc") || die "hosts.backuppc $!";
113 foreach my $k (sort keys %bpc_hosts) {
114 print H $bpc_hosts{$k},"\n";
118 open(H, "> conf/hosts.add") || die "hosts.add $!";
119 foreach my $k (sort keys %hosts) {
120 print H $hosts{$k},"\n";