#!/bin/bash
# -*- mode: sh; tab-width: 8; encoding: utf-8-unix -*-

prog=`basename $0 .bash`
PREFIX=/usr/local
ROLE=gpgkey
TMPDIR=/tmp

DEBUG=1
. /usr/local/bin/usr_local_tput.bash
. /usr/local/bin/gridfire.rc
EXE=veracrypt-console

#? mayaybe not

# text -- Unexpected parameter '--text'
[[ "$*" =~ "--stdin" ]] && \
    LARGS="--text --non-interactive"

if [[ "$*" =~ "--create" ]] ; then
    . /usr/local/bin/veracrypt-create.sh
elif [[ "$*" =~ "--list" ]] ; then
    :
else
    [[ "$*" =~ "--pim" ]] || RARGS="--pim=100 $RARGS"
    [[ "$*" =~ "--volume-type" ]] || [[ $RARGS =~ "--volume-type" ]] || RARGS="--volume-type=normal $RARGS"
    [[ "$*" =~ "--hash" ]] || [[ $RARGS =~ "--hash" ]] || RARGS="--hash=sha512 $RARGS"
    [[ "$*" =~ "--encryption" ]] || [[ $RARGS =~ "--encryption" ]] || RARGS="--encryption=Twofish $RARGS"
# not =''
    [[ "$*" =~ "--keyfiles" ]] || RARGS="--keyfiles '' $RARGS"
fi

DEBUG=1
DBUG $EXE $LARGS $RARGS "$@" >> $TMPDIR/VerC$$.tmp
$EXE $LARGS $RARGS "$@" 2>$TMPDIR/VerC$$.err >$TMPDIR/VerC$$.log
retval=$?
if [ $retval  -eq 0 ] ; then
    INFO see $TMPDIR/VerC$$.log
else
    WARN see $TMPDIR/VerC$$.err
    cat $TMPDIR/VerC$$.err
fi
exit $retval

