-
Notifications
You must be signed in to change notification settings - Fork 5
/
determine_network_scanner_config
executable file
·64 lines (54 loc) · 2.11 KB
/
determine_network_scanner_config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /bin/bash
# Johannes Meixner <jsmeix@suse.de>, 2004, 2005, 2006, 2007, 2008, 2010
#
# Copyright (c) 2010 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#set -x
export PATH="/sbin:/usr/sbin:/usr/bin:/bin"
export LC_ALL="POSIX"
export LANG="POSIX"
umask 022
MY_NAME=${0##*/}
OUTPUT_FORMAT="$1"
[ -z "$OUTPUT_FORMAT" ] && OUTPUT_FORMAT="ASCII"
[ "$OUTPUT_FORMAT" != "ASCII" -a "$OUTPUT_FORMAT" != "YCP" ] && { echo -en "\nUsage:\n$MY_NAME {ASCII|YCP}\n" 1>&2 ; exit 1 ; }
NET_BACKEND_CONFIG_FILE="/etc/sane.d/net.conf"
SANED_CONFIG_FILE="/etc/sane.d/saned.conf"
# Function to extract entries from a SANE config file:
Extract()
{ grep -E -v '^#|^[[:space:]]*$' $1 | tr -d '[:blank:]' | sort -u | tr -s '\n' ','
}
# Get and output the hosts in $NET_BACKEND_CONFIG_FILE
if [ -r $NET_BACKEND_CONFIG_FILE ]
then [ "$OUTPUT_FORMAT" = "YCP" ] && echo -n "\$[ \"net_backend_hosts\":\"" || echo -n "Hosts in $NET_BACKEND_CONFIG_FILE: "
Extract $NET_BACKEND_CONFIG_FILE
[ "$OUTPUT_FORMAT" = "YCP" ] && echo "\"," || echo
else
echo "Cannot read $NET_BACKEND_CONFIG_FILE" 1>&2
exit 2
fi
# Get and output the hosts or subnets in $SANED_CONFIG_FILE
if [ -r $SANED_CONFIG_FILE ]
then [ "$OUTPUT_FORMAT" = "YCP" ] && echo -n " \"saned_hosts\":\"" || echo -n "Hosts or subnets in $SANED_CONFIG_FILE: "
Extract $SANED_CONFIG_FILE
[ "$OUTPUT_FORMAT" = "YCP" ] && echo -e "\"\n]" || echo
else
echo "Cannot read $SANED_CONFIG_FILE" 1>&2
exit 3
fi
exit 0