Continued work on loosening note definition; added framework for color in errors.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
#==============================================================================
|
||||
|
||||
Reference in New Issue
Block a user