Progress. I can now create and edit notes reliably.

This commit is contained in:
Jon-William Lewis
2016-01-25 19:33:48 -06:00
parent 6a21731082
commit 8fc731aaa0
8 changed files with 55 additions and 43 deletions

50
sns.sh
View File

@@ -1,13 +1,13 @@
#!/bin/bash
#==========================================================
# Simple Note System, v2.0a5
# Simple Note System, v2.0a6
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
#==========================================================
if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi
PROD_STR="Simple Note System"
readonly VER_STR="v2.0a5"
readonly VER_STR="v2.0a6"
readonly ROOT_DIR="$HOME"/.config/xenlabs/sns
readonly BASE_DIR="$ROOT_DIR"/notes
readonly TMP_DIR="$ROOT_DIR"/tmp
@@ -32,7 +32,7 @@ EXT=note
#Preferred Editor
if [ -z "$EDITOR" ]; then
echo EDITOR=vim
EDITOR=vim
fi
#Encryption
@@ -76,7 +76,7 @@ function encrypt(){
# output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private
# GPG key.
gpg -r "$PUBKEY" --encrypt-files "$TARGET" --output "$NOTE"
gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET"
}
@@ -101,9 +101,9 @@ function create(){
echo "TITLE: $NAME" > "$NOTE"
echo "DATE: $(date)" >> "$NOTE"
elif [ "$ENCRYPTION" == "TRUE" ]; then
touch "$NOTE"
p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\
-pass pass:"$ENC_KEY"
TARGET="$TMP_DIR"/"$SESSION_ID"
p_header > "$TARGET"
encrypt
fi
if [ -e "$NOTE" ]; then
@@ -131,15 +131,21 @@ if [ ! -r "$NOTE" ]; then
exit 40;
fi
if [ "$ENCRYPTION" == "TRUE" ]; then decrypt
if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk
decrypt
else TARGET="$NOTE"; fi
if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi
echo "$EDITOR" "$TARGET"
"$EDITOR" "$TARGET"
if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi
if [ "$ENCRYPTION" == "TRUE" ]; then
rm "$NOTE"
encrypt;
if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi
fi
@@ -221,13 +227,12 @@ if [ "$ENCRYPTION" == "TRUE" ]; then
ENCRYPTION="FALSE"
fi
command -v openssl >/dev/null 2>&1 ||\
{ ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; }
command -v gpg >/dev/null 2>&1 ||\
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
fi
if [ "$ENCRYPTION" == "TRUE" ]; then
PROD_STR="Simple Note System (Encryption Enabled)"
EXT="$EXT".gpg
if [ ! -d "$BASE_DIR"/tmp ]; then
mkdir -p "$BASE_DIR"/tmp
fi
@@ -235,16 +240,17 @@ fi
echo "$PROD_STR, $VER_STR"
if [ -n "$ERR_NO_SSL" ]; then
echo >&2 " Warning: OpenSSL not installed. Encryption disabled."
fi
if [ -n "$ERR_NO_KEY" ]; then
echo " Warning: No encryption key was provided. Encryption disabled."
if [ -z "$EDITOR" ]; then
>&2 echo "Error no editor specified in environment."
elif [ -n "$ERR_NO_GPG" ]; then
>&2 echo " Error: Encryption was specified, but GPG is not installed."
exit 100
elif [ -n "$ERR_NO_KEY" ]; then
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
exit 110
fi
if [ -n "$ERR_NO_SSL" ] || [ -n "$ERR_NO_KEY" ]; then
pause
fi
#==============================================================================
# End Section: Configuration / Stage 1
@@ -317,7 +323,7 @@ SESSION_ID="$RANDOM"
NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/
NOTE="$NOTE_DIR""$NAME"."$EXT"
if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".enc; fi
if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".gpg; fi
if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
if [ "$CREATE" == "TRUE" ]; then create; fi