From faab86dff29faa19a296974177c9f750eb6cc942 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 00:55:29 -0600 Subject: [PATCH] Continued work on loosening note definition; added framework for color in errors. --- errors.ref | 6 ++-- header.sh | 3 ++ src/main/stage1.sns.sh | 63 +++++++++++++++++------------------ src/main/stage3.sns.sh | 74 +++++++++++++++++++++--------------------- 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/errors.ref b/errors.ref index 28754c8..eb46e38 100644 --- a/errors.ref +++ b/errors.ref @@ -3,12 +3,12 @@ Error Code Reference General------------------------------------------------------------------------- ERR_NO_ARGS 10 No arguments were specified -ERR_NO_OP 20 -ERR_NO_NOTEBOOK 30 A required argument was not provided +ERR_NO_OP 20 No operation was specified +ERR_NO_NOTE 30 A required argument was not provided Encryption---------------------------------------------------------------------- ERR_NO_GPG 100 Encryption is enabled, but GPG is not installed ERR_NO_KEY 110 Encryption is enabled, but no recipient was specified Create-------------------------------------------------------------------------- -ERR_NOTE_EXiSTS 200 The specified note already exists \ No newline at end of file +ERR_NOTE_EXiSTS 200 The specified note already exists diff --git a/header.sh b/header.sh index 9ffc69b..63d8c87 100644 --- a/header.sh +++ b/header.sh @@ -19,6 +19,9 @@ readonly NOTES_DIR="\$ROOT_DIR"/notes readonly TMP_DIR="\$ROOT_DIR"/tmp readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" +readonly RED_COLOR='\033[1;31m' +readonly RESET_COLOR='\033[0m' + printf "%s\n" "\$PROD_STR" printf "%s\n" "------------------" EOF diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index dc3e962..77d5008 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -1,39 +1,36 @@ - #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # Entry Point - #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - #============================================================================== - # Stage 1: Read Configuration / Verify Integrity - #============================================================================== +#============================================================================== +# Stage 1: Read Configuration / Verify Integrity +#============================================================================== - if [ -r "$CONFIG_FILE" ]; then - source "$CONFIG_FILE" - else - init_store - source "$CONFIG_FILE" - fi +if [ -r "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" +else + init_store + source "$CONFIG_FILE" +fi - verify_store +verify_store - if [ "$ENCRYPTION" == "TRUE" ]; then - if [ -z "$PUBKEY" ]; then - ERR_NO_KEY="TRUE" - ENCRYPTION="FALSE" - fi +if [ "$ENCRYPTION" == "TRUE" ]; then + if [ -z "$PUBKEY" ]; then + ERR_NO_KEY="TRUE" + ENCRYPTION="FALSE" + fi - command -v gpg >/dev/null 2>&1 ||\ - { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; } - fi + command -v gpg >/dev/null 2>&1 ||\ + { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; } +fi - if [ "$ENCRYPTION" == "TRUE" ]; then - if [ ! -d "$ROOT_DIR"/tmp ]; then - mkdir -p "$ROOT_DIR"/tmp - fi - fi +if [ "$ENCRYPTION" == "TRUE" ]; then + if [ ! -d "$ROOT_DIR"/tmp ]; then + mkdir -p "$ROOT_DIR"/tmp + fi +fi - if [ -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_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 diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 673b184..3f813f0 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -1,42 +1,42 @@ - #============================================================================== - # Section: Actions / Stage 3 - #============================================================================== - # Default behavior - # If no operation was specified, print help and exit on ERR_NO_OP - if [ "$OP" != "TRUE" ]; then - help; exit 20 - fi - # All options not requiring at least a notebook to be specified have been dealt - # with; if one isn't specified, exit on ERR_NO_NOTEBOOK. - if [ -z "$NOTEBOOK" ]; then - printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" - exit 30 - fi - # List is the only option requiring only a notebook. - # If list isn't the selected option and no note name was specified, throw code 30. - if [ "$LIST" == TRUE ]; then - list - exit 0 - elif [ -z "$NAME" ]; then - printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" - exit 30 - fi +#============================================================================== +# Section: Actions / Stage 3 +#============================================================================== +# Default behavior +# If no operation was specified, print help and exit on ERR_NO_OP + if [ "$OP" != "TRUE" ]; then + help; exit 20 + fi +# All options not requiring a note to be specified have been dealt +# with; if one isn't specified, exit on ERR_NO_NOTE. +if [ -z "$NOTE" ]; then + printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified." + exit 30 +fi +# List is the only option requiring only a notebook. +# If list isn't the selected option and no note name was specified, throw code 30. +if [ "$LIST" == TRUE ]; then + list + exit 0 +elif [ -z "$NAME" ]; then + printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" + exit 30 +fi - NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION" +NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION" - if [ "$ENCRYPTION" == "TRUE" ]; then - SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename - readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg" - else - readonly NOTE="$NOTE_DIR/$NAME.$EXT" - fi +if [ "$ENCRYPTION" == "TRUE" ]; then + SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename + readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg" +else + readonly NOTE="$NOTE_DIR/$NAME.$EXT" +fi - if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi - if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi - if [ "$CREATE" == "TRUE" ]; then create; fi - if [ "$EDIT" == "TRUE" ]; then edit; fi +if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi +if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi +if [ "$CREATE" == "TRUE" ]; then create; fi +if [ "$EDIT" == "TRUE" ]; then edit; fi - #============================================================================== - # End Section: Actions / Stage 3 - #============================================================================== +#============================================================================== +# End Section: Actions / Stage 3 +#==============================================================================