Formatting changes

This commit is contained in:
Jon-William Lewis
2016-02-10 23:34:49 -06:00
parent be3871f859
commit 856b14242c
14 changed files with 267 additions and 282 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -1,3 +1,9 @@
#!/bin/bash
#==========================================================
# Simple Note System - Build Script
# Copyright 2016, Xenese Labs/Sicron-Perion XNF
#==========================================================
S=sns.sh S=sns.sh
bash header.sh > "$S" bash header.sh > "$S"
@@ -13,15 +19,6 @@ cat ./src/includes/edit.sns.sh >> "$S"
cat ./src/includes/print.sns.sh >> "$S" cat ./src/includes/print.sns.sh >> "$S"
cat ./src/includes/list.sns.sh >> "$S" cat ./src/includes/list.sns.sh >> "$S"
printf "%s\n\n\n\n" "# End Section: Functions" >> "$S" printf "%s\n\n\n\n" "# End Section: Functions" >> "$S"
printf "\n" >> "$S"
printf "%s\n" "###############################################################################" >> "$S"
printf "%s\n" "#==============================================================================" >> "$S"
printf "%s\n" "# Begin Main Program" >> "$S"
printf "%s\n" "#==============================================================================" >> "$S"
printf "%s\n" "###############################################################################" >> "$S"
printf "\n" >> "$S"
cat ./src/main/stage1.sns.sh >> "$S" cat ./src/main/stage1.sns.sh >> "$S"
cat ./src/main/stage2.sns.sh >> "$S" cat ./src/main/stage2.sns.sh >> "$S"
cat ./src/main/stage3.sns.sh >> "$S" cat ./src/main/stage3.sns.sh >> "$S"

View File

@@ -9,4 +9,7 @@ ERR_INSUFFICIENT_ARGS 30 A required argument was not provided
Encryption---------------------------------------------------------------------- Encryption----------------------------------------------------------------------
ERR_NO_GPG 100 GPG is not installed ERR_NO_GPG 100 GPG is not installed
ERR_NO_KEY 110 No recipient specified ERR_NO_KEY 110 No recipient specified
Create--------------------------------------------------------------------------
ERR_NOTE_EXiSTS 200 The specified note already exists

View File

@@ -1,13 +1,12 @@
#!/bin/bash
PROD_STR="Simple Note System" PROD_STR="Simple Note System"
VER_STR="v2.0a8" VER_STR="v2.0a8"
YEAR=2016
cat << EOF cat << EOF
#!/bin/bash #!/bin/bash
#========================================================== #==========================================================
# $PROD_STR, $VER_STR # $PROD_STR, $VER_STR
# Copyright 2014, Xenese Labs/Sicron-Perion XNF # Copyright $YEAR, Xenese Labs/Sicron-Perion XNF
#========================================================== #==========================================================
if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi
@@ -19,4 +18,5 @@ 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"
EOF EOF

