From 7c053e67f27af8cf7ad73f8db9c8622634cbabe8 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 11 Oct 2016 23:19:21 +0200 Subject: [PATCH] contrib: add gocryptfs-maybe.bash Conditionally try to mount a gocryptfs filesystem. If either * CIPHERDIR does not exist OR * something is already mounted on MOUNTPOINT print a message to stdout (not stderr!) but exit with 0. This is meant to be called from automated mount systems like pam_mount, where you want to avoid error messages if the filesystem does not exist, or duplicate mounts if the filesystem has already been mounted. --- contrib/gocryptfs-maybe.bash | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 contrib/gocryptfs-maybe.bash diff --git a/contrib/gocryptfs-maybe.bash b/contrib/gocryptfs-maybe.bash new file mode 100755 index 0000000..dcfa965 --- /dev/null +++ b/contrib/gocryptfs-maybe.bash @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Conditionally try to mount a gocryptfs filesystem. If either +# * CIPHERDIR does not exist OR +# * something is already mounted on MOUNTPOINT +# print a message to stdout (not stderr!) but exit with 0. +# +# This is meant to be called from automated mount systems like pam_mount, +# where you want to avoid error messages if the filesystem does not exist, +# or duplicate mounts if the filesystem has already been mounted. +# +# Note that pam_mount ignores messages on stdout which is why printing +# to stdout is ok. +set -eu +MYNAME=$(basename $0) +if [[ $# -lt 2 || $1 == -* ]]; then + echo "Usage: $MYNAME CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]" >&2 + exit 1 +fi +if [[ ! -f $1/gocryptfs.conf ]]; then + echo "$MYNAME: \"$1\" does not look like a gocryptfs filesystem, ignoring mount request" + exit 0 +fi +if mountpoint "$2" > /dev/null; then + echo "$MYNAME: something is already mounted on \"$2\", ignoring mount request" + exit 0 +fi +exec gocryptfs "$@"