mirror of
https://github.com/sigmasternchen/Pensieve
synced 2025-03-15 07:58:54 +00:00
current version
This commit is contained in:
parent
e53bdd7827
commit
f16d683d70
2 changed files with 192 additions and 1 deletions
27
README.md
27
README.md
|
@ -1 +1,26 @@
|
|||
# Pensieve
|
||||
# Pensieve
|
||||
This is a diary script.
|
||||
|
||||
You can add or read a diary, or you can view it's stats.
|
||||
|
||||
Oh, and it's prodected with a symetric encryption from GPG (should be AES-128 or something similar string).
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
./pensieve [OPTIONS] MODE [FILE]
|
||||
|
||||
OPTIONS:
|
||||
-p use pager (only in read-mode)
|
||||
-q quiet (no output except the content)
|
||||
-j DATE jump to DATE (implies -p)
|
||||
DATE YYYY.MM.DD
|
||||
|
||||
MODE: {test|stat|read|add}
|
||||
test check password
|
||||
stat print size, number of entries, ...
|
||||
read read diary
|
||||
add add entry
|
||||
|
||||
FILE: the diary file
|
||||
```
|
||||
|
|
166
pensieve
Executable file
166
pensieve
Executable file
|
@ -0,0 +1,166 @@
|
|||
#!/bin/bash
|
||||
|
||||
# usage: pensieve [OPTIONS] {test|stat|read|add} [file]
|
||||
#
|
||||
# -p pager
|
||||
# -q quiet
|
||||
# -f filter, n.i.
|
||||
# -j DATE jump (implies -p)
|
||||
# DATE: YYYY.MM.DD
|
||||
# -e entries per page (implies -p), n.i.
|
||||
|
||||
EXIT_SUCCESS=0
|
||||
EXIT_FAILURE=1
|
||||
SEPERATOR="####################"
|
||||
|
||||
opts=$(getopt -o "qpfj:e:" -- $@)
|
||||
if test $? != 0; then
|
||||
exit $EXIT_FAILURE
|
||||
fi
|
||||
|
||||
eval set -- "$opts"
|
||||
|
||||
pager=0
|
||||
bquiet=0
|
||||
jump=""
|
||||
epp=-1
|
||||
|
||||
quiet() {
|
||||
test $bquiet != 0
|
||||
return $?
|
||||
}
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-p) pager=1; shift;;
|
||||
-q) bquiet=1; shift;;
|
||||
-f) shift;;
|
||||
-j) jump="$2"; shift 2;;
|
||||
-e) epp=$2; shift 2;;
|
||||
--) shift; break;
|
||||
esac
|
||||
done
|
||||
|
||||
mode=$1
|
||||
file=$2
|
||||
|
||||
if test "$file" = ""; then
|
||||
file=~/.diary
|
||||
fi
|
||||
|
||||
quiet || echo -n "Password: "
|
||||
read -s password
|
||||
quiet || echo
|
||||
sleep 1s
|
||||
quiet || echo
|
||||
|
||||
if test "$mode" = "stat"; then
|
||||
content=$(gpg --quiet --batch --passphrase "$password" --decrypt $file 2> /dev/null)
|
||||
if test $? != 0; then
|
||||
echo "There was an error while decrypting file. Right passord?"
|
||||
exit $EXIT_FAILURE
|
||||
fi
|
||||
|
||||
echo "Encrypted size: $(stat -L --format=%s $file)"
|
||||
echo "Decrypted size: $(echo $content | wc -c)"
|
||||
echo "Entries: $(echo "$content" | grep $SEPERATOR | wc -l)"
|
||||
dates=$(echo "$content" | grep -A 1 $SEPERATOR | grep -v $SEPERATOR)
|
||||
echo "First entry: $(echo "$dates" | head -n 1)"
|
||||
echo "Last entry: $(echo "$dates" | tail -n 1)"
|
||||
|
||||
exit $EXIT_SUCCESS
|
||||
fi
|
||||
|
||||
if test "$mode" = "test"; then
|
||||
gpg --quiet --batch --passphrase "$password" --decrypt $file 2>&1 > /dev/null
|
||||
if test $? = 0; then
|
||||
quiet || echo "Success."
|
||||
exit $EXIT_SUCCESS
|
||||
else
|
||||
quiet || echo "Fail."
|
||||
exit $EXIT_FAILURE
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$mode" = "add"; then
|
||||
tmpfile="/dev/shm/$$.diary.$(echo $file | sed 's/\//-/g')"
|
||||
|
||||
content=""
|
||||
if test -f $file; then
|
||||
content=$(gpg --quiet --batch --passphrase "$password" --decrypt $file)
|
||||
if test $? != 0; then
|
||||
echo "There was an error while decrypting file. Right password?"
|
||||
exit $EXIT_FAILURE
|
||||
fi
|
||||
else
|
||||
touch $file
|
||||
fi
|
||||
|
||||
editor $tmpfile
|
||||
if test $? != 0; then
|
||||
echo "Editor exited with error. Aborting."
|
||||
exit $EXIT_FAILURE
|
||||
fi
|
||||
|
||||
datestring=$(date "+%Y.%m.%d. %H:%M:%S")
|
||||
echo "$content" | cat - <(echo $SEPERATOR) <(echo $datestring) $tmpfile | gpg --batch --passphrase "$password" --symmetric > $file
|
||||
|
||||
rm $tmpfile
|
||||
exit $EXIT_SUCCESS
|
||||
fi
|
||||
|
||||
debug() {
|
||||
cat 1>&2
|
||||
}
|
||||
|
||||
if test "$mode" = "read"; then
|
||||
content=$(gpg --quiet --batch --passphrase "$password" --decrypt $file)
|
||||
if test $? != 0; then
|
||||
echo "There was an error while decrypting file. Right password?"
|
||||
exit $EXIT_FAILURE
|
||||
fi
|
||||
if test "$epp" != "-1"; then
|
||||
#todo
|
||||
|
||||
exit $EXIT_SUCCESS
|
||||
elif test "$jump" != ""; then
|
||||
jY=$(echo $jump | awk -F. '{print $1 }')
|
||||
jM=$(echo $jump | awk -F. '{print $2 }')
|
||||
jD=$(echo $jump | awk -F. '{print $3 }')
|
||||
|
||||
quiet || echo "Searching for year $jY month $jM day $jD..."
|
||||
|
||||
fl=$(echo "$content" | grep -A 1 $SEPERATOR | grep -v -- "--" | grep -v $SEPERATOR | awk -F. '{
|
||||
if ($1 >'$jY')
|
||||
print NR;
|
||||
else if ($1=="'$jY'" && $2 > '$jM')
|
||||
print NR;
|
||||
else if ($1=="'$jY'" && $2=="'$jM'" && $3 >= '$jD')
|
||||
print NR;
|
||||
else
|
||||
;
|
||||
}'
|
||||
)
|
||||
fl=$(echo "$fl" | head -n 1)
|
||||
if test "$fl" == ""; then
|
||||
exit $EXIT_SUCCESS;
|
||||
fi
|
||||
|
||||
fl=$(echo "$content" | grep -n "$SEPERATOR" | sed $fl'q;d' | cut -f1 -d:)
|
||||
|
||||
echo "$content" | less +$fl
|
||||
|
||||
exit $EXIT_SUCCESS
|
||||
fi
|
||||
|
||||
if test "$pager" = 0; then
|
||||
echo "$content"
|
||||
else
|
||||
echo "$content" | less
|
||||
fi
|
||||
exit $EXIT_SUCCESS
|
||||
fi
|
||||
|
||||
|
||||
echo "Unknown mode."
|
||||
exit $EXIT_FAILURE
|
Loading…
Reference in a new issue