From 856b14242c7b78121fa0637e0c82fcc5a58539f4 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Feb 2016 23:34:49 -0600 Subject: [PATCH] Formatting changes --- .DS_Store | Bin 0 -> 6148 bytes build.sh | 15 +- errors.ref | 5 +- header.sh | 6 +- sns.sh | 223 ++++++++---------- sns.xcodeproj/project.pbxproj | 6 +- .../UserInterfaceState.xcuserstate | Bin 0 -> 11909 bytes src/includes/create.sns.sh | 39 +-- src/includes/delete.sns.sh | 20 +- src/includes/edit.sns.sh | 11 +- src/includes/verify_store.sh | 13 +- src/main/stage1.sns.sh | 70 +++--- src/main/stage2.sns.sh | 73 +++--- src/main/stage3.sns.sh | 68 +++--- 14 files changed, 267 insertions(+), 282 deletions(-) create mode 100644 .DS_Store create mode 100644 sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8f18d2b40318d37d87cebb5cd38ad169030026fc GIT binary patch literal 6148 zcmeHK!A=4(5Pemmh?;oxxJOSU{J~0A6AxbS2b5hE4Y&j)@nW){!AE&A9{d{d&9s4C z5fU#(%?z1&-FBwac}ZIez_rI&3)lltrwY~@G+&5}i!R7o=-DAUog+gN_voGU^K`-6 zI*b8h;I}a#d$*1*#<)QrrTyFO=UtA;!Ej7Hn5wV^G;oO#e>wG@JATCPE7|jX@T9D z?;}!HBI_D*WjSuESs;~6O4YB3>|eLe(tI$~4A?(hooA3INj84qN%`{n^sX^0<{sqP zH@t_v@=9Wvd^1$sTFQR8%5{2=kXE@+#>-y1XfuD50p8gn^=*%4jR9l87??32=R-sl zi~|-P_2{6{Cjha=ZWXrWFN4HH0poy$M~+aO4<-6g7oHf-hqFHlesRFUqYsA*j}I3z zyYNDBnw|4U>JArsG;0hP162mr{pX(C|3}N;|J5M-G6sx+f5m{SC1**SC55|np*Xo~ sBkDO-MEnYm8bTAUV{OP)yiZl(SR@T%9I)`n9*X@DP#Vk_13${Z2O~n95C8xG literal 0 HcmV?d00001 diff --git a/build.sh b/build.sh index aad3dcc..77dd483 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,9 @@ +#!/bin/bash +#========================================================== +# Simple Note System - Build Script +# Copyright 2016, Xenese Labs/Sicron-Perion XNF +#========================================================== + S=sns.sh 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/list.sns.sh >> "$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/stage2.sns.sh >> "$S" cat ./src/main/stage3.sns.sh >> "$S" diff --git a/errors.ref b/errors.ref index 508077d..620ffb6 100644 --- a/errors.ref +++ b/errors.ref @@ -9,4 +9,7 @@ ERR_INSUFFICIENT_ARGS 30 A required argument was not provided Encryption---------------------------------------------------------------------- ERR_NO_GPG 100 GPG is not installed -ERR_NO_KEY 110 No recipient specified \ No newline at end of file +ERR_NO_KEY 110 No recipient specified + +Create-------------------------------------------------------------------------- +ERR_NOTE_EXiSTS 200 The specified note already exists \ No newline at end of file diff --git a/header.sh b/header.sh index 6ba4564..cd39b16 100644 --- a/header.sh +++ b/header.sh @@ -1,13 +1,12 @@ -#!/bin/bash - PROD_STR="Simple Note System" VER_STR="v2.0a8" +YEAR=2016 cat << EOF #!/bin/bash #========================================================== # $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 @@ -19,4 +18,5 @@ readonly NOTES_DIR="\$ROOT_DIR"/notes readonly TMP_DIR="\$ROOT_DIR"/tmp readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" + EOF diff --git a/sns.sh b/sns.sh index a2be9c9..8beb03f 100755 --- a/sns.sh +++ b/sns.sh @@ -1,7 +1,7 @@ #!/bin/bash #========================================================== # 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 @@ -14,6 +14,7 @@ readonly TMP_DIR="$ROOT_DIR"/tmp readonly CONFIG_FILE="$ROOT_DIR/sns.conf" + # Section: Functions function create_sns_root { @@ -112,7 +113,6 @@ function create(){ if [ -e "$NOTE" ]; then echo "Created note: $NOTEBOOK/$SECTION/$NAME." fi - } function delete(){ if [ "$DELETE" == "TRUE" ]; then @@ -180,131 +180,114 @@ function list(){ - -############################################################################### -#============================================================================== -# Begin Main Program -#============================================================================== -############################################################################### - -#============================================================================== -# Section: Configuration / Stage 1 -#============================================================================== -if [ -r "$CONFIG_FILE" ]; then - 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" + #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # Entry Point + #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + #============================================================================== + # Stage 1: Read Configuration + #============================================================================== + if [ -r "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" + else + create_sns_root + source "$CONFIG_FILE" 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 -# that can work without any arguments. + if [ "$ENCRYPTION" == "TRUE" ]; then + if [ -z "$PUBKEY" ]; then + ERR_NO_KEY="TRUE" + ENCRYPTION="FALSE" + fi -#============================================================================== -# End Section: Argument Parsing / Stage 2 -#============================================================================== -#============================================================================== -# 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 + command -v gpg >/dev/null 2>&1 ||\ + { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; } + fi -if [ -n "$LIST" ]; then - list - exit 0 -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 -#All other functions require a note title and notebook. + echo "$PROD_STR, $VER_STR" -if [ -z "$NAME" ]; then - echo " ERROR: Insufficient arguments:" - echo " Title not specified" - exit 30 -fi - -SESSION_ID="$RANDOM" -NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/ + 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 + #============================================================================== + # 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 -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" + echo "$NOTE" + 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 -#============================================================================== \ No newline at end of file + #============================================================================== + # End Section: Actions / Stage 3 + #============================================================================== diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index 5eb29b4..d55d3e0 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -15,11 +15,12 @@ 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = ""; }; 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = ""; }; 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = ""; }; - 5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create_sns_root.sns.sh; sourceTree = ""; }; + 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = init_store.sns.sh; sourceTree = ""; }; 5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = ""; }; 5D22D6AE1AFC4F5A0036DC52 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = ""; }; 5D22D6AF1AFC4F5A0036DC52 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = ""; }; 5D22D6B01AFC5B100036DC52 /* libencryption.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = libencryption.sh; sourceTree = ""; }; + 5D75D24F1C5F13DF001E7B33 /* verify_store.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = verify_store.sh; sourceTree = ""; }; 5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = ""; }; 5D7E91FB1B27FB620030B30D /* header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = header.sh; sourceTree = ""; }; 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; @@ -47,8 +48,9 @@ 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */, 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */, - 5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */, + 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */, 5D22D6B01AFC5B100036DC52 /* libencryption.sh */, + 5D75D24F1C5F13DF001E7B33 /* verify_store.sh */, ); path = includes; sourceTree = ""; diff --git a/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate b/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000000000000000000000000000000000000..137df62d63cb18020d85eabbe75a96261554d626 GIT binary patch literal 11909 zcmb_i2Y6G}+dt>r+ax!m*-4wU%`PC6?!_)0GD;b3p|n6q+q48rQJ)5M+ts034t=KxC_k$oL~eMFj=qJ2$uKz<$r?;|FT}m90GzXG ziyU?Wd>{ZypaN>p0dxeNz$2hD=mKIuR}c#lK{^-=hJc}97{~_&pb!iPBR~-t35r1p zaDY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ItI2gO($f)0Rt?pDe#vezp8=xow43+RC>wR*_X=)mRPIF4kmg zsx{r(-P+TdW9@IvwdPreTJx==tQFSBtxs6zTIXAzvM#hfZGFM|l68f3m36gst@SnQ z8`izn&#cF-C#|QgUt7PmUb0@XUbEh?{%pNzy=$Xwa+}T;VT-aEZDw0%TUT4WEzy=@ zOS5Iz2H5g#V{I "$NOTE" - echo "DATE: $(date)" >> "$NOTE" - elif [ "$ENCRYPTION" == "TRUE" ]; then + # Refuse to overwrite a note + if [ -e "$NOTE" ]; then + printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" + 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" p_header > "$TMP_NOTE" encrypt - fi - - if [ -e "$NOTE" ]; then + else + p_header > "$NOTE" + fi + # Make sure the note exists, and inform the user. + if [ -e "$NOTE" ]; then echo "Created note: $NOTEBOOK/$SECTION/$NAME." - fi - + else + printf "%s\n" "Something went wrong." + fi } diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index f0b47dc..696d9d1 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -1,14 +1,10 @@ function delete(){ - if [ "$DELETE" == "TRUE" ]; then - if [ -e "$NOTE" ]; then - rm "$NOTE" - echo "" - echo "Deleted note: $NOTEBOOK/$SECTION/$NAME." - exit - else - echo "" - echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." - exit - fi - fi + #Requires: $NOTE, $NOTEBOOK, $SECTION, $NAME + # Given a valid $NOTE, delete removes $NOTE from sns. + if [ -e "$NOTE" ]; then + rm "$NOTE" + printf "\n%s\n" "Deleted note: $NOTEBOOK/$SECTION/$NAME." + else + printf "\n%s\n" "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." + fi } diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index 91f0e7f..54702c5 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -1,15 +1,20 @@ function edit(){ +# Requires: $EDITOR, $NOTE +# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt + +# Verify an editor was specified if [ -z "$EDITOR" ]; then >&2 echo "Error no editor specified in environment." exit +# Verify the note exists elif [ ! -r "$NOTE" ]; then echo "ERROR: Note cannot be opened for editing." exit 40; fi - +# When encryption is enabled, decrypt $NOTE to a temp file if [ "$ENCRYPTION" == "TRUE" ]; then - cp "$NOTE" "$NOTE".bk - if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi + cp "$NOTE" "$NOTE".bk #Insurance + if [ ! -d "$TMP_DIR" ]; then mkdir "$TMP_DIR"; fi TMP_NOTE="$TMP_DIR/$SESSION_ID" decrypt > "$TMP_NOTE" else TMP_NOTE="$NOTE"; fi diff --git a/src/includes/verify_store.sh b/src/includes/verify_store.sh index 1e75289..f4fc06f 100644 --- a/src/includes/verify_store.sh +++ b/src/includes/verify_store.sh @@ -1,7 +1,6 @@ -#!/bin/sh - -# verify_store.sh -# sns -# -# Created by Jon-William Lewis on 1/31/16. -# +function verify_store { + STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR") + for DIR in ${STORE_DIRS[]}; do + mkdir -p "$DIR" + done +} \ No newline at end of file diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index d0eadd1..b2ddef2 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -1,41 +1,41 @@ -#============================================================================== -# Section: Configuration / Stage 1 -#============================================================================== -if [ -r "$CONFIG_FILE" ]; then - source "$CONFIG_FILE" -else - create_sns_root - source "$CONFIG_FILE" -fi + #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # Entry Point + #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + #============================================================================== + # Stage 1: Read Configuration / Verify Integrity + #============================================================================== + if [ -r "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" + else + init_store + source "$CONFIG_FILE" + fi -if [ "$ENCRYPTION" == "TRUE" ]; then - if [ -z "$PUBKEY" ]; then - ERR_NO_KEY="TRUE" - ENCRYPTION="FALSE" - fi + verify_store - command -v gpg >/dev/null 2>&1 ||\ - { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; } -fi + if [ "$ENCRYPTION" == "TRUE" ]; then + if [ -z "$PUBKEY" ]; then + ERR_NO_KEY="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 + command -v gpg >/dev/null 2>&1 ||\ + { ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; } + 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 - >&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 + echo "$PROD_STR, $VER_STR" - -#============================================================================== -# End Section: Configuration / Stage 1 -#============================================================================== + 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/stage2.sns.sh b/src/main/stage2.sns.sh index b62b775..0fcc5fc 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -1,41 +1,34 @@ -#============================================================================== -# 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" = "-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" + #============================================================================== + # 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 - 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 -# that can work without any arguments. - -#============================================================================== -# End Section: Argument Parsing / Stage 2 -#============================================================================== + # w_conf and help are called here to avoid excess stage 3 code. diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index da7f738..67deb52 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -1,39 +1,37 @@ -#============================================================================== -# 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 - list - exit 0 -fi - -#All other functions require a note title and notebook. - -if [ -z "$NAME" ]; then - echo " ERROR: Insufficient arguments:" - echo " Title not specified" - exit 30 -fi - -SESSION_ID="$RANDOM" -NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/ + #============================================================================== + # 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" ]; + 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 -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 -#============================================================================== \ No newline at end of file + #============================================================================== + # End Section: Actions / Stage 3 + #==============================================================================