Started core37.
[people/pmueller/ipfire-2.x.git] / config / updxlrator / convert
CommitLineData
0a638396
CS
1#!/usr/bin/perl
2#
3# This code is distributed under the terms of the GPL
4#
5# (c) 2007-2008 marco.s - http://update-accelerator.advproxy.net
6#
7# $Id: convert,v 1.0 2007/09/12 00:00:00 marco.s Exp $
8#
9
10use strict;
11
12my $updcache='/var/updatecache/';
13my @metadata=();
14my $filename='';
15my $uuid='';
16my $vendorid='';
17my @cachedirs=qw(download);
18my $i=0;
19my $n=0;
20my $verbose=1;
21my $logging=1;
22my $logfile="/var/log/updatexlrator/convert.log";
23
24if (@ARGV[0] eq '-nv') { $verbose = 0; }
25if (!-d "/var/log/updatexlrator") { $logging = 0; }
26
27&writelog("Converting cached objects from Update Accelerator 1.0 to 2.x");
28&writelog("------------------------------------------------------------");
29
30(-d "$updcache/metadata") || die "No version 1.0 cache found.\n";
31
32if (`ps --no-heading -C wget`)
33{
34 &writelog("WARNING: Download in progress");
35 print "\n";
36 system("killall -9 -i wget");
37 print "\n";
38}
39
40foreach (<$updcache/metadata/*>)
41{
42 $filename = substr($_,rindex($_,'/')+1,length($_));
43 if ((-f "$updcache/$filename") && (-f "$updcache/metadata/$filename"))
44 {
45 &writelog("$filename");
46 open (FILE,$_);
47 @metadata = <FILE>;
48 close FILE;
49 chomp(@metadata);
50 if (@metadata >= 5)
51 {
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")
58 {
59 system("mkdir $updcache/$vendorid");
60 push(@cachedirs,$vendorid);
61 }
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";
67 close FILE;
68 open (FILE,">$updcache/$vendorid/$uuid/status");
69 print FILE "$metadata[2]\n";
70 close FILE;
71 open (FILE,">$updcache/$vendorid/$uuid/checkup.log");
72 print FILE "$metadata[3]\n";
73 close FILE;
74 open (FILE,">$updcache/$vendorid/$uuid/access.log");
75 for($i=4;$i<@metadata;$i++)
76 {
77 print FILE "$metadata[$i]\n";
78 }
79 close FILE;
80 system("mv $updcache/$filename $updcache/$vendorid/$uuid");
81 system("chmod 664 $updcache/$vendorid/$uuid/*");
82 $n++;
83 } else { &writelog("WARNING: Insufficient metadata for $filename"); }
84 }
85}
86
87if (($n) && (-d "$updcache/metadata")) { system("rm -r $updcache/metadata"); }
88
89foreach (@cachedirs) { system("chown -R nobody:squid $updcache/$_"); }
90
91if ($n) { &writelog("------------------------------------------------------------"); }
92
93$verbose=1;
94&writelog("$n objects converted.");
95
96# -------------------------------------------------------------------
97
98sub writelog
99{
100 if ($verbose) { print "$_[0]\n"; }
101 if ($logging)
102 {
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];
106 close LOGFILE;
107 }
108}
109
110# -------------------------------------------------------------------