]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/updxlrator/download
Updatexlrator (not tested yet)
[people/pmueller/ipfire-2.x.git] / config / updxlrator / download
CommitLineData
46c01c09
MT
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
10use strict;
11
12my $apphome="/var/ipfire/updatexlrator";
13my $logfile="/var/log/updatexlrator/download.log";
14my $debug=(-e "$apphome/debug");
15my $updcachedir="/srv/web/ipfire/html/updatecache";
16my $updfile='';
17my @metadata=();
18
19my $sfOk="1";
20
21my $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
30if ($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
39if ($debug) { &writelog("Moving file into the cache directory -> \"$updcachedir/$updfile\""); }
40system("mv $updcachedir/download/$updfile $updcachedir");
41
42# ---------------------------------------------------------------
43# Write metadata
44# ---------------------------------------------------------------
45
46if ($debug) { &writelog("Writing metadata \"$updcachedir/metadata/$updfile\""); }
47
48open(FILE,"$updcachedir/metadata/$updfile");
49@metadata = <FILE>;
50close(FILE);
51chomp @metadata;
52$metadata[2]="$sfOk";
53$metadata[3]=time;
54open(FILE,">$updcachedir/metadata/$updfile");
55foreach (@metadata) { print FILE "$_\n"; }
56print FILE time."\n";
57close(FILE);
58
59# ===============================================================
60
61sub 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# ===============================================================