[Midnightbsd-cvs] src [11623] trunk/etc/autofs: add autofs configs

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jul 8 12:48:56 EDT 2018


Revision: 11623
          http://svnweb.midnightbsd.org/src/?rev=11623
Author:   laffer1
Date:     2018-07-08 12:48:56 -0400 (Sun, 08 Jul 2018)
Log Message:
-----------
add autofs configs

Added Paths:
-----------
    trunk/etc/autofs/
    trunk/etc/autofs/Makefile
    trunk/etc/autofs/include_ldap
    trunk/etc/autofs/special_hosts
    trunk/etc/autofs/special_media
    trunk/etc/autofs/special_noauto
    trunk/etc/autofs/special_null

Added: trunk/etc/autofs/Makefile
===================================================================
--- trunk/etc/autofs/Makefile	                        (rev 0)
+++ trunk/etc/autofs/Makefile	2018-07-08 16:48:56 UTC (rev 11623)
@@ -0,0 +1,9 @@
+# $MidnightBSD$
+
+FILES=		include_ldap special_hosts special_media special_noauto special_null
+
+NO_OBJ=
+FILESDIR=	/etc/autofs
+FILESMODE=	755
+
+.include <bsd.prog.mk>


Property changes on: trunk/etc/autofs/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/etc/autofs/include_ldap
===================================================================
--- trunk/etc/autofs/include_ldap	                        (rev 0)
+++ trunk/etc/autofs/include_ldap	2018-07-08 16:48:56 UTC (rev 11623)
@@ -0,0 +1,55 @@
+#!/bin/sh
+#
+# $MidnightBSD$
+#
+
+# Modify this to suit your needs.  The "$1" is the map name, eg. "auto_master".
+# To debug, simply run this script with map name as the only parameter.  It's
+# supposed to output map contents ("key location" pairs) to standard output.
+SEARCHBASE="ou=$1,dc=example,dc=com"
+ENTRY_ATTRIBUTE="cn"
+VALUE_ATTRIBUTE="automountInformation"
+
+/usr/local/bin/ldapsearch -LLL -x -o ldif-wrap=no -b "$SEARCHBASE" "$ENTRY_ATTRIBUTE" "$VALUE_ATTRIBUTE" | awk '
+$1 == "'$ENTRY_ATTRIBUTE':" {
+	key = $2
+}
+
+$1 == "'$VALUE_ATTRIBUTE':" {
+	for (i = 2; i <= NF; i++) {
+		value[i] = $(i)
+	}
+	nvalues = NF
+	b64 = 0
+}
+
+# Double colon after attribute name means the value is in Base64.
+$1 == "'$VALUE_ATTRIBUTE'::" {
+	for (i = 2; i <= NF; i++) {
+		value[i] = $(i)
+	}
+	nvalues = NF
+	b64 = 1
+}
+
+# Empty line - end of record.
+NF == 0 && key != "" && nvalues > 0 {
+	printf "%s%s", key, OFS
+	for (i = 2; i < nvalues; i++) {
+		printf "%s%s", value[i], OFS
+	}
+	if (b64 == 1) {
+		printf "%s", value[nvalues] | "b64decode -rp"
+		close("b64decode -rp")
+		printf "%s", ORS
+	} else {
+		printf "%s%s", value[nvalues], ORS
+	}
+}
+
+NF == 0 {
+	key = ""
+	nvalues = 0
+	delete value
+}
+'


