File: tools.sh.in

package info (click to toggle)
inetutils 2%3A2.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,684 kB
  • sloc: ansic: 132,371; sh: 12,498; yacc: 1,651; makefile: 725; perl: 72
file content (112 lines) | stat: -rw-r--r-- 2,881 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright (C) 2012-2025 Free Software Foundation, Inc.
#
# This file is part of GNU Inetutils.
#
# GNU Inetutils is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# GNU Inetutils 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, see `http://www.gnu.org/licenses/'.

# Helpers and supporting functionality for test scripts.

GREP=${GREP:-@GREP@}
EGREP=${EGREP:-"@EGREP@"}
FGREP=${FGREP:-"@FGREP@"}
SED=${SED:-@SED@}
DD=${DD:-@DD@}
MKTEMP=${MKTEMP:-@MKTEMP@}
NETSTAT=${NETSTAT:-@NETSTAT@}
TARGET=${TARGET:-@TARGET@}
TARGET6=${TARGET6:-@TARGET6@}
TEST_IPV4=${TEST_IPV4:-@TEST_IPV4@}
TEST_IPV6=${TEST_IPV6:-@TEST_IPV6@}

srcdir=${srcdir:-.}

RUNTIME_IPV4=${RUNTIME_IPV4:-"./runtime-ipv6$EXEEXT -4"}
RUNTIME_IPV6=${RUNTIME_IPV6:-"./runtime-ipv6$EXEEXT -6"}

# Avoid IPv4 when not functional.
if test "$TEST_IPV4" = "auto"; then
    $RUNTIME_IPV4 || { TEST_IPV4="no"
	echo "Suppressing non-supported IPv4."; }
fi

# Avoid IPv6 when not functional.
if test "$TEST_IPV6" = "auto"; then
    $RUNTIME_IPV6 || { TEST_IPV6="no"
	echo "Suppressing non-supported IPv6."; }
fi

# Variables for signalling presence of a utility:
#
#   need_toolname      Set to `false' if `toolname' is missing,
#                      otherwise set to `:'.
#
#   exit_no_toolname   Function to exit with a message related to `toolname'.
#
# Suggested idiom:
#
#   $need_toolname || exit_no_toolname

# `grep', `sed', and `uname' are used already by autoconfiguration,
# so their existence is not tested for.

need_id=false
if id >/dev/null 2>&1; then
	need_id=:
fi

exit_no_id () {
    echo >&2 'No available id(1).  Skipping test.'
    exit 77
}

need_dd=false
if eval "$DD if=/dev/zero bs=5 count=1 >/dev/null 2>&1"; then
	need_dd=:
fi

exit_no_dd () {
    echo >&2 'No available dd(1).  Skipping test.'
    exit 77
}

need_mktemp=false
if eval "$MKTEMP -u temp.XXXXXX >/dev/null 2>&1"; then
	need_mktemp=:
fi

exit_no_mktemp () {
    echo >&2 'No available mktemp(1).  Skipping test.'
    exit 77
}

need_netstat=false
if eval "$NETSTAT -n >/dev/null 2>&1"; then
	need_netstat=:
fi

exit_no_netstat () {
    echo >&2 'No available netstat(1), used for diagnosis.  Skipping test.'
    exit 77
}

# Some Solaris variants provide id(1) lacking `-u' switch.
# Work around this by some computation.

func_id_uid () {
	id $1 2>&1 | $SED -n 's,.*uid=\([0-9]*\).*,\1,p'
}

func_id_user () {
	id $1 2>&1 | $SED -n 's,.*uid=[0-9]*(\([^)]*\).*,\1,p'
}