223
sns.sh
View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
#========================================================== #==========================================================
# Simple Note System, v2.0a8 # Simple Note System, v2.0a8
# Copyright 2014, Xenese Labs/Sicron-Perion XNF # Copyright 2016, Xenese Labs/Sicron-Perion XNF
#========================================================== #==========================================================
if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi
@@ -14,6 +14,7 @@ readonly TMP_DIR="$ROOT_DIR"/tmp
readonly CONFIG_FILE="$ROOT_DIR/sns.conf" readonly CONFIG_FILE="$ROOT_DIR/sns.conf"
# Section: Functions # Section: Functions
function create_sns_root { function create_sns_root {
@@ -112,7 +113,6 @@ function create(){
if [ -e "$NOTE" ]; then if [ -e "$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME." echo "Created note: $NOTEBOOK/$SECTION/$NAME."
fi fi
} }
function delete(){ function delete(){
if [ "$DELETE" == "TRUE" ]; then if [ "$DELETE" == "TRUE" ]; then
@@ -180,131 +180,114 @@ function list(){
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
############################################################################### # Entry Point
#============================================================================== #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Begin Main Program #==============================================================================
#============================================================================== # Stage 1: Read Configuration
############################################################################### #==============================================================================
if [ -r "$CONFIG_FILE" ]; then
#============================================================================== source "$CONFIG_FILE"
# Section: Configuration / Stage 1 else
#============================================================================== create_sns_root
if [ -r "$CONFIG_FILE" ]; then source "$CONFIG_FILE"
source "$CONFIG_FILE"
else
create_sns_root
source "$CONFIG_FILE"
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
if [ "$ENCRYPTION" == "TRUE" ]; then
PROD_STR="Simple Note System (Encryption Enabled)"
if [ ! -d "$ROOT_DIR"/tmp ]; then
mkdir -p "$ROOT_DIR"/tmp
fi
fi
echo "$PROD_STR, $VER_STR"
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
#==============================================================================
# End Section: Configuration / Stage 1
#==============================================================================
#==============================================================================
# Section: Argument Parsing / Stage 2
#==============================================================================
NAME=""
NOTEBOOK=""
SECTION=""
if [ -z "$1" ]; then help; exit 20
else
ARGS=( "$@" )
for ARG in "${ARGS[@]}"; do
if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"
elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"
elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"
elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0
elif [ "$ARG" = "-w" ] || [ "$ARG" == "--wconf" ]; then create_sns_root; exit 0
else
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG"
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"
elif [ -z "$SECTION" ] && [ -n "$ARG" ]; then SECTION="$ARG"
fi fi
fi
done
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
# If we got a note title above, but no notebook, and the list option
# was specified, we assume that the detected note title is actually a
# notebook name.
NOTEBOOK="$NAME"
NAME=""
fi
fi
# Note: w_conf and help have highest priority, as they are the only functions if [ "$ENCRYPTION" == "TRUE" ]; then
# that can work without any arguments. if [ -z "$PUBKEY" ]; then
ERR_NO_KEY="TRUE"
ENCRYPTION="FALSE"
fi
#============================================================================== command -v gpg >/dev/null 2>&1 ||\
# End Section: Argument Parsing / Stage 2 { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
#============================================================================== fi
#==============================================================================
# Section: Actions / Stage 3
#==============================================================================
# List only requires a notebook, and is exclusive.
if [ -z "$NOTEBOOK" ]; then
echo " ERROR: Insufficient arguments:"
echo " Notebook not specified"
exit 30
fi
if [ -n "$LIST" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
list PROD_STR="Simple Note System (Encryption Enabled)"
exit 0 if [ ! -d "$ROOT_DIR"/tmp ]; then
fi mkdir -p "$ROOT_DIR"/tmp
fi
fi
#All other functions require a note title and notebook. echo "$PROD_STR, $VER_STR"
if [ -z "$NAME" ]; then if [ -n "$ERR_NO_GPG" ]; then
echo " ERROR: Insufficient arguments:" >&2 echo " Error: Encryption was specified, but GPG is not installed."
echo " Title not specified" exit 100
exit 30 elif [ -n "$ERR_NO_KEY" ]; then
fi >&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
exit 110
SESSION_ID="$RANDOM" fi
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/ #==============================================================================
# Stage 2: Argument Parsing
#==============================================================================
NAME=""
NOTEBOOK=""
SECTION=""
if [ -z "$1" ]; then help; exit 20
else
ARGS=( "$@" )
for ARG in "${ARGS[@]}"; do
if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"
elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"
elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"
elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0
elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then create_sns_root; exit 0
else
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG"
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"
elif [ -z "$SECTION" ] && [ -n "$ARG" ]; then SECTION="$ARG"
fi
fi
done
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
# If a note title was specified, but no notebook, and the list option
# was specified, assume that the detected note title is actually the
# name of a notebook
NOTEBOOK="$NAME"
NAME=""
fi
fi
# w_conf and help are called here to avoid excess stage 3 code.
#==============================================================================
# Section: Actions / Stage 3
#==============================================================================
# All options not requiring at least a notebook to be specified have been dealt
# with; if one isn't specified, throw code 30.
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
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"
if [ "$ENCRYPTION" == "TRUE" ]; then readonly NOTE="$NOTE_DIR""$NAME"."$EXT".gpg if [ "$ENCRYPTION" == "TRUE" ]; then
else readonly NOTE="$NOTE_DIR""$NAME"."$EXT" SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename
fi readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg"
else
readonly NOTE="$NOTE_DIR/$NAME.$EXT"
echo "$NOTE"
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
#============================================================================== #==============================================================================

View File

@@ -15,11 +15,12 @@
5D22D6A81AFC4F5A0036DC52 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = "<group>"; }; 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = "<group>"; };
5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = "<group>"; }; 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = "<group>"; };
5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = "<group>"; }; 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = "<group>"; };
5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create_sns_root.sns.sh; sourceTree = "<group>"; }; 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = init_store.sns.sh; sourceTree = "<group>"; };
5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = "<group>"; }; 5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = "<group>"; };
5D22D6AE1AFC4F5A0036DC52 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = "<group>"; }; 5D22D6AE1AFC4F5A0036DC52 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = "<group>"; };
5D22D6AF1AFC4F5A0036DC52 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = "<group>"; }; 5D22D6AF1AFC4F5A0036DC52 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = "<group>"; };
5D22D6B01AFC5B100036DC52 /* libencryption.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = libencryption.sh; sourceTree = "<group>"; }; 5D22D6B01AFC5B100036DC52 /* libencryption.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = libencryption.sh; sourceTree = "<group>"; };
5D75D24F1C5F13DF001E7B33 /* verify_store.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = verify_store.sh; sourceTree = "<group>"; };
5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; }; 5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
5D7E91FB1B27FB620030B30D /* header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = header.sh; sourceTree = "<group>"; }; 5D7E91FB1B27FB620030B30D /* header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = header.sh; sourceTree = "<group>"; };
5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = "<group>"; }; 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = "<group>"; };
@@ -47,8 +48,9 @@
5D22D6A81AFC4F5A0036DC52 /* p_header.sh */, 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */,
5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */,
5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */, 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */,
5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */, 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */,
5D22D6B01AFC5B100036DC52 /* libencryption.sh */, 5D22D6B01AFC5B100036DC52 /* libencryption.sh */,
5D75D24F1C5F13DF001E7B33 /* verify_store.sh */,
); );
path = includes; path = includes;
sourceTree = "<group>"; sourceTree = "<group>";

