Subversion Repositories camp_sysinfo_client_3

Rev

Rev 192 | Rev 194 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#! /usr/bin/env perl

use warnings;
use strict;

use LWP::Simple; # apt install libwww-perl

# This is a sample script of how to use the postrun


# find our location and use it for searching for libraries
BEGIN {
   use FindBin;
   use File::Spec;
   use lib File::Spec->catdir($FindBin::Bin);
   eval( 'use YAML::Tiny;' );
   eval( 'use Data::Dumper;' );
}

# contains the directory our script is in
my $scriptDir = File::Spec->catdir($FindBin::Bin);
$scriptDir .= '/' unless substr( $scriptDir, -1 ) eq '/';

my $URL = 'https://www.example.com/uploadFile.php';
my $checksum = 'sysinfo_update.cksum';
my $update = 'sysinfo_update';

sub getWriteFile {
   my ($dir, $url, $filename) = @_;
   return getstore("$url$filename", "$dir$filename");
}

my $currentChecksum = '';
if ( -f "$scriptDir$checksum" ) {
   open CK, "<$scriptDir$checksum" or warn "could not read $scriptDir$checksum: $!\n";
   $currentChecksum = <CK>;
   close CK;
}

my $data = get( $URL . $checksum );
if ( $data && $data ne $currentChecksum ) {
   my $response = getstore( "$URL$checksum", "$scriptDir$checksum" );
   if ( is_success( $response ) ) {
      $response = getstore( "$URL$update", "$scriptDir$update" );
      if ( is_success( $response ) ) {
         chmod 0700, $scriptDir . $update;
         print `$scriptDir$update` if "$scriptDir$update";
      }
   }
}

1;