From a95760dc4b5a4c6985c8babfac05000c7307918f Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 21 Feb 2021 17:40:09 -0300 Subject: Feat: adds tomb-create --- tomb-close | 34 ++++++++++++++++++++++++++++++++++ tomb-create | 47 +++++++++++++++++++++++++++++++++++++++++++++++ tomb-open | 34 ++++++++++++++++++++++++++++++++++ tombclose | 34 ---------------------------------- tombopen | 34 ---------------------------------- 5 files changed, 115 insertions(+), 68 deletions(-) create mode 100755 tomb-close create mode 100755 tomb-create create mode 100755 tomb-open delete mode 100755 tombclose delete mode 100755 tombopen diff --git a/tomb-close b/tomb-close new file mode 100755 index 0000000..3ee08dd --- /dev/null +++ b/tomb-close @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Close a Tomb. +# + +# Parameters +TOMBS="$HOME/data/tombs" +KEYS="$HOME/.tombs" +BASENAME="`basename $0`" +TOMB="$1" + +# Check +if [ ! -d "$TOMBS" ]; then + echo "error: no cemetery available at $TOMBS" + exit 1 +elif [ -z "$TOMB" ]; then + echo "usage: $BASENAME " + echo "available tombs: `ls $TOMBS | xargs basename -a -s .tomb | xargs echo`" + exit 1 +elif [ ! -e "$TOMBS/$TOMB.tomb" ]; then + echo "tomb not found: $TOMBS/$TOMB.tomb" + exit 1 +#elif ! tomb list $TOMB &> /dev/null; then +# echo "tomb $TOMB is already closed" +# exit 1 +fi + +# Dispatch +tomb close $TOMB + +# Annex +if [ -d "$TOMBS/.git/annex" ]; then + ( cd $TOMBS && git annex add $TOMB.tomb ) +fi diff --git a/tomb-create b/tomb-create new file mode 100755 index 0000000..aa211c2 --- /dev/null +++ b/tomb-create @@ -0,0 +1,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 " + 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 diff --git a/tomb-open b/tomb-open new file mode 100755 index 0000000..5154215 --- /dev/null +++ b/tomb-open @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Open a Tomb. +# + +# Parameters +TOMBS="$HOME/data/tombs" +KEYS="$HOME/.tombs" +BASENAME="`basename $0`" +TOMB="$1" + +# Check +if [ ! -d "$TOMBS" ]; then + echo "error: no cemetery available at $TOMBS" + exit 1 +elif [ -z "$TOMB" ]; then + echo "usage: $BASENAME " + echo "available tombs: `ls $TOMBS | xargs basename -a -s .tomb | xargs echo`" + exit 1 +elif [ ! -e "$TOMBS/$TOMB.tomb" ]; then + echo "tomb not found: $TOMBS/$TOMB.tomb" + exit 1 +elif [ ! -e "$KEYS/$TOMB.tomb.key" ]; then + echo "missing keyfile $KEYS/$TOMB.tomb.key" + exit 1 +fi + +# Unnanex +if [ -d "$TOMBS/.git/annex" ] && [ -h "$TOMBS/$TOMB.tomb" ]; then + ( cd $TOMBS && git annex unlock $TOMB.tomb ) +fi + +# Dispatch +tomb open $TOMBS/$TOMB.tomb -k $KEYS/$TOMB.tomb.key diff --git a/tombclose b/tombclose deleted file mode 100755 index 711af86..0000000 --- a/tombclose +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Close a Tomb. -# - -# Parameters -BASENAME="`basename $0`" -TOMB="$1" -TOMBS="$HOME/data/tombs" -KEYS="$HOME/.tombs" - -# Check -if [ ! -d "$TOMBS" ]; then - echo "error: no cemetery available at $TOMBS" - exit 1 -elif [ -z "$TOMB" ]; then - echo "usage: $BASENAME " - echo "available tombs: `ls $TOMBS | xargs basename -a -s .tomb | xargs echo`" - exit 1 -elif [ ! -e "$TOMBS/$TOMB.tomb" ]; then - echo "tomb not found: $TOMBS/$TOMB.tomb" - exit 1 -#elif ! tomb list $TOMB &> /dev/null; then -# echo "tomb $TOMB is already closed" -# exit 1 -fi - -# Dispatch -tomb close $TOMB - -# Annex -if [ -d "$TOMBS/.git/annex" ]; then - ( cd $TOMBS && git annex add $TOMB.tomb ) -fi diff --git a/tombopen b/tombopen deleted file mode 100755 index 0de4e81..0000000 --- a/tombopen +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# Open a Tomb. -# - -# Parameters -BASENAME="`basename $0`" -TOMB="$1" -TOMBS="$HOME/data/tombs" -KEYS="$HOME/.tombs" - -# Check -if [ ! -d "$TOMBS" ]; then - echo "error: no cemetery available at $TOMBS" - exit 1 -elif [ -z "$TOMB" ]; then - echo "usage: $BASENAME " - echo "available tombs: `ls $TOMBS | xargs basename -a -s .tomb | xargs echo`" - exit 1 -elif [ ! -e "$TOMBS/$TOMB.tomb" ]; then - echo "tomb not found: $TOMBS/$TOMB.tomb" - exit 1 -elif [ ! -e "$KEYS/$TOMB.tomb.key" ]; then - echo "missing keyfile $KEYS/$TOMB.tomb.key" - exit 1 -fi - -# Unnanex -if [ -d "$TOMBS/.git/annex" ] && [ -h "$TOMBS/$TOMB.tomb" ]; then - ( cd $TOMBS && git annex unlock $TOMB.tomb ) -fi - -# Dispatch -tomb open $TOMBS/$TOMB.tomb -k $KEYS/$TOMB.tomb.key -- cgit v1.2.3