diff src/sat.sh @ 369:e83d0c21d64d

launching script now read config files added ./sat.conf in possible config file location
author Goffi <goffi@goffi.org>
date Sun, 19 Jun 2011 17:40:36 +0200
parents f147b778511a
children ac568832a71a
line wrap: on
line diff
--- a/src/sat.sh	Sat Jun 18 23:28:10 2011 +0200
+++ b/src/sat.sh	Sun Jun 19 17:40:36 2011 +0200
@@ -16,14 +16,25 @@
 
 NAME='sat'
 
-if [ -n "$SAT_CONST_local_dir" ];then
-	echo "Using overidded local dir: $SAT_CONST_local_dir"
-	PID_FILE="$SAT_CONST_local_dir/$NAME.pid"
-	LOG_FILE="$SAT_CONST_local_dir/$NAME.log"
-else
-	PID_FILE="/tmp/$NAME.pid"
-	LOG_FILE=~/".$NAME/$NAME.log"
-fi
+#We use python to parse config files
+eval `python<<PYTHONEND
+from ConfigParser import SafeConfigParser
+from os.path import expanduser, join
+
+config = SafeConfigParser(defaults={'local_dir':'~/.sat',
+									'pid_dir':'/tmp',
+									'log_dir':'%(local_dir)s'})
+try:
+	config.read(map(expanduser, ['/etc/sat.conf', '~/sat.conf', '~/.sat.conf', 'sat.conf', '.sat.conf']))
+except:
+	print ("Can't read main config !")
+print "LOCAL_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'local_dir')),'')
+print "PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')
+print "LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')
+PYTHONEND
+`
+PID_FILE="$PID_DIR$NAME.pid"
+LOG_FILE="$LOCAL_DIR$NAME.log"
 DAEMON="n"
 MAIN_OPTIONS="-${DAEMON}oy"
 TAP_PATH="./"