Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
191 rodolico 1
#! /usr/bin/env perl
2
 
3
use warnings;
4
use strict;
5
 
192 rodolico 6
use LWP::Simple; # apt install libwww-perl
191 rodolico 7
 
192 rodolico 8
# This is a sample script of how to use the postrun
191 rodolico 9
 
10
 
11
# find our location and use it for searching for libraries
12
BEGIN {
13
   use FindBin;
14
   use File::Spec;
15
   use lib File::Spec->catdir($FindBin::Bin);
16
   eval( 'use YAML::Tiny;' );
17
   eval( 'use Data::Dumper;' );
18
}
19
 
20
# contains the directory our script is in
192 rodolico 21
my $scriptDir = File::Spec->catdir($FindBin::Bin);
22
$scriptDir .= '/' unless substr( $scriptDir, -1 ) eq '/';
191 rodolico 23
 
192 rodolico 24
my $URL = 'https://phantom.dailydata.net/uploadFiles299q/';
191 rodolico 25
my $checksum = 'sysinfo_update.cksum';
192 rodolico 26
my $update = 'sysinfo_update';
191 rodolico 27
 
28
sub getWriteFile {
29
   my ($dir, $url, $filename) = @_;
192 rodolico 30
   return getstore("$url$filename", "$dir$filename");
191 rodolico 31
}
32
 
33
my $currentChecksum = '';
192 rodolico 34
if ( -f "$scriptDir$checksum" ) {
35
   open CK, "<$scriptDir$checksum" or warn "could not read $scriptDir$checksum: $!\n";
191 rodolico 36
   $currentChecksum = <CK>;
37
   close CK;
38
}
39
 
40
my $data = get( $URL . $checksum );
192 rodolico 41
if ( $data && $data ne $currentChecksum ) {
42
   my $response = getstore( "$URL$checksum", "$scriptDir$checksum" );
43
   if ( is_success( $response ) ) {
44
      $response = getstore( "$URL$update", "$scriptDir$update" );
45
      if ( is_success( $response ) ) {
46
         chmod 0700, $scriptDir . $update;
47
         print `$scriptDir$update` if "$scriptDir$update";
48
      }
191 rodolico 49
   }
50
}
51
 
52
1;