[weboob] [PATCH 1/1] Create the cache directory if missing

theo theocrite at theocrite.org
Mon Mar 19 23:08:02 CET 2012


Freemobile munin plugin needs a cache directory to store previous
results.

Let's create it and not expect the user to do it.

Signed-off-by: theo <theocrite at theocrite.org>
---
 contrib/freemobile-munin |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/contrib/freemobile-munin b/contrib/freemobile-munin
index d9c96a1..f9b5a4e 100755
--- a/contrib/freemobile-munin
+++ b/contrib/freemobile-munin
@@ -3,7 +3,7 @@
 =head1 NAME
 freemobile - A plugin to monitor a freemobile subscription
 
-=head1 Installation 
+=head1 Installation
 
 Create a link to this script in /etc/munin/plugins/
 
@@ -41,7 +41,8 @@ use encoding 'iso-8859-1';    # Munin doesn't like utf-8 :-(
 use Encode;
 
 my @monitored = split / /, $ENV{'freemonitored'} || 'voice sms';
-my $cachefile = $ENV{'HOME'} . '/.config/weboob/munin/freemobile-munin';
+my $cachedir  = $ENV{'HOME'} . '/.config/weboob/munin/';
+my $cachefile = "$cachedir/freemobile-munin";
 
 my $refreshtime = $ENV{'cache_expire'} || 10_800;
 my $weboob = '/opt/weboob/bin/weboob-cli ICapBill get_details coin -f table';
@@ -173,6 +174,11 @@ sub fetch {
     return 0;
 }
 
+# Create the munin cache dir if missing
+if ( !-d $cachedir ) {
+    mkdir $cachedir;
+}
+
 if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
     config;
 }
-- 
1.7.9.1



More information about the weboob mailing list