]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/updxlrator/download
Am Pakfire weitergearbeitet.
[people/teissler/ipfire-2.x.git] / config / updxlrator / download
1 #!/usr/bin/perl
2 #
3 # This code is distributed under the terms of the GPL
4 #
5 # (c) 2006 marco.s
6 #
7 # $Id: download,v 1.0 2006/08/30 00:00:00 marco.s Exp $
8 #
9
10 use strict;
11
12 my $logfile="/var/log/updatexlrator/download.log";
13 my $debug = 0;
14 my $updcachedir="/srv/web/ipfire/html/updatecache";
15 my $updfile='';
16 my @metadata=();
17
18 my $sfOk="1";
19
20 my $dsturl=@ARGV[0]; if ($dsturl eq '') { exit; }
21
22 $dsturl =~ s@\%2f@/@ig;
23 $updfile = substr($dsturl,rindex($dsturl,"/")+1);
24
25 # ---------------------------------------------------------------
26 # Retrieve file
27 # ---------------------------------------------------------------
28
29 if ($debug)
30 {
31 &writelog("Retrieving file for local cache: $updfile");
32 `/usr/bin/wget -nc -nd -nv -P $updcachedir/download $dsturl >>$logfile 2>&1`;
33 } else
34 {
35 `/usr/bin/wget -nc -nd -nv -P $updcachedir/download $dsturl 2>&1`;
36 }
37
38 if ($debug) { &writelog("Moving file into the cache directory -> \"$updcachedir/$updfile\""); }
39 system("mv $updcachedir/download/$updfile $updcachedir");
40
41 # ---------------------------------------------------------------
42 # Write metadata
43 # ---------------------------------------------------------------
44
45 if ($debug) { &writelog("Writing metadata \"$updcachedir/metadata/$updfile\""); }
46
47 open(FILE,"$updcachedir/metadata/$updfile");
48 @metadata = <FILE>;
49 close(FILE);
50 chomp @metadata;
51 $metadata[2]="$sfOk";
52 $metadata[3]=time;
53 open(FILE,">$updcachedir/metadata/$updfile");
54 foreach (@metadata) { print FILE "$_\n"; }
55 print FILE time."\n";
56 close(FILE);
57
58 # ===============================================================
59
60 sub writelog
61 {
62 open (LOGFILE,">>$logfile");
63 my @now = localtime(time);
64 printf LOGFILE "%02d:%02d:%02d %s\n",$now[2],$now[1],$now[0],$_[0];
65 close LOGFILE;
66 }
67
68 # ===============================================================