scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit efc8b38339d88ae0b88dacbc091f1db1ab672be5
parent 80c05121877a5a7d7fa7d730ee0960e67e91b03c
Author: dsp <dsp@2f30.org>
Date:   Mon, 13 Feb 2017 03:24:12 -0700

Initial commit of cryptovol.
Cryptovol facilitates working with files as encrypted softraid volumes on OpenBSD
It also securely wipes files. It is recommended to run it into systems with swap encrypt.

Diffstat:
Acryptovol | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+), 0 deletions(-)

diff --git a/cryptovol b/cryptovol @@ -0,0 +1,99 @@ +#!/bin/sh +# this scripts creates (or securely deletes) a file and uses it as an an encrypted softraid device. +# init would create the file, attach would attach it to a mountpoint, detaching a mountpoint would free +# the vnd and scsi devices and remove would securely wipe the file from the computer. + +init() { + if [ ${#} -ne 0 ]; then + usage; exit 1; + fi + echo -n "Enter volumefile name:" + read volfname + if test -e $volfname; then + echo "volume file:" $volfname " exists." + exit 1 + fi + + echo -n "Enter volumefile size (in Mb):" + read volsize + dd if=/dev/urandom of=$volfname bs=1m count=$volsize + /usr/bin/doas /sbin/vnconfig -c vnd0 $volfname + /usr/bin/doas fdisk -iy vnd0 + printf "a\n\n\n\nRAID\nw\nq\n\n" | /usr/bin/doas disklabel -E vnd0 + /usr/bin/doas /sbin/bioctl -c C -l vnd0a softraid0 + cryptdev=`dmesg | tail -1 | grep sd | cut -f 1 -d :` # heuristic should get it since we just attached + echo -n "the new device created is: " $cryptdev + echo -n " shall we go ahead and erase it? [yn]:" + read yn + case $yn in + [Yy]* ) fdisk -iy $cryptdev; printf "a\n\n\n\n4.2BSD\nw\nq\n\n" | /usr/bin/doas disklabel -E $cryptdev; doas newfs ${cryptdev}a + ;; + [Nn]* ) /usr/bin/doas /sbin/bioctl -d $cryptdev; doas /sbin/vnconfig -u vnd0 ;exit 0 + ;; + * ) echo -n " yes or no"; + ;; + esac +} + +attach() { # attach file dir + if [ ${#} -ne 2 ]; then + usage; exit 1; + fi + echo "attaching $1 to mountpoint $2" + /usr/bin/doas /sbin/vnconfig -c vnd0 $1 + /usr/bin/doas /sbin/bioctl -c C -l vnd0a softraid0 + cryptdev=`dmesg | tail -1 | grep sd | cut -f 1 -d :` + mount /dev/${cryptdev}a $2 +} + +detach() { #detach dir + if [ ${#} -ne 1 ]; then + usage; exit 1; + fi + echo "unmounting $1" + /usr/bin/doas umount $1 + cryptdev=`dmesg | tail -4 | grep -G "sd. at" | uniq | cut -f 1 -d\ ` #heuristic + /usr/bin/doas /sbin/bioctl -d $cryptdev + /usr/bin/doas /sbin/vnconfig -u vnd0 + exit 0 +} + +remove() { + if [ ${#} -ne 1 ]; then + usage; exit 1; + fi + echo -n "remove file $1? [yn]:" + read yn + case $yn in + [Yy]* ) nblocks=`/usr/bin/stat -f "%b" $1`; /bin/dd if=/dev/zero of=$1 bs=$nblocks count=1; /bin/sync; /bin/rm $1; /bin/sync + ;; + [Nn]* ) exit 0 + ;; + * ) echo -n " yes or no " + ;; + esac +} + +usage() { + cat << EOF + cryptovol [command] [opts...] + commands: + init + attach file mountpoint + detach mountpoint + remove file +EOF +} + +case $1 in + init ) shift; init $@ + ;; + attach ) shift; attach $@ + ;; + detach ) shift; detach $@ + ;; + remove ) shift; remove $@ + ;; + * ) usage + ;; +esac