1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use FindBin; 7 8exit( run(@ARGV) || 0 ) unless caller; 9 10sub run { 11 my $now = time(); 12 13 my $a_day = 86_400; 14 my $today = $now - $now % $a_day; 15 16 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = 17 gmtime($today); 18 ++$mon; 19 $year += 1_900; 20 21 my $human_ts = sprintf( "%04d-%02d-%02d", $year, $mon, $mday ); 22 23 print qq[# Updating D_PPP_RELEASE_DATE timestamp to $today /* $human_ts */\n]; 24 25 my $f = q[parts/inc/version]; 26 my $file_to_patch = $FindBin::Bin . '/../' . $f; 27 die "Cannot find $f: $!" unless -e $file_to_patch; 28 29 my $content; 30 open( my $fh, '+<', $file_to_patch ) or die "$f: $!\n"; 31 { 32 local $/; 33 $content = <$fh>; 34 } 35 die qq[No content for file $f\n] unless $content; 36 37 $content =~ 38 s{^(\#\s*define\s+D_PPP_RELEASE_DATE)\b.*$}{$1 $today /* $human_ts */}m 39 or die "Cannot find D_PPP_RELEASE_DATE pattern in file $f"; 40 41 { 42 truncate $fh, 0; 43 seek $fh, 0, 0; 44 print {$fh} $content; 45 } 46 47 close($fh); 48 49 print qq[$f patched with D_PPP_RELEASE_DATE\n]; 50 51 return; 52} 53 541; 55