Property changes on: trunk/etc/autofs/include_ldap
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: trunk/etc/autofs/special_hosts
===================================================================
--- trunk/etc/autofs/special_hosts	                        (rev 0)
+++ trunk/etc/autofs/special_hosts	2018-07-08 16:48:56 UTC (rev 11623)
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# $MidnightBSD$
+#
+
+if [ $# -eq 0 ]; then
+	out=`getent hosts`
+	[ $? -eq 0 ] || exit 1
+	echo "$out" | awk '{ print $2 }' | sort -u
+	exit 0
+fi
+
+out=`showmount -E "$1"`
+[ $? -eq 0 ] || exit 1
+echo "$out" | awk -v host="$1" \
+    '{ printf "\"%s\"\t\"%s:%s\" ", $0, host, $0 } END { printf "\n" }'
+


Property changes on: trunk/etc/autofs/special_hosts
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: trunk/etc/autofs/special_media
===================================================================
--- trunk/etc/autofs/special_media	                        (rev 0)
+++ trunk/etc/autofs/special_media	2018-07-08 16:48:56 UTC (rev 11623)
@@ -0,0 +1,93 @@
+#!/bin/sh
+#
+# $MidnightBSD$
+#
+
+# Print newline-separated list of devices available for mounting.
+# If there is a filesystem label - use it, otherwise use device name.
+print_available() {
+	local _fstype _fstype_and_label _label _p
+
+	for _p in ${providers}; do
+		_fstype_and_label="$(fstyp -l "/dev/${_p}" 2> /dev/null)"
+		if [ $? -ne 0 ]; then
+			# Ignore devices for which we were unable
+			# to determine filesystem type.
+			continue
+		fi
+
+		_fstype="${_fstype_and_label%% *}"
+		if [ "${_fstype}" != "${_fstype_and_label}" ]; then
+			_label="${_fstype_and_label#* }"
+			echo "${_label}"
+			continue
+		fi
+
+		echo "${_p}"
+	done
+}
+
+# Print a single map entry.
+print_one() {
+	local _fstype _fstype_and_label _label _key _p
+
+	_key="$1"
+
+	_fstype="$(fstyp "/dev/${_key}" 2> /dev/null)"
+	if [ $? -eq 0 ]; then
+		echo "-fstype=${_fstype},nosuid	:/dev/${_key}" 
+		return
+	fi
+
+	for _p in ${providers}; do
+		_fstype_and_label="$(fstyp -l "/dev/${_p}" 2> /dev/null)"
+		if [ $? -ne 0 ]; then
+			# Ignore devices for which we were unable
+			# to determine filesystem type.
+			continue
+		fi
+
+		_fstype="${_fstype_and_label%% *}"
+		if [ "${_fstype}" = "${_fstype_and_label}" ]; then
+			# No label, try another device.
+			continue
+		fi
+
+		_label="${_fstype_and_label#* }"
+		if [ "${_label}" != "${_key}" ]; then
+			# Labels don't match, try another device.
+			continue
+		fi
+
+		echo "-fstype=${_fstype},nosuid	:/dev/${_p}" 
+	done
+
+	# No matching device - don't print anything, autofs will handle it.
+}
+
+# Obtain a list of (geom-provider-name, access-count) pairs, turning this:
+#
+# z0xfffff80005085d00 [shape=hexagon,label="ada0\nr2w2e3\nerr#0\nsector=512\nstripe=0"];
+#
+# Into this:
+#
+# ada0 r2w2e3
+#
+# XXX: It would be easier to use kern.geom.conftxt instead, but it lacks
+#      access counts.
+pairs=$(sysctl kern.geom.confdot | sed -n 's/^.*hexagon,label="\([^\]*\)\\n\([^\]*\).*/\1 \2/p')
+
+# Obtain a list of GEOM providers that are not already open - not mounted,
+# and without other GEOM class, such as gpart, attached.  In other words,
+# grep for "r0w0e0".  Skip providers with names containing slashes; we're
+# not interested in geom_label(4) creations.
+providers=$(echo "$pairs" | awk '$2 == "r0w0e0" && $1 !~ /\// { print $1 }')
+
+if [ $# -eq 0 ]; then
+	print_available
+	exit 0
+fi
+
+print_one "$1"
+exit 0
+


Property changes on: trunk/etc/autofs/special_media
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: trunk/etc/autofs/special_noauto
===================================================================
--- trunk/etc/autofs/special_noauto	                        (rev 0)
+++ trunk/etc/autofs/special_noauto	2018-07-08 16:48:56 UTC (rev 11623)
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# $MidnightBSD$
+#
+
+print_available() {
+	sed 's/#.*//' /etc/fstab | awk '$4 ~ /noauto/ { print $2 }'
+}
+
+print_one() {
+	local _mntpoint
+
+	_mntpoint="${1%/}"
+	
+	sed 's/#.*//' /etc/fstab | awk '
+	$2 == "'"${_mntpoint}"'" && $4 ~ /noauto/ {
+		if ($1 ~ /:/) { dev=$1 } else { dev=":"$1 }
+		print "-fstype=" $3 "," $4, dev
+	}'
+}
+
+if [ $# -eq 0 ]; then
+	print_available
+	exit 0
+fi
+
+print_one "$1"
+exit 0
+


Property changes on: trunk/etc/autofs/special_noauto
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: trunk/etc/autofs/special_null
===================================================================
--- trunk/etc/autofs/special_null	                        (rev 0)
+++ trunk/etc/autofs/special_null	2018-07-08 16:48:56 UTC (rev 11623)
@@ -0,0 +1,4 @@
+#!/usr/bin/true
+#
+# $MidnightBSD$
+#


Property changes on: trunk/etc/autofs/special_null
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list