Debian Codegraph @

scripts/bin/drbl-get-network

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: Get the network address from IP address and netmask
5 # Notes: "ipcalc" program is totally different in Debian and RedHat-like distribution.
6 # NOTE! We do NOT use this program in drblpush anymore. Just use the perl script ipcalc which is collected in package drbl.
7
8 # Load DRBL setting and functions
9 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
10
11 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
12
13 export LC_ALL=C
14 # Append a default search path.
15 PATH="$PATH:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
16 export PATH
17
18 Usage() {
19 echo "Get the network address from IP address and netmask"
20 echo "Usage:"
21 echo "$(basename $0) IPADDR NETMASK"
22 echo "Ex: $(basename $0) 192.168.10.213 255.255.255.240"
23 }
24
25 # Parse command-line options
26 while [ $# -gt 0 ]; do
27 case "$1" in
28 -*) echo "${0}: ${1}: invalid option" >&2
29 Usage >& 2
30 exit 2 ;;
31 *) break ;;
32 esac
33 done
34
35 ipaddr=$1
36 netmask=$2
37 [ -z "$ipaddr" ] && exit 0
38 [ -z "$netmask" ] && exit 0
39
40 # The output of ipcalc without "=", it must be in Debian... we use ipsc.
41 # Debian's ipcalc output like this
42 # Network: 192.168.103.208/28 11000000.10101000.01100111.1101 0000
43 network="$(drbl-ipcalc $ipaddr $netmask | awk -F" " '/Network:/ {print $2}' | sed -e "s/\/.*//g")"
44 echo $network