mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

luks_mount (647B)


      1 #!/bin/bash
      2 
      3 set -e
      4 
      5 VOLUME="$1"
      6 MACHINE="$2"
      7 # shift two parameters to have cryptsetup options after
      8 if [ "$#" -ge 2 ]; then
      9     shift 2
     10 else
     11     shift 1
     12 fi
     13 
     14 if [ -z "$MACHINE" ]
     15 then
     16   COMMAND=""
     17 else
     18   COMMAND="ssh $MACHINE"
     19 fi
     20 ID=$(duuid "$VOLUME")
     21 
     22 KEY="$HOME/credentials/$VOLUME.key"
     23 if echo "$VOLUME" | grep '_home$' > /dev/null
     24 then
     25   FOLDER="/home"
     26 else
     27   FOLDER="/mnt/$VOLUME"
     28 fi
     29 
     30 if [ -f "$KEY" ]
     31 then
     32   cat "$KEY" | $COMMAND sudo cryptsetup luksOpen "$@" --key-file=- "$ID" "$VOLUME"
     33 else
     34   $COMMAND sudo cryptsetup luksOpen "$@" "$ID" "$VOLUME"
     35 fi
     36 $COMMAND sudo mkdir -p "$FOLDER"
     37 $COMMAND sudo mount "/dev/mapper/$VOLUME" "$FOLDER"
     38