From: Joey Hess Date: Mon, 12 May 2008 19:16:14 +0000 (-0400) Subject: Allow environment variables in section headers. Pass such headers through the shell... X-Git-Url: https://git.madduck.net/code/myrepos.git/commitdiff_plain/9a9cbb453427926f2f658734285f6305c7502afb?ds=inline Allow environment variables in section headers. Pass such headers through the shell to expand them. Closes: #480580 --- diff --git a/debian/changelog b/debian/changelog index 32045e7..44bb058 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +mr (0.29) UNRELEASED; urgency=low + + * Allow environment variables in section headers. Pass such headers + through the shell to expand them. Closes: #480580 + + -- Joey Hess Mon, 12 May 2008 15:15:48 -0400 + mr (0.28) unstable; urgency=low * Use debhelper v7, rules file minimisation. diff --git a/mr b/mr index d4622d9..bb98ba6 100755 --- a/mr +++ b/mr @@ -224,7 +224,9 @@ is an alias, and its value is the action to use. All other sections add repositories. The section header specifies the directory where the repository is located. This is relative to the directory that contains the mrconfig file, but you can also choose to use absolute -paths. +paths. (Note that you can use environment variables in section names; they +will be passed through the shell for expansion. For example, +"[$HOSTNAME]", or "[${HOSTNAME}foo]") Within a section, each parameter defines a shell command to run to handle a given action. mr contains default handlers for "update", "status", @@ -717,6 +719,18 @@ sub selectrepos { #{{{ return @repos; } #}}} +sub expandenv { #{{{ + my $val=shift; + + + if ($val=~/\$/) { + $val=`echo "$val"`; + chomp $val; + } + + return $val; +} #}}} + my %loaded; sub loadconfig { #{{{ my $f=shift; @@ -777,7 +791,7 @@ sub loadconfig { #{{{ chomp; next if /^\s*\#/ || /^\s*$/; if (/^\[([^\]]*)\]\s*$/) { - $section=$1; + $section=expandenv($1); } elsif (/^(\w+)\s*=\s*(.*)/) { my $parameter=$1; @@ -900,7 +914,7 @@ sub modifyconfig { #{{{ $addfields->(); } - $section=$1; + $section=expandenv($1); push @out, $_; }