diff --git a/createmodule.py b/createmodule.py index 60c6ba7..2588333 100755 --- a/createmodule.py +++ b/createmodule.py @@ -19,7 +19,7 @@ # along with this program. If not, see . from optparse import OptionParser -import os,sys +import os,sys,re from subprocess import * # Handle options @@ -48,14 +48,23 @@ def getenv(cmd = ':'): print "WARNING: initscript sent the following to stderr:" print stderr # Parse the output key=value pairs + skip = False for line in stdout.splitlines(): + if skip: + if line == '}': + skip = False + continue try: (var,value) = line.split('=',1) except ValueError: - print "ERROR: Could not parse output:" - print stdout + print "ERROR: Could not parse output line:" + print line exit(1) - env[var] = value + # Exported functions - not handled + if value.find('() {') == 0: + skip = True + else: + env[var] = value return env #Record initial environment @@ -116,7 +125,7 @@ for key in env1.keys(): # We're left with new keys in env2 for key in env2.keys(): # Use prepend-path for new paths - if ('PATH' in key) or (':' in env2[key]): + if (re.search('(DIRS|FILES|PATH)$',key)) or (':' in env2[key]): prependpaths = env2[key].strip(':').split(':') # MANPATH can have system defaults added it it wasn't previously set # LICENSE variables often include paths outside install directory diff --git a/createmodule.sh b/createmodule.sh index b44cf05..5a37b3e 100755 --- a/createmodule.sh +++ b/createmodule.sh @@ -150,7 +150,7 @@ do continue fi #Use prepend-path for new paths - if [ "${key/PATH/}" != "$key" ] + if [ "${key: -4}" = PATH -o "${key: -4}" = DIRS -o "${key: -4}" = FILES ] then # TODO - Need to handle stripping of default MANPATH echo -e "prepend-path\t${key}\t"$(dedup ${env2[$key]})