mybin

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

luks_mount (522B)


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