head	1.1;
access;
symbols
	perseant-exfatfs-base-20261102:1.1
	netbsd-11-1-RELEASE:1.1
	netbsd-10-2-RELEASE:1.1
	netbsd-9-5-RELEASE:1.1
	netbsd-11-0-RELEASE:1.1
	netbsd-11-0-RC7:1.1
	netbsd-11-0-RC6:1.1
	netbsd-11-0-RC5:1.1
	netbsd-11-0-RC4:1.1
	netbsd-11-0-RC3:1.1
	netbsd-11-0-RC2:1.1
	netbsd-11-0-RC1:1.1
	perseant-exfatfs-base-20250801:1.1
	netbsd-11:1.1.0.18
	netbsd-11-base:1.1
	netbsd-10-1-RELEASE:1.1
	perseant-exfatfs-base-20240630:1.1
	perseant-exfatfs:1.1.0.16
	perseant-exfatfs-base:1.1
	netbsd-9-4-RELEASE:1.1
	netbsd-10-0-RELEASE:1.1
	netbsd-10-0-RC6:1.1
	netbsd-10-0-RC5:1.1
	netbsd-10-0-RC4:1.1
	netbsd-10-0-RC3:1.1
	netbsd-10-0-RC2:1.1
	netbsd-10-0-RC1:1.1
	netbsd-10:1.1.0.14
	netbsd-10-base:1.1
	netbsd-9-3-RELEASE:1.1
	cjep_sun2x-base1:1.1
	cjep_sun2x:1.1.0.12
	cjep_sun2x-base:1.1
	cjep_staticlib_x-base1:1.1
	netbsd-9-2-RELEASE:1.1
	cjep_staticlib_x:1.1.0.10
	cjep_staticlib_x-base:1.1
	netbsd-9-1-RELEASE:1.1
	phil-wifi-20200421:1.1
	phil-wifi-20200411:1.1
	is-mlppp:1.1.0.8
	is-mlppp-base:1.1
	phil-wifi-20200406:1.1
	netbsd-9-0-RELEASE:1.1
	netbsd-9-0-RC2:1.1
	netbsd-9-0-RC1:1.1
	phil-wifi-20191119:1.1
	netbsd-9:1.1.0.6
	netbsd-9-base:1.1
	phil-wifi-20190609:1.1
	pgoyette-compat-merge-20190127:1.1
	pgoyette-compat-20190127:1.1
	pgoyette-compat-20190118:1.1
	pgoyette-compat-1226:1.1
	pgoyette-compat-1126:1.1
	pgoyette-compat-1020:1.1
	pgoyette-compat-0930:1.1
	pgoyette-compat-0906:1.1
	pgoyette-compat-0728:1.1
	phil-wifi:1.1.0.4
	phil-wifi-base:1.1
	pgoyette-compat-0625:1.1
	pgoyette-compat-0521:1.1
	pgoyette-compat-0502:1.1
	pgoyette-compat-0422:1.1
	pgoyette-compat-0415:1.1
	pgoyette-compat-0407:1.1
	pgoyette-compat-0330:1.1
	pgoyette-compat-0322:1.1
	pgoyette-compat-0315:1.1
	pgoyette-compat:1.1.0.2
	pgoyette-compat-base:1.1;
locks; strict;
comment	@# @;


1.1
date	2018.01.09.03.31.14;	author christos;	state Exp;
branches;
next	;
commitid	nhHsbnoK9vzLm9mA;


desc
@@


1.1
log
@Merge autofs support from: Tomohiro Kusumi
XXX: Does not work yet
@
text
@#!/bin/sh
#
# $NetBSD$
#

# 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 ${DEVICES}; 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#* }"
			# Replace plus signs and slashes with minuses;
			# leading plus signs have special meaning in maps,
			# and multi-component keys are just not supported.
			_label="$(echo ${_label} | sed 's,[+/],-,g')"
			echo "${_label}"
			continue
		fi

		echo "${_p}"
	done
}

# Print a single map entry.
print_map_entry() {
	local _fstype _p

	_fstype="$1"
	_p="$2"

	case "${_fstype}" in
	"exfat")
		if [ -f "/usr/local/sbin/mount.exfat" ]; then
			echo "-mountprog=/usr/local/sbin/mount.exfat,fstype=${_fstype},nosuid	:/dev/${_p}"
		else
			/usr/bin/logger -p info -t "special_media[$$]" \
			    "Cannot mount ${_fstype} formatted device /dev/${_p}: Install sysutils/fusefs-exfat first"
			exit 1
		fi
		;;
	"ntfs")
		if [ -f "/usr/local/bin/ntfs-3g" ]; then
			echo "-mountprog=/usr/local/bin/ntfs-3g,fstype=${_fstype},nosuid	:/dev/${_p}"
		else
			/usr/bin/logger -p info -t "special_media[$$]" \
			    "Cannot mount ${_fstype} formatted device /dev/${_p}: Install sysutils/fusefs-ntfs first"
			exit 1
		fi
		;;
	"ext2fs" | "msdosfs")
		echo "-fstype=${_fstype},nosuid,async	:/dev/${_p}"
		;;
	*)
		echo "-fstype=${_fstype},nosuid	:/dev/${_p}"
		;;
	esac
}

# Determine map entry contents for the given key and print out the entry.
print_one() {
	local _fstype _fstype_and_label _label _key _p

	_key="$1"

	_fstype="$(fstyp "/dev/${_key}" 2> /dev/null)"
	if [ $? -eq 0 ]; then
		print_map_entry "${_fstype}" "${_key}"
		return
	fi

	for _p in ${DEVICES}; 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#* }"
		# Replace plus signs and slashes with minuses;
		# leading plus signs have special meaning in maps,
		# and multi-component keys are just not supported.
		_label="$(echo ${_label} | sed 's,[+/],-,g')"
		if [ "${_label}" != "${_key}" ]; then
			# Labels don't match, try another device.
			continue
		fi

		print_map_entry "${_fstype}" "${_p}"
	done

	# No matching device - don't print anything, autofs will handle it.
}

# XXX: -media map is unusable at the moment.
# This script needs to be able to get the list of devices/partitions. FreeBSD can do this via GEOM sysctl.
#HW_DISKNAMES=$(sysctl hw.disknames)
#if [ $? -ne 0 ]; then
#	exit 1
#fi
# Cut "hw.disknames =" and ignore the next " " before names start.
#DEVICES=$(echo ${HW_DISKNAMES} | awk '{$1=$2=""; print substr($0,3)}' | awk '{gsub(" ", "\n"); print}' | sort)

# ${DEVICES} should contain one device/partition for each line.
DEVICES=""

if [ $# -eq 0 ]; then
	print_available
	exit 0
fi

print_one "$1"
exit 0

@
