diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c9e5843 Binary files /dev/null and b/.DS_Store differ diff --git a/build.sh b/build.sh index a1f65a8..aad3dcc 100644 --- a/build.sh +++ b/build.sh @@ -1,20 +1,29 @@ S=sns.sh bash header.sh > "$S" -echo -e "\n# Section: Functions" >> "$S" -cat ./src/includes/w_conf.sns.sh >> "$S" -cat ./src/includes/pause.sns.sh >> "$S" -cat ./src/includes/help.sns.sh >> "$S" -cat ./src/includes/p_header.sh >> "$S" -cat ./src/includes/libencryption.sh >> "$S" -cat ./src/includes/create.sns.sh >> "$S" -cat ./src/includes/delete.sns.sh >> "$S" -cat ./src/includes/edit.sns.sh >> "$S" -cat ./src/includes/print.sns.sh >> "$S" -cat ./src/includes/list.sns.sh >> "$S" -echo -e "# End Section: Functions\n" >> "$S" -cat ./src/main/stage1.sns.sh >> "$S" -cat ./src/main/stage2.sns.sh >> "$S" -cat ./src/main/stage3.sns.sh >> "$S" +echo -e "\n# Section: Functions" >> "$S" +cat ./src/includes/create_sns_root.sns.sh >> "$S" +cat ./src/includes/pause.sns.sh >> "$S" +cat ./src/includes/help.sns.sh >> "$S" +cat ./src/includes/p_header.sh >> "$S" +cat ./src/includes/libencryption.sh >> "$S" +cat ./src/includes/create.sns.sh >> "$S" +cat ./src/includes/delete.sns.sh >> "$S" +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" exit diff --git a/errors.ref b/errors.ref index ce7c5f3..508077d 100644 --- a/errors.ref +++ b/errors.ref @@ -8,5 +8,5 @@ ERR_INSUFFICIENT_ARGS 30 A required argument was not provided Encryption---------------------------------------------------------------------- -ERR_NO_SSL 100 Cannot execute openssl -ERR_NO_KEY 110 No encryption key in sns.conf \ No newline at end of file +ERR_NO_GPG 100 GPG is not installed +ERR_NO_KEY 110 No recipient specified \ No newline at end of file diff --git a/header.sh b/header.sh index 850669c..6ba4564 100644 --- a/header.sh +++ b/header.sh @@ -1,7 +1,7 @@ #!/bin/bash PROD_STR="Simple Note System" -VER_STR="v2.0a5" +VER_STR="v2.0a8" cat << EOF #!/bin/bash @@ -13,9 +13,10 @@ cat << EOF if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi PROD_STR="$PROD_STR" -VER_STR="$VER_STR" -ROOTDIR="\$HOME"/.config/sns -BASEDIR="\$ROOTDIR"/notes -CONFIGURATION="\$ROOTDIR/sns.conf" +readonly VER_STR="$VER_STR" +readonly ROOT_DIR="\$HOME"/.config/xenlabs/sns +readonly NOTES_DIR="\$ROOT_DIR"/notes +readonly TMP_DIR="\$ROOT_DIR"/tmp +readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" EOF diff --git a/nul b/nul new file mode 100644 index 0000000..e69de29 diff --git a/null b/null new file mode 100644 index 0000000..e69de29 diff --git a/sns.sh b/sns.sh index 4bc5972..4bbfa8c 100644 --- a/sns.sh +++ b/sns.sh @@ -1,24 +1,29 @@ #!/bin/bash #========================================================== -# Simple Note System, v2.0a5 +# Simple Note System, v2.0a8 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -if [ -z "/Users/xilmwa" ]; then HOME=/home/"$(whoami)"; fi +if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi PROD_STR="Simple Note System" -VER_STR="v2.0a5" -ROOTDIR="$HOME"/.config/sns -BASEDIR="$ROOTDIR"/notes -CONFIGURATION="$ROOTDIR/sns.conf" +readonly VER_STR="v2.0a8" +readonly ROOT_DIR="$HOME"/.config/xenlabs/sns +readonly NOTES_DIR="$ROOT_DIR"/notes +readonly TMP_DIR="$ROOT_DIR"/tmp +readonly CONFIG_FILE="$ROOT_DIR/sns.conf" # Section: Functions function w_conf { -if [ ! -r "$ROOTDIR" ]; then mkdir -p "$ROOTDIR"; fi -cat > "$CONFIGURATION" << EOF + +if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi +if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi + + +cat > "$CONFIG_FILE" << EOF #========================================================== -# Simple Note System Config, v2.0a5 +# Simple Note System Config, v2.0a8 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== @@ -32,14 +37,17 @@ fi #Encryption #WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST + +#ENCRYPTION="TRUE" ENCRYPTION="FALSE" -ENC_KEY="" + +PUBKEY="" EOF -chmod 600 "$CONFIGURATION" +chmod 600 "$CONFIG_FILE" } function pause { - read -p " Press [Enter] to continue." + read -rp " Press [Enter] to continue." echo "" } function help { @@ -64,28 +72,35 @@ function p_header(){ printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" } function encrypt(){ - openssl enc -aes-256-cbc -salt -in "$TARGET" -out "$NOTE" -pass pass:"$ENC_KEY" +# This function, given a recipient, $PUBKEY; a file to encrypt, $TMP_NOTE; and an +# output file, "$NOTE", will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private +# GPG key. + + gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE" + } function decrypt(){ - TARGET="$ROOTDIR"/tmp/"$RANDOM" - openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET" +# This function, given a recipient, $PUBKEY; a file to decrypt, $TMP_NOTE; and an +# output file, "$NOTE", will decrpyt $TMP_NOTE to $NOTE against $PUBKEY's private +# GPG key. + gpg -d "$NOTE" } function create(){ if [ -e "$NOTE" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else - mkdir -p "$NOTEDIR" + mkdir -p "$NOTE_DIR" fi if [ -z "$ENCRYPTION" ]; then echo "TITLE: $NAME" > "$NOTE" echo "DATE: $(date)" >> "$NOTE" elif [ "$ENCRYPTION" == "TRUE" ]; then - touch "$NOTE" - p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ - -pass pass:"$ENC_KEY" + TMP_NOTE="$TMP_DIR"/"$SESSION_ID" + p_header > "$TMP_NOTE" + encrypt fi if [ -e "$NOTE" ]; then @@ -113,110 +128,102 @@ if [ ! -r "$NOTE" ]; then exit 40; fi -if [ "$ENCRYPTION" == "TRUE" ]; then decrypt -else TARGET="$NOTE"; fi +if [ "$ENCRYPTION" == "TRUE" ]; then + cp "$NOTE" "$NOTE".bk + if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi + TMP_NOTE="$TMP_DIR/$SESSION_ID" + decrypt > "$TMP_NOTE" +else TMP_NOTE="$NOTE"; fi -if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi - -"$EDITOR" "$TARGET" - -if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi - +if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TMP_NOTE"; fi +"$EDITOR" "$TMP_NOTE" +if [ "$ENCRYPTION" == "TRUE" ]; then + rm "$NOTE" + encrypt; + if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi +fi } function print(){ - if [ "$PRINT" == "TRUE" ]; then - if [ -r "$NOTE" ] || [ -r "${NOTE%.*}" ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -d -aes-256-cbc -in "${NOTE%.*}" -pass pass:"$ENC_KEY" - else - cat "$NOTE" - echo "" >> "$NOTE" - fi + if [ -r "$NOTE" ]; then + if [ -z "$CREATE" ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + decrypt else - echo "" - echo "ERROR: Note cannot be found." - echo "" - + cat "$NOTE" fi + else + printf "\nERROR: Note cannot be found.\n" fi fi } function list(){ - if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then - printf "\nNotes in %s:\n" "$(basename "$NOTEBOOK")" - - NOTES=( $(find "$BASEDIR"/"$NOTEBOOK" -name "*.$EXT" -print0 | sed s:"$BASEDIR"/"$NOTEBOOK"/: " " :g | sed -e s:".$EXT"::g | tr "/" " ") ) - let i=0 - for NOTE in "${NOTES[@]}"; do - if [ -d "$BASEDIR"/"$NOTEBOOK"/"$NOTE" ]; then - if [ "$LAST_SECTION" != "$NOTE" ]; then - printf " Section: %s\n" "$NOTE" - fi - LAST_SECTION="$NOTE" - else - #if [ $(($i % 1)) -eq 0 ]; then - # printf "\n " - #fi - printf " %s\n" "$NOTE" - fi - let i++ + if [ -d "$NOTES_DIR"/"$NOTEBOOK" ]; then + printf "+%s\n" "$NOTEBOOK" + find "$NOTES_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do + printf " -%s\n" "$(basename \"$NOTE\" | cut -d . -f 1 )" done - printf "\n" - else - echo "" - echo "ERROR: Notebook $NOTEBOOK does not exist." - echo "" fi } # End Section: Functions + + + +############################################################################### #============================================================================== -# Section: Configuration +# Begin Main Program #============================================================================== -if [ -r "$CONFIGURATION" ]; then - source "$CONFIGURATION" +############################################################################### + +#============================================================================== +# Section: Configuration / Stage 1 +#============================================================================== +if [ -r "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" else - w_conf - source "$CONFIGURATION" + create_sns_root + source "$CONFIG_FILE" fi if [ "$ENCRYPTION" == "TRUE" ]; then -if [ -z "$ENC_KEY" ]; then -ERR_NO_KEY="TRUE" -ENCRYPTION="FALSE" -fi -command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } + 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)" -EXT="$EXT" -if [ ! -d "$BASEDIR"/tmp ]; then -mkdir -p "$BASEDIR"/tmp -fi + 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_SSL" ]; then -echo >&2 " Warning: OpenSSL not installed. Encryption disabled." -fi -if [ -n "$ERR_NO_KEY" ]; then -echo " Warning: No encryption key was provided. Encryption disabled." + +if [ -z "$EDITOR" ]; then + >&2 echo "Error no editor specified in environment." + +elif [ -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_SSL" ] || [ -n "$ERR_NO_KEY" ]; then -pause -fi #============================================================================== -# End Section: Configuration +# End Section: Configuration / Stage 1 #============================================================================== #============================================================================== -# Section: Argument Parsing +# Section: Argument Parsing / Stage 2 #============================================================================== NAME="" @@ -233,7 +240,7 @@ else 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 w_conf; 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" @@ -254,11 +261,11 @@ fi # that can work without any arguments. #============================================================================== -# End Section: Argument Parsing +# End Section: Argument Parsing / Stage 2 +#============================================================================== +#============================================================================== +# Section: Actions / Stage 3 #============================================================================== -# Help requires no arguments, and is exclusive. -if [ -n "$HELP" ]; then help; exit 0; fi - # List only requires a notebook, and is exclusive. if [ -z "$NOTEBOOK" ]; then echo " ERROR: Insufficient arguments:" @@ -279,11 +286,19 @@ if [ -z "$NAME" ]; then exit 30 fi -NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ -NOTE="$NOTEDIR""$NAME"."$EXT" +SESSION_ID="$RANDOM" +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 NOTE="$NOTE".enc; 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 \ No newline at end of file +if [ "$EDIT" == "TRUE" ]; then edit; fi + +#============================================================================== +# End Section: Actions / Stage 3 +#============================================================================== \ No newline at end of file diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index c70fecd..5eb29b4 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ 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 /* w_conf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = w_conf.sns.sh; sourceTree = ""; }; + 5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create_sns_root.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 = ""; }; @@ -47,7 +47,7 @@ 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */, 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */, - 5D22D6AB1AFC4F5A0036DC52 /* w_conf.sns.sh */, + 5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */, 5D22D6B01AFC5B100036DC52 /* libencryption.sh */, ); path = includes; 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 0000000..5bc316e Binary files /dev/null and b/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index e4a9fbc..54de245 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -3,16 +3,16 @@ function create(){ printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else - mkdir -p "$NOTEDIR" + mkdir -p "$NOTE_DIR" fi if [ -z "$ENCRYPTION" ]; then echo "TITLE: $NAME" > "$NOTE" echo "DATE: $(date)" >> "$NOTE" elif [ "$ENCRYPTION" == "TRUE" ]; then - touch "$NOTE" - p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ - -pass pass:"$ENC_KEY" + TMP_NOTE="$TMP_DIR"/"$SESSION_ID" + p_header > "$TMP_NOTE" + encrypt fi if [ -e "$NOTE" ]; then diff --git a/src/includes/w_conf.sns.sh b/src/includes/create_sns_root.sns.sh similarity index 63% rename from src/includes/w_conf.sns.sh rename to src/includes/create_sns_root.sns.sh index 5aadbb6..81cfb01 100644 --- a/src/includes/w_conf.sns.sh +++ b/src/includes/create_sns_root.sns.sh @@ -1,8 +1,12 @@ function w_conf { -if [ ! -r "$ROOTDIR" ]; then mkdir -p "$ROOTDIR"; fi -cat > "$CONFIGURATION" << EOF + +if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi +if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi + + +cat > "$CONFIG_FILE" << EOF #========================================================== -# Simple Note System Config, v2.0a5 +# Simple Note System Config, v2.0a8 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== @@ -16,9 +20,12 @@ fi #Encryption #WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST + +#ENCRYPTION="TRUE" ENCRYPTION="FALSE" -ENC_KEY="" + +PUBKEY="" EOF -chmod 600 "$CONFIGURATION" +chmod 600 "$CONFIG_FILE" } diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index e67afe4..e63c412 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -4,16 +4,21 @@ if [ ! -r "$NOTE" ]; then exit 40; fi -if [ "$ENCRYPTION" == "TRUE" ]; then decrypt -else TARGET="$NOTE"; fi +if [ "$ENCRYPTION" == "TRUE" ]; then + cp "$NOTE" "$NOTE".bk + if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi + TMP_NOTE="$TMP_DIR/$SESSION_ID" + decrypt > "$TMP_NOTE" +else TMP_NOTE="$NOTE"; fi -if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi - -"$EDITOR" "$TARGET" - -if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi - +if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TMP_NOTE"; fi +"$EDITOR" "$TMP_NOTE" +if [ "$ENCRYPTION" == "TRUE" ]; then + rm "$NOTE" + encrypt; + if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi +fi } diff --git a/src/includes/libencryption.sh b/src/includes/libencryption.sh index 392bf8d..71b1181 100644 --- a/src/includes/libencryption.sh +++ b/src/includes/libencryption.sh @@ -1,8 +1,15 @@ function encrypt(){ - openssl enc -aes-256-cbc -salt -in "$TARGET" -out "$NOTE" -pass pass:"$ENC_KEY" +# This function, given a recipient, $PUBKEY; a file to encrypt, $TMP_NOTE; and an +# output file, "$NOTE", will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private +# GPG key. + + gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE" + } function decrypt(){ - TARGET="$ROOTDIR"/tmp/"$RANDOM" - openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET" +# This function, given a recipient, $PUBKEY; a file to decrypt, $TMP_NOTE; and an +# output file, "$NOTE", will decrpyt $TMP_NOTE to $NOTE against $PUBKEY's private +# GPG key. + gpg -d "$NOTE" } diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index 7bc95b9..d65d4f7 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,27 +1,8 @@ function list(){ - if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then - printf "\nNotes in %s:\n" "$(basename "$NOTEBOOK")" - - NOTES=( $(find "$BASEDIR"/"$NOTEBOOK" -name "*.$EXT" -print0 | sed s:"$BASEDIR"/"$NOTEBOOK"/: " " :g | sed -e s:".$EXT"::g | tr "/" " ") ) - let i=0 - for NOTE in "${NOTES[@]}"; do - if [ -d "$BASEDIR"/"$NOTEBOOK"/"$NOTE" ]; then - if [ "$LAST_SECTION" != "$NOTE" ]; then - printf " Section: %s\n" "$NOTE" - fi - LAST_SECTION="$NOTE" - else - #if [ $(($i % 1)) -eq 0 ]; then - # printf "\n " - #fi - printf " %s\n" "$NOTE" - fi - let i++ + if [ -d "$NOTES_DIR"/"$NOTEBOOK" ]; then + printf "+%s\n" "$NOTEBOOK" + find "$NOTES_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do + printf " -%s\n" "$(basename \"$NOTE\" | cut -d . -f 1 )" done - printf "\n" - else - echo "" - echo "ERROR: Notebook $NOTEBOOK does not exist." - echo "" fi } diff --git a/src/includes/pause.sns.sh b/src/includes/pause.sns.sh index 5884408..ace9b99 100644 --- a/src/includes/pause.sns.sh +++ b/src/includes/pause.sns.sh @@ -1,4 +1,4 @@ function pause { - read -p " Press [Enter] to continue." + read -rp " Press [Enter] to continue." echo "" } diff --git a/src/includes/print.sns.sh b/src/includes/print.sns.sh index 6058435..a24cd2b 100644 --- a/src/includes/print.sns.sh +++ b/src/includes/print.sns.sh @@ -1,19 +1,13 @@ function print(){ - if [ "$PRINT" == "TRUE" ]; then - if [ -r "$NOTE" ] || [ -r "${NOTE%.*}" ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -d -aes-256-cbc -in "${NOTE%.*}" -pass pass:"$ENC_KEY" - else - cat "$NOTE" - echo "" >> "$NOTE" - fi + if [ -r "$NOTE" ]; then + if [ -z "$CREATE" ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + decrypt else - echo "" - echo "ERROR: Note cannot be found." - echo "" - + cat "$NOTE" fi + else + printf "\nERROR: Note cannot be found.\n" fi fi } diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 45ea735..af57da1 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -1,41 +1,44 @@ #============================================================================== -# Section: Configuration +# Section: Configuration / Stage 1 #============================================================================== -if [ -r "$CONFIGURATION" ]; then - source "$CONFIGURATION" +if [ -r "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" else - w_conf - source "$CONFIGURATION" + create_sns_root + source "$CONFIG_FILE" fi if [ "$ENCRYPTION" == "TRUE" ]; then -if [ -z "$ENC_KEY" ]; then -ERR_NO_KEY="TRUE" -ENCRYPTION="FALSE" -fi -command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } + 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)" -EXT="$EXT" -if [ ! -d "$BASEDIR"/tmp ]; then -mkdir -p "$BASEDIR"/tmp -fi + 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_SSL" ]; then -echo >&2 " Warning: OpenSSL not installed. Encryption disabled." -fi -if [ -n "$ERR_NO_KEY" ]; then -echo " Warning: No encryption key was provided. Encryption disabled." + +if [ -z "$EDITOR" ]; then + >&2 echo "Error no editor specified in environment." + +elif [ -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_SSL" ] || [ -n "$ERR_NO_KEY" ]; then -pause -fi #============================================================================== -# End Section: Configuration +# End Section: Configuration / Stage 1 #============================================================================== diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index debc0fa..97c0392 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -1,5 +1,5 @@ #============================================================================== -# Section: Argument Parsing +# Section: Argument Parsing / Stage 2 #============================================================================== NAME="" @@ -16,7 +16,7 @@ else 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 w_conf; 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" @@ -37,5 +37,5 @@ fi # that can work without any arguments. #============================================================================== -# End Section: Argument Parsing +# End Section: Argument Parsing / Stage 2 #============================================================================== diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 955713f..da7f738 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -1,6 +1,6 @@ -# Help requires no arguments, and is exclusive. -if [ -n "$HELP" ]; then help; exit 0; fi - +#============================================================================== +# Section: Actions / Stage 3 +#============================================================================== # List only requires a notebook, and is exclusive. if [ -z "$NOTEBOOK" ]; then echo " ERROR: Insufficient arguments:" @@ -21,11 +21,19 @@ if [ -z "$NAME" ]; then exit 30 fi -NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ -NOTE="$NOTEDIR""$NAME"."$EXT" +SESSION_ID="$RANDOM" +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 NOTE="$NOTE".enc; 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 \ No newline at end of file +if [ "$EDIT" == "TRUE" ]; then edit; fi + +#============================================================================== +# End Section: Actions / Stage 3 +#============================================================================== \ No newline at end of file