View File

@@ -1,22 +1,31 @@
function create(){ function create(){
if [ -e "$NOTE" ]; then # Depends : p_header
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" # Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME
exit # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt
else # Given a valid setup, create writes the standard note header as specified
mkdir -p "$NOTE_DIR" # by p_header, to $NOTE.
fi
if [ -z "$ENCRYPTION" ]; then # Refuse to overwrite a note
echo "TITLE: $NAME" > "$NOTE" if [ -e "$NOTE" ]; then
echo "DATE: $(date)" >> "$NOTE" printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
elif [ "$ENCRYPTION" == "TRUE" ]; then exit 200
# If the notebook doesn't exist, create it.
elif [ ! -d "$NOTE_DIR" ]; then
mkdir -p "$NOTE_DIR"
fi
# Write the standard note header
if [ "$ENCRYPTION" == "TRUE" ]; then
TMP_NOTE="$TMP_DIR"/"$SESSION_ID" TMP_NOTE="$TMP_DIR"/"$SESSION_ID"
p_header > "$TMP_NOTE" p_header > "$TMP_NOTE"
encrypt encrypt
fi else
p_header > "$NOTE"
if [ -e "$NOTE" ]; then fi
# Make sure the note exists, and inform the user.
if [ -e "$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME." echo "Created note: $NOTEBOOK/$SECTION/$NAME."
fi else
printf "%s\n" "Something went wrong."
fi
} }

View File

@@ -1,14 +1,10 @@
function delete(){ function delete(){
if [ "$DELETE" == "TRUE" ]; then #Requires: $NOTE, $NOTEBOOK, $SECTION, $NAME
if [ -e "$NOTE" ]; then # Given a valid $NOTE, delete removes $NOTE from sns.
rm "$NOTE" if [ -e "$NOTE" ]; then
echo "" rm "$NOTE"
echo "Deleted note: $NOTEBOOK/$SECTION/$NAME." printf "\n%s\n" "Deleted note: $NOTEBOOK/$SECTION/$NAME."
exit else
else printf "\n%s\n" "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
echo "" fi
echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
exit
fi
fi
} }

View File

@@ -1,15 +1,20 @@
function edit(){ function edit(){
# Requires: $EDITOR, $NOTE
# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt
# Verify an editor was specified
if [ -z "$EDITOR" ]; then if [ -z "$EDITOR" ]; then
>&2 echo "Error no editor specified in environment." >&2 echo "Error no editor specified in environment."
exit exit
# Verify the note exists
elif [ ! -r "$NOTE" ]; then elif [ ! -r "$NOTE" ]; then
echo "ERROR: Note cannot be opened for editing." echo "ERROR: Note cannot be opened for editing."
exit 40; exit 40;
fi fi
# When encryption is enabled, decrypt $NOTE to a temp file
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk cp "$NOTE" "$NOTE".bk #Insurance
if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi if [ ! -d "$TMP_DIR" ]; then mkdir "$TMP_DIR"; fi
TMP_NOTE="$TMP_DIR/$SESSION_ID" TMP_NOTE="$TMP_DIR/$SESSION_ID"
decrypt > "$TMP_NOTE" decrypt > "$TMP_NOTE"
else TMP_NOTE="$NOTE"; fi else TMP_NOTE="$NOTE"; fi

View File

@@ -1,7 +1,6 @@
#!/bin/sh function verify_store {
STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR")
# verify_store.sh for DIR in ${STORE_DIRS[]}; do
# sns mkdir -p "$DIR"
# done
# Created by Jon-William Lewis on 1/31/16. }
#

View File

@@ -1,41 +1,41 @@
#============================================================================== #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Section: Configuration / Stage 1 # Entry Point
#============================================================================== #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if [ -r "$CONFIG_FILE" ]; then #==============================================================================
source "$CONFIG_FILE" # Stage 1: Read Configuration / Verify Integrity
else #==============================================================================
create_sns_root if [ -r "$CONFIG_FILE" ]; then
source "$CONFIG_FILE" source "$CONFIG_FILE"
fi else
init_store
source "$CONFIG_FILE"
fi
if [ "$ENCRYPTION" == "TRUE" ]; then verify_store
if [ -z "$PUBKEY" ]; then
ERR_NO_KEY="TRUE"
ENCRYPTION="FALSE"
fi
command -v gpg >/dev/null 2>&1 ||\ if [ "$ENCRYPTION" == "TRUE" ]; then
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; } if [ -z "$PUBKEY" ]; then
fi ERR_NO_KEY="TRUE"
ENCRYPTION="FALSE"
fi
if [ "$ENCRYPTION" == "TRUE" ]; then command -v gpg >/dev/null 2>&1 ||\
PROD_STR="Simple Note System (Encryption Enabled)" { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
if [ ! -d "$ROOT_DIR"/tmp ]; then fi
mkdir -p "$ROOT_DIR"/tmp
fi
fi
echo "$PROD_STR, $VER_STR" if [ "$ENCRYPTION" == "TRUE" ]; then
PROD_STR="Simple Note System (Encryption Enabled)"
if [ ! -d "$ROOT_DIR"/tmp ]; then
mkdir -p "$ROOT_DIR"/tmp
fi
fi
if [ -n "$ERR_NO_GPG" ]; then echo "$PROD_STR, $VER_STR"
>&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."
# End Section: Configuration / Stage 1 exit 100
#============================================================================== elif [ -n "$ERR_NO_KEY" ]; then
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
exit 110
fi

View File

@@ -1,41 +1,34 @@
#============================================================================== #==============================================================================
# Section: Argument Parsing / Stage 2 # Stage 2: Argument Parsing
#============================================================================== #==============================================================================
NAME=""
NAME="" NOTEBOOK=""
NOTEBOOK="" SECTION=""
SECTION="" if [ -z "$1" ]; then help; exit 20
if [ -z "$1" ]; then help; exit 20 else
else ARGS=( "$@" )
ARGS=( "$@" ) for ARG in "${ARGS[@]}"; do
for ARG in "${ARGS[@]}"; do if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"
if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE" elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"
elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE" elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"
elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE" elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"
elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE" elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE" elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE" elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then create_sns_root; exit 0
elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then create_sns_root; exit 0 else
else if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG"
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" elif [ -z "$SECTION" ] && [ -n "$ARG" ]; then SECTION="$ARG"
elif [ -z "$SECTION" ] && [ -n "$ARG" ]; then SECTION="$ARG" fi
fi
done
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
# If a note title was specified, but no notebook, and the list option
# was specified, assume that the detected note title is actually the
# name of a notebook
NOTEBOOK="$NAME"
NAME=""
fi
fi fi
fi # w_conf and help are called here to avoid excess stage 3 code.
done
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
# If we got a note title above, but no notebook, and the list option
# was specified, we assume that the detected note title is actually a
# notebook name.
NOTEBOOK="$NAME"
NAME=""
fi
fi
# Note: w_conf and help have highest priority, as they are the only functions
# that can work without any arguments.
#==============================================================================
# End Section: Argument Parsing / Stage 2
#==============================================================================

View File

@@ -1,39 +1,37 @@
#============================================================================== #==============================================================================
# Section: Actions / Stage 3 # Section: Actions / Stage 3
#============================================================================== #==============================================================================
# List only requires a notebook, and is exclusive. # All options not requiring at least a notebook to be specified have been dealt
if [ -z "$NOTEBOOK" ]; then # with; if one isn't specified, throw code 30.
echo " ERROR: Insufficient arguments:" if [ -z "$NOTEBOOK" ]; then
echo " Notebook not specified" printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30 exit 30
fi fi
# List is the only option requiring only a notebook.
if [ -n "$LIST" ]; then # If list isn't the selected option and no note name was specified, throw code 30.
list if [ "$LIST" == TRUE ]; then
exit 0 list
fi exit 0
elif [ -z "$NAME" ];
#All other functions require a note title and notebook. printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30
if [ -z "$NAME" ]; then fi
echo " ERROR: Insufficient arguments:"
echo " Title not specified" NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"
exit 30
fi
SESSION_ID="$RANDOM"
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/
if [ "$ENCRYPTION" == "TRUE" ]; then readonly NOTE="$NOTE_DIR""$NAME"."$EXT".gpg if [ "$ENCRYPTION" == "TRUE" ]; then
else readonly NOTE="$NOTE_DIR""$NAME"."$EXT" SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename
fi readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg"
else
readonly NOTE="$NOTE_DIR/$NAME.$EXT"
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
#============================================================================== #==============================================================================