X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=check-crypttab;fp=check-crypttab;h=2bbbdeaf35eb114e61a19408d2c2c7480192dd89;hb=5b09fb8ae01ae1c9aa5c3ccde60f6e6a22f7d6a6;hp=0000000000000000000000000000000000000000;hpb=205510f1ebae68147df7c73bc71c692fd03ff045;p=distro-setup diff --git a/check-crypttab b/check-crypttab new file mode 100755 index 0000000..2bbbdea --- /dev/null +++ b/check-crypttab @@ -0,0 +1,38 @@ +#!/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