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

View File

@@ -8,5 +8,5 @@ ERR_INSUFFICIENT_ARGS 30 A required argument was not provided
Encryption---------------------------------------------------------------------- Encryption----------------------------------------------------------------------
ERR_NO_SSL 100 Cannot execute openssl ERR_NO_GPG 100 GPG is not installed
ERR_NO_KEY 110 No encryption key in sns.conf ERR_NO_KEY 110 No recipient specified

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
PROD_STR="Simple Note System" PROD_STR="Simple Note System"
VER_STR="v2.0a5" VER_STR="v2.0a6"
cat << EOF cat << EOF
#!/bin/bash #!/bin/bash

50
sns.sh
View File

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

View File

@@ -10,9 +10,9 @@ function create(){
echo "TITLE: $NAME" > "$NOTE" echo "TITLE: $NAME" > "$NOTE"
echo "DATE: $(date)" >> "$NOTE" echo "DATE: $(date)" >> "$NOTE"
elif [ "$ENCRYPTION" == "TRUE" ]; then elif [ "$ENCRYPTION" == "TRUE" ]; then
touch "$NOTE" TARGET="$TMP_DIR"/"$SESSION_ID"
p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ p_header > "$TARGET"
-pass pass:"$ENC_KEY" encrypt
fi fi
if [ -e "$NOTE" ]; then if [ -e "$NOTE" ]; then

View File

@@ -4,7 +4,9 @@ if [ ! -r "$NOTE" ]; then
exit 40; exit 40;
fi fi
if [ "$ENCRYPTION" == "TRUE" ]; then decrypt if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk
decrypt
else TARGET="$NOTE"; fi else TARGET="$NOTE"; fi
@@ -12,7 +14,11 @@ if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi
"$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

View File

@@ -3,7 +3,7 @@ function encrypt(){
# output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private # output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private
# GPG key. # GPG key.
gpg -r "$PUBKEY" --encrypt-files "$TARGET" --output "$NOTE" gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET"
} }

View File

@@ -14,13 +14,12 @@ if [ "$ENCRYPTION" == "TRUE" ]; then
ENCRYPTION="FALSE" ENCRYPTION="FALSE"
fi fi
command -v openssl >/dev/null 2>&1 ||\ command -v gpg >/dev/null 2>&1 ||\
{ ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
fi fi
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
PROD_STR="Simple Note System (Encryption Enabled)" PROD_STR="Simple Note System (Encryption Enabled)"
EXT="$EXT".gpg
if [ ! -d "$BASE_DIR"/tmp ]; then if [ ! -d "$BASE_DIR"/tmp ]; then
mkdir -p "$BASE_DIR"/tmp mkdir -p "$BASE_DIR"/tmp
fi fi
@@ -28,16 +27,17 @@ fi
echo "$PROD_STR, $VER_STR" echo "$PROD_STR, $VER_STR"
if [ -n "$ERR_NO_SSL" ]; then if [ -z "$EDITOR" ]; then
echo >&2 " Warning: OpenSSL not installed. Encryption disabled." >&2 echo "Error no editor specified in environment."
fi
if [ -n "$ERR_NO_KEY" ]; then elif [ -n "$ERR_NO_GPG" ]; then
echo " Warning: No encryption key was provided. Encryption disabled." >&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 fi
if [ -n "$ERR_NO_SSL" ] || [ -n "$ERR_NO_KEY" ]; then
pause
fi
#============================================================================== #==============================================================================
# End Section: Configuration / Stage 1 # End Section: Configuration / Stage 1

View File

@@ -25,7 +25,7 @@ SESSION_ID="$RANDOM"
NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/
NOTE="$NOTE_DIR""$NAME"."$EXT" 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 [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
if [ "$CREATE" == "TRUE" ]; then create; fi if [ "$CREATE" == "TRUE" ]; then create; fi