From 9afa2d4f6cf6f6e90369b44ef4eb243fe65af8a0 Mon Sep 17 00:00:00 2001 From: Gerhard <gerhard@tinned-software.net> Date: Wed, 25 Sep 2013 01:36:02 +0200 Subject: [PATCH] Changed behaviour of loading config file. First from /etc second from the script directory. --- ssh-tunnel-manager.conf | 4 +++- ssh-tunnel-manager.sh | 32 +++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ssh-tunnel-manager.conf b/ssh-tunnel-manager.conf index 1f8a546..8a7a613 100644 --- a/ssh-tunnel-manager.conf +++ b/ssh-tunnel-manager.conf @@ -2,11 +2,13 @@ # # @author Gerhard Steinbeis (info [at] tinned-software [dot] net) # @copyright Copyright (c) 2013 +# # @license http://opensource.org/licenses/GPL-3.0 GNU General Public License, version 3 # @package net # # Configuration file for the ssh-tunnel-manager script. Default location for -# the config file is /etc/ssh-tunnel-manager.conf +# the config file is /etc/ssh-tunnel-manager.conf or if that does not exist, +# the ssh-tunnel-manager.conf in the same directory as the script itself. # # diff --git a/ssh-tunnel-manager.sh b/ssh-tunnel-manager.sh index cb19eee..9d8f825 100755 --- a/ssh-tunnel-manager.sh +++ b/ssh-tunnel-manager.sh @@ -2,10 +2,14 @@ # # @author Gerhard Steinbeis (info [at] tinned-software [dot] net) # @copyright Copyright (c) 2013 -version=0.6.0 +version=0.6.1 # @license http://opensource.org/licenses/GPL-3.0 GNU General Public License, version 3 # @package net # +# Configuration file for the ssh-tunnel-manager script. Default location for +# the config file is /etc/ssh-tunnel-manager.conf or if that does not exist, +# the ssh-tunnel-manager.conf in the same directory as the script itself. +# # # Ths TUNNEL array is used to configure the individual tunnels. Each @@ -40,7 +44,7 @@ DBG=0 # # Default configuration file to load settings from can be defined here. # -DEFAULT_CONFIG="/etc/ssh-tunnel-manager.conf" +DEFAULT_CONFIG="ssh-tunnel-manager.conf" # # Non Config values @@ -74,9 +78,14 @@ while [ $# -gt 0 ]; do # specific parameters --config) # load settings file - . $2 - CONFIG_FILE=$2 - CONFIG_LOADED=1 + if [[ -f "$2" ]]; then + . $2 + CONFIG_FILE=$2 + CONFIG_LOADED=1 + else + HELP=1 + echo "ERROR: Specified config file cound not be found." + fi shift 2 ;; @@ -115,7 +124,7 @@ while [ $# -gt 0 ]; do # undefined parameter *) - echo "Unknown option '$1'" + echo "ERROR: Unknown option '$1'" HELP=1 shift break @@ -134,9 +143,14 @@ fi # Load the default configuration file if no other configuration file is provided if [[ -z "$CONFIG_LOADED" ]]; then # Check if configuration file exists - if [[ -f "$DEFAULT_CONFIG" ]]; then - . $DEFAULT_CONFIG - CONFIG_FILE=$DEFAULT_CONFIG + if [[ -f "/etc/$DEFAULT_CONFIG" ]]; then + . /etc/$DEFAULT_CONFIG + CONFIG_FILE=/etc/$DEFAULT_CONFIG + else + if [[ -f "$SCRIPT_PATH/$DEFAULT_CONFIG" ]]; then + . $SCRIPT_PATH/$DEFAULT_CONFIG + CONFIG_FILE=$SCRIPT_PATH/$DEFAULT_CONFIG + fi fi fi -- GitLab