xref: /freebsd/usr.sbin/bsdconfig/networking/share/common.subr (revision ab2043b81eaba0d7d7769b4a58b2b6d17bc464a3)
1*ab2043b8SDevin Teskeif [ ! "$_NETWORKING_COMMON_SUBR" ]; then _NETWORKING_COMMON_SUBR=1
2*ab2043b8SDevin Teske#
3*ab2043b8SDevin Teske# Copyright (c) 2006-2012 Devin Teske
4*ab2043b8SDevin Teske# All Rights Reserved.
5*ab2043b8SDevin Teske#
6*ab2043b8SDevin Teske# Redistribution and use in source and binary forms, with or without
7*ab2043b8SDevin Teske# modification, are permitted provided that the following conditions
8*ab2043b8SDevin Teske# are met:
9*ab2043b8SDevin Teske# 1. Redistributions of source code must retain the above copyright
10*ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer.
11*ab2043b8SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
12*ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer in the
13*ab2043b8SDevin Teske#    documentation and/or other materials provided with the distribution.
14*ab2043b8SDevin Teske#
15*ab2043b8SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*ab2043b8SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17*ab2043b8SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*ab2043b8SDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*ab2043b8SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*ab2043b8SDevin Teske# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*ab2043b8SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*ab2043b8SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*ab2043b8SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*ab2043b8SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*ab2043b8SDevin Teske# SUCH DAMAGE.
26*ab2043b8SDevin Teske#
27*ab2043b8SDevin Teske# $FreeBSD$
28*ab2043b8SDevin Teske#
29*ab2043b8SDevin Teske############################################################ INCLUDES
30*ab2043b8SDevin Teske
31*ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
32*ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
33*ab2043b8SDevin Teske
34*ab2043b8SDevin Teske############################################################ FUNCTIONS
35*ab2043b8SDevin Teske
36*ab2043b8SDevin Teske# f_mounted $local_directory
37*ab2043b8SDevin Teske#
38*ab2043b8SDevin Teske# Return success if a filesystem is mounted on a particular directory.
39*ab2043b8SDevin Teske#
40*ab2043b8SDevin Teskef_mounted()
41*ab2043b8SDevin Teske{
42*ab2043b8SDevin Teske	local dir="$1"
43*ab2043b8SDevin Teske	[ -d "$dir" ] || return $FAILURE
44*ab2043b8SDevin Teske	mount | grep -Eq " on $dir \([^)]+\)$"
45*ab2043b8SDevin Teske}
46*ab2043b8SDevin Teske
47*ab2043b8SDevin Teske# f_jailed
48*ab2043b8SDevin Teske#
49*ab2043b8SDevin Teske# Returns true if the current process is jail(8)ed.
50*ab2043b8SDevin Teske#
51*ab2043b8SDevin Teskef_jailed()
52*ab2043b8SDevin Teske{
53*ab2043b8SDevin Teske	! f_quietly ps 1
54*ab2043b8SDevin Teske}
55*ab2043b8SDevin Teske
56*ab2043b8SDevin Teske# f_nfs_mounted
57*ab2043b8SDevin Teske#
58*ab2043b8SDevin Teske# Returns true if there are any NFS mounts currently active, otherwise false.
59*ab2043b8SDevin Teske#
60*ab2043b8SDevin Teskef_nfs_mounted()
61*ab2043b8SDevin Teske{
62*ab2043b8SDevin Teske	[ "$( df -t nfs )" ]
63*ab2043b8SDevin Teske}
64*ab2043b8SDevin Teske
65*ab2043b8SDevin Teskefi # ! $_NETWORKING_COMMON_SUBR
66