]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/updxlrator/convert
3 # This code is distributed under the terms of the GPL
5 # (c) 2007-2008 marco.s - http://update-accelerator.advproxy.net
7 # $Id: convert,v 1.0 2007/09/12 00:00:00 marco.s Exp $
12 my $updcache='/var/updatecache/';
17 my @cachedirs=qw(download);
22 my $logfile="/var/log/updatexlrator/convert.log";
24 if (@ARGV[0] eq '-nv') { $verbose = 0; }
25 if (!-d
"/var/log/updatexlrator") { $logging = 0; }
27 &writelog
("Converting cached objects from Update Accelerator 1.0 to 2.x");
28 &writelog
("------------------------------------------------------------");
30 (-d
"$updcache/metadata") || die "No version 1.0 cache found.\n";
32 if (`ps --no-heading -C wget`)
34 &writelog
("WARNING: Download in progress");
36 system("killall -9 -i wget");
40 foreach (<$updcache/metadata/*>)
42 $filename = substr($_,rindex($_,'/')+1,length($_));
43 if ((-f
"$updcache/$filename") && (-f
"$updcache/metadata/$filename"))
45 &writelog
("$filename");
52 $uuid = `echo $metadata[0] | md5sum`;
53 $uuid =~ s/[^0-9a-f]//g;
54 $uuid =~ s/([a-f\d]{8})([a-f\d]{4})([a-f\d]{4})([a-f\d]{4})([a-f\d]{12})/$1-$2-$3-$4-$5/;
55 $vendorid = $metadata[1];
56 $vendorid =~ tr/A-Z/a-z/;
57 unless (-d
"$updcache/$vendorid")
59 system("mkdir $updcache/$vendorid");
60 push(@cachedirs,$vendorid);
62 system("chmod 775 $updcache/$vendorid");
63 unless (-d
"$updcache/$vendorid/$uuid") { system("mkdir $updcache/$vendorid/$uuid"); }
64 system("chmod 775 $updcache/$vendorid/$uuid");
65 open (FILE
,">$updcache/$vendorid/$uuid/source.url");
66 print FILE
"$metadata[0]\n";
68 open (FILE
,">$updcache/$vendorid/$uuid/status");
69 print FILE
"$metadata[2]\n";
71 open (FILE
,">$updcache/$vendorid/$uuid/checkup.log");
72 print FILE
"$metadata[3]\n";
74 open (FILE
,">$updcache/$vendorid/$uuid/access.log");
75 for($i=4;$i<@metadata;$i++)
77 print FILE
"$metadata[$i]\n";
80 system("mv $updcache/$filename $updcache/$vendorid/$uuid");
81 system("chmod 664 $updcache/$vendorid/$uuid/*");
83 } else { &writelog
("WARNING: Insufficient metadata for $filename"); }
87 if (($n) && (-d
"$updcache/metadata")) { system("rm -r $updcache/metadata"); }
89 foreach (@cachedirs) { system("chown -R nobody:squid $updcache/$_"); }
91 if ($n) { &writelog
("------------------------------------------------------------"); }
94 &writelog
("$n objects converted.");
96 # -------------------------------------------------------------------
100 if ($verbose) { print "$_[0]\n"; }
103 open (LOGFILE
,">>$logfile");
104 my @now = localtime(time);
105 printf LOGFILE
"%04d-%02d-%02d %02d:%02d:%02d %s\n",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0],$_[0];
110 # -------------------------------------------------------------------