--- /dev/null
+#!/bin/bash
+
+# I somehow ended up with an empty crypttab, and had to rescue my
+# system. So, lets check for some basic validity.
+
+if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
+shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
+
+debug=false
+if [[ $1 ]]; then
+ debug=true
+fi
+d() {
+ if $debug; then
+ printf "%s\n" "$*"
+ fi
+}
+
+metric_dir=/var/lib/prometheus/node-exporter
+mnt="$(findmnt -fn -o SOURCE /)"
+case $mnt in
+ /dev/mapper/crypt_dev_*)
+ tmp=${mnt#/dev/mapper/}
+ dev=${tmp%%\[*}
+ if ! grep -qF $dev /etc/crypttab; then
+ d $dev
+ if [[ -e $metric_dir ]]; then
+ echo "crypttab_check 1" > $metric_dir/crypttab_check.prom
+ exit 0
+ fi
+ fi
+ ;;
+esac
+if [[ -e $metric_dir ]]; then
+ echo "crypttab_check 0" > $metric_dir/crypttab_check.prom
+fi