#!/bin/sh # $OpenBSD: mount_vnd,v 1.1 2007/04/14 11:54:00 grunk Exp $ # # Copyright (c) 2005, 2006, 2007 David Krause # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. progname=`basename "$0"` usage() { cat <<-EOF usage: $progname [-k] [-K rounds] [-o options] [-S saltfile] image node EOF exit 1 } kflag= ROUNDS= SALTFILE= args=`getopt kK:o:S: $*` if [ $? -ne 0 ]; then usage fi set -eu set -- $args while [ $# -ge 0 ]; do case "$1" in -k) kflag="$1"; shift;; -K) ROUNDS="$2"; shift; shift;; -o) # currently, no mount options have effect for vnd shift; shift;; -S) SALTFILE="$2"; shift; shift;; --) shift; break;; esac done if [ $# -ne 2 ]; then usage fi IMAGE="$1" VND="$2" if [ -n "${ROUNDS}" -a ! -n "${SALTFILE}" ]; then SALTFILE="${IMAGE}.slt" fi if [ -n "${ROUNDS}" -a -n "${kflag}" ]; then echo "$progname: -k and -K are mutually exclusive" 1>&2 exit 1 elif [ -n "${SALTFILE}" -a ! -n "${ROUNDS}" ]; then echo "$progname: -S only makes sense when used with -K" 1>&2 exit 1 elif [ ! -b "${IMAGE}" -a ! -f "${IMAGE}" ]; then echo "$progname: ${IMAGE}: No such file" 1>&2 exit 1 elif [ -n "${SALTFILE}" -a ! -f "${SALTFILE}" ]; then echo "$progname: ${SALTFILE}: No such file" 1>&2 exit 1 elif [ ! -b "${VND}" ]; then echo "$progname: ${VND}: No such block device" 1>&2 exit 1 fi vnconfig -l ${VND} > /dev/null if vnconfig -l ${VND} | fgrep -q covering; then echo "$progname: ${VND} is already in use" 1>&2 exit 1 fi echo "${IMAGE} on ${VND}" if [ -n "${ROUNDS}" ]; then vnconfig -K ${ROUNDS} -S ${SALTFILE} ${VND} ${IMAGE} elif [ -n "${kflag}" ]; then vnconfig -k ${VND} ${IMAGE} else vnconfig ${VND} ${IMAGE} fi