Continued work on loosening note definition; added framework for color in errors.
This commit is contained in:
@@ -3,8 +3,8 @@ Error Code Reference
|
|||||||
|
|
||||||
General-------------------------------------------------------------------------
|
General-------------------------------------------------------------------------
|
||||||
ERR_NO_ARGS 10 No arguments were specified
|
ERR_NO_ARGS 10 No arguments were specified
|
||||||
ERR_NO_OP 20
|
ERR_NO_OP 20 No operation was specified
|
||||||
ERR_NO_NOTEBOOK 30 A required argument was not provided
|
ERR_NO_NOTE 30 A required argument was not provided
|
||||||
|
|
||||||
Encryption----------------------------------------------------------------------
|
Encryption----------------------------------------------------------------------
|
||||||
ERR_NO_GPG 100 Encryption is enabled, but GPG is not installed
|
ERR_NO_GPG 100 Encryption is enabled, but GPG is not installed
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ readonly NOTES_DIR="\$ROOT_DIR"/notes
|
|||||||
readonly TMP_DIR="\$ROOT_DIR"/tmp
|
readonly TMP_DIR="\$ROOT_DIR"/tmp
|
||||||
readonly CONFIG_FILE="\$ROOT_DIR/sns.conf"
|
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" "\$PROD_STR"
|
||||||
printf "%s\n" "------------------"
|
printf "%s\n" "------------------"
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
#==============================================================================
|
||||||
# Entry Point
|
# Stage 1: Read Configuration / Verify Integrity
|
||||||
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
#==============================================================================
|
||||||
#==============================================================================
|
|
||||||
# Stage 1: Read Configuration / Verify Integrity
|
|
||||||
#==============================================================================
|
|
||||||
|
|
||||||
if [ -r "$CONFIG_FILE" ]; then
|
if [ -r "$CONFIG_FILE" ]; then
|
||||||
source "$CONFIG_FILE"
|
source "$CONFIG_FILE"
|
||||||
else
|
else
|
||||||
init_store
|
init_store
|
||||||
source "$CONFIG_FILE"
|
source "$CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
verify_store
|
verify_store
|
||||||
|
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
if [ -z "$PUBKEY" ]; then
|
if [ -z "$PUBKEY" ]; then
|
||||||
ERR_NO_KEY="TRUE"
|
ERR_NO_KEY="TRUE"
|
||||||
ENCRYPTION="FALSE"
|
ENCRYPTION="FALSE"
|
||||||
@@ -22,18 +19,18 @@
|
|||||||
|
|
||||||
command -v gpg >/dev/null 2>&1 ||\
|
command -v gpg >/dev/null 2>&1 ||\
|
||||||
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
|
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
if [ ! -d "$ROOT_DIR"/tmp ]; then
|
if [ ! -d "$ROOT_DIR"/tmp ]; then
|
||||||
mkdir -p "$ROOT_DIR"/tmp
|
mkdir -p "$ROOT_DIR"/tmp
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$ERR_NO_GPG" ]; then
|
if [ -n "$ERR_NO_GPG" ]; then
|
||||||
>&2 echo " Error: Encryption was specified, but GPG is not installed."
|
>&2 echo " Error: Encryption was specified, but GPG is not installed."
|
||||||
exit 100
|
exit 100
|
||||||
elif [ -n "$ERR_NO_KEY" ]; then
|
elif [ -n "$ERR_NO_KEY" ]; then
|
||||||
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
|
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
|
||||||
exit 110
|
exit 110
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,42 +1,42 @@
|
|||||||
#==============================================================================
|
#==============================================================================
|
||||||
# Section: Actions / Stage 3
|
# Section: Actions / Stage 3
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
# Default behavior
|
# Default behavior
|
||||||
# If no operation was specified, print help and exit on ERR_NO_OP
|
# If no operation was specified, print help and exit on ERR_NO_OP
|
||||||
if [ "$OP" != "TRUE" ]; then
|
if [ "$OP" != "TRUE" ]; then
|
||||||
help; exit 20
|
help; exit 20
|
||||||
fi
|
fi
|
||||||
# All options not requiring at least a notebook to be specified have been dealt
|
# All options not requiring a note to be specified have been dealt
|
||||||
# with; if one isn't specified, exit on ERR_NO_NOTEBOOK.
|
# with; if one isn't specified, exit on ERR_NO_NOTE.
|
||||||
if [ -z "$NOTEBOOK" ]; then
|
if [ -z "$NOTE" ]; then
|
||||||
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
|
printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified."
|
||||||
exit 30
|
exit 30
|
||||||
fi
|
fi
|
||||||
# List is the only option requiring only a notebook.
|
# 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 isn't the selected option and no note name was specified, throw code 30.
|
||||||
if [ "$LIST" == TRUE ]; then
|
if [ "$LIST" == TRUE ]; then
|
||||||
list
|
list
|
||||||
exit 0
|
exit 0
|
||||||
elif [ -z "$NAME" ]; then
|
elif [ -z "$NAME" ]; then
|
||||||
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
|
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
|
||||||
exit 30
|
exit 30
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"
|
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"
|
||||||
|
|
||||||
|
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename
|
SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename
|
||||||
readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg"
|
readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg"
|
||||||
else
|
else
|
||||||
readonly NOTE="$NOTE_DIR/$NAME.$EXT"
|
readonly NOTE="$NOTE_DIR/$NAME.$EXT"
|
||||||
fi
|
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
|
||||||
if [ "$EDIT" == "TRUE" ]; then edit; fi
|
if [ "$EDIT" == "TRUE" ]; then edit; fi
|
||||||
|
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
# End Section: Actions / Stage 3
|
# End Section: Actions / Stage 3
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user