#!/bin/sh # map v1.3.2 (c) 26.7.2000 by Andreas Ley (u) 24.4.2008 # Add map entry usage() { echo "Usage: `basename $0` map key fs" >&2 echo " `basename $0` map key rfs rhost" >&2 echo " `basename $0` -d map key" >&2 echo " `basename $0` -r map [filename]" >&2 echo "map is given as the mountpoint prefix, e.g. /home/ws" >&2 echo "-d delete map entry" >&2 echo "-r rebuild map from stdin or given filename" >&2 echo " input must be three or four fields per line, seperated by whitespace" >&2 exit 1 } set -- `getopt drhx $*` || usage TRACE=false while :; do case $1 in -h) sed '1d;s/^# *//;/^$/q' $0; usage;; -x) set -x; TRACE=true; shift;; -d) delete=true; shift;; -r) rebuild=true; shift;; --) shift; break;; esac done test -z "${delete}${rebuild}" -a $# -ne 3 -a $# -ne 4 -o -n "${delete}" -a -z "${rebuild}" -a $# -ne 2 -o -n "${rebuild}" -a $# -lt 1 -o -n "${delete}" -a -n "${rebuild}" && usage map="$1" shift if test -n "${rebuild}"; then tmp=`/usr/machine/bin/mktemp -c` trap "rm -f ${tmp}; exit 0" 0 1 2 3 15 sort -u ${1+"$@"} >${tmp} else key="$1" rfs="$2" rhost="$3" fi umask 0022 PATH=$PATH:/usr/sbin:/etc; export PATH nodevs="nodevs" test "`uname`" = "Linux" && nodevs="nodev" ################################################################################ # # AMD # mapfile="/etc/amd.maps/`echo ${map} | tr / \#`" if test -f "${mapfile}" -o -n "${rebuild}" -a \( -x /usr/sbin/amd -o -x /etc/amd \); then # If we're not rebuilding and the key is already in the file, delete it first if test -z "${rebuild}" && grep "^${key}[ ]" "${mapfile}" >/dev/null; then sed "/^${key}[ ]/d" "${mapfile}" >"${mapfile}.tmp" && \ cat "${mapfile}.tmp" >"${mapfile}" fi rm -f "${mapfile}.tmp" # If we're rebuilding or the map is empty anyway, add header line test -n "${rebuild}" -o ! -s "${mapfile}" && \ echo "/defaults type:=nfs;opts:=hard,nointr,nosuid,${nodevs};sublink:=\${key}" >"${mapfile}" # If not deleting, add new key(s) if test -z "${delete}"; then # If not rebuilding, add single key if test -z "${rebuild}"; then if test -z "${rhost}"; then echo "${key} type:=linkx;fs:=${rfs}" else echo "${key} rfs:=${rfs};rhost:=${rhost}" fi # if rebuilding, read entries from given files else while read key rfs rhost; do if test -z "${rhost}"; then echo "${key} type:=linkx;fs:=${rfs}" else echo "${key} rfs:=${rfs};rhost:=${rhost}" fi done <${tmp} fi >>"${mapfile}" fi amq -f fi ################################################################################ # # Autofs # mapfile="/etc/auto`echo ${map} | tr / .`" if test -f "${mapfile}" -o -n "${rebuild}" -a -x /usr/sbin/automount; then # If we're not rebuilding and the key is already in the file, delete it first if test -z "${rebuild}" && grep "^${key}[ ]" "${mapfile}" >/dev/null; then sed "/^${key}[ ]/d" "${mapfile}" >"${mapfile}.tmp" && \ cat "${mapfile}.tmp" >"${mapfile}" fi rm -f "${mapfile}.tmp" # If we're rebuilding or the map is empty anyway, add header line test -n "${rebuild}" -o ! -s "${mapfile}" && \ echo '# ' >"${mapfile}" # If not deleting, add new key(s) if test -z "${delete}"; then # If not rebuilding, add single key if test -z "${rebuild}"; then if test -z "${rhost}"; then echo "Can't use local links with autofs maps" >&2 exit 1 else echo "${key} -hard,nointr,nosuid,${nodevs} ${rhost}:${rfs}/${key}" fi # if rebuilding, read entries from given files else while read key rfs rhost; do if test -z "${rhost}"; then echo "Can't use local links with autofs maps: ${key}" >&2 else echo "${key} -hard,nointr,nosuid,${nodevs} ${rhost}:${rfs}/${key}" fi done <${tmp} fi >>"${mapfile}" fi fi ################################################################################ # # Automounter # if test -f /etc/auto.direct; then echo "Automounter not yet implemented" >&2 exit 1 fi exit 0