aboutsummaryrefslogtreecommitdiff
path: root/tomb-create
blob: aa211c2c7b182331927bd584164d8d479f0afa9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
#
# Create a Tomb.
#

# Parameters
TOMBS="$HOME/data/tombs"
KEYS="$HOME/.tombs"
BASENAME="`basename $0`"
TOMB="$1"
SIZE="$2"

# Check
if [ ! -d "$TOMBS" ]; then
  echo "error: no cemetery available at $TOMBS"
  exit 1
elif [ -z "$TOMB" ]; then
  echo "usage: $BASENAME <tomb>"
  exit 1
elif [ -e "$TOMBS/$TOMB.tomb" ]; then
  echo "tomb already exists: $TOMBS/$TOMB.tomb"
  exit 1
elif [ ! -e "$KEYS/$TOMB.tomb.key" ]; then
  echo "missing keyfile $KEYS/$TOMB.tomb.key"
  exit 1
fi

# Set
if [ -z "$SIZE" ]; then
  SIZE="16"
fi

# Create password
keyringer default pwgen tombs/$TOMB.tomb.key.passwd

# Dispatch
tomb dig   $TOMBS/$TOMB.tomb -s $SIZE
tomb forge $KEYS/$TOMB.tomb.key
tomb lock  $TOMBS/$TOMB.tomb -k $KEYS/$TOMB.tomb.key

# Add key into keyringer
keyringer default encrypt tombs/$TOMB.tomb.key $KEYS/$TOMB.tomb.key

# Annex
#if [ -d "$TOMBS/.git/annex" ] && [ -h "$TOMBS/$TOMB.tomb" ]; then
#  ( cd $TOMBS && git annex unlock $TOMB.tomb )
#fi