]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/updxlrator/download
Updatexlrator (not tested yet)
[people/pmueller/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 $apphome="/var/ipfire/updatexlrator";
13 my $logfile="/var/log/updatexlrator/download.log";
14 my $debug=(-e "$apphome/debug");
15 my $updcachedir="/srv/web/ipfire/html/updatecache";
16 my $updfile='';
17 my @metadata=();
18
19 my $sfOk="1";
20
21 my $dsturl=@ARGV[0]; if ($dsturl eq '') { exit; }
22
23 $dsturl =~ s@\%2f@/@ig;
24 $updfile = substr($dsturl,rindex($dsturl,"/")+1);
25
26 # ---------------------------------------------------------------
27 # Retrieve file
28 # ---------------------------------------------------------------
29
30 if ($debug)
31 {
32 &writelog("Retrieving file for local cache: $updfile");
33 `$apphome/bin/wget -nc -nd -nv -P $updcachedir/download $dsturl >>$logfile 2>&1`;
34 } else
35 {
36 `$apphome/bin/wget -nc -nd -nv -P $updcachedir/download $dsturl 2>&1`;
37 }
38
39 if ($debug) { &writelog("Moving file into the cache directory -> \"$updcachedir/$updfile\""); }
40 system("mv $updcachedir/download/$updfile $updcachedir");
41
42 # ---------------------------------------------------------------
43 # Write metadata
44 # ---------------------------------------------------------------
45
46 if ($debug) { &writelog("Writing metadata \"$updcachedir/metadata/$updfile\""); }
47
48 open(FILE,"$updcachedir/metadata/$updfile");
49 @metadata = <FILE>;
50 close(FILE);
51 chomp @metadata;
52 $metadata[2]="$sfOk";
53 $metadata[3]=time;
54 open(FILE,">$updcachedir/metadata/$updfile");
55 foreach (@metadata) { print FILE "$_\n"; }
56 print FILE time."\n";
57 close(FILE);
58
59 # ===============================================================
60
61 sub writelog
62 {
63 open (LOGFILE,">>$logfile");
64 my @now = localtime(time);
65 printf LOGFILE "%02d:%02d:%02d %s\n",$now[2],$now[1],$now[0],$_[0];
66 close LOGFILE;
67 }
68
69 # ===============================================================