From 8fc731aaa0f2f3f561b1b453184b0ce9fa4dda0c Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 25 Jan 2016 19:33:48 -0600 Subject: [PATCH] Progress. I can now create and edit notes reliably. --- errors.ref | 4 +-- header.sh | 2 +- sns.sh | 50 ++++++++++++++++++++--------------- src/includes/create.sns.sh | 6 ++--- src/includes/edit.sns.sh | 10 +++++-- src/includes/libencryption.sh | 2 +- src/main/stage1.sns.sh | 22 +++++++-------- src/main/stage3.sns.sh | 2 +- 8 files changed, 55 insertions(+), 43 deletions(-) diff --git a/errors.ref b/errors.ref index ce7c5f3..508077d 100644 --- a/errors.ref +++ b/errors.ref @@ -8,5 +8,5 @@ ERR_INSUFFICIENT_ARGS 30 A required argument was not provided Encryption---------------------------------------------------------------------- -ERR_NO_SSL 100 Cannot execute openssl -ERR_NO_KEY 110 No encryption key in sns.conf \ No newline at end of file +ERR_NO_GPG 100 GPG is not installed +ERR_NO_KEY 110 No recipient specified \ No newline at end of file diff --git a/header.sh b/header.sh index 5a9d6da..5d4a8c4 100644 --- a/header.sh +++ b/header.sh @@ -1,7 +1,7 @@ #!/bin/bash PROD_STR="Simple Note System" -VER_STR="v2.0a5" +VER_STR="v2.0a6" cat << EOF #!/bin/bash diff --git a/sns.sh b/sns.sh index b4dac20..e7f57bc 100755 --- a/sns.sh +++ b/sns.sh @@ -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 diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 29fddc0..403eae1 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -10,9 +10,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 diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index e67afe4..64014d6 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -4,7 +4,9 @@ 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 @@ -12,7 +14,11 @@ if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi "$EDITOR" "$TARGET" -if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi +if [ "$ENCRYPTION" == "TRUE" ]; then + rm "$NOTE" + encrypt; + if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi +fi diff --git a/src/includes/libencryption.sh b/src/includes/libencryption.sh index ed2215f..a6fcec7 100644 --- a/src/includes/libencryption.sh +++ b/src/includes/libencryption.sh @@ -3,7 +3,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" } diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 06d1b2f..4cb45f7 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -14,13 +14,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 @@ -28,16 +27,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 diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 6c640ff..1686c7b 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -25,7 +25,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