From c6b4eda8115f5ae452cc72d0df7181fb1c0f166f Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Fri, 23 Apr 2021 12:51:14 +0200 Subject: [PATCH] add controlfile and git pre-commit hook --- controls_FHEMbackup.txt | 2 ++ hooks/pre-commit | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 controls_FHEMbackup.txt create mode 100755 hooks/pre-commit diff --git a/controls_FHEMbackup.txt b/controls_FHEMbackup.txt new file mode 100644 index 0000000..a498cbe --- /dev/null +++ b/controls_FHEMbackup.txt @@ -0,0 +1,2 @@ +UPD 2021-04-23_12:44:47 3363 FHEM/98_backup.pm +UPD 2021-04-23_12:41:19 8885 lib/FHEM/Core/Utils/FHEMbackup.pm diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..8ff408d --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w + +use File::Basename; +use POSIX qw(strftime); +use strict; + +my @filenames = ( 'FHEM/98_backup.pm', + 'lib/FHEM/Core/Utils/FHEMbackup.pm' + ); + +my $controlsfile = 'controls_FHEMbackup.txt'; + +open(FH, ">$controlsfile") || return("Can't open $controlsfile: $!"); + +for my $filename (@filenames) { + my @statOutput = stat($filename); + + if (scalar @statOutput != 13) { + printf 'error: stat has unexpected return value for ' . $filename . "\n"; + next; + } + + my $mtime = $statOutput[9]; + my $date = POSIX::strftime("%Y-%m-%d", localtime($mtime)); + my $time = POSIX::strftime("%H:%M:%S", localtime($mtime)); + my $filetime = $date."_".$time; + + my $filesize = $statOutput[7]; + + printf FH 'UPD ' . $filetime . ' ' . $filesize . ' ' .$filename . "\n"; +} + +close(FH); + +system("git add $controlsfile"); + +print 'Create controls File succesfully' . "\n"; + +exit 0;