#!/bin/sh
### BEGIN INIT INFO
# Provides: veracrypt
# Required-Start:   
# Required-Stop: $remote_fs
# Should-Start:      
# Should-Stop:
# Default-Start:
# Default-Stop: 0 1 6
# Short-Description: Remove remaining VeraCrypt device mappings.
# Description:       This init script will dismount mounted VeraCrypt partitions before shutdown.
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
VERACRYPT_SHUTDOWN_UNMOUNT="yes"

. /lib/lsb/init-functions

[ -x /usr/bin/veracrypt ] || exit 0

if [ -r /etc/default/veracrypt ]; then
        . /etc/default/veracrypt
fi

case "${VERACRYPT_SHUTDOWN_UNMOUNT}" in
[Nn]*)
        exit 0
        ;;
esac

do_stop()
{
  log_action_begin_msg "Removing VeraCrypt device mappings"
  veracrypt -d
  log_action_end_msg $?
}

case "$1" in
  start)
        # No-op
        ;;
  status)
        veracrypt --list
        ;;
  restart|reload|force-reload)
        # No-op
        ;;
  stop)
        do_stop
        ;;
  *)
        echo "Usage: $0 stop|status" >&2
        exit 3
        ;;
esac