From cba92f4598048eb5ccd26d8ef48d2d2f4ed65771 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 16 Mar 2015 12:40:34 -0500 Subject: [PATCH 01/52] Initial Commit --- sns.xcodeproj/project.pbxproj | 67 +++++++++++++++++++ .../contents.xcworkspacedata | 7 ++ 2 files changed, 74 insertions(+) create mode 100644 sns.xcodeproj/project.pbxproj create mode 100644 sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f2708a0 --- /dev/null +++ b/sns.xcodeproj/project.pbxproj @@ -0,0 +1,67 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXGroup section */ + 5D7E61181AB74D11001D49B9 = { + isa = PBXGroup; + children = ( + ); + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXProject section */ + 5D7E61191AB74D11001D49B9 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0620; + }; + buildConfigurationList = 5D7E611C1AB74D11001D49B9 /* Build configuration list for PBXProject "sns" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 5D7E61181AB74D11001D49B9; + projectDirPath = ""; + projectRoot = ""; + targets = ( + ); + }; +/* End PBXProject section */ + +/* Begin XCBuildConfiguration section */ + 5D7E611D1AB74D11001D49B9 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + 5D7E611E1AB74D11001D49B9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5D7E611C1AB74D11001D49B9 /* Build configuration list for PBXProject "sns" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5D7E611D1AB74D11001D49B9 /* Debug */, + 5D7E611E1AB74D11001D49B9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 5D7E61191AB74D11001D49B9 /* Project object */; +} diff --git a/sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..dccdea5 --- /dev/null +++ b/sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + From 971734e40e43a0717ecf27570b1f2728bb845aa4 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 16 Mar 2015 12:42:25 -0500 Subject: [PATCH 02/52] Initial Commit --- sns.sh | 316 ++++++++++++++++++++++++++++++++++ sns.xcodeproj/project.pbxproj | 5 + 2 files changed, 321 insertions(+) create mode 100644 sns.sh diff --git a/sns.sh b/sns.sh new file mode 100644 index 0000000..2bc0873 --- /dev/null +++ b/sns.sh @@ -0,0 +1,316 @@ +#!/bin/bash +#========================================================== +# Simple Note System, v1.1 +# Copyright 2014, Xenese Labs/Sicron-Perion XNF +#========================================================== + +PROD_STR="Simple Note System" +VER_STR=v1.1 + +#============================================================================== +# Section: Helper Functions +#============================================================================== +function writeconf { +cat > $HOME/.sns << EOF +#========================================================== +# Simple Note System Config, v1.1 +# Copyright 2014, Xenese Labs/Sicron-Perion XNF +#========================================================== + +#Directory where notes will be stored +BASEDIR=$HOME/notes + +#File extension to use (for listing notes) +EXT=note + +#Preferred Editor +EDITOR=vim + +#Encryption +#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST +ENCRYPTION="FALSE" +ENC_KEY="" +EOF + +chmod 600 $HOME/.sns +} + +function help { +echo "" +echo "usage: sns [-ce] NAME NOTEBOOK SECTION" +echo " sns [-d ] NAME NOTEBOOK SECTION" +echo " sns [-l ] NOTEBOOK" +echo " sns [-w ]" + +echo "" +echo " -c | --create : Create note" +echo " -d | --delete : Delete note" +echo " -e | --edit : Open note for editing" +echo " -p | --print : Print note to console" +echo " -l | --list : List all notes in NOTEBOOK" +echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" +echo "" +} + +function pause { +read -p " Press [Enter] to continue." +echo "" +} + +#============================================================================== +# End Section: Helper Functions +#============================================================================== + +#============================================================================== +# Section: Configuration +#============================================================================== +if [ -r $HOME/.sns ]; then +source $HOME/.sns +else +BASEDIR=$HOME/notes +EDITOR=vim +EXT=note +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then +if [ -z "$ENC_KEY" ]; then +ERR_NO_KEY="TRUE" +ENCRYPTION="FALSE" +pause +fi +command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then +PROD_STR="Simple Note System (Encryption Enabled)" +EXT="$EXT.enc" +if [ ! -d ~/.tmp ]; then +mkdir -p ~/.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." +fi + +if [ -n "$ERR_NO_SSL" -o -n "$ERR_NO_KEY" ]; then +pause +fi + +#============================================================================== +# End Section: Read Configuration +#============================================================================== + + +#============================================================================== +# Section: Argument Parsing +#============================================================================== + +NAME="" +NOTEBOOK="" +SECTION="" + +if [ -z "$1" ]; then #If no input was given, print help +help +exit +else #Assume the user wants to do something. +ARGS=( "$@" ) +for ARG in ${ARGS[@]};do +if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" +elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" +elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" +elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" +elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" +elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" +elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 +elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit +else +if [ -z "$NAME" -a -n $ARG ]; then +NAME=$ARG +echo "Name: $NAME" +elif [ -z "$NOTEBOOK" -a -n $ARG ]; then +NOTEBOOK=$ARG +echo "Notebook: $NOTEBOOK" +elif [ -z "$SECTION" -a -n $ARG ]; then +SECTION=$ARG +echo "Section: $SECTION" +fi +fi +done +fi + +#============================================================================== +# End Section: Argument Parsing +#============================================================================== + +#============================================================================== +# Section: Main +#============================================================================== + +NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ +NOTE=$NOTEDIR$NAME.$EXT + +if [ "$ENCRYPTION" == "TRUE" ]; then +NOTE=$NOTE.tmp +fi + +#========================================================================== +# Subection: List +#========================================================================== +if [ -n "$LIST" ]; then +NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. +if [ -z "$NOTEBOOK" ]; then +echo " ERROR: Insufficient arguments" +help +exit +else +if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then + +echo "" +printf "Notes in $(basename $NOTEBOOK):" +echo "" +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: $NOTE\n" +fi +LAST_SECTION=$NOTE +else +#if [ $(($i % 1)) -eq 0 ]; then +# printf "\n " +#fi +printf " $NOTE\n" +fi +let i++ +done +printf "\n" +else +echo "" +echo "ERROR: Notebook $NOTEBOOK does not exist." +echo "" +fi +fi +exit +fi +#====================================================================== +# Sanity Check - Actions below require a valid $NAME and $NOTEBOOK +#====================================================================== +if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then +echo " ERROR: Insufficient arguments" +help +exit 10 +fi +#========================================================================== +# Subection: Delete +#========================================================================== +if [ "$DELETE" == "TRUE" ]; then +if [ -e $NOTE -o -e ${NOTE%.*} ]; then +if [ "$ENCRYPTION" == "TRUE" ]; then +rm ${NOTE%.*} +else +rm $NOTE +fi + +echo "" +echo "Deleted note: $NOTEBOOK/$SECTION$NAME." +exit +else + +echo "" +echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." +exit +fi +fi + +#========================================================================== +# Subection: Create +#========================================================================== +if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit +help +exit +else + + +if [ "$CREATE" == "TRUE" ]; then +if [ -e $NOTE -o -e ${NOTE%.*} ]; then + +echo "" +echo "ERROR: Note already exists" +echo "Hint: use -e to edit the note." +echo "" +exit +else +#Create any necessary folders +mkdir -p $NOTEDIR + +#Fill in title +echo "TITLE: $NAME" > $NOTE +#Fill the second line with the date +echo "DATE: $(date)" >> $NOTE + +if [ "$ENCRYPTION" == "TRUE" ]; then +if [ $EDIT == "FALSE" ]; then +openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY +fi +fi +fi +fi + +#========================================================================== +# Subection: Edit +#========================================================================== +if [ "$EDIT" == "TRUE" ]; then +if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then +if [ -z "$CREATE" ]; then +if [ "$ENCRYPTION" == "TRUE" ]; then +openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $NOTE +fi +echo "" >> $NOTE +echo "EDIT $(date)" >> $NOTE +fi +$EDITOR $NOTE +if [ "$ENCRYPTION" == "TRUE" ]; then +openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY +rm $NOTE +fi + +else + +echo "" +echo "ERROR: Note cannot be opened for editting." +echo "" + +fi +fi + +fi +#========================================================================== +# Subection: Print +#========================================================================== +if [ "$PRINT" == "TRUE" ]; then +if [ -r "$NOTE" -o -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 +else + +echo "" +echo "ERROR: Note cannot be found." +echo "" + +fi +fi + +fi + +exit diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index f2708a0..11d1fa6 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -6,10 +6,15 @@ objectVersion = 46; objects = { +/* Begin PBXFileReference section */ + 5D7E611F1AB74D33001D49B9 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; +/* End PBXFileReference section */ + /* Begin PBXGroup section */ 5D7E61181AB74D11001D49B9 = { isa = PBXGroup; children = ( + 5D7E611F1AB74D33001D49B9 /* sns.sh */, ); sourceTree = ""; }; From 1864543bf5f39f38c8e1cc31d64e58b28cc46069 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 16 Mar 2015 12:46:01 -0500 Subject: [PATCH 03/52] Added comment declaring end of interface section in preparation for sns 2 --- sns.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sns.sh b/sns.sh index 2bc0873..820c85f 100644 --- a/sns.sh +++ b/sns.sh @@ -147,6 +147,16 @@ fi # End Section: Argument Parsing #============================================================================== +#============================================================================== +#============================================================================== +# +# End of Setup process. By now, we should have a $BASEDIR, $NOTEBOOK, $SECTION, +# $NOTEDIR, and $EXT +# +#============================================================================== +#============================================================================== + + #============================================================================== # Section: Main #============================================================================== From 45717e33b523e7c180b73e504f577b3a107754dd Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 18 Mar 2015 12:52:00 -0500 Subject: [PATCH 04/52] Simple Note System v2.0a2 Changes: Split script into several different files for easier editting Added build.sh to compile Simple Note System from tree Changed config file to config folder; $HOME/.sns now contains configuration and notes Testing: Script runs and produces help screen; no further testing done. --- build.sh | 34 ++++ functions/create.sns.sh | 33 ++++ functions/delete.sns.sh | 20 ++ functions/edit.sns.sh | 30 +++ functions/help.sns.sh | 20 ++ functions/list.sns.sh | 39 ++++ functions/print.sns.sh | 22 +++ functions/wconf.sns.sh | 35 ++++ init/stage1.sns.sh | 43 +++++ init/stage2.sns.sh | 40 ++++ init/stage3.sns.sh | 22 +++ sns.sh | 333 ++++++++++++++++------------------ sns.xcodeproj/project.pbxproj | 42 ++++- 13 files changed, 538 insertions(+), 175 deletions(-) create mode 100644 build.sh create mode 100644 functions/create.sns.sh create mode 100644 functions/delete.sns.sh create mode 100644 functions/edit.sns.sh create mode 100644 functions/help.sns.sh create mode 100644 functions/list.sns.sh create mode 100644 functions/print.sns.sh create mode 100644 functions/wconf.sns.sh create mode 100644 init/stage1.sns.sh create mode 100644 init/stage2.sns.sh create mode 100644 init/stage3.sns.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..f9f3000 --- /dev/null +++ b/build.sh @@ -0,0 +1,34 @@ +S=sns.sh + +PROD_STR="Simple Note System" +VER_STR=v2.0a2 + +cat > $S << EOF +#!/bin/bash +#========================================================== +# Simple Note System, v2.0a1 +# Copyright 2014, Xenese Labs/Sicron-Perion XNF +#========================================================== + +PROD_STR=$PROD_STR +VER_STR=$VER_STR + +EOF + +cat functions/wconf.sns.sh >> $S +cat functions/help.sns.sh >> $S +cat ./init/stage1.sns.sh >> $S +cat ./init/stage2.sns.sh >> $S +cat ./init/stage3.sns.sh >> $S + +cat ./functions/create.sns.sh >> $S +cat ./functions/delete.sns.sh >> $S +cat ./functions/edit.sns.sh >> $S +cat ./functions/print.sns.sh >> $S +cat ./functions/list.sns.sh >> $S + + + + + +exit diff --git a/functions/create.sns.sh b/functions/create.sns.sh new file mode 100644 index 0000000..30d094a --- /dev/null +++ b/functions/create.sns.sh @@ -0,0 +1,33 @@ +#========================================================================== +# Subection: Create +#========================================================================== +if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit +help +exit +else + + +if [ "$CREATE" == "TRUE" ]; then +if [ -e $NOTE -o -e ${NOTE%.*} ]; then + +echo "" +echo "ERROR: Note already exists" +echo "Hint: use -e to edit the note." +echo "" +exit +else +#Create any necessary folders +mkdir -p $NOTEDIR + +#Fill in title +echo "TITLE: $NAME" > $NOTE +#Fill the second line with the date +echo "DATE: $(date)" >> $NOTE + +if [ "$ENCRYPTION" == "TRUE" ]; then +if [ $EDIT == "FALSE" ]; then +openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY +fi +fi +fi +fi diff --git a/functions/delete.sns.sh b/functions/delete.sns.sh new file mode 100644 index 0000000..b59189e --- /dev/null +++ b/functions/delete.sns.sh @@ -0,0 +1,20 @@ +# delete.sns.sh + +if [ "$DELETE" == "TRUE" ]; then +if [ -e $NOTE -o -e ${NOTE%.*} ]; then +if [ "$ENCRYPTION" == "TRUE" ]; then +rm ${NOTE%.*} +else +rm $NOTE +fi + +echo "" +echo "Deleted note: $NOTEBOOK/$SECTION$NAME." +exit +else + +echo "" +echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." +exit +fi +fi diff --git a/functions/edit.sns.sh b/functions/edit.sns.sh new file mode 100644 index 0000000..9603706 --- /dev/null +++ b/functions/edit.sns.sh @@ -0,0 +1,30 @@ +#========================================================================== +# Subection: Edit +#========================================================================== +if [ "$EDIT" == "TRUE" ]; then +if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then +if [ -z "$CREATE" ]; then +if [ "$ENCRYPTION" == "TRUE" ]; then +TMP_NAME=$ROOTDIR/tmp/$RANDOM +openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME +echo "" >> $TMP_NAME +echo "EDIT $(date)" >> $TMP_NAME +else +echo "" >> $NOTE +echo "EDIT $(date)" >> $NOTE +fi +fi +$EDITOR $NOTE +if [ "$ENCRYPTION" == "TRUE" ]; then +openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY +rm $NOTE +fi + +else +echo "" +echo "ERROR: Note cannot be opened for editting." +echo "" +fi +fi + +fi diff --git a/functions/help.sns.sh b/functions/help.sns.sh new file mode 100644 index 0000000..b926b9e --- /dev/null +++ b/functions/help.sns.sh @@ -0,0 +1,20 @@ +function help { +echo "" +echo "usage: sns [-ce] NAME NOTEBOOK SECTION" +echo " sns [-d ] NAME NOTEBOOK SECTION" +echo " sns [-l ] NOTEBOOK" +echo " sns [-w ]" + +echo "" +echo " -c | --create : Create note" +echo " -d | --delete : Delete note" +echo " -e | --edit : Open note for editing" +echo " -p | --print : Print note to console" +echo " -l | --list : List all notes in NOTEBOOK" +echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" +echo "" +} + +#============================================================================== +# End Section: Helper Functions +#============================================================================== diff --git a/functions/list.sns.sh b/functions/list.sns.sh new file mode 100644 index 0000000..628539a --- /dev/null +++ b/functions/list.sns.sh @@ -0,0 +1,39 @@ +# list.sns.sh + +if [ -n "$LIST" ]; then +NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. +if [ -z "$NOTEBOOK" ]; then +echo " ERROR: Insufficient arguments" +help +exit +else +if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then + +echo "" +printf "Notes in $(basename $NOTEBOOK):" +echo "" +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: $NOTE\n" +fi +LAST_SECTION=$NOTE +else +#if [ $(($i % 1)) -eq 0 ]; then +# printf "\n " +#fi +printf " $NOTE\n" +fi +let i++ +done +printf "\n" +else +echo "" +echo "ERROR: Notebook $NOTEBOOK does not exist." +echo "" +fi +fi +exit +fi diff --git a/functions/print.sns.sh b/functions/print.sns.sh new file mode 100644 index 0000000..1c057c5 --- /dev/null +++ b/functions/print.sns.sh @@ -0,0 +1,22 @@ +#========================================================================== +# Subection: Print +#========================================================================== +if [ "$PRINT" == "TRUE" ]; then +if [ -r "$NOTE" -o -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 +else + +echo "" +echo "ERROR: Note cannot be found." +echo "" + +fi +fi + +fi diff --git a/functions/wconf.sns.sh b/functions/wconf.sns.sh new file mode 100644 index 0000000..b0d524f --- /dev/null +++ b/functions/wconf.sns.sh @@ -0,0 +1,35 @@ +#============================================================================== +# Section: Helper Functions +#============================================================================== +function writeconf { +cat > $HOME/.sns/sns.conf << EOF +#========================================================== +# Simple Note System Config, v2.0a1 +# Copyright 2014, Xenese Labs/Sicron-Perion XNF +#========================================================== + +#Directory where notes will be stored +ROOTDIR=$HOME/.sns +BASEDIR=$ROOTDIR/notes + +#File extension to use (for listing notes) +EXT=note + +#Preferred Editor +EDITOR=vim + +#Encryption +#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST +ENCRYPTION="FALSE" +ENC_KEY="" +EOF + +chmod 600 $ROOTDIR/sns.conf +} + + +function pause { +read -p " Press [Enter] to continue." +echo "" +} + diff --git a/init/stage1.sns.sh b/init/stage1.sns.sh new file mode 100644 index 0000000..c949e19 --- /dev/null +++ b/init/stage1.sns.sh @@ -0,0 +1,43 @@ +#============================================================================== +# Section: Configuration +#============================================================================== +if [ -r $HOME/.sns/sns.conf ]; then +source $HOME/.sns/sns.conf +else +ROOTDIR=$HOME/.sns +BASEDIR=$ROOTDIR/notes +EDITOR=vim +EXT=note +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"; } +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then +PROD_STR="Simple Note System (Encryption Enabled)" +EXT="$EXT.enc" +if [ ! -d ~/.sns/tmp ]; then +mkdir -p ~/.sns/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." +fi + +if [ -n "$ERR_NO_SSL" -o -n "$ERR_NO_KEY" ]; then +pause +fi + +#============================================================================== +# End Section: Read Configuration +#============================================================================== diff --git a/init/stage2.sns.sh b/init/stage2.sns.sh new file mode 100644 index 0000000..fd26a51 --- /dev/null +++ b/init/stage2.sns.sh @@ -0,0 +1,40 @@ +#============================================================================== +# Section: Argument Parsing +#============================================================================== + +NAME="" +NOTEBOOK="" +SECTION="" + +if [ -z "$1" ]; then #If no input was given, print help + help + exit +else #Assume the user wants to do something. + ARGS=( "$@" ) + for ARG in ${ARGS[@]};do + if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" + elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" + elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" + elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" + elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" + elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" + elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 + elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit + else + if [ -z "$NAME" -a -n $ARG ]; then + NAME=$ARG + echo "Name: $NAME" + elif [ -z "$NOTEBOOK" -a -n $ARG ]; then + NOTEBOOK=$ARG + echo "Notebook: $NOTEBOOK" + elif [ -z "$SECTION" -a -n $ARG ]; then + SECTION=$ARG + echo "Section: $SECTION" + fi + fi + done +fi + +#============================================================================== +# End Section: Argument Parsing +#============================================================================== diff --git a/init/stage3.sns.sh b/init/stage3.sns.sh new file mode 100644 index 0000000..9008b32 --- /dev/null +++ b/init/stage3.sns.sh @@ -0,0 +1,22 @@ + + + + + + + +# If no name or notebook is specified, the create, edit, and print functions will not function properly. +# Check $NAME and $NOTEBOOK and exit if either are empty. +if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then; + echo " ERROR: Insufficient arguments"; + help; #Remind the user how to use the script + exit 10; +fi + + +NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ +NOTE=$NOTEDIR$NAME.$EXT + +if [ "$ENCRYPTION" == "TRUE" ]; then +NOTE=$NOTE.tmp +fi diff --git a/sns.sh b/sns.sh index 820c85f..c3084c4 100644 --- a/sns.sh +++ b/sns.sh @@ -1,24 +1,25 @@ #!/bin/bash #========================================================== -# Simple Note System, v1.1 +# Simple Note System, v2.0a1 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== PROD_STR="Simple Note System" -VER_STR=v1.1 +VER_STR=v2.0a1 #============================================================================== # Section: Helper Functions #============================================================================== function writeconf { -cat > $HOME/.sns << EOF +cat > $HOME/.sns/sns.conf << EOF #========================================================== -# Simple Note System Config, v1.1 +# Simple Note System Config, v2.0a1 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== #Directory where notes will be stored -BASEDIR=$HOME/notes +ROOTDIR=$HOME/.sns +BASEDIR=$ROOTDIR/notes #File extension to use (for listing notes) EXT=note @@ -32,7 +33,13 @@ ENCRYPTION="FALSE" ENC_KEY="" EOF -chmod 600 $HOME/.sns +chmod 600 $ROOTDIR/sns.conf +} + + +function pause { +read -p " Press [Enter] to continue." +echo "" } function help { @@ -52,22 +59,17 @@ echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryp echo "" } -function pause { -read -p " Press [Enter] to continue." -echo "" -} - #============================================================================== # End Section: Helper Functions #============================================================================== - #============================================================================== # Section: Configuration #============================================================================== -if [ -r $HOME/.sns ]; then -source $HOME/.sns +if [ -r $HOME/.sns/sns.conf ]; then +source $HOME/.sns/sns.conf else -BASEDIR=$HOME/notes +ROOTDIR=$HOME/.sns +BASEDIR=$ROOTDIR/notes EDITOR=vim EXT=note fi @@ -76,7 +78,6 @@ if [ "$ENCRYPTION" == "TRUE" ]; then if [ -z "$ENC_KEY" ]; then ERR_NO_KEY="TRUE" ENCRYPTION="FALSE" -pause fi command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } fi @@ -84,8 +85,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" EXT="$EXT.enc" -if [ ! -d ~/.tmp ]; then -mkdir -p ~/.tmp +if [ ! -d ~/.sns/tmp ]; then +mkdir -p ~/.sns/tmp fi fi @@ -104,8 +105,6 @@ fi #============================================================================== # End Section: Read Configuration #============================================================================== - - #============================================================================== # Section: Argument Parsing #============================================================================== @@ -115,51 +114,52 @@ NOTEBOOK="" SECTION="" if [ -z "$1" ]; then #If no input was given, print help -help -exit + help + exit else #Assume the user wants to do something. -ARGS=( "$@" ) -for ARG in ${ARGS[@]};do -if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" -elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" -elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" -elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" -elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" -elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" -elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 -elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit -else -if [ -z "$NAME" -a -n $ARG ]; then -NAME=$ARG -echo "Name: $NAME" -elif [ -z "$NOTEBOOK" -a -n $ARG ]; then -NOTEBOOK=$ARG -echo "Notebook: $NOTEBOOK" -elif [ -z "$SECTION" -a -n $ARG ]; then -SECTION=$ARG -echo "Section: $SECTION" -fi -fi -done + ARGS=( "$@" ) + for ARG in ${ARGS[@]};do + if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" + elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" + elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" + elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" + elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" + elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" + elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 + elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit + else + if [ -z "$NAME" -a -n $ARG ]; then + NAME=$ARG + echo "Name: $NAME" + elif [ -z "$NOTEBOOK" -a -n $ARG ]; then + NOTEBOOK=$ARG + echo "Notebook: $NOTEBOOK" + elif [ -z "$SECTION" -a -n $ARG ]; then + SECTION=$ARG + echo "Section: $SECTION" + fi + fi + done fi #============================================================================== # End Section: Argument Parsing #============================================================================== -#============================================================================== -#============================================================================== -# -# End of Setup process. By now, we should have a $BASEDIR, $NOTEBOOK, $SECTION, -# $NOTEDIR, and $EXT -# -#============================================================================== -#============================================================================== -#============================================================================== -# Section: Main -#============================================================================== + + + + +# If no name or notebook is specified, the create, edit, and print functions will not function properly. +# Check $NAME and $NOTEBOOK and exit if either are empty. +if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then; + echo " ERROR: Insufficient arguments"; + help; #Remind the user how to use the script + exit 10; +fi + NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ NOTE=$NOTEDIR$NAME.$EXT @@ -167,10 +167,113 @@ NOTE=$NOTEDIR$NAME.$EXT if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.tmp fi +#========================================================================== +# Subection: Create +#========================================================================== +if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit +help +exit +else + +if [ "$CREATE" == "TRUE" ]; then +if [ -e $NOTE -o -e ${NOTE%.*} ]; then + +echo "" +echo "ERROR: Note already exists" +echo "Hint: use -e to edit the note." +echo "" +exit +else +#Create any necessary folders +mkdir -p $NOTEDIR + +#Fill in title +echo "TITLE: $NAME" > $NOTE +#Fill the second line with the date +echo "DATE: $(date)" >> $NOTE + +if [ "$ENCRYPTION" == "TRUE" ]; then +if [ $EDIT == "FALSE" ]; then +openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY +fi +fi +fi +fi +# delete.sns.sh + +if [ "$DELETE" == "TRUE" ]; then +if [ -e $NOTE -o -e ${NOTE%.*} ]; then +if [ "$ENCRYPTION" == "TRUE" ]; then +rm ${NOTE%.*} +else +rm $NOTE +fi + +echo "" +echo "Deleted note: $NOTEBOOK/$SECTION$NAME." +exit +else + +echo "" +echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." +exit +fi +fi #========================================================================== -# Subection: List +# Subection: Edit #========================================================================== +if [ "$EDIT" == "TRUE" ]; then +if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then +if [ -z "$CREATE" ]; then +if [ "$ENCRYPTION" == "TRUE" ]; then +TMP_NAME=$ROOTDIR/tmp/$RANDOM +openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME +echo "" >> $TMP_NAME +echo "EDIT $(date)" >> $TMP_NAME +else +echo "" >> $NOTE +echo "EDIT $(date)" >> $NOTE +fi +fi +$EDITOR $NOTE +if [ "$ENCRYPTION" == "TRUE" ]; then +openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY +rm $NOTE +fi + +else +echo "" +echo "ERROR: Note cannot be opened for editting." +echo "" +fi +fi + +fi +#========================================================================== +# Subection: Print +#========================================================================== +if [ "$PRINT" == "TRUE" ]; then +if [ -r "$NOTE" -o -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 +else + +echo "" +echo "ERROR: Note cannot be found." +echo "" + +fi +fi + +fi +# list.sns.sh + if [ -n "$LIST" ]; then NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. if [ -z "$NOTEBOOK" ]; then @@ -208,119 +311,3 @@ fi fi exit fi -#====================================================================== -# Sanity Check - Actions below require a valid $NAME and $NOTEBOOK -#====================================================================== -if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then -echo " ERROR: Insufficient arguments" -help -exit 10 -fi -#========================================================================== -# Subection: Delete -#========================================================================== -if [ "$DELETE" == "TRUE" ]; then -if [ -e $NOTE -o -e ${NOTE%.*} ]; then -if [ "$ENCRYPTION" == "TRUE" ]; then -rm ${NOTE%.*} -else -rm $NOTE -fi - -echo "" -echo "Deleted note: $NOTEBOOK/$SECTION$NAME." -exit -else - -echo "" -echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." -exit -fi -fi - -#========================================================================== -# Subection: Create -#========================================================================== -if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit -help -exit -else - - -if [ "$CREATE" == "TRUE" ]; then -if [ -e $NOTE -o -e ${NOTE%.*} ]; then - -echo "" -echo "ERROR: Note already exists" -echo "Hint: use -e to edit the note." -echo "" -exit -else -#Create any necessary folders -mkdir -p $NOTEDIR - -#Fill in title -echo "TITLE: $NAME" > $NOTE -#Fill the second line with the date -echo "DATE: $(date)" >> $NOTE - -if [ "$ENCRYPTION" == "TRUE" ]; then -if [ $EDIT == "FALSE" ]; then -openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY -fi -fi -fi -fi - -#========================================================================== -# Subection: Edit -#========================================================================== -if [ "$EDIT" == "TRUE" ]; then -if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then -if [ -z "$CREATE" ]; then -if [ "$ENCRYPTION" == "TRUE" ]; then -openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $NOTE -fi -echo "" >> $NOTE -echo "EDIT $(date)" >> $NOTE -fi -$EDITOR $NOTE -if [ "$ENCRYPTION" == "TRUE" ]; then -openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY -rm $NOTE -fi - -else - -echo "" -echo "ERROR: Note cannot be opened for editting." -echo "" - -fi -fi - -fi -#========================================================================== -# Subection: Print -#========================================================================== -if [ "$PRINT" == "TRUE" ]; then -if [ -r "$NOTE" -o -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 -else - -echo "" -echo "ERROR: Note cannot be found." -echo "" - -fi -fi - -fi - -exit diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index 11d1fa6..91cdc64 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -7,17 +7,55 @@ objects = { /* Begin PBXFileReference section */ - 5D7E611F1AB74D33001D49B9 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; + 5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = ""; }; + 5DE839761AB9D42F006CB4F6 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = ""; }; + 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = ""; }; + 5DE8397B1AB9D629006CB4F6 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = ""; }; + 5DE8397C1AB9D64B006CB4F6 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = ""; }; + 5DE8397D1AB9D694006CB4F6 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = ""; }; + 5DE8397E1AB9D72D006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; + 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = ""; }; + 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = ""; }; + 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = ""; }; + 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = wconf.sns.sh; sourceTree = ""; }; + 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ 5D7E61181AB74D11001D49B9 = { isa = PBXGroup; children = ( - 5D7E611F1AB74D33001D49B9 /* sns.sh */, + 5DE839831AB9DACE006CB4F6 /* sns.sh */, + 5DE839791AB9D5F8006CB4F6 /* init */, + 5D7E611F1AB74D33001D49B9 /* build.sh */, + 5DE839751AB9D41B006CB4F6 /* functions */, ); sourceTree = ""; }; + 5DE839751AB9D41B006CB4F6 /* functions */ = { + isa = PBXGroup; + children = ( + 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */, + 5DE839761AB9D42F006CB4F6 /* list.sns.sh */, + 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */, + 5DE8397E1AB9D72D006CB4F6 /* help.sns.sh */, + 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */, + 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */, + 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */, + ); + path = functions; + sourceTree = ""; + }; + 5DE839791AB9D5F8006CB4F6 /* init */ = { + isa = PBXGroup; + children = ( + 5DE8397D1AB9D694006CB4F6 /* stage3.sns.sh */, + 5DE8397B1AB9D629006CB4F6 /* stage1.sns.sh */, + 5DE8397C1AB9D64B006CB4F6 /* stage2.sns.sh */, + ); + path = init; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXProject section */ From a0ad2e7d48712b0b577344b9439fc4e3b24c38e3 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 18 Mar 2015 14:53:05 -0500 Subject: [PATCH 05/52] Alpha 3 Testing: Print function works --- build.sh | 29 ++- errors.ref | 12 + functions/create.sns.sh | 57 ++-- functions/delete.sns.sh | 38 ++- functions/edit.sns.sh | 55 ++-- functions/help.sns.sh | 32 ++- functions/init_default_config.sns.sh | 7 + functions/list.sns.sh | 66 ++--- functions/pause.sns.sh | 4 + functions/print.sns.sh | 39 ++- functions/wconf.sns.sh | 10 - init/stage1.sns.sh | 7 +- init/stage2.sns.sh | 12 +- init/stage3.sns.sh | 38 +-- sns.sh | 371 +++++++++++++-------------- sns.xcodeproj/project.pbxproj | 10 +- 16 files changed, 389 insertions(+), 398 deletions(-) create mode 100644 errors.ref create mode 100644 functions/init_default_config.sns.sh create mode 100644 functions/pause.sns.sh diff --git a/build.sh b/build.sh index f9f3000..397e97b 100644 --- a/build.sh +++ b/build.sh @@ -1,34 +1,35 @@ S=sns.sh PROD_STR="Simple Note System" -VER_STR=v2.0a2 +VER_STR=v2.0a3 cat > $S << EOF #!/bin/bash #========================================================== -# Simple Note System, v2.0a1 +# $PROD_STR, $VER_STR # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -PROD_STR=$PROD_STR -VER_STR=$VER_STR +PROD_STR="$PROD_STR" +VER_STR="$VER_STR" EOF -cat functions/wconf.sns.sh >> $S -cat functions/help.sns.sh >> $S +echo "# Section: Functions" >> $S +cat ./functions/init_default_config.sns.sh >> $S +cat ./functions/wconf.sns.sh >> $S +cat ./functions/pause.sns.sh >> $S +cat ./functions/help.sns.sh >> $S +cat ./functions/create.sns.sh >> $S +cat ./functions/delete.sns.sh >> $S +cat ./functions/edit.sns.sh >> $S +cat ./functions/print.sns.sh >> $S +cat ./functions/list.sns.sh >> $S +echo "# End Section: Functions" >> $S cat ./init/stage1.sns.sh >> $S cat ./init/stage2.sns.sh >> $S cat ./init/stage3.sns.sh >> $S -cat ./functions/create.sns.sh >> $S -cat ./functions/delete.sns.sh >> $S -cat ./functions/edit.sns.sh >> $S -cat ./functions/print.sns.sh >> $S -cat ./functions/list.sns.sh >> $S - - - exit diff --git a/errors.ref b/errors.ref new file mode 100644 index 0000000..ce7c5f3 --- /dev/null +++ b/errors.ref @@ -0,0 +1,12 @@ +Simple Note System, version 2 +Error Code Reference + +General------------------------------------------------------------------------- +ERR_NO_ARGS 10 No arguments were specified +ERR_NO_OP 20 +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 diff --git a/functions/create.sns.sh b/functions/create.sns.sh index 30d094a..80447ab 100644 --- a/functions/create.sns.sh +++ b/functions/create.sns.sh @@ -1,33 +1,28 @@ -#========================================================================== -# Subection: Create -#========================================================================== -if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit -help -exit -else +function create(){ + if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit + help + exit + elif [ "$CREATE" == "TRUE" ]; then + if [ -e $NOTE -o -e ${NOTE%.*} ]; then + echo "" + echo "ERROR: Note already exists" + echo "Hint: use -e to edit the note." + echo "" + exit + else + #Create any necessary folders + mkdir -p $NOTEDIR + #Fill in title + echo "TITLE: $NAME" > $NOTE + #Fill the second line with the date + echo "DATE: $(date)" >> $NOTE -if [ "$CREATE" == "TRUE" ]; then -if [ -e $NOTE -o -e ${NOTE%.*} ]; then - -echo "" -echo "ERROR: Note already exists" -echo "Hint: use -e to edit the note." -echo "" -exit -else -#Create any necessary folders -mkdir -p $NOTEDIR - -#Fill in title -echo "TITLE: $NAME" > $NOTE -#Fill the second line with the date -echo "DATE: $(date)" >> $NOTE - -if [ "$ENCRYPTION" == "TRUE" ]; then -if [ $EDIT == "FALSE" ]; then -openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY -fi -fi -fi -fi + if [ "$ENCRYPTION" == "TRUE" ]; then + if [ $EDIT == "FALSE" ]; then + openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY + fi + fi + fi + fi +} diff --git a/functions/delete.sns.sh b/functions/delete.sns.sh index b59189e..dafe3e7 100644 --- a/functions/delete.sns.sh +++ b/functions/delete.sns.sh @@ -1,20 +1,18 @@ -# delete.sns.sh - -if [ "$DELETE" == "TRUE" ]; then -if [ -e $NOTE -o -e ${NOTE%.*} ]; then -if [ "$ENCRYPTION" == "TRUE" ]; then -rm ${NOTE%.*} -else -rm $NOTE -fi - -echo "" -echo "Deleted note: $NOTEBOOK/$SECTION$NAME." -exit -else - -echo "" -echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." -exit -fi -fi +function delete(){ + if [ "$DELETE" == "TRUE" ]; then + if [ -e $NOTE -o -e ${NOTE%.*} ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + rm ${NOTE%.*} + else + rm $NOTE + fi + echo "" + echo "Deleted note: $NOTEBOOK/$SECTION$NAME." + exit + else + echo "" + echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." + exit + fi + fi +} diff --git a/functions/edit.sns.sh b/functions/edit.sns.sh index 9603706..140a117 100644 --- a/functions/edit.sns.sh +++ b/functions/edit.sns.sh @@ -1,30 +1,27 @@ -#========================================================================== -# Subection: Edit -#========================================================================== -if [ "$EDIT" == "TRUE" ]; then -if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then -if [ -z "$CREATE" ]; then -if [ "$ENCRYPTION" == "TRUE" ]; then -TMP_NAME=$ROOTDIR/tmp/$RANDOM -openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME -echo "" >> $TMP_NAME -echo "EDIT $(date)" >> $TMP_NAME -else -echo "" >> $NOTE -echo "EDIT $(date)" >> $NOTE -fi -fi -$EDITOR $NOTE -if [ "$ENCRYPTION" == "TRUE" ]; then -openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY -rm $NOTE -fi +function edit (){ + if [ "$EDIT" == "TRUE" ]; then + if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then + if [ -z "$CREATE" ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + TMP_NAME=$ROOTDIR/tmp/$RANDOM + openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME + echo "" >> $TMP_NAME + echo "EDIT $(date)" >> $TMP_NAME + else + echo "" >> $NOTE + echo "EDIT $(date)" >> $NOTE + fi + fi + $EDITOR $NOTE + if [ "$ENCRYPTION" == "TRUE" ]; then + openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY + rm $NOTE + fi -else -echo "" -echo "ERROR: Note cannot be opened for editting." -echo "" -fi -fi - -fi + else + echo "" + echo "ERROR: Note cannot be opened for editting." + echo "" + fi + fi +} diff --git a/functions/help.sns.sh b/functions/help.sns.sh index b926b9e..0727bd6 100644 --- a/functions/help.sns.sh +++ b/functions/help.sns.sh @@ -1,20 +1,18 @@ function help { -echo "" -echo "usage: sns [-ce] NAME NOTEBOOK SECTION" -echo " sns [-d ] NAME NOTEBOOK SECTION" -echo " sns [-l ] NOTEBOOK" -echo " sns [-w ]" + echo "" + echo "usage: sns [-ce] NAME NOTEBOOK SECTION" + echo " sns [-d ] NAME NOTEBOOK SECTION" + echo " sns [-lp] NOTEBOOK" + echo " sns [-w ]" + echo " sns [-h ]" -echo "" -echo " -c | --create : Create note" -echo " -d | --delete : Delete note" -echo " -e | --edit : Open note for editing" -echo " -p | --print : Print note to console" -echo " -l | --list : List all notes in NOTEBOOK" -echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" -echo "" + echo "" + echo " -c | --create : Create note" + echo " -d | --delete : Delete note" + echo " -e | --edit : Open note for editing" + echo " -h | --help : Display this message" + echo " -p | --print : Print note to console" + echo " -l | --list : List all notes in NOTEBOOK" + echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" + echo "" } - -#============================================================================== -# End Section: Helper Functions -#============================================================================== diff --git a/functions/init_default_config.sns.sh b/functions/init_default_config.sns.sh new file mode 100644 index 0000000..5bdd1dd --- /dev/null +++ b/functions/init_default_config.sns.sh @@ -0,0 +1,7 @@ +function init_default_config() { + ROOTDIR=$HOME/.sns + BASEDIR=$ROOTDIR/notes + EXT=note + EDITOR=vim + ENCRYPTION="FALSE" +} diff --git a/functions/list.sns.sh b/functions/list.sns.sh index 628539a..797a065 100644 --- a/functions/list.sns.sh +++ b/functions/list.sns.sh @@ -1,39 +1,29 @@ -# list.sns.sh +function list(){ + if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then + echo "" + printf "Notes in $(basename $NOTEBOOK):" + echo "" -if [ -n "$LIST" ]; then -NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. -if [ -z "$NOTEBOOK" ]; then -echo " ERROR: Insufficient arguments" -help -exit -else -if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then - -echo "" -printf "Notes in $(basename $NOTEBOOK):" -echo "" -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: $NOTE\n" -fi -LAST_SECTION=$NOTE -else -#if [ $(($i % 1)) -eq 0 ]; then -# printf "\n " -#fi -printf " $NOTE\n" -fi -let i++ -done -printf "\n" -else -echo "" -echo "ERROR: Notebook $NOTEBOOK does not exist." -echo "" -fi -fi -exit -fi + 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: $NOTE\n" + fi + LAST_SECTION=$NOTE + else + #if [ $(($i % 1)) -eq 0 ]; then + # printf "\n " + #fi + printf " $NOTE\n" + fi + let i++ + done + printf "\n" + else + echo "" + echo "ERROR: Notebook $NOTEBOOK does not exist." + echo "" + fi +} diff --git a/functions/pause.sns.sh b/functions/pause.sns.sh new file mode 100644 index 0000000..5884408 --- /dev/null +++ b/functions/pause.sns.sh @@ -0,0 +1,4 @@ +function pause { + read -p " Press [Enter] to continue." + echo "" +} diff --git a/functions/print.sns.sh b/functions/print.sns.sh index 1c057c5..c0a3aaf 100644 --- a/functions/print.sns.sh +++ b/functions/print.sns.sh @@ -1,22 +1,19 @@ -#========================================================================== -# Subection: Print -#========================================================================== -if [ "$PRINT" == "TRUE" ]; then -if [ -r "$NOTE" -o -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 -else +function print(){ + if [ "$PRINT" == "TRUE" ]; then + if [ -r "$NOTE" -o -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 + else + echo "" + echo "ERROR: Note cannot be found." + echo "" -echo "" -echo "ERROR: Note cannot be found." -echo "" - -fi -fi - -fi + fi + fi + fi +} diff --git a/functions/wconf.sns.sh b/functions/wconf.sns.sh index b0d524f..b6ea422 100644 --- a/functions/wconf.sns.sh +++ b/functions/wconf.sns.sh @@ -1,6 +1,3 @@ -#============================================================================== -# Section: Helper Functions -#============================================================================== function writeconf { cat > $HOME/.sns/sns.conf << EOF #========================================================== @@ -26,10 +23,3 @@ EOF chmod 600 $ROOTDIR/sns.conf } - - -function pause { -read -p " Press [Enter] to continue." -echo "" -} - diff --git a/init/stage1.sns.sh b/init/stage1.sns.sh index c949e19..89ab8d2 100644 --- a/init/stage1.sns.sh +++ b/init/stage1.sns.sh @@ -2,12 +2,9 @@ # Section: Configuration #============================================================================== if [ -r $HOME/.sns/sns.conf ]; then -source $HOME/.sns/sns.conf + source $HOME/.sns/sns.conf else -ROOTDIR=$HOME/.sns -BASEDIR=$ROOTDIR/notes -EDITOR=vim -EXT=note + init_default_config fi if [ "$ENCRYPTION" == "TRUE" ]; then diff --git a/init/stage2.sns.sh b/init/stage2.sns.sh index fd26a51..03ece6c 100644 --- a/init/stage2.sns.sh +++ b/init/stage2.sns.sh @@ -8,7 +8,7 @@ SECTION="" if [ -z "$1" ]; then #If no input was given, print help help - exit + exit 20 else #Assume the user wants to do something. ARGS=( "$@" ) for ARG in ${ARGS[@]};do @@ -23,18 +23,22 @@ else #Assume the user wants to do something. else if [ -z "$NAME" -a -n $ARG ]; then NAME=$ARG - echo "Name: $NAME" elif [ -z "$NOTEBOOK" -a -n $ARG ]; then NOTEBOOK=$ARG - echo "Notebook: $NOTEBOOK" elif [ -z "$SECTION" -a -n $ARG ]; then SECTION=$ARG - echo "Section: $SECTION" fi fi done + if [ -n "$NAME" -a -z "$NOTEBOOK" ]; then + NOTEBOOK="$NAME" + NAME="" + fi fi +# Note: writeconf has highest priority, and it is the only function that can +# work without any parameters. + #============================================================================== # End Section: Argument Parsing #============================================================================== diff --git a/init/stage3.sns.sh b/init/stage3.sns.sh index 9008b32..c9dd616 100644 --- a/init/stage3.sns.sh +++ b/init/stage3.sns.sh @@ -1,22 +1,30 @@ +# Help requires no arguments, and is exclusive. +if [ -n "$HELP" ]; then help; exit 0; fi - - - - - - -# If no name or notebook is specified, the create, edit, and print functions will not function properly. -# Check $NAME and $NOTEBOOK and exit if either are empty. -if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then; - echo " ERROR: Insufficient arguments"; - help; #Remind the user how to use the script - exit 10; +# 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 NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ NOTE=$NOTEDIR$NAME.$EXT -if [ "$ENCRYPTION" == "TRUE" ]; then -NOTE=$NOTE.tmp -fi +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.tmp fi + + diff --git a/sns.sh b/sns.sh index c3084c4..75b48fd 100644 --- a/sns.sh +++ b/sns.sh @@ -1,15 +1,20 @@ #!/bin/bash #========================================================== -# Simple Note System, v2.0a1 +# Simple Note System, v2.0a3 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== PROD_STR="Simple Note System" -VER_STR=v2.0a1 +VER_STR="v2.0a3" -#============================================================================== -# Section: Helper Functions -#============================================================================== +# Section: Functions +function init_default_config() { + ROOTDIR=$HOME/.sns + BASEDIR=$ROOTDIR/notes + EXT=note + EDITOR=vim + ENCRYPTION="FALSE" +} function writeconf { cat > $HOME/.sns/sns.conf << EOF #========================================================== @@ -35,43 +40,157 @@ EOF chmod 600 $ROOTDIR/sns.conf } - - function pause { -read -p " Press [Enter] to continue." -echo "" + read -p " Press [Enter] to continue." + echo "" } - function help { -echo "" -echo "usage: sns [-ce] NAME NOTEBOOK SECTION" -echo " sns [-d ] NAME NOTEBOOK SECTION" -echo " sns [-l ] NOTEBOOK" -echo " sns [-w ]" + echo "" + echo "usage: sns [-ce] NAME NOTEBOOK SECTION" + echo " sns [-d ] NAME NOTEBOOK SECTION" + echo " sns [-lp] NOTEBOOK" + echo " sns [-w ]" + echo " sns [-h ]" -echo "" -echo " -c | --create : Create note" -echo " -d | --delete : Delete note" -echo " -e | --edit : Open note for editing" -echo " -p | --print : Print note to console" -echo " -l | --list : List all notes in NOTEBOOK" -echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" -echo "" + echo "" + echo " -c | --create : Create note" + echo " -d | --delete : Delete note" + echo " -e | --edit : Open note for editing" + echo " -h | --help : Display this message" + echo " -p | --print : Print note to console" + echo " -l | --list : List all notes in NOTEBOOK" + echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" + echo "" } +function create(){ + if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit + help + exit + elif [ "$CREATE" == "TRUE" ]; then + if [ -e $NOTE -o -e ${NOTE%.*} ]; then + echo "" + echo "ERROR: Note already exists" + echo "Hint: use -e to edit the note." + echo "" + exit + else + #Create any necessary folders + mkdir -p $NOTEDIR -#============================================================================== -# End Section: Helper Functions -#============================================================================== + #Fill in title + echo "TITLE: $NAME" > $NOTE + #Fill the second line with the date + echo "DATE: $(date)" >> $NOTE + + if [ "$ENCRYPTION" == "TRUE" ]; then + if [ $EDIT == "FALSE" ]; then + openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY + fi + fi + fi + fi +} +function delete(){ + if [ "$DELETE" == "TRUE" ]; then + if [ -e $NOTE -o -e ${NOTE%.*} ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + rm ${NOTE%.*} + else + rm $NOTE + fi + echo "" + echo "Deleted note: $NOTEBOOK/$SECTION$NAME." + exit + else + echo "" + echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." + exit + fi + fi +} +function edit (){ + if [ "$EDIT" == "TRUE" ]; then + if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then + if [ -z "$CREATE" ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + TMP_NAME=$ROOTDIR/tmp/$RANDOM + openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME + echo "" >> $TMP_NAME + echo "EDIT $(date)" >> $TMP_NAME + else + echo "" >> $NOTE + echo "EDIT $(date)" >> $NOTE + fi + fi + $EDITOR $NOTE + if [ "$ENCRYPTION" == "TRUE" ]; then + openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY + rm $NOTE + fi + + else + echo "" + echo "ERROR: Note cannot be opened for editting." + echo "" + fi + fi +} +function print(){ + if [ "$PRINT" == "TRUE" ]; then + if [ -r "$NOTE" -o -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 + else + echo "" + echo "ERROR: Note cannot be found." + echo "" + + fi + fi + fi +} +function list(){ + if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then + echo "" + printf "Notes in $(basename $NOTEBOOK):" + echo "" + + 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: $NOTE\n" + fi + LAST_SECTION=$NOTE + else + #if [ $(($i % 1)) -eq 0 ]; then + # printf "\n " + #fi + printf " $NOTE\n" + fi + let i++ + done + printf "\n" + else + echo "" + echo "ERROR: Notebook $NOTEBOOK does not exist." + echo "" + fi +} +# End Section: Functions #============================================================================== # Section: Configuration #============================================================================== if [ -r $HOME/.sns/sns.conf ]; then -source $HOME/.sns/sns.conf + source $HOME/.sns/sns.conf else -ROOTDIR=$HOME/.sns -BASEDIR=$ROOTDIR/notes -EDITOR=vim -EXT=note + init_default_config fi if [ "$ENCRYPTION" == "TRUE" ]; then @@ -115,7 +234,7 @@ SECTION="" if [ -z "$1" ]; then #If no input was given, print help help - exit + exit 20 else #Assume the user wants to do something. ARGS=( "$@" ) for ARG in ${ARGS[@]};do @@ -130,184 +249,52 @@ else #Assume the user wants to do something. else if [ -z "$NAME" -a -n $ARG ]; then NAME=$ARG - echo "Name: $NAME" elif [ -z "$NOTEBOOK" -a -n $ARG ]; then NOTEBOOK=$ARG - echo "Notebook: $NOTEBOOK" elif [ -z "$SECTION" -a -n $ARG ]; then SECTION=$ARG - echo "Section: $SECTION" fi fi done + if [ -n "$NAME" -a -z "$NOTEBOOK" ]; then + NOTEBOOK="$NAME" + NAME="" + fi fi +# Note: writeconf has highest priority, and it is the only function that can +# work without any parameters. + #============================================================================== # End Section: Argument Parsing #============================================================================== +# Help requires no arguments, and is exclusive. +if [ -n "$HELP" ]; then help; exit 0; fi - - - - - - -# If no name or notebook is specified, the create, edit, and print functions will not function properly. -# Check $NAME and $NOTEBOOK and exit if either are empty. -if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then; - echo " ERROR: Insufficient arguments"; - help; #Remind the user how to use the script - exit 10; +# 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 NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ NOTE=$NOTEDIR$NAME.$EXT -if [ "$ENCRYPTION" == "TRUE" ]; then -NOTE=$NOTE.tmp -fi -#========================================================================== -# Subection: Create -#========================================================================== -if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit -help -exit -else +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.tmp fi -if [ "$CREATE" == "TRUE" ]; then -if [ -e $NOTE -o -e ${NOTE%.*} ]; then - -echo "" -echo "ERROR: Note already exists" -echo "Hint: use -e to edit the note." -echo "" -exit -else -#Create any necessary folders -mkdir -p $NOTEDIR - -#Fill in title -echo "TITLE: $NAME" > $NOTE -#Fill the second line with the date -echo "DATE: $(date)" >> $NOTE - -if [ "$ENCRYPTION" == "TRUE" ]; then -if [ $EDIT == "FALSE" ]; then -openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY -fi -fi -fi -fi -# delete.sns.sh - -if [ "$DELETE" == "TRUE" ]; then -if [ -e $NOTE -o -e ${NOTE%.*} ]; then -if [ "$ENCRYPTION" == "TRUE" ]; then -rm ${NOTE%.*} -else -rm $NOTE -fi - -echo "" -echo "Deleted note: $NOTEBOOK/$SECTION$NAME." -exit -else - -echo "" -echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." -exit -fi -fi -#========================================================================== -# Subection: Edit -#========================================================================== -if [ "$EDIT" == "TRUE" ]; then -if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then -if [ -z "$CREATE" ]; then -if [ "$ENCRYPTION" == "TRUE" ]; then -TMP_NAME=$ROOTDIR/tmp/$RANDOM -openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME -echo "" >> $TMP_NAME -echo "EDIT $(date)" >> $TMP_NAME -else -echo "" >> $NOTE -echo "EDIT $(date)" >> $NOTE -fi -fi -$EDITOR $NOTE -if [ "$ENCRYPTION" == "TRUE" ]; then -openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY -rm $NOTE -fi - -else -echo "" -echo "ERROR: Note cannot be opened for editting." -echo "" -fi -fi - -fi -#========================================================================== -# Subection: Print -#========================================================================== -if [ "$PRINT" == "TRUE" ]; then -if [ -r "$NOTE" -o -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 -else - -echo "" -echo "ERROR: Note cannot be found." -echo "" - -fi -fi - -fi -# list.sns.sh - -if [ -n "$LIST" ]; then -NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. -if [ -z "$NOTEBOOK" ]; then -echo " ERROR: Insufficient arguments" -help -exit -else -if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then - -echo "" -printf "Notes in $(basename $NOTEBOOK):" -echo "" -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: $NOTE\n" -fi -LAST_SECTION=$NOTE -else -#if [ $(($i % 1)) -eq 0 ]; then -# printf "\n " -#fi -printf " $NOTE\n" -fi -let i++ -done -printf "\n" -else -echo "" -echo "ERROR: Notebook $NOTEBOOK does not exist." -echo "" -fi -fi -exit -fi diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index 91cdc64..c31e0a4 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -13,18 +13,22 @@ 5DE8397B1AB9D629006CB4F6 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = ""; }; 5DE8397C1AB9D64B006CB4F6 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = ""; }; 5DE8397D1AB9D694006CB4F6 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = ""; }; - 5DE8397E1AB9D72D006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = ""; }; 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = ""; }; 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = ""; }; 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = wconf.sns.sh; sourceTree = ""; }; 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; + 5DE839841AB9FDF9006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; + 5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = ""; }; + 5DE839861AB9FF14006CB4F6 /* init_default_config.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = init_default_config.sns.sh; sourceTree = ""; }; + 5DE839881ABA04DD006CB4F6 /* errors.ref */ = {isa = PBXFileReference; lastKnownFileType = text; path = errors.ref; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ 5D7E61181AB74D11001D49B9 = { isa = PBXGroup; children = ( + 5DE839881ABA04DD006CB4F6 /* errors.ref */, 5DE839831AB9DACE006CB4F6 /* sns.sh */, 5DE839791AB9D5F8006CB4F6 /* init */, 5D7E611F1AB74D33001D49B9 /* build.sh */, @@ -35,10 +39,12 @@ 5DE839751AB9D41B006CB4F6 /* functions */ = { isa = PBXGroup; children = ( + 5DE839861AB9FF14006CB4F6 /* init_default_config.sns.sh */, 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */, + 5DE839841AB9FDF9006CB4F6 /* help.sns.sh */, + 5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */, 5DE839761AB9D42F006CB4F6 /* list.sns.sh */, 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */, - 5DE8397E1AB9D72D006CB4F6 /* help.sns.sh */, 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */, 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */, 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */, From 64e504ebcbaa5a363f91f43bd18ef88ff82d0e1a Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Thu, 7 May 2015 21:23:12 -0500 Subject: [PATCH 06/52] v2.0a3 -> v2.0a4 Rearranged tree to be more sane. Made formatting changes to stage 2. Fixed a bug where edit would be bypassed if the note was just created. --- build.sh | 3 +- functions/create.sns.sh | 62 ++++++---- functions/edit.sns.sh | 41 ++++--- functions/init_default_config.sns.sh | 12 ++ functions/p_header.sh | 3 + functions/{wconf.sns.sh => w_conf.sns.sh} | 2 +- init/stage1.sns.sh | 4 +- init/stage2.sns.sh | 4 +- init/stage3.sns.sh | 7 +- sns.sh | 135 +++++++++++++--------- sns.xcodeproj/project.pbxproj | 6 +- 11 files changed, 170 insertions(+), 109 deletions(-) mode change 100644 => 100755 build.sh create mode 100644 functions/p_header.sh rename functions/{wconf.sns.sh => w_conf.sns.sh} (96%) mode change 100644 => 100755 sns.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 397e97b..8b308d4 --- a/build.sh +++ b/build.sh @@ -17,9 +17,10 @@ EOF echo "# Section: Functions" >> $S cat ./functions/init_default_config.sns.sh >> $S -cat ./functions/wconf.sns.sh >> $S +cat ./functions/w_conf.sns.sh >> $S cat ./functions/pause.sns.sh >> $S cat ./functions/help.sns.sh >> $S +cat ./functions/p_header.sh >> $S cat ./functions/create.sns.sh >> $S cat ./functions/delete.sns.sh >> $S cat ./functions/edit.sns.sh >> $S diff --git a/functions/create.sns.sh b/functions/create.sns.sh index 80447ab..cb6519e 100644 --- a/functions/create.sns.sh +++ b/functions/create.sns.sh @@ -1,28 +1,42 @@ +#function create(){ +# +# #Check if note exists +# if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then +# echo "" +# echo "ERROR: Note already exists" +# echo "Hint: use -e to edit the note." +# echo "" +# exit +# else +# #Create any necessary folders +# mkdir -p $NOTEDIR +# +# #Fill in title +# echo "TITLE: $NAME" > $NOTE +# #Fill the second line with the date +# echo "DATE: $(date)" >> $NOTE +# +# if [ "$ENCRYPTION" == "TRUE" ]; then +# if [ "$EDIT" == "FALSE" ]; then +# echo " openssl enc -aes-256-cbc -salt -in $NOTE -out $NOTE.enc -pass pass:$ENC_KEY" +# fi +# fi +# fi +#} + function create(){ - if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit - help - exit - elif [ "$CREATE" == "TRUE" ]; then - if [ -e $NOTE -o -e ${NOTE%.*} ]; then - echo "" - echo "ERROR: Note already exists" - echo "Hint: use -e to edit the note." - echo "" - exit - else - #Create any necessary folders - mkdir -p $NOTEDIR + if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then + printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" + exit + elif [ -z "$ENCRYPTION" ]; then + echo "TITLE: $NAME" > $NOTE + echo "DATE: $(date)" >> $NOTE + elif [ "$ENCRYPTION" == "TRUE" ]; then + mkdir -p "$NOTEDIR" + touch "$NOTE" + echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ + -pass pass:$ENC_KEY - #Fill in title - echo "TITLE: $NAME" > $NOTE - #Fill the second line with the date - echo "DATE: $(date)" >> $NOTE - - if [ "$ENCRYPTION" == "TRUE" ]; then - if [ $EDIT == "FALSE" ]; then - openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY - fi - fi - fi fi + echo "$NOTE" } diff --git a/functions/edit.sns.sh b/functions/edit.sns.sh index 140a117..1fb0181 100644 --- a/functions/edit.sns.sh +++ b/functions/edit.sns.sh @@ -1,27 +1,26 @@ function edit (){ - if [ "$EDIT" == "TRUE" ]; then - if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - TMP_NAME=$ROOTDIR/tmp/$RANDOM - openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME - echo "" >> $TMP_NAME - echo "EDIT $(date)" >> $TMP_NAME - else - echo "" >> $NOTE - echo "EDIT $(date)" >> $NOTE - fi - fi - $EDITOR $NOTE + if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then + #Pre-Processing (Encryption) + if [ -z "$CREATE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY - rm $NOTE + TMP_NAME="$ROOTDIR"/tmp/"$RANDOM" + openssl enc -d -aes-256-cbc -in $NOTE -pass pass:$ENC_KEY > $TMP_NAME + echo "" >> $TMP_NAME + echo "EDIT $(date)" >> $TMP_NAME + $EDITOR $TMP_NAME + else + echo "" >> $NOTE + echo "EDIT $(date)" >> $NOTE + $EDITOR $NOTE fi - - else - echo "" - echo "ERROR: Note cannot be opened for editting." - echo "" fi + #Post-Processing (Encryption) + if [ "$ENCRYPTION" == "TRUE" ]; then + openssl enc -aes-256-cbc -salt -in $TMP_NAME -out $NOTE -pass pass:$ENC_KEY + rm "$TMP_NAME" + fi + + else + printf "\nERROR: Note cannot be opened for editting.\n" fi } diff --git a/functions/init_default_config.sns.sh b/functions/init_default_config.sns.sh index 5bdd1dd..9ed8c69 100644 --- a/functions/init_default_config.sns.sh +++ b/functions/init_default_config.sns.sh @@ -1,7 +1,19 @@ function init_default_config() { +if [ -z "$ROOTDIR" ]; then ROOTDIR=$HOME/.sns +fi +if [ -z "$BASEDIR" ]; then BASEDIR=$ROOTDIR/notes +fi +if [ -z "$EXT" ]; then EXT=note +fi +if [ -z "$EDITOR" ]; then EDITOR=vim +fi +if [ -z "$ENC_KEY" ]; then ENCRYPTION="FALSE" +else + ENCRYPTION="TRUE" +fi } diff --git a/functions/p_header.sh b/functions/p_header.sh new file mode 100644 index 0000000..537085a --- /dev/null +++ b/functions/p_header.sh @@ -0,0 +1,3 @@ +function p_header(){ + printf "TITLE: $NAME\nDATE: $(date)\n" +} diff --git a/functions/wconf.sns.sh b/functions/w_conf.sns.sh similarity index 96% rename from functions/wconf.sns.sh rename to functions/w_conf.sns.sh index b6ea422..4ac6034 100644 --- a/functions/wconf.sns.sh +++ b/functions/w_conf.sns.sh @@ -1,4 +1,4 @@ -function writeconf { +function w_conf { cat > $HOME/.sns/sns.conf << EOF #========================================================== # Simple Note System Config, v2.0a1 diff --git a/init/stage1.sns.sh b/init/stage1.sns.sh index 89ab8d2..5647731 100644 --- a/init/stage1.sns.sh +++ b/init/stage1.sns.sh @@ -17,7 +17,7 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" -EXT="$EXT.enc" +EXT="$EXT" if [ ! -d ~/.sns/tmp ]; then mkdir -p ~/.sns/tmp fi @@ -36,5 +36,5 @@ pause fi #============================================================================== -# End Section: Read Configuration +# End Section: Configuration #============================================================================== diff --git a/init/stage2.sns.sh b/init/stage2.sns.sh index 03ece6c..fd8bf45 100644 --- a/init/stage2.sns.sh +++ b/init/stage2.sns.sh @@ -19,7 +19,7 @@ else #Assume the user wants to do something. elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit + elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit else if [ -z "$NAME" -a -n $ARG ]; then NAME=$ARG @@ -36,7 +36,7 @@ else #Assume the user wants to do something. fi fi -# Note: writeconf has highest priority, and it is the only function that can +# Note: w_conf has highest priority, and it is the only function that can # work without any parameters. #============================================================================== diff --git a/init/stage3.sns.sh b/init/stage3.sns.sh index c9dd616..73b9276 100644 --- a/init/stage3.sns.sh +++ b/init/stage3.sns.sh @@ -25,6 +25,7 @@ fi NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ NOTE=$NOTEDIR$NAME.$EXT -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.tmp fi - - +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; fi +if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi +if [ "$CREATE" == "TRUE" ]; then create; fi +if [ "$EDIT" == "TRUE" ]; then edit; fi \ No newline at end of file diff --git a/sns.sh b/sns.sh old mode 100644 new mode 100755 index 75b48fd..cede94d --- a/sns.sh +++ b/sns.sh @@ -9,13 +9,25 @@ VER_STR="v2.0a3" # Section: Functions function init_default_config() { +if [ -z "$ROOTDIR" ]; then ROOTDIR=$HOME/.sns +fi +if [ -z "$BASEDIR" ]; then BASEDIR=$ROOTDIR/notes +fi +if [ -z "$EXT" ]; then EXT=note +fi +if [ -z "$EDITOR" ]; then EDITOR=vim +fi +if [ -z "$ENC_KEY" ]; then ENCRYPTION="FALSE" +else + ENCRYPTION="TRUE" +fi } -function writeconf { +function w_conf { cat > $HOME/.sns/sns.conf << EOF #========================================================== # Simple Note System Config, v2.0a1 @@ -62,33 +74,50 @@ function help { echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" echo "" } +function p_header(){ + printf "TITLE: $NAME\nDATE: $(date)\n" +} +#function create(){ +# +# #Check if note exists +# if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then +# echo "" +# echo "ERROR: Note already exists" +# echo "Hint: use -e to edit the note." +# echo "" +# exit +# else +# #Create any necessary folders +# mkdir -p $NOTEDIR +# +# #Fill in title +# echo "TITLE: $NAME" > $NOTE +# #Fill the second line with the date +# echo "DATE: $(date)" >> $NOTE +# +# if [ "$ENCRYPTION" == "TRUE" ]; then +# if [ "$EDIT" == "FALSE" ]; then +# echo " openssl enc -aes-256-cbc -salt -in $NOTE -out $NOTE.enc -pass pass:$ENC_KEY" +# fi +# fi +# fi +#} + function create(){ - if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit - help - exit - elif [ "$CREATE" == "TRUE" ]; then - if [ -e $NOTE -o -e ${NOTE%.*} ]; then - echo "" - echo "ERROR: Note already exists" - echo "Hint: use -e to edit the note." - echo "" - exit - else - #Create any necessary folders - mkdir -p $NOTEDIR + if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then + printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" + exit + elif [ -z "$ENCRYPTION" ]; then + echo "TITLE: $NAME" > $NOTE + echo "DATE: $(date)" >> $NOTE + elif [ "$ENCRYPTION" == "TRUE" ]; then + mkdir -p "$NOTEDIR" + touch "$NOTE" + echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ + -pass pass:$ENC_KEY - #Fill in title - echo "TITLE: $NAME" > $NOTE - #Fill the second line with the date - echo "DATE: $(date)" >> $NOTE - - if [ "$ENCRYPTION" == "TRUE" ]; then - if [ $EDIT == "FALSE" ]; then - openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY - fi - fi - fi fi + echo "$NOTE" } function delete(){ if [ "$DELETE" == "TRUE" ]; then @@ -109,30 +138,29 @@ function delete(){ fi } function edit (){ - if [ "$EDIT" == "TRUE" ]; then - if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - TMP_NAME=$ROOTDIR/tmp/$RANDOM - openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME - echo "" >> $TMP_NAME - echo "EDIT $(date)" >> $TMP_NAME - else - echo "" >> $NOTE - echo "EDIT $(date)" >> $NOTE - fi - fi - $EDITOR $NOTE + if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then + #Pre-Processing (Encryption) + if [ -z "$CREATE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY - rm $NOTE + TMP_NAME="$ROOTDIR"/tmp/"$RANDOM" + openssl enc -d -aes-256-cbc -in $NOTE -pass pass:$ENC_KEY > $TMP_NAME + echo "" >> $TMP_NAME + echo "EDIT $(date)" >> $TMP_NAME + $EDITOR $TMP_NAME + else + echo "" >> $NOTE + echo "EDIT $(date)" >> $NOTE + $EDITOR $NOTE fi - - else - echo "" - echo "ERROR: Note cannot be opened for editting." - echo "" fi + #Post-Processing (Encryption) + if [ "$ENCRYPTION" == "TRUE" ]; then + openssl enc -aes-256-cbc -salt -in $TMP_NAME -out $NOTE -pass pass:$ENC_KEY + rm "$TMP_NAME" + fi + + else + printf "\nERROR: Note cannot be opened for editting.\n" fi } function print(){ @@ -203,7 +231,7 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" -EXT="$EXT.enc" +EXT="$EXT" if [ ! -d ~/.sns/tmp ]; then mkdir -p ~/.sns/tmp fi @@ -222,7 +250,7 @@ pause fi #============================================================================== -# End Section: Read Configuration +# End Section: Configuration #============================================================================== #============================================================================== # Section: Argument Parsing @@ -245,7 +273,7 @@ else #Assume the user wants to do something. elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit + elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit else if [ -z "$NAME" -a -n $ARG ]; then NAME=$ARG @@ -262,7 +290,7 @@ else #Assume the user wants to do something. fi fi -# Note: writeconf has highest priority, and it is the only function that can +# Note: w_conf has highest priority, and it is the only function that can # work without any parameters. #============================================================================== @@ -295,6 +323,7 @@ fi NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ NOTE=$NOTEDIR$NAME.$EXT -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.tmp fi - - +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; fi +if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi +if [ "$CREATE" == "TRUE" ]; then create; fi +if [ "$EDIT" == "TRUE" ]; then edit; fi \ No newline at end of file diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index c31e0a4..a1b54d1 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXFileReference section */ + 5D5625481AC8A26500D6E1B5 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = ""; }; 5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = ""; }; 5DE839761AB9D42F006CB4F6 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = ""; }; 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = ""; }; @@ -16,7 +17,7 @@ 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = ""; }; 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = ""; }; 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = ""; }; - 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = wconf.sns.sh; sourceTree = ""; }; + 5DE839821AB9DAA6006CB4F6 /* w_conf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = w_conf.sns.sh; sourceTree = ""; }; 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; 5DE839841AB9FDF9006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; 5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = ""; }; @@ -40,12 +41,13 @@ isa = PBXGroup; children = ( 5DE839861AB9FF14006CB4F6 /* init_default_config.sns.sh */, - 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */, + 5DE839821AB9DAA6006CB4F6 /* w_conf.sns.sh */, 5DE839841AB9FDF9006CB4F6 /* help.sns.sh */, 5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */, 5DE839761AB9D42F006CB4F6 /* list.sns.sh */, 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */, 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */, + 5D5625481AC8A26500D6E1B5 /* p_header.sh */, 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */, 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */, ); From 3cb375f64b6c4d80b64e03e829a5c75c5c1d2ac1 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Thu, 7 May 2015 22:11:13 -0500 Subject: [PATCH 07/52] 2.0a4 -> 2.0a5 Changed some filenames Rewrote edit function to be more sane Separated encryption and decryption functions from edit into libencryption.sh Fixed a bug where an edit tag would be added regardless of create status --- build.sh | 33 +- errors.ref | 12 - functions/edit.sns.sh | 26 -- init/stage2.sns.sh | 44 --- sns.sh | 119 +++---- sns.xcodeproj/project.pbxproj | 97 +++--- .../WorkspaceSettings.xcsettings | 10 + sns1.sh | 316 ++++++++++++++++++ {functions => src/includes}/create.sns.sh | 12 +- .../includes/defaults.sh | 0 {functions => src/includes}/delete.sns.sh | 0 src/includes/edit.sns.sh | 21 ++ {functions => src/includes}/help.sns.sh | 0 src/includes/libencryption.sh | 8 + {functions => src/includes}/list.sns.sh | 0 {functions => src/includes}/p_header.sh | 0 {functions => src/includes}/pause.sns.sh | 0 {functions => src/includes}/print.sns.sh | 0 {functions => src/includes}/w_conf.sns.sh | 4 +- {init => src/main}/stage1.sns.sh | 0 src/main/stage2.sns.sh | 41 +++ {init => src/main}/stage3.sns.sh | 5 +- 22 files changed, 540 insertions(+), 208 deletions(-) delete mode 100644 errors.ref delete mode 100644 functions/edit.sns.sh delete mode 100644 init/stage2.sns.sh create mode 100644 sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/WorkspaceSettings.xcsettings create mode 100644 sns1.sh rename {functions => src/includes}/create.sns.sh (87%) rename functions/init_default_config.sns.sh => src/includes/defaults.sh (100%) rename {functions => src/includes}/delete.sns.sh (100%) create mode 100644 src/includes/edit.sns.sh rename {functions => src/includes}/help.sns.sh (100%) create mode 100644 src/includes/libencryption.sh rename {functions => src/includes}/list.sns.sh (100%) rename {functions => src/includes}/p_header.sh (100%) rename {functions => src/includes}/pause.sns.sh (100%) rename {functions => src/includes}/print.sns.sh (100%) rename {functions => src/includes}/w_conf.sns.sh (92%) rename {init => src/main}/stage1.sns.sh (100%) create mode 100644 src/main/stage2.sns.sh rename {init => src/main}/stage3.sns.sh (90%) diff --git a/build.sh b/build.sh index 8b308d4..a41ef91 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ S=sns.sh PROD_STR="Simple Note System" -VER_STR=v2.0a3 +VER_STR=v2.0a4 cat > $S << EOF #!/bin/bash @@ -15,21 +15,22 @@ VER_STR="$VER_STR" EOF -echo "# Section: Functions" >> $S -cat ./functions/init_default_config.sns.sh >> $S -cat ./functions/w_conf.sns.sh >> $S -cat ./functions/pause.sns.sh >> $S -cat ./functions/help.sns.sh >> $S -cat ./functions/p_header.sh >> $S -cat ./functions/create.sns.sh >> $S -cat ./functions/delete.sns.sh >> $S -cat ./functions/edit.sns.sh >> $S -cat ./functions/print.sns.sh >> $S -cat ./functions/list.sns.sh >> $S -echo "# End Section: Functions" >> $S -cat ./init/stage1.sns.sh >> $S -cat ./init/stage2.sns.sh >> $S -cat ./init/stage3.sns.sh >> $S +echo "# Section: Functions" >> $S +cat ./src/includes/defaults.sh >> $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 "# End Section: Functions" >> $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 deleted file mode 100644 index ce7c5f3..0000000 --- a/errors.ref +++ /dev/null @@ -1,12 +0,0 @@ -Simple Note System, version 2 -Error Code Reference - -General------------------------------------------------------------------------- -ERR_NO_ARGS 10 No arguments were specified -ERR_NO_OP 20 -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 diff --git a/functions/edit.sns.sh b/functions/edit.sns.sh deleted file mode 100644 index 1fb0181..0000000 --- a/functions/edit.sns.sh +++ /dev/null @@ -1,26 +0,0 @@ -function edit (){ - if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then - #Pre-Processing (Encryption) - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - TMP_NAME="$ROOTDIR"/tmp/"$RANDOM" - openssl enc -d -aes-256-cbc -in $NOTE -pass pass:$ENC_KEY > $TMP_NAME - echo "" >> $TMP_NAME - echo "EDIT $(date)" >> $TMP_NAME - $EDITOR $TMP_NAME - else - echo "" >> $NOTE - echo "EDIT $(date)" >> $NOTE - $EDITOR $NOTE - fi - fi - #Post-Processing (Encryption) - if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -aes-256-cbc -salt -in $TMP_NAME -out $NOTE -pass pass:$ENC_KEY - rm "$TMP_NAME" - fi - - else - printf "\nERROR: Note cannot be opened for editting.\n" - fi -} diff --git a/init/stage2.sns.sh b/init/stage2.sns.sh deleted file mode 100644 index fd8bf45..0000000 --- a/init/stage2.sns.sh +++ /dev/null @@ -1,44 +0,0 @@ -#============================================================================== -# Section: Argument Parsing -#============================================================================== - -NAME="" -NOTEBOOK="" -SECTION="" - -if [ -z "$1" ]; then #If no input was given, print help - help - exit 20 -else #Assume the user wants to do something. - ARGS=( "$@" ) - for ARG in ${ARGS[@]};do - if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" - elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" - elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" - elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" - elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" - elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" - elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit - else - if [ -z "$NAME" -a -n $ARG ]; then - NAME=$ARG - elif [ -z "$NOTEBOOK" -a -n $ARG ]; then - NOTEBOOK=$ARG - elif [ -z "$SECTION" -a -n $ARG ]; then - SECTION=$ARG - fi - fi - done - if [ -n "$NAME" -a -z "$NOTEBOOK" ]; then - NOTEBOOK="$NAME" - NAME="" - fi -fi - -# Note: w_conf has highest priority, and it is the only function that can -# work without any parameters. - -#============================================================================== -# End Section: Argument Parsing -#============================================================================== diff --git a/sns.sh b/sns.sh index cede94d..434f2f4 100755 --- a/sns.sh +++ b/sns.sh @@ -1,11 +1,11 @@ #!/bin/bash #========================================================== -# Simple Note System, v2.0a3 +# Simple Note System, v2.0a4 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== PROD_STR="Simple Note System" -VER_STR="v2.0a3" +VER_STR="v2.0a4" # Section: Functions function init_default_config() { @@ -42,7 +42,9 @@ BASEDIR=$ROOTDIR/notes EXT=note #Preferred Editor -EDITOR=vim +if [ -z "$EDITOR" ]; then + EDITOR=vim +fi #Encryption #WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST @@ -77,6 +79,14 @@ function help { function p_header(){ printf "TITLE: $NAME\nDATE: $(date)\n" } +function encrypt(){ + openssl enc -aes-256-cbc -salt -in "$TARGET" -out "$NOTE" -pass pass:"$ENC_KEY" +} + +function decrypt(){ + TARGET="$ROOTDIR"/tmp/"$RANDOM" + openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET" +} #function create(){ # # #Check if note exists @@ -107,15 +117,17 @@ function create(){ if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit - elif [ -z "$ENCRYPTION" ]; then + else + mkdir -p "$NOTEDIR" + fi + + if [ -z "$ENCRYPTION" ]; then echo "TITLE: $NAME" > $NOTE echo "DATE: $(date)" >> $NOTE elif [ "$ENCRYPTION" == "TRUE" ]; then - mkdir -p "$NOTEDIR" touch "$NOTE" - echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ - -pass pass:$ENC_KEY - + echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ + -pass pass:$ENC_KEY fi echo "$NOTE" } @@ -137,31 +149,26 @@ function delete(){ fi fi } -function edit (){ - if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then - #Pre-Processing (Encryption) - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - TMP_NAME="$ROOTDIR"/tmp/"$RANDOM" - openssl enc -d -aes-256-cbc -in $NOTE -pass pass:$ENC_KEY > $TMP_NAME - echo "" >> $TMP_NAME - echo "EDIT $(date)" >> $TMP_NAME - $EDITOR $TMP_NAME - else - echo "" >> $NOTE - echo "EDIT $(date)" >> $NOTE - $EDITOR $NOTE - fi - fi - #Post-Processing (Encryption) - if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -aes-256-cbc -salt -in $TMP_NAME -out $NOTE -pass pass:$ENC_KEY - rm "$TMP_NAME" - fi +function edit(){ +if [ ! -r "$NOTE" ]; then + echo "ERROR: Note cannot be opened for editing." + exit 40; +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then decrypt +else TARGET="$NOTE"; fi + + +if [ -z "$CREATE" ]; then printf "\nEDIT $(date)" >> "$TARGET"; fi + + + +"$EDITOR" "$TARGET" + +if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi + + - else - printf "\nERROR: Note cannot be opened for editting.\n" - fi } function print(){ if [ "$PRINT" == "TRUE" ]; then @@ -259,39 +266,36 @@ fi NAME="" NOTEBOOK="" SECTION="" - -if [ -z "$1" ]; then #If no input was given, print help - help - exit 20 -else #Assume the user wants to do something. +if [ -z "$1" ]; then help; exit 20 +else ARGS=( "$@" ) - for ARG in ${ARGS[@]};do - if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" - elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" - elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" - elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" - elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" - elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" - elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit + for ARG in ${ARGS[@]}; do + if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" + elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" + elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" + elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE" + elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" + elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" + elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 + elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit 0 else - if [ -z "$NAME" -a -n $ARG ]; then - NAME=$ARG - elif [ -z "$NOTEBOOK" -a -n $ARG ]; then - NOTEBOOK=$ARG - elif [ -z "$SECTION" -a -n $ARG ]; then - SECTION=$ARG + if [ -z "$NAME" -a -n $ARG ]; then NAME="$ARG" + elif [ -z "$NOTEBOOK" -a -n $ARG ]; then NOTEBOOK="$ARG" + elif [ -z "$SECTION" -a -n $ARG ]; then SECTION="$ARG" fi fi done - if [ -n "$NAME" -a -z "$NOTEBOOK" ]; then + if [ -n "$NAME" -a -z "$NOTEBOOK" -a -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 has highest priority, and it is the only function that can -# work without any parameters. +# Note: w_conf and help have highest priority, as they are the only functions +# that can work without any parameters. #============================================================================== # End Section: Argument Parsing @@ -307,7 +311,6 @@ if [ -z "$NOTEBOOK" ]; then fi if [ -n "$LIST" ]; then - list exit 0 fi @@ -320,8 +323,8 @@ if [ -z "$NAME" ]; then exit 30 fi -NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ -NOTE=$NOTEDIR$NAME.$EXT +NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ +NOTE="$NOTEDIR""$NAME"."$EXT" if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index a1b54d1..6dec092 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -7,70 +7,80 @@ objects = { /* Begin PBXFileReference section */ - 5D5625481AC8A26500D6E1B5 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = ""; }; + 5D22D6A21AFC4F5A0036DC52 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = ""; }; + 5D22D6A31AFC4F5A0036DC52 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = ""; }; + 5D22D6A41AFC4F5A0036DC52 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = ""; }; + 5D22D6A51AFC4F5A0036DC52 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; + 5D22D6A61AFC4F5A0036DC52 /* defaults.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = defaults.sh; sourceTree = ""; }; + 5D22D6A71AFC4F5A0036DC52 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = ""; }; + 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 = ""; }; + 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 = ""; }; 5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = ""; }; - 5DE839761AB9D42F006CB4F6 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = ""; }; - 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = ""; }; - 5DE8397B1AB9D629006CB4F6 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = ""; }; - 5DE8397C1AB9D64B006CB4F6 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = ""; }; - 5DE8397D1AB9D694006CB4F6 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = ""; }; - 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = ""; }; - 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = ""; }; - 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = ""; }; - 5DE839821AB9DAA6006CB4F6 /* w_conf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = w_conf.sns.sh; sourceTree = ""; }; 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; - 5DE839841AB9FDF9006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; - 5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = ""; }; - 5DE839861AB9FF14006CB4F6 /* init_default_config.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = init_default_config.sns.sh; sourceTree = ""; }; 5DE839881ABA04DD006CB4F6 /* errors.ref */ = {isa = PBXFileReference; lastKnownFileType = text; path = errors.ref; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ + 5D22D6A01AFC4F5A0036DC52 /* src */ = { + isa = PBXGroup; + children = ( + 5D22D6A11AFC4F5A0036DC52 /* includes */, + 5D22D6AC1AFC4F5A0036DC52 /* main */, + ); + path = src; + sourceTree = ""; + }; + 5D22D6A11AFC4F5A0036DC52 /* includes */ = { + isa = PBXGroup; + children = ( + 5D22D6A21AFC4F5A0036DC52 /* create.sns.sh */, + 5D22D6A31AFC4F5A0036DC52 /* delete.sns.sh */, + 5D22D6A41AFC4F5A0036DC52 /* edit.sns.sh */, + 5D22D6A51AFC4F5A0036DC52 /* help.sns.sh */, + 5D22D6A61AFC4F5A0036DC52 /* defaults.sh */, + 5D22D6A71AFC4F5A0036DC52 /* list.sns.sh */, + 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */, + 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, + 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */, + 5D22D6AB1AFC4F5A0036DC52 /* w_conf.sns.sh */, + 5D22D6B01AFC5B100036DC52 /* libencryption.sh */, + ); + path = includes; + sourceTree = ""; + }; + 5D22D6AC1AFC4F5A0036DC52 /* main */ = { + isa = PBXGroup; + children = ( + 5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */, + 5D22D6AE1AFC4F5A0036DC52 /* stage2.sns.sh */, + 5D22D6AF1AFC4F5A0036DC52 /* stage3.sns.sh */, + ); + path = main; + sourceTree = ""; + }; 5D7E61181AB74D11001D49B9 = { isa = PBXGroup; children = ( + 5D22D6A01AFC4F5A0036DC52 /* src */, 5DE839881ABA04DD006CB4F6 /* errors.ref */, 5DE839831AB9DACE006CB4F6 /* sns.sh */, - 5DE839791AB9D5F8006CB4F6 /* init */, 5D7E611F1AB74D33001D49B9 /* build.sh */, - 5DE839751AB9D41B006CB4F6 /* functions */, ); sourceTree = ""; }; - 5DE839751AB9D41B006CB4F6 /* functions */ = { - isa = PBXGroup; - children = ( - 5DE839861AB9FF14006CB4F6 /* init_default_config.sns.sh */, - 5DE839821AB9DAA6006CB4F6 /* w_conf.sns.sh */, - 5DE839841AB9FDF9006CB4F6 /* help.sns.sh */, - 5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */, - 5DE839761AB9D42F006CB4F6 /* list.sns.sh */, - 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */, - 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */, - 5D5625481AC8A26500D6E1B5 /* p_header.sh */, - 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */, - 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */, - ); - path = functions; - sourceTree = ""; - }; - 5DE839791AB9D5F8006CB4F6 /* init */ = { - isa = PBXGroup; - children = ( - 5DE8397D1AB9D694006CB4F6 /* stage3.sns.sh */, - 5DE8397B1AB9D629006CB4F6 /* stage1.sns.sh */, - 5DE8397C1AB9D64B006CB4F6 /* stage2.sns.sh */, - ); - path = init; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXProject section */ 5D7E61191AB74D11001D49B9 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0620; + LastUpgradeCheck = 0630; }; buildConfigurationList = 5D7E611C1AB74D11001D49B9 /* Build configuration list for PBXProject "sns" */; compatibilityVersion = "Xcode 3.2"; @@ -91,6 +101,7 @@ 5D7E611D1AB74D11001D49B9 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ONLY_ACTIVE_ARCH = YES; }; name = Debug; }; diff --git a/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/WorkspaceSettings.xcsettings b/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..659c876 --- /dev/null +++ b/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/WorkspaceSettings.xcsettings @@ -0,0 +1,10 @@ + + + + + HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges + + SnapshotAutomaticallyBeforeSignificantChanges + + + diff --git a/sns1.sh b/sns1.sh new file mode 100644 index 0000000..e1c251f --- /dev/null +++ b/sns1.sh @@ -0,0 +1,316 @@ +#!/bin/bash +#========================================================== +# Simple Note System, v1.1 +# Copyright 2014, Xenese Labs/Sicron-Perion XNF +#========================================================== + +PROD_STR="Simple Note System" +VER_STR=v1.1 + +#============================================================================== +# Section: Helper Functions +#============================================================================== +function writeconf { +cat > $HOME/.sns << EOF +#========================================================== +# Simple Note System Config, v1.1 +# Copyright 2014, Xenese Labs/Sicron-Perion XNF +#========================================================== + +#Directory where notes will be stored +BASEDIR=$HOME/notes + +#File extension to use (for listing notes) +EXT=note + +#Preferred Editor +EDITOR=vim + +#Encryption +#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST +ENCRYPTION="FALSE" +ENC_KEY="" +EOF + +chmod 600 $HOME/.sns +} + +function help { + echo "" + echo "usage: sns [-ce] NAME NOTEBOOK SECTION" + echo " sns [-d ] NAME NOTEBOOK SECTION" + echo " sns [-l ] NOTEBOOK" + echo " sns [-w ]" + + echo "" + echo " -c | --create : Create note" + echo " -d | --delete : Delete note" + echo " -e | --edit : Open note for editing" + echo " -p | --print : Print note to console" + echo " -l | --list : List all notes in NOTEBOOK" + echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" + echo "" +} + +function pause { + read -p " Press [Enter] to continue." + echo "" +} + +#============================================================================== +# End Section: Helper Functions +#============================================================================== + +#============================================================================== +# Section: Configuration +#============================================================================== +if [ -r $HOME/.sns ]; then + source $HOME/.sns +else + BASEDIR=$HOME/notes + EDITOR=vim + EXT=note +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then + if [ -z "$ENC_KEY" ]; then + ERR_NO_KEY="TRUE" + ENCRYPTION="FALSE" + pause + fi + command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then + PROD_STR="Simple Note System (Encryption Enabled)" + EXT="$EXT.enc" + if [ ! -d ~/.tmp ]; then + mkdir -p ~/.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." +fi + +if [ -n "$ERR_NO_SSL" -o -n "$ERR_NO_KEY" ]; then + pause +fi + +#============================================================================== +# End Section: Read Configuration +#============================================================================== + + +#============================================================================== +# Section: Argument Parsing +#============================================================================== + +NAME="" +NOTEBOOK="" +SECTION="" + +if [ -z "$1" ]; then #If no input was given, print help + help + exit +else #Assume the user wants to do something. + ARGS=( "$@" ) + for ARG in ${ARGS[@]};do + if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" + elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" + elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" + elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" + elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" + elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" + elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 + elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit + else + if [ -z "$NAME" -a -n $ARG ]; then + NAME=$ARG + echo "Name: $NAME" + elif [ -z "$NOTEBOOK" -a -n $ARG ]; then + NOTEBOOK=$ARG + echo "Notebook: $NOTEBOOK" + elif [ -z "$SECTION" -a -n $ARG ]; then + SECTION=$ARG + echo "Section: $SECTION" + fi + fi + done +fi + +#============================================================================== +# End Section: Argument Parsing +#============================================================================== + +#============================================================================== +# Section: Main +#============================================================================== + + NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ + NOTE=$NOTEDIR$NAME.$EXT + + if [ "$ENCRYPTION" == "TRUE" ]; then + NOTE=$NOTE.tmp + fi + + #========================================================================== + # Subection: List + #========================================================================== + if [ -n "$LIST" ]; then + NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. + if [ -z "$NOTEBOOK" ]; then + echo " ERROR: Insufficient arguments" + help + exit + else + if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then + + echo "" + printf "Notes in $(basename $NOTEBOOK):" + echo "" + 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: $NOTE\n" + fi + LAST_SECTION=$NOTE + else + #if [ $(($i % 1)) -eq 0 ]; then + # printf "\n " + #fi + printf " $NOTE\n" + fi + let i++ + done + printf "\n" + else + echo "" + echo "ERROR: Notebook $NOTEBOOK does not exist." + echo "" + fi + fi + exit + fi + #====================================================================== + # Sanity Check - Actions below require a valid $NAME and $NOTEBOOK + #====================================================================== + if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then + echo " ERROR: Insufficient arguments" + help + exit 10 + fi + #========================================================================== + # Subection: Delete + #========================================================================== + if [ "$DELETE" == "TRUE" ]; then + if [ -e $NOTE -o -e ${NOTE%.*} ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + rm ${NOTE%.*} + else + rm $NOTE + fi + + echo "" + echo "Deleted note: $NOTEBOOK/$SECTION$NAME." + exit + else + + echo "" + echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." + exit + fi + fi + + #========================================================================== + # Subection: Create + #========================================================================== + if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit + help + exit + else + + + if [ "$CREATE" == "TRUE" ]; then + if [ -e $NOTE -o -e ${NOTE%.*} ]; then + + echo "" + echo "ERROR: Note already exists" + echo "Hint: use -e to edit the note." + echo "" + exit + else + #Create any necessary folders + mkdir -p $NOTEDIR + + #Fill in title + echo "TITLE: $NAME" > $NOTE + #Fill the second line with the date + echo "DATE: $(date)" >> $NOTE + + if [ "$ENCRYPTION" == "TRUE" ]; then + if [ $EDIT == "FALSE" ]; then + openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY + fi + fi + fi + fi + + #========================================================================== + # Subection: Edit + #========================================================================== + if [ "$EDIT" == "TRUE" ]; then + if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then + if [ -z "$CREATE" ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then + openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $NOTE + fi + echo "" >> $NOTE + echo "EDIT $(date)" >> $NOTE + fi + $EDITOR $NOTE + if [ "$ENCRYPTION" == "TRUE" ]; then + openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY + rm $NOTE + fi + + else + + echo "" + echo "ERROR: Note cannot be opened for editting." + echo "" + + fi + fi + +fi + #========================================================================== + # Subection: Print + #========================================================================== + if [ "$PRINT" == "TRUE" ]; then + if [ -r "$NOTE" -o -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 + else + + echo "" + echo "ERROR: Note cannot be found." + echo "" + + fi + fi + +fi + +exit diff --git a/functions/create.sns.sh b/src/includes/create.sns.sh similarity index 87% rename from functions/create.sns.sh rename to src/includes/create.sns.sh index cb6519e..cedeaa9 100644 --- a/functions/create.sns.sh +++ b/src/includes/create.sns.sh @@ -28,15 +28,17 @@ function create(){ if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit - elif [ -z "$ENCRYPTION" ]; then + else + mkdir -p "$NOTEDIR" + fi + + if [ -z "$ENCRYPTION" ]; then echo "TITLE: $NAME" > $NOTE echo "DATE: $(date)" >> $NOTE elif [ "$ENCRYPTION" == "TRUE" ]; then - mkdir -p "$NOTEDIR" touch "$NOTE" - echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ - -pass pass:$ENC_KEY - + echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ + -pass pass:$ENC_KEY fi echo "$NOTE" } diff --git a/functions/init_default_config.sns.sh b/src/includes/defaults.sh similarity index 100% rename from functions/init_default_config.sns.sh rename to src/includes/defaults.sh diff --git a/functions/delete.sns.sh b/src/includes/delete.sns.sh similarity index 100% rename from functions/delete.sns.sh rename to src/includes/delete.sns.sh diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh new file mode 100644 index 0000000..a0c5477 --- /dev/null +++ b/src/includes/edit.sns.sh @@ -0,0 +1,21 @@ +function edit(){ +if [ ! -r "$NOTE" ]; then + echo "ERROR: Note cannot be opened for editing." + exit 40; +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then decrypt +else TARGET="$NOTE"; fi + + +if [ -z "$CREATE" ]; then printf "\nEDIT $(date)" >> "$TARGET"; fi + + + +"$EDITOR" "$TARGET" + +if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi + + + +} diff --git a/functions/help.sns.sh b/src/includes/help.sns.sh similarity index 100% rename from functions/help.sns.sh rename to src/includes/help.sns.sh diff --git a/src/includes/libencryption.sh b/src/includes/libencryption.sh new file mode 100644 index 0000000..392bf8d --- /dev/null +++ b/src/includes/libencryption.sh @@ -0,0 +1,8 @@ +function encrypt(){ + openssl enc -aes-256-cbc -salt -in "$TARGET" -out "$NOTE" -pass pass:"$ENC_KEY" +} + +function decrypt(){ + TARGET="$ROOTDIR"/tmp/"$RANDOM" + openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET" +} diff --git a/functions/list.sns.sh b/src/includes/list.sns.sh similarity index 100% rename from functions/list.sns.sh rename to src/includes/list.sns.sh diff --git a/functions/p_header.sh b/src/includes/p_header.sh similarity index 100% rename from functions/p_header.sh rename to src/includes/p_header.sh diff --git a/functions/pause.sns.sh b/src/includes/pause.sns.sh similarity index 100% rename from functions/pause.sns.sh rename to src/includes/pause.sns.sh diff --git a/functions/print.sns.sh b/src/includes/print.sns.sh similarity index 100% rename from functions/print.sns.sh rename to src/includes/print.sns.sh diff --git a/functions/w_conf.sns.sh b/src/includes/w_conf.sns.sh similarity index 92% rename from functions/w_conf.sns.sh rename to src/includes/w_conf.sns.sh index 4ac6034..d934cc1 100644 --- a/functions/w_conf.sns.sh +++ b/src/includes/w_conf.sns.sh @@ -13,7 +13,9 @@ BASEDIR=$ROOTDIR/notes EXT=note #Preferred Editor -EDITOR=vim +if [ -z "$EDITOR" ]; then + EDITOR=vim +fi #Encryption #WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST diff --git a/init/stage1.sns.sh b/src/main/stage1.sns.sh similarity index 100% rename from init/stage1.sns.sh rename to src/main/stage1.sns.sh diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh new file mode 100644 index 0000000..5694d64 --- /dev/null +++ b/src/main/stage2.sns.sh @@ -0,0 +1,41 @@ +#============================================================================== +# Section: Argument Parsing +#============================================================================== + +NAME="" +NOTEBOOK="" +SECTION="" +if [ -z "$1" ]; then help; exit 20 +else + ARGS=( "$@" ) + for ARG in ${ARGS[@]}; do + if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" + elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" + elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" + elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE" + elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" + elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" + elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 + elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit 0 + else + if [ -z "$NAME" -a -n $ARG ]; then NAME="$ARG" + elif [ -z "$NOTEBOOK" -a -n $ARG ]; then NOTEBOOK="$ARG" + elif [ -z "$SECTION" -a -n $ARG ]; then SECTION="$ARG" + fi + fi + done + if [ -n "$NAME" -a -z "$NOTEBOOK" -a -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 parameters. + +#============================================================================== +# End Section: Argument Parsing +#============================================================================== diff --git a/init/stage3.sns.sh b/src/main/stage3.sns.sh similarity index 90% rename from init/stage3.sns.sh rename to src/main/stage3.sns.sh index 73b9276..1aa53e4 100644 --- a/init/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -9,7 +9,6 @@ if [ -z "$NOTEBOOK" ]; then fi if [ -n "$LIST" ]; then - list exit 0 fi @@ -22,8 +21,8 @@ if [ -z "$NAME" ]; then exit 30 fi -NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ -NOTE=$NOTEDIR$NAME.$EXT +NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ +NOTE="$NOTEDIR""$NAME"."$EXT" if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi From cc2a235c9e7384a1defbb4a7a157b5c9ae591464 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Thu, 7 May 2015 22:14:43 -0500 Subject: [PATCH 08/52] Accidentally deleted errors.ref --- errors.ref | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 errors.ref diff --git a/errors.ref b/errors.ref new file mode 100644 index 0000000..ce7c5f3 --- /dev/null +++ b/errors.ref @@ -0,0 +1,12 @@ +Simple Note System, version 2 +Error Code Reference + +General------------------------------------------------------------------------- +ERR_NO_ARGS 10 No arguments were specified +ERR_NO_OP 20 +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 From 21b457c38c4dd38b6fafe3ac8c4f4fdb85c3860f Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Thu, 14 May 2015 23:23:57 -0500 Subject: [PATCH 09/52] Officially changed version string to 2.0a5; no other changes --- build.sh | 2 +- src/includes/w_conf.sns.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index a41ef91..6a073c3 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ S=sns.sh PROD_STR="Simple Note System" -VER_STR=v2.0a4 +VER_STR=v2.0a5 cat > $S << EOF #!/bin/bash diff --git a/src/includes/w_conf.sns.sh b/src/includes/w_conf.sns.sh index d934cc1..eab3a6c 100644 --- a/src/includes/w_conf.sns.sh +++ b/src/includes/w_conf.sns.sh @@ -1,7 +1,7 @@ function w_conf { cat > $HOME/.sns/sns.conf << EOF #========================================================== -# Simple Note System Config, v2.0a1 +# Simple Note System Config, v2.0a5 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== From 9334f3ba45888dc505b00b84c9569682ad5bdeb4 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Jun 2015 00:23:33 -0500 Subject: [PATCH 10/52] Made configuration directory static Moved header variables to new file Started sanitizing variable references --- build.sh | 49 ++++++++++++----------------------- header.sh | 11 ++++++++ sns.sh | 45 ++++++++++---------------------- sns.xcodeproj/project.pbxproj | 4 +-- src/includes/defaults.sh | 19 -------------- src/includes/help.sns.sh | 2 +- src/includes/w_conf.sns.sh | 9 +++---- src/main/stage1.sns.sh | 7 ++--- 8 files changed, 51 insertions(+), 95 deletions(-) create mode 100644 header.sh delete mode 100644 src/includes/defaults.sh diff --git a/build.sh b/build.sh index 6a073c3..3b30651 100755 --- a/build.sh +++ b/build.sh @@ -1,37 +1,20 @@ S=sns.sh -PROD_STR="Simple Note System" -VER_STR=v2.0a5 - -cat > $S << EOF -#!/bin/bash -#========================================================== -# $PROD_STR, $VER_STR -# Copyright 2014, Xenese Labs/Sicron-Perion XNF -#========================================================== - -PROD_STR="$PROD_STR" -VER_STR="$VER_STR" - -EOF - -echo "# Section: Functions" >> $S -cat ./src/includes/defaults.sh >> $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 "# End Section: Functions" >> $S -cat ./src/main/stage1.sns.sh >> $S -cat ./src/main/stage2.sns.sh >> $S -cat ./src/main/stage3.sns.sh >> $S - - +cat 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" exit diff --git a/header.sh b/header.sh new file mode 100644 index 0000000..d298d7e --- /dev/null +++ b/header.sh @@ -0,0 +1,11 @@ +#!/bin/bash +#========================================================== +# $PROD_STR, $VER_STR +# Copyright 2014, Xenese Labs/Sicron-Perion XNF +#========================================================== + +PROD_STR="Simple Note System" +VER_STR="v2.0a5" +ROOTDIR=$HOME/.config/sns +BASEDIR="$ROOTDIR"/notes +CONFIGURATION="$ROOTDIR/sns.conf" diff --git a/sns.sh b/sns.sh index 434f2f4..190b2c2 100755 --- a/sns.sh +++ b/sns.sh @@ -1,43 +1,24 @@ #!/bin/bash #========================================================== -# Simple Note System, v2.0a4 +# $PROD_STR, $VER_STR # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== PROD_STR="Simple Note System" -VER_STR="v2.0a4" +VER_STR="v2.0a5" +ROOTDIR=$HOME/.config/sns +BASEDIR="$ROOTDIR"/notes +CONFIGURATION="$ROOTDIR/sns.conf" # Section: Functions -function init_default_config() { -if [ -z "$ROOTDIR" ]; then - ROOTDIR=$HOME/.sns -fi -if [ -z "$BASEDIR" ]; then - BASEDIR=$ROOTDIR/notes -fi -if [ -z "$EXT" ]; then - EXT=note -fi -if [ -z "$EDITOR" ]; then - EDITOR=vim -fi -if [ -z "$ENC_KEY" ]; then - ENCRYPTION="FALSE" -else - ENCRYPTION="TRUE" -fi -} function w_conf { -cat > $HOME/.sns/sns.conf << EOF +if [ ! -r "$ROOTDIR" ]; then mkdir -p $ROOTDIR; fi +cat > "$CONFIGURATION" << EOF #========================================================== -# Simple Note System Config, v2.0a1 +# Simple Note System Config, v2.0a5 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -#Directory where notes will be stored -ROOTDIR=$HOME/.sns -BASEDIR=$ROOTDIR/notes - #File extension to use (for listing notes) EXT=note @@ -52,7 +33,7 @@ ENCRYPTION="FALSE" ENC_KEY="" EOF -chmod 600 $ROOTDIR/sns.conf +chmod 600 "$CONFIGURATION" } function pause { read -p " Press [Enter] to continue." @@ -219,13 +200,15 @@ function list(){ fi } # End Section: Functions + #============================================================================== # Section: Configuration #============================================================================== -if [ -r $HOME/.sns/sns.conf ]; then - source $HOME/.sns/sns.conf +if [ -r "$CONFIGURATION" ]; then + source "$CONFIGURATION" else - init_default_config + w_conf + source "$CONFIGURATION" fi if [ "$ENCRYPTION" == "TRUE" ]; then diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index 6dec092..6c96cd3 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 5D22D6A31AFC4F5A0036DC52 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = ""; }; 5D22D6A41AFC4F5A0036DC52 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = ""; }; 5D22D6A51AFC4F5A0036DC52 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; - 5D22D6A61AFC4F5A0036DC52 /* defaults.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = defaults.sh; sourceTree = ""; }; 5D22D6A71AFC4F5A0036DC52 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = ""; }; 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 = ""; }; @@ -22,6 +21,7 @@ 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 = ""; }; 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 = ""; }; 5DE839881ABA04DD006CB4F6 /* errors.ref */ = {isa = PBXFileReference; lastKnownFileType = text; path = errors.ref; sourceTree = ""; }; /* End PBXFileReference section */ @@ -43,7 +43,6 @@ 5D22D6A31AFC4F5A0036DC52 /* delete.sns.sh */, 5D22D6A41AFC4F5A0036DC52 /* edit.sns.sh */, 5D22D6A51AFC4F5A0036DC52 /* help.sns.sh */, - 5D22D6A61AFC4F5A0036DC52 /* defaults.sh */, 5D22D6A71AFC4F5A0036DC52 /* list.sns.sh */, 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */, 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, @@ -71,6 +70,7 @@ 5DE839881ABA04DD006CB4F6 /* errors.ref */, 5DE839831AB9DACE006CB4F6 /* sns.sh */, 5D7E611F1AB74D33001D49B9 /* build.sh */, + 5D7E91FB1B27FB620030B30D /* header.sh */, ); sourceTree = ""; }; diff --git a/src/includes/defaults.sh b/src/includes/defaults.sh deleted file mode 100644 index 9ed8c69..0000000 --- a/src/includes/defaults.sh +++ /dev/null @@ -1,19 +0,0 @@ -function init_default_config() { -if [ -z "$ROOTDIR" ]; then - ROOTDIR=$HOME/.sns -fi -if [ -z "$BASEDIR" ]; then - BASEDIR=$ROOTDIR/notes -fi -if [ -z "$EXT" ]; then - EXT=note -fi -if [ -z "$EDITOR" ]; then - EDITOR=vim -fi -if [ -z "$ENC_KEY" ]; then - ENCRYPTION="FALSE" -else - ENCRYPTION="TRUE" -fi -} diff --git a/src/includes/help.sns.sh b/src/includes/help.sns.sh index 0727bd6..e6b9802 100644 --- a/src/includes/help.sns.sh +++ b/src/includes/help.sns.sh @@ -13,6 +13,6 @@ function help { echo " -h | --help : Display this message" echo " -p | --print : Print note to console" echo " -l | --list : List all notes in NOTEBOOK" - echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" + echo " -w | --wconf : Rewrite default configuration" echo "" } diff --git a/src/includes/w_conf.sns.sh b/src/includes/w_conf.sns.sh index eab3a6c..98917c0 100644 --- a/src/includes/w_conf.sns.sh +++ b/src/includes/w_conf.sns.sh @@ -1,14 +1,11 @@ function w_conf { -cat > $HOME/.sns/sns.conf << EOF +if [ ! -r "$ROOTDIR" ]; then mkdir -p $ROOTDIR; fi +cat > "$CONFIGURATION" << EOF #========================================================== # Simple Note System Config, v2.0a5 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -#Directory where notes will be stored -ROOTDIR=$HOME/.sns -BASEDIR=$ROOTDIR/notes - #File extension to use (for listing notes) EXT=note @@ -23,5 +20,5 @@ ENCRYPTION="FALSE" ENC_KEY="" EOF -chmod 600 $ROOTDIR/sns.conf +chmod 600 "$CONFIGURATION" } diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 5647731..6b701fb 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -1,10 +1,11 @@ #============================================================================== # Section: Configuration #============================================================================== -if [ -r $HOME/.sns/sns.conf ]; then - source $HOME/.sns/sns.conf +if [ -r "$CONFIGURATION" ]; then + source "$CONFIGURATION" else - init_default_config + w_conf + source "$CONFIGURATION" fi if [ "$ENCRYPTION" == "TRUE" ]; then From 121abb1df7a68b8b0c8493fb0110bd5939b70091 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Jun 2015 08:35:16 -0500 Subject: [PATCH 11/52] Further sanitization of variables; checks out with shellcheck.net now --- header.sh | 4 ++- sns.sh | 62 ++++++++++++++++++-------------------- src/includes/create.sns.sh | 10 +++--- src/includes/delete.sns.sh | 6 ++-- src/includes/edit.sns.sh | 4 +-- src/includes/list.sns.sh | 16 +++++----- src/includes/p_header.sh | 2 +- src/includes/print.sns.sh | 8 ++--- src/includes/w_conf.sns.sh | 2 +- src/main/stage2.sns.sh | 10 +++--- 10 files changed, 60 insertions(+), 64 deletions(-) diff --git a/header.sh b/header.sh index d298d7e..e5d7bbb 100644 --- a/header.sh +++ b/header.sh @@ -4,8 +4,10 @@ # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== +if [ -z "$HOME" ]; then HOME=/home/$(whoami); fi + PROD_STR="Simple Note System" VER_STR="v2.0a5" -ROOTDIR=$HOME/.config/sns +ROOTDIR="$HOME"/.config/sns BASEDIR="$ROOTDIR"/notes CONFIGURATION="$ROOTDIR/sns.conf" diff --git a/sns.sh b/sns.sh index 190b2c2..5045781 100755 --- a/sns.sh +++ b/sns.sh @@ -4,15 +4,17 @@ # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== +if [ -z "$HOME" ]; then HOME=/home/$(whoami); fi + PROD_STR="Simple Note System" VER_STR="v2.0a5" -ROOTDIR=$HOME/.config/sns +ROOTDIR="$HOME"/.config/sns BASEDIR="$ROOTDIR"/notes CONFIGURATION="$ROOTDIR/sns.conf" # Section: Functions function w_conf { -if [ ! -r "$ROOTDIR" ]; then mkdir -p $ROOTDIR; fi +if [ ! -r "$ROOTDIR" ]; then mkdir -p "$ROOTDIR"; fi cat > "$CONFIGURATION" << EOF #========================================================== # Simple Note System Config, v2.0a5 @@ -54,11 +56,11 @@ function help { echo " -h | --help : Display this message" echo " -p | --print : Print note to console" echo " -l | --list : List all notes in NOTEBOOK" - echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" + echo " -w | --wconf : Rewrite default configuration" echo "" } function p_header(){ - printf "TITLE: $NAME\nDATE: $(date)\n" + printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" } function encrypt(){ openssl enc -aes-256-cbc -salt -in "$TARGET" -out "$NOTE" -pass pass:"$ENC_KEY" @@ -95,7 +97,7 @@ function decrypt(){ #} function create(){ - if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then + if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else @@ -103,22 +105,22 @@ function create(){ fi if [ -z "$ENCRYPTION" ]; then - echo "TITLE: $NAME" > $NOTE - echo "DATE: $(date)" >> $NOTE + echo "TITLE: $NAME" > "$NOTE" + echo "DATE: $(date)" >> "$NOTE" elif [ "$ENCRYPTION" == "TRUE" ]; then touch "$NOTE" - echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ - -pass pass:$ENC_KEY + p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ + -pass pass:"$ENC_KEY" fi echo "$NOTE" } function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e $NOTE -o -e ${NOTE%.*} ]; then + if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then - rm ${NOTE%.*} + rm "${NOTE%.*}" else - rm $NOTE + rm "$NOTE" fi echo "" echo "Deleted note: $NOTEBOOK/$SECTION$NAME." @@ -140,9 +142,7 @@ if [ "$ENCRYPTION" == "TRUE" ]; then decrypt else TARGET="$NOTE"; fi -if [ -z "$CREATE" ]; then printf "\nEDIT $(date)" >> "$TARGET"; fi - - +if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi "$EDITOR" "$TARGET" @@ -153,13 +153,13 @@ if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi } function print(){ if [ "$PRINT" == "TRUE" ]; then - if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then + if [ -r "$NOTE" -o -r "${NOTE%.*}" ]; then if [ -z "$CREATE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY + openssl enc -d -aes-256-cbc -in "${NOTE%.*}" -pass pass:"$ENC_KEY" else - cat $NOTE - echo "" >> $NOTE + cat "$NOTE" + echo "" >> "$NOTE" fi else echo "" @@ -172,23 +172,21 @@ function print(){ } function list(){ if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then - echo "" - printf "Notes in $(basename $NOTEBOOK):" - echo "" + 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 "/" " ") ) + 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 + for NOTE in "${NOTES[@]}"; do + if [ -d "$BASEDIR"/"$NOTEBOOK"/"$NOTE" ]; then if [ "$LAST_SECTION" != "$NOTE" ]; then - printf " Section: $NOTE\n" + printf " Section: %s\n" "$NOTE" fi - LAST_SECTION=$NOTE + LAST_SECTION="$NOTE" else #if [ $(($i % 1)) -eq 0 ]; then # printf "\n " #fi - printf " $NOTE\n" + printf " %s\n" "$NOTE" fi let i++ done @@ -252,7 +250,7 @@ SECTION="" if [ -z "$1" ]; then help; exit 20 else ARGS=( "$@" ) - for ARG in ${ARGS[@]}; do + for ARG in "${ARGS[@]}"; do if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" @@ -262,9 +260,9 @@ else elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit 0 else - if [ -z "$NAME" -a -n $ARG ]; then NAME="$ARG" - elif [ -z "$NOTEBOOK" -a -n $ARG ]; then NOTEBOOK="$ARG" - elif [ -z "$SECTION" -a -n $ARG ]; then SECTION="$ARG" + if [ -z "$NAME" -a -n "$ARG" ]; then NAME="$ARG" + elif [ -z "$NOTEBOOK" -a -n "$ARG" ]; then NOTEBOOK="$ARG" + elif [ -z "$SECTION" -a -n "$ARG" ]; then SECTION="$ARG" fi fi done diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index cedeaa9..bcec402 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -25,7 +25,7 @@ #} function create(){ - if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then + if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else @@ -33,12 +33,12 @@ function create(){ fi if [ -z "$ENCRYPTION" ]; then - echo "TITLE: $NAME" > $NOTE - echo "DATE: $(date)" >> $NOTE + echo "TITLE: $NAME" > "$NOTE" + echo "DATE: $(date)" >> "$NOTE" elif [ "$ENCRYPTION" == "TRUE" ]; then touch "$NOTE" - echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\ - -pass pass:$ENC_KEY + p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ + -pass pass:"$ENC_KEY" fi echo "$NOTE" } diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index dafe3e7..25f3608 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -1,10 +1,10 @@ function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e $NOTE -o -e ${NOTE%.*} ]; then + if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then - rm ${NOTE%.*} + rm "${NOTE%.*}" else - rm $NOTE + rm "$NOTE" fi echo "" echo "Deleted note: $NOTEBOOK/$SECTION$NAME." diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index a0c5477..e67afe4 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -8,9 +8,7 @@ if [ "$ENCRYPTION" == "TRUE" ]; then decrypt else TARGET="$NOTE"; fi -if [ -z "$CREATE" ]; then printf "\nEDIT $(date)" >> "$TARGET"; fi - - +if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi "$EDITOR" "$TARGET" diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index 797a065..7bc95b9 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,22 +1,20 @@ function list(){ if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then - echo "" - printf "Notes in $(basename $NOTEBOOK):" - echo "" + 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 "/" " ") ) + 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 + for NOTE in "${NOTES[@]}"; do + if [ -d "$BASEDIR"/"$NOTEBOOK"/"$NOTE" ]; then if [ "$LAST_SECTION" != "$NOTE" ]; then - printf " Section: $NOTE\n" + printf " Section: %s\n" "$NOTE" fi - LAST_SECTION=$NOTE + LAST_SECTION="$NOTE" else #if [ $(($i % 1)) -eq 0 ]; then # printf "\n " #fi - printf " $NOTE\n" + printf " %s\n" "$NOTE" fi let i++ done diff --git a/src/includes/p_header.sh b/src/includes/p_header.sh index 537085a..f3b1156 100644 --- a/src/includes/p_header.sh +++ b/src/includes/p_header.sh @@ -1,3 +1,3 @@ function p_header(){ - printf "TITLE: $NAME\nDATE: $(date)\n" + printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" } diff --git a/src/includes/print.sns.sh b/src/includes/print.sns.sh index c0a3aaf..4d99e02 100644 --- a/src/includes/print.sns.sh +++ b/src/includes/print.sns.sh @@ -1,12 +1,12 @@ function print(){ if [ "$PRINT" == "TRUE" ]; then - if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then + if [ -r "$NOTE" -o -r "${NOTE%.*}" ]; then if [ -z "$CREATE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY + openssl enc -d -aes-256-cbc -in "${NOTE%.*}" -pass pass:"$ENC_KEY" else - cat $NOTE - echo "" >> $NOTE + cat "$NOTE" + echo "" >> "$NOTE" fi else echo "" diff --git a/src/includes/w_conf.sns.sh b/src/includes/w_conf.sns.sh index 98917c0..5aadbb6 100644 --- a/src/includes/w_conf.sns.sh +++ b/src/includes/w_conf.sns.sh @@ -1,5 +1,5 @@ function w_conf { -if [ ! -r "$ROOTDIR" ]; then mkdir -p $ROOTDIR; fi +if [ ! -r "$ROOTDIR" ]; then mkdir -p "$ROOTDIR"; fi cat > "$CONFIGURATION" << EOF #========================================================== # Simple Note System Config, v2.0a5 diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 5694d64..48f63fe 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -8,7 +8,7 @@ SECTION="" if [ -z "$1" ]; then help; exit 20 else ARGS=( "$@" ) - for ARG in ${ARGS[@]}; do + for ARG in "${ARGS[@]}"; do if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" @@ -18,9 +18,9 @@ else elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit 0 else - if [ -z "$NAME" -a -n $ARG ]; then NAME="$ARG" - elif [ -z "$NOTEBOOK" -a -n $ARG ]; then NOTEBOOK="$ARG" - elif [ -z "$SECTION" -a -n $ARG ]; then SECTION="$ARG" + if [ -z "$NAME" -a -n "$ARG" ]; then NAME="$ARG" + elif [ -z "$NOTEBOOK" -a -n "$ARG" ]; then NOTEBOOK="$ARG" + elif [ -z "$SECTION" -a -n "$ARG" ]; then SECTION="$ARG" fi fi done @@ -34,7 +34,7 @@ else fi # Note: w_conf and help have highest priority, as they are the only functions -# that can work without any parameters. +# that can work without any arguments. #============================================================================== # End Section: Argument Parsing From d70d3b431270d9cea3dec15522d4608a41ccdb49 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Jun 2015 08:38:25 -0500 Subject: [PATCH 12/52] fixed bug in build script that caused incorrect header comment --- build.sh | 2 +- header.sh | 12 ++++++++++-- sns.sh | 13 +++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index 3b30651..a1f65a8 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ S=sns.sh -cat header.sh > "$S" +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" diff --git a/header.sh b/header.sh index e5d7bbb..c7b1aca 100644 --- a/header.sh +++ b/header.sh @@ -1,4 +1,10 @@ #!/bin/bash + +PROD_STR="Simple Note System" +VER_STR="v2.0a5" + +cat << EOF +#!/bin/bash #========================================================== # $PROD_STR, $VER_STR # Copyright 2014, Xenese Labs/Sicron-Perion XNF @@ -6,8 +12,10 @@ if [ -z "$HOME" ]; then HOME=/home/$(whoami); fi -PROD_STR="Simple Note System" -VER_STR="v2.0a5" +PROD_STR="$PROD_STR" +VER_STR="$VER_STR" ROOTDIR="$HOME"/.config/sns BASEDIR="$ROOTDIR"/notes CONFIGURATION="$ROOTDIR/sns.conf" + +EOF diff --git a/sns.sh b/sns.sh index 5045781..96a7e69 100755 --- a/sns.sh +++ b/sns.sh @@ -1,16 +1,17 @@ #!/bin/bash #========================================================== -# $PROD_STR, $VER_STR +# Simple Note System, v2.0a5 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -if [ -z "$HOME" ]; then HOME=/home/$(whoami); fi +if [ -z "/Users/xilmwa" ]; then HOME=/home/xilmwa; fi PROD_STR="Simple Note System" VER_STR="v2.0a5" -ROOTDIR="$HOME"/.config/sns -BASEDIR="$ROOTDIR"/notes -CONFIGURATION="$ROOTDIR/sns.conf" +ROOTDIR="/Users/xilmwa"/.config/sns +BASEDIR=""/notes +CONFIGURATION="/sns.conf" + # Section: Functions function w_conf { @@ -276,7 +277,7 @@ else fi # Note: w_conf and help have highest priority, as they are the only functions -# that can work without any parameters. +# that can work without any arguments. #============================================================================== # End Section: Argument Parsing From 9a9dbcc1719195551ff8bc32cede289e105d167f Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Jun 2015 08:39:49 -0500 Subject: [PATCH 13/52] Fixed bug in header script which caused default home directory to be mine, instead of $(whoami) --- header.sh | 2 +- sns.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/header.sh b/header.sh index c7b1aca..0cc33bb 100644 --- a/header.sh +++ b/header.sh @@ -10,7 +10,7 @@ cat << EOF # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -if [ -z "$HOME" ]; then HOME=/home/$(whoami); fi +if [ -z "$HOME" ]; then HOME=/home/"\$(whoami)"; fi PROD_STR="$PROD_STR" VER_STR="$VER_STR" diff --git a/sns.sh b/sns.sh index 96a7e69..3cfb2cb 100755 --- a/sns.sh +++ b/sns.sh @@ -4,7 +4,7 @@ # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -if [ -z "/Users/xilmwa" ]; then HOME=/home/xilmwa; fi +if [ -z "/Users/xilmwa" ]; then HOME=/home/"$(whoami)"; fi PROD_STR="Simple Note System" VER_STR="v2.0a5" From 6e7f4c3e95e0635929acdf60cc44f287e587ade5 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Jun 2015 08:43:01 -0500 Subject: [PATCH 14/52] Fixed a bug in header script which caused my home directory to be used instead of variables --- header.sh | 6 +++--- sns.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/header.sh b/header.sh index 0cc33bb..fc022e1 100644 --- a/header.sh +++ b/header.sh @@ -14,8 +14,8 @@ 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" +ROOTDIR="\$HOME"/.config/sns +BASEDIR="\$ROOTDIR"/notes +CONFIGURATION="\$ROOTDIR/sns.conf" EOF diff --git a/sns.sh b/sns.sh index 3cfb2cb..509ee1e 100755 --- a/sns.sh +++ b/sns.sh @@ -8,9 +8,9 @@ if [ -z "/Users/xilmwa" ]; then HOME=/home/"$(whoami)"; fi PROD_STR="Simple Note System" VER_STR="v2.0a5" -ROOTDIR="/Users/xilmwa"/.config/sns -BASEDIR=""/notes -CONFIGURATION="/sns.conf" +ROOTDIR="$HOME"/.config/sns +BASEDIR="$ROOTDIR"/notes +CONFIGURATION="$ROOTDIR/sns.conf" # Section: Functions From 337a1bf3a36632a7c06c24400303d2514375cb60 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sat, 19 Sep 2015 18:23:47 -0500 Subject: [PATCH 15/52] Replaced all [ p -o q ] with [ p ] || [ q ] and all [ p -a q ] with [ p ] && [ q ] --- sns.sh | 32 ++++++++++++++++---------------- src/includes/create.sns.sh | 2 +- src/includes/delete.sns.sh | 2 +- src/includes/print.sns.sh | 2 +- src/main/stage1.sns.sh | 2 +- src/main/stage2.sns.sh | 24 ++++++++++++------------ 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/sns.sh b/sns.sh index 509ee1e..2359cd7 100755 --- a/sns.sh +++ b/sns.sh @@ -98,7 +98,7 @@ function decrypt(){ #} function create(){ - if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else @@ -117,7 +117,7 @@ function create(){ } function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then rm "${NOTE%.*}" else @@ -154,7 +154,7 @@ if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi } function print(){ if [ "$PRINT" == "TRUE" ]; then - if [ -r "$NOTE" -o -r "${NOTE%.*}" ]; 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" @@ -234,7 +234,7 @@ if [ -n "$ERR_NO_KEY" ]; then echo " Warning: No encryption key was provided. Encryption disabled." fi -if [ -n "$ERR_NO_SSL" -o -n "$ERR_NO_KEY" ]; then +if [ -n "$ERR_NO_SSL" ] || [ -n "$ERR_NO_KEY" ]; then pause fi @@ -252,22 +252,22 @@ if [ -z "$1" ]; then help; exit 20 else ARGS=( "$@" ) for ARG in "${ARGS[@]}"; do - if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" - elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" - elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" - elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE" - elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" - elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" - elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit 0 + 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 w_conf; exit 0 else - if [ -z "$NAME" -a -n "$ARG" ]; then NAME="$ARG" - elif [ -z "$NOTEBOOK" -a -n "$ARG" ]; then NOTEBOOK="$ARG" - elif [ -z "$SECTION" -a -n "$ARG" ]; then SECTION="$ARG" + 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" -a -z "$NOTEBOOK" -a -n "$LIST" ]; then + 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. diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index bcec402..5559417 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -25,7 +25,7 @@ #} function create(){ - if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index 25f3608..2efdcd6 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -1,6 +1,6 @@ function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e "$NOTE" -o -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then rm "${NOTE%.*}" else diff --git a/src/includes/print.sns.sh b/src/includes/print.sns.sh index 4d99e02..6058435 100644 --- a/src/includes/print.sns.sh +++ b/src/includes/print.sns.sh @@ -1,6 +1,6 @@ function print(){ if [ "$PRINT" == "TRUE" ]; then - if [ -r "$NOTE" -o -r "${NOTE%.*}" ]; 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" diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 6b701fb..9a4b12d 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -32,7 +32,7 @@ if [ -n "$ERR_NO_KEY" ]; then echo " Warning: No encryption key was provided. Encryption disabled." fi -if [ -n "$ERR_NO_SSL" -o -n "$ERR_NO_KEY" ]; then +if [ -n "$ERR_NO_SSL" ] || [ -n "$ERR_NO_KEY" ]; then pause fi diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 48f63fe..debc0fa 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -9,22 +9,22 @@ if [ -z "$1" ]; then help; exit 20 else ARGS=( "$@" ) for ARG in "${ARGS[@]}"; do - if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" - elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" - elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" - elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE" - elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" - elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" - elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then w_conf; exit 0 + 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 w_conf; exit 0 else - if [ -z "$NAME" -a -n "$ARG" ]; then NAME="$ARG" - elif [ -z "$NOTEBOOK" -a -n "$ARG" ]; then NOTEBOOK="$ARG" - elif [ -z "$SECTION" -a -n "$ARG" ]; then SECTION="$ARG" + 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" -a -z "$NOTEBOOK" -a -n "$LIST" ]; then + 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. From 35094aed04ac9cf91495b34ef1366835047f419c Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sat, 19 Sep 2015 18:40:43 -0500 Subject: [PATCH 16/52] Fixed erroneous reference to former static ~/.sns BASEDIR Added hook to actually delete a note if requested Removed old, commented code Simplified create and delete logic by removing unnecessary checks that make no sense to me now Cleaned up output from create event --- sns.sh | 53 ++++++++++---------------------------- src/includes/create.sns.sh | 34 +++++------------------- src/includes/delete.sns.sh | 12 +++------ src/main/stage1.sns.sh | 4 +-- src/main/stage3.sns.sh | 3 ++- 5 files changed, 28 insertions(+), 78 deletions(-) diff --git a/sns.sh b/sns.sh index 2359cd7..4bc5972 100755 --- a/sns.sh +++ b/sns.sh @@ -71,34 +71,8 @@ function decrypt(){ TARGET="$ROOTDIR"/tmp/"$RANDOM" openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET" } -#function create(){ -# -# #Check if note exists -# if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then -# echo "" -# echo "ERROR: Note already exists" -# echo "Hint: use -e to edit the note." -# echo "" -# exit -# else -# #Create any necessary folders -# mkdir -p $NOTEDIR -# -# #Fill in title -# echo "TITLE: $NAME" > $NOTE -# #Fill the second line with the date -# echo "DATE: $(date)" >> $NOTE -# -# if [ "$ENCRYPTION" == "TRUE" ]; then -# if [ "$EDIT" == "FALSE" ]; then -# echo " openssl enc -aes-256-cbc -salt -in $NOTE -out $NOTE.enc -pass pass:$ENC_KEY" -# fi -# fi -# fi -#} - function create(){ - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else @@ -113,22 +87,22 @@ function create(){ p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ -pass pass:"$ENC_KEY" fi - echo "$NOTE" + + if [ -e "$NOTE" ]; then + echo "Created note: $NOTEBOOK/$SECTION/$NAME." + fi + } function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - rm "${NOTE%.*}" - else - rm "$NOTE" - fi + if [ -e "$NOTE" ]; then + rm "$NOTE" echo "" - echo "Deleted note: $NOTEBOOK/$SECTION$NAME." + echo "Deleted note: $NOTEBOOK/$SECTION/$NAME." exit else echo "" - echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." + echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." exit fi fi @@ -221,8 +195,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" EXT="$EXT" -if [ ! -d ~/.sns/tmp ]; then -mkdir -p ~/.sns/tmp +if [ ! -d "$BASEDIR"/tmp ]; then +mkdir -p "$BASEDIR"/tmp fi fi @@ -308,7 +282,8 @@ fi NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ NOTE="$NOTEDIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; 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 diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 5559417..e4a9fbc 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -1,31 +1,5 @@ -#function create(){ -# -# #Check if note exists -# if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then -# echo "" -# echo "ERROR: Note already exists" -# echo "Hint: use -e to edit the note." -# echo "" -# exit -# else -# #Create any necessary folders -# mkdir -p $NOTEDIR -# -# #Fill in title -# echo "TITLE: $NAME" > $NOTE -# #Fill the second line with the date -# echo "DATE: $(date)" >> $NOTE -# -# if [ "$ENCRYPTION" == "TRUE" ]; then -# if [ "$EDIT" == "FALSE" ]; then -# echo " openssl enc -aes-256-cbc -salt -in $NOTE -out $NOTE.enc -pass pass:$ENC_KEY" -# fi -# fi -# fi -#} - function create(){ - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then + if [ -e "$NOTE" ]; then printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" exit else @@ -40,5 +14,9 @@ function create(){ p_header | openssl enc -aes-256-cbc -salt -out "$NOTE"\ -pass pass:"$ENC_KEY" fi - echo "$NOTE" + + if [ -e "$NOTE" ]; then + echo "Created note: $NOTEBOOK/$SECTION/$NAME." + fi + } diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index 2efdcd6..f0b47dc 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -1,17 +1,13 @@ function delete(){ if [ "$DELETE" == "TRUE" ]; then - if [ -e "$NOTE" ] || [ -e "${NOTE%.*}" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - rm "${NOTE%.*}" - else - rm "$NOTE" - fi + if [ -e "$NOTE" ]; then + rm "$NOTE" echo "" - echo "Deleted note: $NOTEBOOK/$SECTION$NAME." + echo "Deleted note: $NOTEBOOK/$SECTION/$NAME." exit else echo "" - echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." + echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." exit fi fi diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 9a4b12d..45ea735 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -19,8 +19,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" EXT="$EXT" -if [ ! -d ~/.sns/tmp ]; then -mkdir -p ~/.sns/tmp +if [ ! -d "$BASEDIR"/tmp ]; then +mkdir -p "$BASEDIR"/tmp fi fi diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 1aa53e4..955713f 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -24,7 +24,8 @@ fi NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ NOTE="$NOTEDIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.enc; 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 From 631d52689e65cec5f132e8639e2ebe1ce97a2b74 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sat, 19 Sep 2015 19:12:00 -0500 Subject: [PATCH 17/52] Fixed another bug which causes my home directory to be referenced as opposed to generic "$HOME" --- header.sh | 2 +- sns.xcodeproj/project.pbxproj | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/header.sh b/header.sh index fc022e1..850669c 100644 --- a/header.sh +++ b/header.sh @@ -10,7 +10,7 @@ cat << EOF # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== -if [ -z "$HOME" ]; then HOME=/home/"\$(whoami)"; fi +if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi PROD_STR="$PROD_STR" VER_STR="$VER_STR" diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index 6c96cd3..c70fecd 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -80,7 +80,7 @@ 5D7E61191AB74D11001D49B9 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0630; + LastUpgradeCheck = 0700; }; buildConfigurationList = 5D7E611C1AB74D11001D49B9 /* Build configuration list for PBXProject "sns" */; compatibilityVersion = "Xcode 3.2"; @@ -101,6 +101,7 @@ 5D7E611D1AB74D11001D49B9 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ENABLE_TESTABILITY = YES; ONLY_ACTIVE_ARCH = YES; }; name = Debug; From 908b93242c52fba1bf6bd0453c624f5ca6685f32 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sat, 31 Oct 2015 14:24:33 -0500 Subject: [PATCH 18/52] Added initial readme --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..41e571c --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +Simple Note System +================== + +The Simple Note System is a shell script enabling easy management of plain-text +notes. SNS depends on OpenSSL for encryption and uses the vim editor by default. + + usage: sns [-ce] NAME NOTEBOOK SECTION" + sns [-d ] NAME NOTEBOOK SECTION" + sns [-lp] NOTEBOOK" + sns [-w ]" + sns [-h ]" + + -c | --create : Create note" + -d | --delete : Delete note" + -e | --edit : Open note for editing" + -h | --help : Display this message" + -p | --print : Print note to console" + -l | --list : List all notes in NOTEBOOK" + -w | --wconf : Rewrite default configuration" From 6a21731082bcd716236e477f06a5d192fbdf98ac Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 25 Jan 2016 17:20:05 -0600 Subject: [PATCH 19/52] Variable name reworking; laid foundation for GPG encryption (instead of OpenSSL) --- build.sh | 39 +++--- header.sh | 9 +- sns.sh | 127 ++++++++++++------ sns.xcodeproj/project.pbxproj | 4 +- src/includes/create.sns.sh | 2 +- .../{w_conf.sns.sh => create_sns_root.sns.sh} | 15 ++- src/includes/libencryption.sh | 16 ++- src/includes/list.sns.sh | 10 +- src/includes/pause.sns.sh | 2 +- src/main/stage1.sns.sh | 35 ++--- src/main/stage2.sns.sh | 6 +- src/main/stage3.sns.sh | 17 ++- 12 files changed, 180 insertions(+), 102 deletions(-) rename src/includes/{w_conf.sns.sh => create_sns_root.sns.sh} (68%) diff --git a/build.sh b/build.sh index a1f65a8..aad3dcc 100755 --- 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/header.sh b/header.sh index 850669c..5a9d6da 100644 --- a/header.sh +++ b/header.sh @@ -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 BASE_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 4bc5972..b4dac20 100755 --- a/sns.sh +++ b/sns.sh @@ -4,19 +4,24 @@ # 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.0a5" +readonly ROOT_DIR="$HOME"/.config/xenlabs/sns +readonly BASE_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 # Copyright 2014, Xenese Labs/Sicron-Perion XNF @@ -27,19 +32,22 @@ EXT=note #Preferred Editor if [ -z "$EDITOR" ]; then - EDITOR=vim + echo EDITOR=vim 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,19 +72,29 @@ 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, $TARGET; and an +# output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private +# GPG key. + +gpg -r "$PUBKEY" --encrypt-files "$TARGET" --output "$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, $TARGET; and an +# output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private +# GPG key. + + if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi + TARGET="$TMP_DIR/$RANDOM" + gpg -d "$NOTE" > "$TARGET" } 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 @@ -119,7 +137,7 @@ else TARGET="$NOTE"; fi if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi -"$EDITOR" "$TARGET" +echo "$EDITOR" "$TARGET" if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi @@ -146,13 +164,17 @@ function print(){ fi } function list(){ - if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then + if [ -d "$BASE_DIR"/"$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 "/" " ") ) + NOTES=( + $(find "$BASE_DIR"/"$NOTEBOOK" -name "*.$EXT" -print0 |\ + sed s:"$BASE_DIR"/"$NOTEBOOK"/: " " :g |\ + sed -e s:".$EXT"::g | tr "/" " ") + ) let i=0 for NOTE in "${NOTES[@]}"; do - if [ -d "$BASEDIR"/"$NOTEBOOK"/"$NOTE" ]; then + if [ -d "$BASE_DIR"/"$NOTEBOOK"/"$NOTE" ]; then if [ "$LAST_SECTION" != "$NOTE" ]; then printf " Section: %s\n" "$NOTE" fi @@ -174,33 +196,45 @@ function list(){ } # 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 openssl >/dev/null 2>&1 ||\ + { ERR_NO_SSL="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)" + EXT="$EXT".gpg + if [ ! -d "$BASE_DIR"/tmp ]; then + mkdir -p "$BASE_DIR"/tmp + fi fi echo "$PROD_STR, $VER_STR" + if [ -n "$ERR_NO_SSL" ]; then echo >&2 " Warning: OpenSSL not installed. Encryption disabled." fi @@ -213,10 +247,10 @@ pause fi #============================================================================== -# End Section: Configuration +# End Section: Configuration / Stage 1 #============================================================================== #============================================================================== -# Section: Argument Parsing +# Section: Argument Parsing / Stage 2 #============================================================================== NAME="" @@ -233,7 +267,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 +288,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 +313,16 @@ if [ -z "$NAME" ]; then exit 30 fi -NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ -NOTE="$NOTEDIR""$NAME"."$EXT" +SESSION_ID="$RANDOM" +NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ +NOTE="$NOTE_DIR""$NAME"."$EXT" 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/src/includes/create.sns.sh b/src/includes/create.sns.sh index e4a9fbc..29fddc0 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -3,7 +3,7 @@ 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 diff --git a/src/includes/w_conf.sns.sh b/src/includes/create_sns_root.sns.sh similarity index 68% rename from src/includes/w_conf.sns.sh rename to src/includes/create_sns_root.sns.sh index 5aadbb6..5e1b5ad 100644 --- a/src/includes/w_conf.sns.sh +++ b/src/includes/create_sns_root.sns.sh @@ -1,6 +1,10 @@ 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 # 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/libencryption.sh b/src/includes/libencryption.sh index 392bf8d..ed2215f 100644 --- a/src/includes/libencryption.sh +++ b/src/includes/libencryption.sh @@ -1,8 +1,18 @@ 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, $TARGET; and an +# output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private +# GPG key. + +gpg -r "$PUBKEY" --encrypt-files "$TARGET" --output "$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, $TARGET; and an +# output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private +# GPG key. + + if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi + TARGET="$TMP_DIR/$RANDOM" + gpg -d "$NOTE" > "$TARGET" } diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index 7bc95b9..3224a0c 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,11 +1,15 @@ function list(){ - if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then + if [ -d "$BASE_DIR"/"$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 "/" " ") ) + NOTES=( + $(find "$BASE_DIR"/"$NOTEBOOK" -name "*.$EXT" -print0 |\ + sed s:"$BASE_DIR"/"$NOTEBOOK"/: " " :g |\ + sed -e s:".$EXT"::g | tr "/" " ") + ) let i=0 for NOTE in "${NOTES[@]}"; do - if [ -d "$BASEDIR"/"$NOTEBOOK"/"$NOTE" ]; then + if [ -d "$BASE_DIR"/"$NOTEBOOK"/"$NOTE" ]; then if [ "$LAST_SECTION" != "$NOTE" ]; then printf " Section: %s\n" "$NOTE" 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/main/stage1.sns.sh b/src/main/stage1.sns.sh index 45ea735..06d1b2f 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -1,30 +1,33 @@ #============================================================================== -# 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 openssl >/dev/null 2>&1 ||\ + { ERR_NO_SSL="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)" + EXT="$EXT".gpg + if [ ! -d "$BASE_DIR"/tmp ]; then + mkdir -p "$BASE_DIR"/tmp + fi fi echo "$PROD_STR, $VER_STR" + if [ -n "$ERR_NO_SSL" ]; then echo >&2 " Warning: OpenSSL not installed. Encryption disabled." fi @@ -37,5 +40,5 @@ 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..6c640ff 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,16 @@ if [ -z "$NAME" ]; then exit 30 fi -NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/ -NOTE="$NOTEDIR""$NAME"."$EXT" +SESSION_ID="$RANDOM" +NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ +NOTE="$NOTE_DIR""$NAME"."$EXT" 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 From 8fc731aaa0f2f3f561b1b453184b0ce9fa4dda0c Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 25 Jan 2016 19:33:48 -0600 Subject: [PATCH 20/52] Progress. I can now create and edit notes reliably. --- errors.ref | 4 +-- header.sh | 2 +- sns.sh | 50 ++++++++++++++++++++--------------- src/includes/create.sns.sh | 6 ++--- src/includes/edit.sns.sh | 10 +++++-- src/includes/libencryption.sh | 2 +- src/main/stage1.sns.sh | 22 +++++++-------- src/main/stage3.sns.sh | 2 +- 8 files changed, 55 insertions(+), 43 deletions(-) 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 5a9d6da..5d4a8c4 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.0a6" cat << EOF #!/bin/bash diff --git a/sns.sh b/sns.sh index b4dac20..e7f57bc 100755 --- a/sns.sh +++ b/sns.sh @@ -1,13 +1,13 @@ #!/bin/bash #========================================================== -# Simple Note System, v2.0a5 +# Simple Note System, v2.0a6 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi PROD_STR="Simple Note System" -readonly VER_STR="v2.0a5" +readonly VER_STR="v2.0a6" readonly ROOT_DIR="$HOME"/.config/xenlabs/sns readonly BASE_DIR="$ROOT_DIR"/notes readonly TMP_DIR="$ROOT_DIR"/tmp @@ -32,7 +32,7 @@ EXT=note #Preferred Editor if [ -z "$EDITOR" ]; then - echo EDITOR=vim + EDITOR=vim fi #Encryption @@ -76,7 +76,7 @@ function encrypt(){ # output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private # GPG key. -gpg -r "$PUBKEY" --encrypt-files "$TARGET" --output "$NOTE" +gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET" } @@ -101,9 +101,9 @@ function create(){ 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" + TARGET="$TMP_DIR"/"$SESSION_ID" + p_header > "$TARGET" + encrypt fi if [ -e "$NOTE" ]; then @@ -131,15 +131,21 @@ if [ ! -r "$NOTE" ]; then exit 40; fi -if [ "$ENCRYPTION" == "TRUE" ]; then decrypt +if [ "$ENCRYPTION" == "TRUE" ]; then + cp "$NOTE" "$NOTE".bk + decrypt else TARGET="$NOTE"; fi if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi -echo "$EDITOR" "$TARGET" +"$EDITOR" "$TARGET" -if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi +if [ "$ENCRYPTION" == "TRUE" ]; then + rm "$NOTE" + encrypt; + if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi +fi @@ -221,13 +227,12 @@ if [ "$ENCRYPTION" == "TRUE" ]; then ENCRYPTION="FALSE" fi - command -v openssl >/dev/null 2>&1 ||\ - { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } + 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".gpg if [ ! -d "$BASE_DIR"/tmp ]; then mkdir -p "$BASE_DIR"/tmp fi @@ -235,16 +240,17 @@ 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 / Stage 1 @@ -317,7 +323,7 @@ SESSION_ID="$RANDOM" NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ NOTE="$NOTE_DIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".enc; fi +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".gpg; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$CREATE" == "TRUE" ]; then create; fi diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 29fddc0..403eae1 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -10,9 +10,9 @@ function create(){ 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" + TARGET="$TMP_DIR"/"$SESSION_ID" + p_header > "$TARGET" + encrypt fi if [ -e "$NOTE" ]; then diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index e67afe4..64014d6 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -4,7 +4,9 @@ if [ ! -r "$NOTE" ]; then exit 40; fi -if [ "$ENCRYPTION" == "TRUE" ]; then decrypt +if [ "$ENCRYPTION" == "TRUE" ]; then + cp "$NOTE" "$NOTE".bk + decrypt else TARGET="$NOTE"; fi @@ -12,7 +14,11 @@ if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TARGET"; fi "$EDITOR" "$TARGET" -if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi +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 ed2215f..a6fcec7 100644 --- a/src/includes/libencryption.sh +++ b/src/includes/libencryption.sh @@ -3,7 +3,7 @@ function encrypt(){ # output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private # GPG key. -gpg -r "$PUBKEY" --encrypt-files "$TARGET" --output "$NOTE" +gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET" } diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 06d1b2f..4cb45f7 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -14,13 +14,12 @@ if [ "$ENCRYPTION" == "TRUE" ]; then ENCRYPTION="FALSE" fi - command -v openssl >/dev/null 2>&1 ||\ - { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } + 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".gpg if [ ! -d "$BASE_DIR"/tmp ]; then mkdir -p "$BASE_DIR"/tmp fi @@ -28,16 +27,17 @@ 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 / Stage 1 diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 6c640ff..1686c7b 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -25,7 +25,7 @@ SESSION_ID="$RANDOM" NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ NOTE="$NOTE_DIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".enc; fi +if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".gpg; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$CREATE" == "TRUE" ]; then create; fi From 2d8db83c3c9ca44e072c457b7d006c3147658978 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 25 Jan 2016 21:00:43 -0600 Subject: [PATCH 21/52] Reworked print function --- header.sh | 2 +- sns.sh | 61 ++++++++--------------------------- src/includes/edit.sns.sh | 6 ++-- src/includes/libencryption.sh | 6 ++-- src/includes/list.sns.sh | 29 ++--------------- src/includes/print.sns.sh | 20 ++++-------- 6 files changed, 29 insertions(+), 95 deletions(-) diff --git a/header.sh b/header.sh index 5d4a8c4..7f582a6 100644 --- a/header.sh +++ b/header.sh @@ -1,7 +1,7 @@ #!/bin/bash PROD_STR="Simple Note System" -VER_STR="v2.0a6" +VER_STR="v2.0a7" cat << EOF #!/bin/bash diff --git a/sns.sh b/sns.sh index e7f57bc..7f07f64 100755 --- a/sns.sh +++ b/sns.sh @@ -76,7 +76,7 @@ function encrypt(){ # output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private # GPG key. -gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET" + gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET" } @@ -85,9 +85,7 @@ function decrypt(){ # output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private # GPG key. - if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi - TARGET="$TMP_DIR/$RANDOM" - gpg -d "$NOTE" > "$TARGET" + gpg -d "$NOTE" } function create(){ if [ -e "$NOTE" ]; then @@ -133,7 +131,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then cp "$NOTE" "$NOTE".bk - decrypt + if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi + decrypt > "$TMP_DIR/$RANDOM" else TARGET="$NOTE"; fi @@ -146,58 +145,26 @@ if [ "$ENCRYPTION" == "TRUE" ]; then 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 "$BASE_DIR"/"$NOTEBOOK" ]; then - printf "\nNotes in %s:\n" "$(basename "$NOTEBOOK")" - - NOTES=( - $(find "$BASE_DIR"/"$NOTEBOOK" -name "*.$EXT" -print0 |\ - sed s:"$BASE_DIR"/"$NOTEBOOK"/: " " :g |\ - sed -e s:".$EXT"::g | tr "/" " ") - ) - let i=0 - for NOTE in "${NOTES[@]}"; do - if [ -d "$BASE_DIR"/"$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++ + printf "+%s\n" "$NOTEBOOK" + find "$BASE_DIR"/"$NOTEBOOK" -type f | while read 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 diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index 64014d6..c260f8d 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -6,7 +6,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then cp "$NOTE" "$NOTE".bk - decrypt + if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi + decrypt > "$TMP_DIR/$RANDOM" else TARGET="$NOTE"; fi @@ -19,7 +20,4 @@ if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi fi - - - } diff --git a/src/includes/libencryption.sh b/src/includes/libencryption.sh index a6fcec7..265c331 100644 --- a/src/includes/libencryption.sh +++ b/src/includes/libencryption.sh @@ -3,7 +3,7 @@ function encrypt(){ # output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private # GPG key. -gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET" + gpg -r "$PUBKEY" -o "$NOTE" -e "$TARGET" } @@ -12,7 +12,5 @@ function decrypt(){ # output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private # GPG key. - if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi - TARGET="$TMP_DIR/$RANDOM" - gpg -d "$NOTE" > "$TARGET" + gpg -d "$NOTE" } diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index 3224a0c..429203c 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,31 +1,8 @@ function list(){ if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then - printf "\nNotes in %s:\n" "$(basename "$NOTEBOOK")" - - NOTES=( - $(find "$BASE_DIR"/"$NOTEBOOK" -name "*.$EXT" -print0 |\ - sed s:"$BASE_DIR"/"$NOTEBOOK"/: " " :g |\ - sed -e s:".$EXT"::g | tr "/" " ") - ) - let i=0 - for NOTE in "${NOTES[@]}"; do - if [ -d "$BASE_DIR"/"$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++ + printf "+%s\n" "$NOTEBOOK" + find "$BASE_DIR"/"$NOTEBOOK" -type f | while read 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/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 } From 25e5d399d1e9c096deabca98d0c21cda5fd69ce4 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 25 Jan 2016 21:20:20 -0600 Subject: [PATCH 22/52] fixed print function and made appropriate changes to other parts of the program; changed version to alpha 8 --- header.sh | 2 +- sns.sh | 20 ++++++++++++-------- src/includes/edit.sns.sh | 3 ++- src/includes/libencryption.sh | 2 +- src/includes/list.sns.sh | 4 ++-- src/main/stage3.sns.sh | 7 +++++-- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/header.sh b/header.sh index 7f582a6..7a591c0 100644 --- a/header.sh +++ b/header.sh @@ -1,7 +1,7 @@ #!/bin/bash PROD_STR="Simple Note System" -VER_STR="v2.0a7" +VER_STR="v2.0a8" cat << EOF #!/bin/bash diff --git a/sns.sh b/sns.sh index 7f07f64..33cf6b0 100755 --- a/sns.sh +++ b/sns.sh @@ -1,13 +1,13 @@ #!/bin/bash #========================================================== -# Simple Note System, v2.0a6 +# Simple Note System, v2.0a7 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi PROD_STR="Simple Note System" -readonly VER_STR="v2.0a6" +readonly VER_STR="v2.0a7" readonly ROOT_DIR="$HOME"/.config/xenlabs/sns readonly BASE_DIR="$ROOT_DIR"/notes readonly TMP_DIR="$ROOT_DIR"/tmp @@ -84,7 +84,7 @@ function decrypt(){ # This function, given a recipient, $PUBKEY; a file to decrypt, $TARGET; and an # output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private # GPG key. - + echo "$NOTE"; pause gpg -d "$NOTE" } function create(){ @@ -132,7 +132,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then cp "$NOTE" "$NOTE".bk if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi - decrypt > "$TMP_DIR/$RANDOM" + TARGET="$TMP_DIR/$SESSION_ID" + decrypt > "$TARGET" else TARGET="$NOTE"; fi @@ -162,8 +163,8 @@ function print(){ function list(){ if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then printf "+%s\n" "$NOTEBOOK" - find "$BASE_DIR"/"$NOTEBOOK" -type f | while read NOTE; do - printf " -%s\n" "$(basename $NOTE | cut -d . -f 1)" + find "$BASE_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do + printf " -%s\n" "$(basename \"$NOTE\" | cut -d . -f 1 )" done fi } @@ -288,9 +289,12 @@ fi SESSION_ID="$RANDOM" NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ -NOTE="$NOTE_DIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".gpg; fi + +if [ "$ENCRYPTION" == "TRUE" ]; then 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 diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index c260f8d..cc5e15f 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -7,7 +7,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then cp "$NOTE" "$NOTE".bk if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi - decrypt > "$TMP_DIR/$RANDOM" + TARGET="$TMP_DIR/$SESSION_ID" + decrypt > "$TARGET" else TARGET="$NOTE"; fi diff --git a/src/includes/libencryption.sh b/src/includes/libencryption.sh index 265c331..d87fb52 100644 --- a/src/includes/libencryption.sh +++ b/src/includes/libencryption.sh @@ -11,6 +11,6 @@ function decrypt(){ # This function, given a recipient, $PUBKEY; a file to decrypt, $TARGET; and an # output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private # GPG key. - + echo "$NOTE"; pause gpg -d "$NOTE" } diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index 429203c..e4c75da 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,8 +1,8 @@ function list(){ if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then printf "+%s\n" "$NOTEBOOK" - find "$BASE_DIR"/"$NOTEBOOK" -type f | while read NOTE; do - printf " -%s\n" "$(basename $NOTE | cut -d . -f 1)" + find "$BASE_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do + printf " -%s\n" "$(basename \"$NOTE\" | cut -d . -f 1 )" done fi } diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 1686c7b..d9a046b 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -23,9 +23,12 @@ fi SESSION_ID="$RANDOM" NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ -NOTE="$NOTE_DIR""$NAME"."$EXT" -if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".gpg; fi + +if [ "$ENCRYPTION" == "TRUE" ]; then 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 From 238934c979cf571921266ae91d8cc9399acb275f Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 25 Jan 2016 21:21:49 -0600 Subject: [PATCH 23/52] fixed init function to reflect version change --- src/includes/create_sns_root.sns.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/includes/create_sns_root.sns.sh b/src/includes/create_sns_root.sns.sh index 5e1b5ad..81cfb01 100644 --- a/src/includes/create_sns_root.sns.sh +++ b/src/includes/create_sns_root.sns.sh @@ -6,7 +6,7 @@ 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 #========================================================== From 77c3398c5f64024608c5eaef8a78bb629af6d3d2 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 25 Jan 2016 23:41:41 -0600 Subject: [PATCH 24/52] Corrected issues arising from "$BASE_DIR" vs "$ROOT_DIR" --- header.sh | 2 +- sns.sh | 43 +++++++++++++++++------------------ src/includes/create.sns.sh | 4 ++-- src/includes/edit.sns.sh | 10 ++++---- src/includes/libencryption.sh | 11 ++++----- src/includes/list.sns.sh | 4 ++-- src/main/stage1.sns.sh | 4 ++-- src/main/stage3.sns.sh | 2 +- 8 files changed, 39 insertions(+), 41 deletions(-) diff --git a/header.sh b/header.sh index 7a591c0..6ba4564 100644 --- a/header.sh +++ b/header.sh @@ -15,7 +15,7 @@ if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi PROD_STR="$PROD_STR" readonly VER_STR="$VER_STR" readonly ROOT_DIR="\$HOME"/.config/xenlabs/sns -readonly BASE_DIR="\$ROOT_DIR"/notes +readonly NOTES_DIR="\$ROOT_DIR"/notes readonly TMP_DIR="\$ROOT_DIR"/tmp readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" diff --git a/sns.sh b/sns.sh index 33cf6b0..4bbfa8c 100755 --- a/sns.sh +++ b/sns.sh @@ -1,15 +1,15 @@ #!/bin/bash #========================================================== -# Simple Note System, v2.0a7 +# Simple Note System, v2.0a8 # Copyright 2014, Xenese Labs/Sicron-Perion XNF #========================================================== if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi PROD_STR="Simple Note System" -readonly VER_STR="v2.0a7" +readonly VER_STR="v2.0a8" readonly ROOT_DIR="$HOME"/.config/xenlabs/sns -readonly BASE_DIR="$ROOT_DIR"/notes +readonly NOTES_DIR="$ROOT_DIR"/notes readonly TMP_DIR="$ROOT_DIR"/tmp readonly CONFIG_FILE="$ROOT_DIR/sns.conf" @@ -23,7 +23,7 @@ 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 #========================================================== @@ -72,19 +72,18 @@ function p_header(){ printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" } function encrypt(){ -# This function, given a recipient, $PUBKEY; a file to encrypt, $TARGET; and an -# output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private +# 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 "$TARGET" + gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE" } function decrypt(){ -# This function, given a recipient, $PUBKEY; a file to decrypt, $TARGET; and an -# output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private +# 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. - echo "$NOTE"; pause gpg -d "$NOTE" } function create(){ @@ -99,8 +98,8 @@ function create(){ echo "TITLE: $NAME" > "$NOTE" echo "DATE: $(date)" >> "$NOTE" elif [ "$ENCRYPTION" == "TRUE" ]; then - TARGET="$TMP_DIR"/"$SESSION_ID" - p_header > "$TARGET" + TMP_NOTE="$TMP_DIR"/"$SESSION_ID" + p_header > "$TMP_NOTE" encrypt fi @@ -132,14 +131,14 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then cp "$NOTE" "$NOTE".bk if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi - TARGET="$TMP_DIR/$SESSION_ID" - decrypt > "$TARGET" -else TARGET="$NOTE"; 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 +if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TMP_NOTE"; fi -"$EDITOR" "$TARGET" +"$EDITOR" "$TMP_NOTE" if [ "$ENCRYPTION" == "TRUE" ]; then rm "$NOTE" @@ -161,9 +160,9 @@ function print(){ fi } function list(){ - if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then + if [ -d "$NOTES_DIR"/"$NOTEBOOK" ]; then printf "+%s\n" "$NOTEBOOK" - find "$BASE_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do + find "$NOTES_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do printf " -%s\n" "$(basename \"$NOTE\" | cut -d . -f 1 )" done fi @@ -201,8 +200,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" - if [ ! -d "$BASE_DIR"/tmp ]; then - mkdir -p "$BASE_DIR"/tmp + if [ ! -d "$ROOT_DIR"/tmp ]; then + mkdir -p "$ROOT_DIR"/tmp fi fi @@ -288,7 +287,7 @@ if [ -z "$NAME" ]; then fi SESSION_ID="$RANDOM" -NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ +NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/ if [ "$ENCRYPTION" == "TRUE" ]; then readonly NOTE="$NOTE_DIR""$NAME"."$EXT".gpg diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 403eae1..54de245 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -10,8 +10,8 @@ function create(){ echo "TITLE: $NAME" > "$NOTE" echo "DATE: $(date)" >> "$NOTE" elif [ "$ENCRYPTION" == "TRUE" ]; then - TARGET="$TMP_DIR"/"$SESSION_ID" - p_header > "$TARGET" + TMP_NOTE="$TMP_DIR"/"$SESSION_ID" + p_header > "$TMP_NOTE" encrypt fi diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index cc5e15f..e63c412 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -7,14 +7,14 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then cp "$NOTE" "$NOTE".bk if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi - TARGET="$TMP_DIR/$SESSION_ID" - decrypt > "$TARGET" -else TARGET="$NOTE"; 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 +if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TMP_NOTE"; fi -"$EDITOR" "$TARGET" +"$EDITOR" "$TMP_NOTE" if [ "$ENCRYPTION" == "TRUE" ]; then rm "$NOTE" diff --git a/src/includes/libencryption.sh b/src/includes/libencryption.sh index d87fb52..71b1181 100644 --- a/src/includes/libencryption.sh +++ b/src/includes/libencryption.sh @@ -1,16 +1,15 @@ function encrypt(){ -# This function, given a recipient, $PUBKEY; a file to encrypt, $TARGET; and an -# output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private +# 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 "$TARGET" + gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE" } function decrypt(){ -# This function, given a recipient, $PUBKEY; a file to decrypt, $TARGET; and an -# output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private +# 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. - echo "$NOTE"; pause gpg -d "$NOTE" } diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index e4c75da..d65d4f7 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,7 +1,7 @@ function list(){ - if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then + if [ -d "$NOTES_DIR"/"$NOTEBOOK" ]; then printf "+%s\n" "$NOTEBOOK" - find "$BASE_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do + find "$NOTES_DIR"/"$NOTEBOOK" -type f | while read -r NOTE; do printf " -%s\n" "$(basename \"$NOTE\" | cut -d . -f 1 )" done fi diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 4cb45f7..af57da1 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -20,8 +20,8 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then PROD_STR="Simple Note System (Encryption Enabled)" - if [ ! -d "$BASE_DIR"/tmp ]; then - mkdir -p "$BASE_DIR"/tmp + if [ ! -d "$ROOT_DIR"/tmp ]; then + mkdir -p "$ROOT_DIR"/tmp fi fi diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index d9a046b..da7f738 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -22,7 +22,7 @@ if [ -z "$NAME" ]; then fi SESSION_ID="$RANDOM" -NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/ +NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/ if [ "$ENCRYPTION" == "TRUE" ]; then readonly NOTE="$NOTE_DIR""$NAME"."$EXT".gpg From ef1469762bb953487ce26d240519c2383e0d676c Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sun, 31 Jan 2016 21:30:39 -0600 Subject: [PATCH 25/52] * Moved no editor warning to edit function * Added message in create_sns_root showing SNS's environment was actually initialized * Changed flag to create SNS's environment from -w to -i --- sns.sh | 22 ++++++++++++++-------- src/includes/create_sns_root.sns.sh | 12 +++++++++--- src/includes/edit.sns.sh | 5 ++++- src/main/stage1.sns.sh | 5 +---- src/main/stage2.sns.sh | 2 +- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/sns.sh b/sns.sh index 4bbfa8c..a2be9c9 100755 --- a/sns.sh +++ b/sns.sh @@ -15,10 +15,10 @@ readonly CONFIG_FILE="$ROOT_DIR/sns.conf" # Section: Functions -function w_conf { +function create_sns_root { -if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi -if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi +if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi +if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi cat > "$CONFIG_FILE" << EOF @@ -45,6 +45,12 @@ PUBKEY="" EOF chmod 600 "$CONFIG_FILE" + +if [ "$WILL_INIT" == "TRUE" ]; then + printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" +else + printf "%s\n" "Environment already initialized." +fi } function pause { read -rp " Press [Enter] to continue." @@ -123,7 +129,10 @@ function delete(){ fi } function edit(){ -if [ ! -r "$NOTE" ]; then +if [ -z "$EDITOR" ]; then + >&2 echo "Error no editor specified in environment." + exit +elif [ ! -r "$NOTE" ]; then echo "ERROR: Note cannot be opened for editing." exit 40; fi @@ -207,10 +216,7 @@ fi echo "$PROD_STR, $VER_STR" -if [ -z "$EDITOR" ]; then - >&2 echo "Error no editor specified in environment." - -elif [ -n "$ERR_NO_GPG" ]; then +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 diff --git a/src/includes/create_sns_root.sns.sh b/src/includes/create_sns_root.sns.sh index 81cfb01..d3b8bf9 100644 --- a/src/includes/create_sns_root.sns.sh +++ b/src/includes/create_sns_root.sns.sh @@ -1,7 +1,7 @@ -function w_conf { +function create_sns_root { -if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi -if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi +if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi +if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi cat > "$CONFIG_FILE" << EOF @@ -28,4 +28,10 @@ PUBKEY="" EOF chmod 600 "$CONFIG_FILE" + +if [ "$WILL_INIT" == "TRUE" ]; then + printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" +else + printf "%s\n" "Environment already initialized." +fi } diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index e63c412..91f0e7f 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -1,5 +1,8 @@ function edit(){ -if [ ! -r "$NOTE" ]; then +if [ -z "$EDITOR" ]; then + >&2 echo "Error no editor specified in environment." + exit +elif [ ! -r "$NOTE" ]; then echo "ERROR: Note cannot be opened for editing." exit 40; fi diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index af57da1..d0eadd1 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -27,10 +27,7 @@ fi echo "$PROD_STR, $VER_STR" -if [ -z "$EDITOR" ]; then - >&2 echo "Error no editor specified in environment." - -elif [ -n "$ERR_NO_GPG" ]; then +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 diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 97c0392..b62b775 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -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 create_sns_root; 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" From 221dcded682aa2cad8ba2ff7904ecb288f69d611 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Tue, 9 Feb 2016 20:35:53 -0600 Subject: [PATCH 26/52] Not sure --- build.sh | 0 sns.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 build.sh mode change 100755 => 100644 sns.sh diff --git a/build.sh b/build.sh old mode 100755 new mode 100644 diff --git a/sns.sh b/sns.sh old mode 100755 new mode 100644 From e50e9464af083cd150d3e8fa0319f676586c5d80 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Tue, 9 Feb 2016 20:36:44 -0600 Subject: [PATCH 27/52] Making sure all progress was committed --- .DS_Store | Bin 0 -> 6148 bytes nul | 0 null | 0 .../UserInterfaceState.xcuserstate | Bin 0 -> 14273 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store create mode 100644 nul create mode 100644 null 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..c9e58434546dd724b3fb2231c5e8379282892f4c GIT binary patch literal 6148 zcmeHK%}&BV5dNkR1&s+uk3D)K;SDM&CLX-t-6%za1g(LPcwzsO zw_GJ#hKw7GF-EvViW_1dFPPTbkgpxa5qtCMdKA{+w)W_5C-9W}{0>^m;$E2!4%-0t=2j9Xweif z1x$fb0sTJ2bj2iK;n96M7~Bzn*k-Xa-s>-;a^iqVz``Tn(8N=To+{ypA)e0iIOHV( z3y+=-35O2}ElW6|h-;no$1WX`c(iB=m;!YLTK=)8`~T?o^M9RWPo{t=@UIk*c6yr* zIi#?+HU_7AZA`zXt7%^0v83?EZN<#ht@xbojODT35R-s~N0!j+N5IKo!4x>C0zV#> BamN4v literal 0 HcmV?d00001 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.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate b/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000000000000000000000000000000000000..5bc316e6f5cc09a715182b63729e258a30610a44 GIT binary patch literal 14273 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 C%|BiM literal 0 HcmV?d00001 From be3871f85946917062edd423cb8d2d531bbc840a Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Feb 2016 23:33:43 -0600 Subject: [PATCH 28/52] Formatting changes --- src/includes/{create_sns_root.sns.sh => init_store.sns.sh} | 2 +- src/includes/verify_store.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) rename src/includes/{create_sns_root.sns.sh => init_store.sns.sh} (96%) create mode 100644 src/includes/verify_store.sh diff --git a/src/includes/create_sns_root.sns.sh b/src/includes/init_store.sns.sh similarity index 96% rename from src/includes/create_sns_root.sns.sh rename to src/includes/init_store.sns.sh index d3b8bf9..6883fff 100644 --- a/src/includes/create_sns_root.sns.sh +++ b/src/includes/init_store.sns.sh @@ -1,4 +1,4 @@ -function create_sns_root { +function init_store { if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi diff --git a/src/includes/verify_store.sh b/src/includes/verify_store.sh new file mode 100644 index 0000000..1e75289 --- /dev/null +++ b/src/includes/verify_store.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# verify_store.sh +# sns +# +# Created by Jon-William Lewis on 1/31/16. +# From 856b14242c7b78121fa0637e0c82fcc5a58539f4 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Wed, 10 Feb 2016 23:34:49 -0600 Subject: [PATCH 29/52] 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 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 "$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 + #============================================================================== From 993a6508d33d59ba29a6440530f0b4bbf6e025a9 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Thu, 11 Feb 2016 00:22:34 -0600 Subject: [PATCH 30/52] Code cleanup --- build.sh | 5 +- errors.ref | 7 +- header.sh | 5 +- sns.sh | 150 ++++++++++-------- sns.xcodeproj/project.pbxproj | 8 +- .../UserInterfaceState.xcuserstate | Bin 11909 -> 15437 bytes src/includes/help.sns.sh | 2 +- src/includes/init_store.sns.sh | 35 ++-- ...{libencryption.sh => libencryption.sns.sh} | 0 src/includes/verify_store.sh | 6 - src/includes/verify_store.sns.sh | 7 + src/main/stage2.sns.sh | 15 +- src/main/stage3.sns.sh | 7 +- 13 files changed, 135 insertions(+), 112 deletions(-) rename src/includes/{libencryption.sh => libencryption.sns.sh} (100%) delete mode 100644 src/includes/verify_store.sh create mode 100644 src/includes/verify_store.sns.sh diff --git a/build.sh b/build.sh index 77dd483..d23b4e5 100755 --- a/build.sh +++ b/build.sh @@ -8,11 +8,12 @@ S=sns.sh bash header.sh > "$S" echo -e "\n# Section: Functions" >> "$S" -cat ./src/includes/create_sns_root.sns.sh >> "$S" +cat ./src/includes/init_store.sns.sh >> "$S" +cat ./src/includes/verify_store.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/libencryption.sns.sh >> "$S" cat ./src/includes/create.sns.sh >> "$S" cat ./src/includes/delete.sns.sh >> "$S" cat ./src/includes/edit.sns.sh >> "$S" diff --git a/errors.ref b/errors.ref index 620ffb6..28754c8 100644 --- a/errors.ref +++ b/errors.ref @@ -4,12 +4,11 @@ Error Code Reference General------------------------------------------------------------------------- ERR_NO_ARGS 10 No arguments were specified ERR_NO_OP 20 -ERR_INSUFFICIENT_ARGS 30 A required argument was not provided - +ERR_NO_NOTEBOOK 30 A required argument was not provided Encryption---------------------------------------------------------------------- -ERR_NO_GPG 100 GPG is not installed -ERR_NO_KEY 110 No recipient specified +ERR_NO_GPG 100 Encryption is enabled, but GPG is not installed +ERR_NO_KEY 110 Encryption is enabled, but no recipient was 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 cd39b16..454afb9 100644 --- a/header.sh +++ b/header.sh @@ -9,14 +9,13 @@ cat << EOF # Copyright $YEAR, Xenese Labs/Sicron-Perion XNF #========================================================== +# Prevent freak accidents involving the root directory if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi PROD_STR="$PROD_STR" readonly VER_STR="$VER_STR" -readonly ROOT_DIR="\$HOME"/.config/xenlabs/sns +readonly ROOT_DIR="\$HOME"/.config/sns 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 8beb03f..ec6ad02 100755 --- a/sns.sh +++ b/sns.sh @@ -8,51 +8,53 @@ if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi PROD_STR="Simple Note System" readonly VER_STR="v2.0a8" -readonly ROOT_DIR="$HOME"/.config/xenlabs/sns +readonly ROOT_DIR="$HOME"/.config/sns readonly NOTES_DIR="$ROOT_DIR"/notes readonly TMP_DIR="$ROOT_DIR"/tmp readonly CONFIG_FILE="$ROOT_DIR/sns.conf" - - # Section: Functions -function create_sns_root { +function init_store { -if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi +if [ ! -d "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi cat > "$CONFIG_FILE" << EOF -#========================================================== -# Simple Note System Config, v2.0a8 -# Copyright 2014, Xenese Labs/Sicron-Perion XNF -#========================================================== +# This file contains directives for the Simple Note System. -#File extension to use (for listing notes) -EXT=note +EXT=note # File extension to use (for listing notes) -#Preferred Editor -if [ -z "$EDITOR" ]; then - EDITOR=vim -fi +#EDITOR= # Preferred Editor: + # If you would like to specify a different editor for + # sns to use, you may do so here. -#Encryption -#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST +ENCRYPTION="FALSE" # Main Encryption Toggle: + # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST + # Change this to TRUE to enable encryption. -#ENCRYPTION="TRUE" -ENCRYPTION="FALSE" - -PUBKEY="" +PUBKEY="" # Public Key + # Encryption is done using GPG. You must enter your + # public key's identifier here. EOF chmod 600 "$CONFIG_FILE" +printf " - %s\n" "Rewrote Default Configuration" + if [ "$WILL_INIT" == "TRUE" ]; then - printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" + printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR" else - printf "%s\n" "Environment already initialized." + printf " - %s\n" "Store already initialized." fi } +function verify_store { + ETC_DIR="$(dirname \"$CONFIG_FILE\")" + STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") + for DIR in ${STORE_DIRS[@]}; do + mkdir -p "$DIR" + done +} function pause { read -rp " Press [Enter] to continue." echo "" @@ -72,7 +74,7 @@ function help { echo " -h | --help : Display this message" echo " -p | --print : Print note to console" echo " -l | --list : List all notes in NOTEBOOK" - echo " -w | --wconf : Rewrite default configuration" + echo " -i | --init : Write default config and initalize SNS store" echo "" } function p_header(){ @@ -94,52 +96,63 @@ function decrypt(){ 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 "$NOTE_DIR" - fi + # Depends : p_header + # Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME + # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt + # Given a valid setup, create writes the standard note header as specified + # by p_header, to $NOTE. - if [ -z "$ENCRYPTION" ]; then - echo "TITLE: $NAME" > "$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 } 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 } 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 @@ -184,15 +197,17 @@ function list(){ # Entry Point #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #============================================================================== - # Stage 1: Read Configuration + # Stage 1: Read Configuration / Verify Integrity #============================================================================== if [ -r "$CONFIG_FILE" ]; then source "$CONFIG_FILE" else - create_sns_root + init_store source "$CONFIG_FILE" fi + verify_store + if [ "$ENCRYPTION" == "TRUE" ]; then if [ -z "$PUBKEY" ]; then ERR_NO_KEY="TRUE" @@ -229,14 +244,14 @@ function list(){ 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" + if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"; OP="TRUE" + elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE" + elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE" + elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE" + elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" + elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" 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 init_store; exit 0 else if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" @@ -252,12 +267,18 @@ function list(){ NAME="" fi fi + # w_conf and help are called here to avoid excess stage 3 code. #============================================================================== # 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, throw code 30. + # 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 @@ -267,7 +288,7 @@ function list(){ if [ "$LIST" == TRUE ]; then list exit 0 - elif [ -z "$NAME" ]; then + elif [ -z "$NAME" ]; printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" exit 30 fi @@ -280,7 +301,6 @@ function list(){ 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 diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj index d55d3e0..0c77465 100644 --- a/sns.xcodeproj/project.pbxproj +++ b/sns.xcodeproj/project.pbxproj @@ -19,8 +19,8 @@ 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 = ""; }; + 5D22D6B01AFC5B100036DC52 /* libencryption.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = libencryption.sns.sh; sourceTree = ""; }; + 5D75D24F1C5F13DF001E7B33 /* verify_store.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = verify_store.sns.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 = ""; }; @@ -49,8 +49,8 @@ 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */, 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */, - 5D22D6B01AFC5B100036DC52 /* libencryption.sh */, - 5D75D24F1C5F13DF001E7B33 /* verify_store.sh */, + 5D22D6B01AFC5B100036DC52 /* libencryption.sns.sh */, + 5D75D24F1C5F13DF001E7B33 /* verify_store.sns.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 index 137df62d63cb18020d85eabbe75a96261554d626..c97975e4e9623f6bed218612f7107acedad50a09 100644 GIT binary patch literal 15437 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 AUjP6A 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-!3EZFtJPtg-3nqdmz;rMJ%mxd=BJea=308py&W_gRj6ba0Z+Mm%ue}6Z{JPga8U41LaTwbx;o@U;<2pNiZ3vz*Lw9(_uH* z9cIA3upjIX^I-ujgu`Jmtb!9@HFU!o_&D@HFZ4kS{cr}H31`9Ca1NXcpM}rC7vV~{ z3a){#!cA~1d>y_4cf+^gUbqh)fS{2G1(zlCSvkMJtI2Cu^#@E3R+{sI3) z0EHk43Pl>EMS5gH(WonmMR6z%rK4`BFUm#3&`2~IIgk^%(0Ejhyl4`tL(|byXaQP? z7NMun%V-s9Kx@%D^dGblZ9!Yn4zv@!iQYo*qW94I=mT^ReT+UsN6~$XqG(D$F_eS~ zr4*Es(o$hm1Qkh{C^HpJb)Y&^U8p!Jo=T=tsJ>Jtl|^M!L#bg@K2<=Cr5sc#RZY36 z8tQSXo_d0sPGM>RwUAmwJx#qty-dAAt)TuxZKO6)yQw#+x2TV(1Jpt4W9k@noH{|B zq<)|-P#39RsGHQUG@v1k=ulcp%jgI?l8&McbZ5E?9Yc4eyV2e09&|stKRtjRNRKGA zR@YWl9R&;!0uc}cDNu~a%kTP_bBec^yf?+;aBEqW!|QDX5)g_JrW%0^$T5w#VXIwc zjZaKU>zkaA6_XU7lM<7Zos%BZH>YoMOlDGCc0xjCa$HIS1dSC!XB3}8fx!J$9LaOwTCuk+f_d(Jt%N8nBHtdvZoXTt?qyVxRQBIWb9z znaMF}@qJTcvePo+?XqwdAh3)Ax4Wv;;py)k?((`ytH_GNTE-luecKFa z>gwXU7?V@$yBO=@6Vk}%)P%VD`Y!`cjROe{Ku=5+`XxvL$sh%!7IXfrCYCDVK03X` z?HL}AV@e~LkXDqJKR7@|K?ijMSs;1?=ni^-o}d@#4f=o#&=+K48J1%OR$>)aV-42g zuni!aIOtK(5A+8E$fsN|2!|6V>2U<^gdZiJ2IC>Pqg|%S@OlX$I;wry=LZp(31IfpoW<3^LO+#1*$Wq>KE zv5#{)Nbq&_jtg3F6c_`d8^CBB*#PV~inV||Yj{DkqWyi&30}@)WuT%FlmjO=U>oib z1Q-V%1ByoA0^_j}n;JnCn1IdLf~}(oOzSw6k?-u%2RSOMUB23K=MYPuIvHU9aS`AH zwWIR#vs@&W-PH~cak&qq1;tDPQy&mBjfjcHR!bkZu@wjg{xNy^gKB*a5}kp_Sq(57 zJDiM}V3u8`Y@W~}Y&DqKTHG8kA4E5TxnLfC1b1!(^T1QMGwu>FPrkE?R6}QZv-j*W zV^NvA+}V{Fe4xwMwRxaxzRy!z=BxEMgUfgZJP)GRfoH*UU@=$%mV#wC26x4=I1b0- zgmvHrU<1p^|ChllIFT?&FY><+&S2%TOqD&k#!+4FEDw04z~gLUlwr;?!UsY2BL4R| zJ+A7?>}u8sGjE7b<0ud~AKaW>z{_0-K^3mb&5;gklj6{q5k`QB=8 z5N8K?gLTDDunVW*^hU6oeCUSL*-4(VA;DSig8d+RHP{9Af_-GLJMO`LAusZUeRV8y zRhLzfsPh&~aJZ@k!TSz@&ziOT9QVf7;J^_QmC>tK1uP%nu{f5-5|Y!q7*i6G>+6H_ zj)RlU0H<)@7J#q8x6O+>i!*V@;2qzCAJ~DNIIRI(z*#K=m%$ZwU@z|80Di>TEd$rV zPwc=AoYN3kP{;N%`8RNjofOFA+qfU@$Yt#vP_Y`^1^2*TxIZ3<2Q_Cdgph8NQoSLM z@Z|tDrE2;FQmRQ~D1?$WGc%zShv8gy=G?t)W-6hk^-QQGn0YKFM|jOt#Svcr*g`KU zd9jmSRTCyTVuJzfjm>gSbXK`**jgN0<8cSN&sY)@vBc%EK}W{^oz7q+>_7?vjDiMe zgeGW)7HEYw7>$SGVK^Tb;6gkckHAHE#v#)K>Wd5;%Bc)1@Ko?Oq=-!Z2rz$LS>>94t4I9zh;dsF|pXs{(bZ zRa(IwuosC4*b|pDz}|QiyBHfMy{V@CZvujT&xF}5Ko%a|0CVsd+_7K~$(`Wn0GJ09 ztKmSH3kP949*Z5T;b3CTp}3S-a5n4nPHn`ogyPI6<+Hjn@UfYFN$s-B)NSWBG0KD2 zA9cDXIDMWef#8NCND~2za2XB_Dpdl@NXrIC!O?IGw8OE`0ZVZ?cH#$)5*#ZWmP?9NO>JqFtBjOvXH`{>)AjWjzr##N(PkifRzMz%{|? z^*JWgkWTr5p(b|E9Ov*jNS*Txb5vJ4NB47;J2R@P`g^^EzDXcGa8s}Xw7tuc@pgIj zy(R0+BiK$bHKl$y`yN++494Y1KJV+(3a><}3w z0|Il0I9#4axEiGWA9I2d_mcElL5f>Ao)WyYGjJ)b)g`z&aH*cX6ey%{8!`2ExC8El zyGqKN_BbTCM*4z5fTv@Ofn7GFf&_oJ*w}~0%bXG3gl~~RCjDQ~M?wEK!aeNT+Z*EU zdWzo%H!8UGOwg;8$n(wallsPjAX&;6Ai3#6_ zyWod#2fGt3b$Fd6wzNw%=?5KB~_;yE~! zl!cadA~l7iLrPjgb2|YK!($+N4LkzBgh%05cpjdQpTtkCfydzqcoLq%3-EJz30_M2 znOtW@U@I|ln5%MJ;8QV2>w%giQ?tb=xZP+jEO^s~^ z1Gl?9q|$LLM)p=@yVYh&0G%aX&T2n_gjFrneiQ!2R-<3>;s%gS^dq{-$;R00u4-yv z*@eqsaEW)|y~D6|cYzEgE$|kF=J9 zI-@RlC0>QCBZ*_VK(+L7jcp?_9woK8CmE&SM!Y)MdIx(3w#%^e8MQZX?^mch>VbL! z5$XkZp*|?XE>n2iZXXv*Y&((1_Bb+arL)>q>*XY~=Mm1yK5itehAS<98^W)Vv{;K@ zKaMg{77>t*a?qnhNG~)1{(%O9q9SsdSXJ(ERu8XnkiWi?G8VVm$3_5&o*-5IZ|Pp* z_PByQ5s~y7-ip_?sw`*_%Ht{v-i+6Cg&+`DD4)&%%A4q6KPq66!WNI+%F`7-d2KmtpG!xCj z+wl&(6YpAs=AgM~9^sld@F(~X$2DQxPPQ!%6DB1@Aq~-57=dW|1GN1<00jlv^N#4 zBlAE2_v44=&x9s_a(Vd)sAvG}@p~%RdfwqM>o(<=x6i`x`}>8zoFmJEp!|Gf&N5y&|P#7 zpU0Q*kN7(N1^$ZHvFLobdlryAYuM3Dr^B+Uq38=waEH=06r2B_3gvtXDT*;`JG*s@o!Dl z^2DW8>L&$Yzkg_{@2K@QrzH2#luD&~usgg5&xWX;R4-to`rse%1+vS#h&z%q8oN4a z`jput*|VAW<_?c5lp%8uWbO0hfHI6JVAvM1B@;ua}cCjW?QwUZazKMS&Sid#d3Qhi6 z!PzP`ExvwaU3^?xQfo9nHK$#)xzs#@_9VWAZxggXnv4~4;PSTt&C-(6iDpUZsjab| zp_aCbwTyb6V7-X%;JXCtUK3W&!tLptW^w7s1S~zF%`#U~YuW`{ORWo7{k|Upg63^n zXRc$&hJa?|p+~dlHdEW$#n?{mU@`m<`61N;!Y~b~=K~-~DT&P>d#Jtbg6yOAlU04- zharCQ+@Pl)@;Ox$YXsp>1W*zaStBJTwlVl8)EDi-9j1;DxTAi^_@R)66LE0LD@k9U z;cT85S3jaIo;=fO39M5Td2Z8A;+&d$sj?of9*Yb*Uw)naW`_iod+1VB>aQiIl}DO%7T2+hz!4n*UJ z+7=LX|FzTn0g&YM77#hDX%|FGhXEU{^TTjIBtLoZLw!>$4%ol;HW!NtsR{MPb&2tW zQR2yu0h%mC8);j+h|zQhg4oFqBmFRnMKo}Tp%ZnR$8vflC6ORVPHat4bS$0JE?hF5 z!mZNehvt@5G9g{A#c-$6$;~SDr2Dpukx6F}m2&*h>W4N~rRb(b-uH*622_eqN+Bx6 zC$)}CI+q^WF5EEgc-{{?Hl5G2G)K~r(-2Rf%X%eg}jr{@S=OqUb}cDERk z-&utNGw4iyFVPM3CSC7K=vDITpFLPGdTdQpR@!Q{6+`BWh_f*MJcP@}0T>KW=i>KtvRd(k6l4_!w;L1TIb{S>{7UP-T~ zH_TnYIxerJ9RKbD`#ui$(6m_LI*i$8}ykN+fp0slq*OZ->(EBOul)%>;m_564F-wWh| zI6-g0P{A01Lr^BD5R4Oy7fch(7c3Ag5BkIU z1~G$~q0AV@!IUu-%s6H|Gl`kXOk<`qer6`~46~S7%DliVXI^GDFq@dynAe%@%uZ$> z^Eq>bIm#SoPBN#N^UM|IDs!FriTQ=OFQkP$p+G1RN`-QvQWzoZBQQ<}5W#JX!RpE8vPr_e>zY2dB-WG{O5|LCS z7b!(*kyaEg(u*QR22p}&plGD1MpP$yRT7oFnch9w5#Y=Zg!)Bg7-cCE~f_mEt$Vd&TdIKNKGje%8(mv9G(xK9PX`yt4bfmOY>X*)uu9a?+?vU=1?v{QiJs|y9dPsUwdRqFm z^jqoo(i_q{vJe?x#>hmnF|tZoy=;c;1zCgaQ`r&OUAax3Anzv6k@u4ikmt$^6-!0!KKO{dczb?O{pcOoYKp|9! z6>5c65w6fHA{7QjPerk!Ua?HEQn5=WvXea*{TJq7gT#x2UH)c4yism?esUD&prY=wqR~M@* z)h_j8>Iv#O>UruX)eF>%)X%Gzt6x^HP_I`XQ6JX;4Wo(GBx#B@m6{rjN8{5>)J)d+ zH8VA{HFGudHBV{QX?AOlX|8I1(+ag>ZKzhJRcKXOjW$fH(?)2cv_@@=HdY(2P1MfO zF4iv9KCgXIdsX{~_Kx(cwM4ymTsZ$8QpWbCAtRP8r?eG2Hi&8X5Cx5 z3%X0X|LT6!UDMsr{j9sG`%QOC_lNF|?w;8tg1`g;9zy$A<`5%F>+?)?8v#1^CK@s{u=pv;}YXC;|s>+#+QvNjO&eCjqeygG9EO3V*J$jx$%VYl<|!58{=8yIpY=MP2*h? zV^Ww@CXFe~q%&DeHd6;vCsSurj48#`$27n+!Zg-YYAQEXn8ukNH+fC9rb(tLraIFs z(?ZiS(`wTu(`%-!rfsGjrgu#5nf969H+^V2U^;9%Z8~rI$@GWmj_IE1z8RW@X0cgn zmYbDkwK>Y%!JK67Y3^;#FlU;x&3Wdb<^uC@bCJ2&TxPB^PchFh&oa+3&oe)1UTj`w ze$o7rd4+kEd4qYId5`&^`H1q*=OKdRlTUgDs;hPD`c5WqHgp!7|Y@#WKzEgvD=}X<1-dYH74=v~0F) zvAk~CZh71Co@Kw~1ItI2gO($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 "$CONFIG_FILE" << EOF -#========================================================== -# Simple Note System Config, v2.0a8 -# Copyright 2014, Xenese Labs/Sicron-Perion XNF -#========================================================== +# This file contains directives for the Simple Note System. -#File extension to use (for listing notes) -EXT=note +EXT=note # File extension to use (for listing notes) -#Preferred Editor -if [ -z "$EDITOR" ]; then - EDITOR=vim -fi +#EDITOR= # Preferred Editor: + # If you would like to specify a different editor for + # sns to use, you may do so here. -#Encryption -#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST +ENCRYPTION="FALSE" # Main Encryption Toggle: + # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST + # Change this to TRUE to enable encryption. -#ENCRYPTION="TRUE" -ENCRYPTION="FALSE" - -PUBKEY="" +PUBKEY="" # Public Key + # Encryption is done using GPG. You must enter your + # public key's identifier here. EOF chmod 600 "$CONFIG_FILE" +printf " - %s\n" "Rewrote Default Configuration" + if [ "$WILL_INIT" == "TRUE" ]; then - printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" + printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR" else - printf "%s\n" "Environment already initialized." + printf " - %s\n" "Store already initialized." fi } diff --git a/src/includes/libencryption.sh b/src/includes/libencryption.sns.sh similarity index 100% rename from src/includes/libencryption.sh rename to src/includes/libencryption.sns.sh diff --git a/src/includes/verify_store.sh b/src/includes/verify_store.sh deleted file mode 100644 index f4fc06f..0000000 --- a/src/includes/verify_store.sh +++ /dev/null @@ -1,6 +0,0 @@ -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/includes/verify_store.sns.sh b/src/includes/verify_store.sns.sh new file mode 100644 index 0000000..9604d8d --- /dev/null +++ b/src/includes/verify_store.sns.sh @@ -0,0 +1,7 @@ +function verify_store { + ETC_DIR="$(dirname \"$CONFIG_FILE\")" + STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") + for DIR in ${STORE_DIRS[@]}; do + mkdir -p "$DIR" + done +} diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 0fcc5fc..ed56a34 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -8,14 +8,14 @@ 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" + if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"; OP="TRUE" + elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE" + elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE" + elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE" + elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" + elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" 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 init_store; exit 0 else if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" @@ -31,4 +31,5 @@ NAME="" fi fi + # 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 67deb52..a0a1adf 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -1,8 +1,13 @@ #============================================================================== # 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, throw code 30. + # 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 From 1cce779aa7e46297fdf754d767e7e3b494c402d6 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sun, 14 Feb 2016 22:54:01 -0600 Subject: [PATCH 31/52] Changed readme to match recent changes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41e571c..7984fd9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Simple Note System ================== The Simple Note System is a shell script enabling easy management of plain-text -notes. SNS depends on OpenSSL for encryption and uses the vim editor by default. +notes. SNS depends on GPG for encryption and uses the vim editor by default. usage: sns [-ce] NAME NOTEBOOK SECTION" sns [-d ] NAME NOTEBOOK SECTION" @@ -16,4 +16,4 @@ notes. SNS depends on OpenSSL for encryption and uses the vim editor by default. -h | --help : Display this message" -p | --print : Print note to console" -l | --list : List all notes in NOTEBOOK" - -w | --wconf : Rewrite default configuration" + -i | --init : Write default config and initalize SNS store" From 48b65a6bef2e20d3c9d064747e59ebc687b8b979 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sun, 14 Feb 2016 22:58:47 -0600 Subject: [PATCH 32/52] Cleaned up unnecessary files --- nul | 0 null | 0 sns.sh | 313 ------------------------------------------------------- sns1.sh | 316 -------------------------------------------------------- 4 files changed, 629 deletions(-) delete mode 100644 nul delete mode 100644 null delete mode 100755 sns.sh delete mode 100644 sns1.sh diff --git a/nul b/nul deleted file mode 100644 index e69de29..0000000 diff --git a/null b/null deleted file mode 100644 index e69de29..0000000 diff --git a/sns.sh b/sns.sh deleted file mode 100755 index ec6ad02..0000000 --- a/sns.sh +++ /dev/null @@ -1,313 +0,0 @@ -#!/bin/bash -#========================================================== -# Simple Note System, v2.0a8 -# Copyright 2016, Xenese Labs/Sicron-Perion XNF -#========================================================== - -if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi - -PROD_STR="Simple Note System" -readonly VER_STR="v2.0a8" -readonly ROOT_DIR="$HOME"/.config/sns -readonly NOTES_DIR="$ROOT_DIR"/notes -readonly TMP_DIR="$ROOT_DIR"/tmp -readonly CONFIG_FILE="$ROOT_DIR/sns.conf" - -# Section: Functions -function init_store { - -if [ ! -d "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi -if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi - - -cat > "$CONFIG_FILE" << EOF -# This file contains directives for the Simple Note System. - -EXT=note # File extension to use (for listing notes) - -#EDITOR= # Preferred Editor: - # If you would like to specify a different editor for - # sns to use, you may do so here. - -ENCRYPTION="FALSE" # Main Encryption Toggle: - # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST - # Change this to TRUE to enable encryption. - -PUBKEY="" # Public Key - # Encryption is done using GPG. You must enter your - # public key's identifier here. -EOF - -chmod 600 "$CONFIG_FILE" - -printf " - %s\n" "Rewrote Default Configuration" - -if [ "$WILL_INIT" == "TRUE" ]; then - printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR" -else - printf " - %s\n" "Store already initialized." -fi -} -function verify_store { - ETC_DIR="$(dirname \"$CONFIG_FILE\")" - STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") - for DIR in ${STORE_DIRS[@]}; do - mkdir -p "$DIR" - done -} -function pause { - read -rp " Press [Enter] to continue." - echo "" -} -function help { - echo "" - echo "usage: sns [-ce] NAME NOTEBOOK SECTION" - echo " sns [-d ] NAME NOTEBOOK SECTION" - echo " sns [-lp] NOTEBOOK" - echo " sns [-w ]" - echo " sns [-h ]" - - echo "" - echo " -c | --create : Create note" - echo " -d | --delete : Delete note" - echo " -e | --edit : Open note for editing" - echo " -h | --help : Display this message" - echo " -p | --print : Print note to console" - echo " -l | --list : List all notes in NOTEBOOK" - echo " -i | --init : Write default config and initalize SNS store" - echo "" -} -function p_header(){ - printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" -} -function encrypt(){ -# 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(){ -# 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(){ - # Depends : p_header - # Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME - # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt - # Given a valid setup, create writes the standard note header as specified - # by p_header, to $NOTE. - - # 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 - else - p_header > "$NOTE" - fi - # Make sure the note exists, and inform the user. - if [ -e "$NOTE" ]; then - echo "Created note: $NOTEBOOK/$SECTION/$NAME." - else - printf "%s\n" "Something went wrong." - fi -} -function delete(){ - #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 -} -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 #Insurance - if [ ! -d "$TMP_DIR" ]; then mkdir "$TMP_DIR"; fi - TMP_NOTE="$TMP_DIR/$SESSION_ID" - decrypt > "$TMP_NOTE" -else TMP_NOTE="$NOTE"; 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 [ -r "$NOTE" ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - decrypt - else - cat "$NOTE" - fi - else - printf "\nERROR: Note cannot be found.\n" - fi - fi -} -function list(){ - 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 - fi -} -# End Section: Functions - - - - #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # Entry Point - #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - #============================================================================== - # Stage 1: Read Configuration / Verify Integrity - #============================================================================== - if [ -r "$CONFIG_FILE" ]; then - source "$CONFIG_FILE" - else - init_store - source "$CONFIG_FILE" - fi - - verify_store - - 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 - #============================================================================== - # 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"; OP="TRUE" - elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" - elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then init_store; 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 - #============================================================================== - # 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" ]; - 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 - 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 - - #============================================================================== - # End Section: Actions / Stage 3 - #============================================================================== diff --git a/sns1.sh b/sns1.sh deleted file mode 100644 index e1c251f..0000000 --- a/sns1.sh +++ /dev/null @@ -1,316 +0,0 @@ -#!/bin/bash -#========================================================== -# Simple Note System, v1.1 -# Copyright 2014, Xenese Labs/Sicron-Perion XNF -#========================================================== - -PROD_STR="Simple Note System" -VER_STR=v1.1 - -#============================================================================== -# Section: Helper Functions -#============================================================================== -function writeconf { -cat > $HOME/.sns << EOF -#========================================================== -# Simple Note System Config, v1.1 -# Copyright 2014, Xenese Labs/Sicron-Perion XNF -#========================================================== - -#Directory where notes will be stored -BASEDIR=$HOME/notes - -#File extension to use (for listing notes) -EXT=note - -#Preferred Editor -EDITOR=vim - -#Encryption -#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST -ENCRYPTION="FALSE" -ENC_KEY="" -EOF - -chmod 600 $HOME/.sns -} - -function help { - echo "" - echo "usage: sns [-ce] NAME NOTEBOOK SECTION" - echo " sns [-d ] NAME NOTEBOOK SECTION" - echo " sns [-l ] NOTEBOOK" - echo " sns [-w ]" - - echo "" - echo " -c | --create : Create note" - echo " -d | --delete : Delete note" - echo " -e | --edit : Open note for editing" - echo " -p | --print : Print note to console" - echo " -l | --list : List all notes in NOTEBOOK" - echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" - echo "" -} - -function pause { - read -p " Press [Enter] to continue." - echo "" -} - -#============================================================================== -# End Section: Helper Functions -#============================================================================== - -#============================================================================== -# Section: Configuration -#============================================================================== -if [ -r $HOME/.sns ]; then - source $HOME/.sns -else - BASEDIR=$HOME/notes - EDITOR=vim - EXT=note -fi - -if [ "$ENCRYPTION" == "TRUE" ]; then - if [ -z "$ENC_KEY" ]; then - ERR_NO_KEY="TRUE" - ENCRYPTION="FALSE" - pause - fi - command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; } -fi - -if [ "$ENCRYPTION" == "TRUE" ]; then - PROD_STR="Simple Note System (Encryption Enabled)" - EXT="$EXT.enc" - if [ ! -d ~/.tmp ]; then - mkdir -p ~/.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." -fi - -if [ -n "$ERR_NO_SSL" -o -n "$ERR_NO_KEY" ]; then - pause -fi - -#============================================================================== -# End Section: Read Configuration -#============================================================================== - - -#============================================================================== -# Section: Argument Parsing -#============================================================================== - -NAME="" -NOTEBOOK="" -SECTION="" - -if [ -z "$1" ]; then #If no input was given, print help - help - exit -else #Assume the user wants to do something. - ARGS=( "$@" ) - for ARG in ${ARGS[@]};do - if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE" - elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE" - elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE" - elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE" - elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE" - elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE" - elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit - else - if [ -z "$NAME" -a -n $ARG ]; then - NAME=$ARG - echo "Name: $NAME" - elif [ -z "$NOTEBOOK" -a -n $ARG ]; then - NOTEBOOK=$ARG - echo "Notebook: $NOTEBOOK" - elif [ -z "$SECTION" -a -n $ARG ]; then - SECTION=$ARG - echo "Section: $SECTION" - fi - fi - done -fi - -#============================================================================== -# End Section: Argument Parsing -#============================================================================== - -#============================================================================== -# Section: Main -#============================================================================== - - NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ - NOTE=$NOTEDIR$NAME.$EXT - - if [ "$ENCRYPTION" == "TRUE" ]; then - NOTE=$NOTE.tmp - fi - - #========================================================================== - # Subection: List - #========================================================================== - if [ -n "$LIST" ]; then - NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. - if [ -z "$NOTEBOOK" ]; then - echo " ERROR: Insufficient arguments" - help - exit - else - if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then - - echo "" - printf "Notes in $(basename $NOTEBOOK):" - echo "" - 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: $NOTE\n" - fi - LAST_SECTION=$NOTE - else - #if [ $(($i % 1)) -eq 0 ]; then - # printf "\n " - #fi - printf " $NOTE\n" - fi - let i++ - done - printf "\n" - else - echo "" - echo "ERROR: Notebook $NOTEBOOK does not exist." - echo "" - fi - fi - exit - fi - #====================================================================== - # Sanity Check - Actions below require a valid $NAME and $NOTEBOOK - #====================================================================== - if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then - echo " ERROR: Insufficient arguments" - help - exit 10 - fi - #========================================================================== - # Subection: Delete - #========================================================================== - if [ "$DELETE" == "TRUE" ]; then - if [ -e $NOTE -o -e ${NOTE%.*} ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - rm ${NOTE%.*} - else - rm $NOTE - fi - - echo "" - echo "Deleted note: $NOTEBOOK/$SECTION$NAME." - exit - else - - echo "" - echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist." - exit - fi - fi - - #========================================================================== - # Subection: Create - #========================================================================== - if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit - help - exit - else - - - if [ "$CREATE" == "TRUE" ]; then - if [ -e $NOTE -o -e ${NOTE%.*} ]; then - - echo "" - echo "ERROR: Note already exists" - echo "Hint: use -e to edit the note." - echo "" - exit - else - #Create any necessary folders - mkdir -p $NOTEDIR - - #Fill in title - echo "TITLE: $NAME" > $NOTE - #Fill the second line with the date - echo "DATE: $(date)" >> $NOTE - - if [ "$ENCRYPTION" == "TRUE" ]; then - if [ $EDIT == "FALSE" ]; then - openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY - fi - fi - fi - fi - - #========================================================================== - # Subection: Edit - #========================================================================== - if [ "$EDIT" == "TRUE" ]; then - if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $NOTE - fi - echo "" >> $NOTE - echo "EDIT $(date)" >> $NOTE - fi - $EDITOR $NOTE - if [ "$ENCRYPTION" == "TRUE" ]; then - openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY - rm $NOTE - fi - - else - - echo "" - echo "ERROR: Note cannot be opened for editting." - echo "" - - fi - fi - -fi - #========================================================================== - # Subection: Print - #========================================================================== - if [ "$PRINT" == "TRUE" ]; then - if [ -r "$NOTE" -o -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 - else - - echo "" - echo "ERROR: Note cannot be found." - echo "" - - fi - fi - -fi - -exit From 54e2cdedd6d3d3fb38a33ee38a1bdda66a15dde6 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sun, 14 Feb 2016 23:26:25 -0600 Subject: [PATCH 33/52] Made changes to help system --- sns.sh | 313 --------------------------------------------------------- 1 file changed, 313 deletions(-) delete mode 100755 sns.sh diff --git a/sns.sh b/sns.sh deleted file mode 100755 index ec6ad02..0000000 --- a/sns.sh +++ /dev/null @@ -1,313 +0,0 @@ -#!/bin/bash -#========================================================== -# Simple Note System, v2.0a8 -# Copyright 2016, Xenese Labs/Sicron-Perion XNF -#========================================================== - -if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi - -PROD_STR="Simple Note System" -readonly VER_STR="v2.0a8" -readonly ROOT_DIR="$HOME"/.config/sns -readonly NOTES_DIR="$ROOT_DIR"/notes -readonly TMP_DIR="$ROOT_DIR"/tmp -readonly CONFIG_FILE="$ROOT_DIR/sns.conf" - -# Section: Functions -function init_store { - -if [ ! -d "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi -if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi - - -cat > "$CONFIG_FILE" << EOF -# This file contains directives for the Simple Note System. - -EXT=note # File extension to use (for listing notes) - -#EDITOR= # Preferred Editor: - # If you would like to specify a different editor for - # sns to use, you may do so here. - -ENCRYPTION="FALSE" # Main Encryption Toggle: - # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST - # Change this to TRUE to enable encryption. - -PUBKEY="" # Public Key - # Encryption is done using GPG. You must enter your - # public key's identifier here. -EOF - -chmod 600 "$CONFIG_FILE" - -printf " - %s\n" "Rewrote Default Configuration" - -if [ "$WILL_INIT" == "TRUE" ]; then - printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR" -else - printf " - %s\n" "Store already initialized." -fi -} -function verify_store { - ETC_DIR="$(dirname \"$CONFIG_FILE\")" - STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") - for DIR in ${STORE_DIRS[@]}; do - mkdir -p "$DIR" - done -} -function pause { - read -rp " Press [Enter] to continue." - echo "" -} -function help { - echo "" - echo "usage: sns [-ce] NAME NOTEBOOK SECTION" - echo " sns [-d ] NAME NOTEBOOK SECTION" - echo " sns [-lp] NOTEBOOK" - echo " sns [-w ]" - echo " sns [-h ]" - - echo "" - echo " -c | --create : Create note" - echo " -d | --delete : Delete note" - echo " -e | --edit : Open note for editing" - echo " -h | --help : Display this message" - echo " -p | --print : Print note to console" - echo " -l | --list : List all notes in NOTEBOOK" - echo " -i | --init : Write default config and initalize SNS store" - echo "" -} -function p_header(){ - printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" -} -function encrypt(){ -# 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(){ -# 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(){ - # Depends : p_header - # Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME - # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt - # Given a valid setup, create writes the standard note header as specified - # by p_header, to $NOTE. - - # 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 - else - p_header > "$NOTE" - fi - # Make sure the note exists, and inform the user. - if [ -e "$NOTE" ]; then - echo "Created note: $NOTEBOOK/$SECTION/$NAME." - else - printf "%s\n" "Something went wrong." - fi -} -function delete(){ - #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 -} -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 #Insurance - if [ ! -d "$TMP_DIR" ]; then mkdir "$TMP_DIR"; fi - TMP_NOTE="$TMP_DIR/$SESSION_ID" - decrypt > "$TMP_NOTE" -else TMP_NOTE="$NOTE"; 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 [ -r "$NOTE" ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - decrypt - else - cat "$NOTE" - fi - else - printf "\nERROR: Note cannot be found.\n" - fi - fi -} -function list(){ - 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 - fi -} -# End Section: Functions - - - - #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # Entry Point - #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - #============================================================================== - # Stage 1: Read Configuration / Verify Integrity - #============================================================================== - if [ -r "$CONFIG_FILE" ]; then - source "$CONFIG_FILE" - else - init_store - source "$CONFIG_FILE" - fi - - verify_store - - 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 - #============================================================================== - # 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"; OP="TRUE" - elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" - elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then init_store; 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 - #============================================================================== - # 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" ]; - 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 - 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 - - #============================================================================== - # End Section: Actions / Stage 3 - #============================================================================== From b2482ca1e4840a67c13dbce5bd811b50f5c8d606 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Sun, 14 Feb 2016 23:56:32 -0600 Subject: [PATCH 34/52] Improvded README --- README.md | 40 ++++++++++++------ .../UserInterfaceState.xcuserstate | Bin 15437 -> 15437 bytes src/main/stage2.sns.sh | 2 +- src/main/stage3.sns.sh | 4 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7984fd9..2cfb451 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,31 @@ Simple Note System ================== -The Simple Note System is a shell script enabling easy management of plain-text -notes. SNS depends on GPG for encryption and uses the vim editor by default. +The Simple Note System is a shell script partially inspired by [pass], in that +it stores notes as normal, plaintext, files in normal folders. It uses the +environment-specified editor, and can be configured to use GPG encryption. - usage: sns [-ce] NAME NOTEBOOK SECTION" - sns [-d ] NAME NOTEBOOK SECTION" - sns [-lp] NOTEBOOK" - sns [-w ]" - sns [-h ]" +SNS was originally conceived one morning during an update to a popular note-taking +app. The thought occurred that a note system need not reinvent the wheel with +its own GUI editor and proprietary file format, but instead could use the tools +already provided by the operating system. - -c | --create : Create note" - -d | --delete : Delete note" - -e | --edit : Open note for editing" - -h | --help : Display this message" - -p | --print : Print note to console" - -l | --list : List all notes in NOTEBOOK" - -i | --init : Write default config and initalize SNS store" +As it developed, OpenSSL encryption was dropped in favor of GPG, and the script +was almost entirely rewritten as SNSv2. + + simple note system + ================== + + usage: sns [-cedp] NAME NOTEBOOK SECTION + sns [-l] NOTEBOOK + sns [-hi] + -c | --create : Create note + -d | --delete : Delete note + -e | --edit : Open note for editing + -h | --help : Display this message + -p | --print : Print note to console + -l | --list : List all notes in NOTEBOOK + -i | --init : Write default config and initalize SNS store" + + +[pass]: http://passwordstore.org diff --git a/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate b/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate index c97975e4e9623f6bed218612f7107acedad50a09..df0db656877e336bd9f922a0891aabdacbe362db 100644 GIT binary patch delta 27 icmX?GakgSZKOc+Ts?4>UC-bq%16d*uHqX`Fzy|=UN(*iP delta 27 jcmX?GakgSZKOc)o1HbF$$$V_`EF$#}S8SfEyMYe?nl}oV diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index ed56a34..10cbc02 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -15,7 +15,7 @@ elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then init_store; exit 0 + elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then init_store; exit 0 else if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index a0a1adf..673b184 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -17,11 +17,11 @@ if [ "$LIST" == TRUE ]; then list exit 0 - elif [ -z "$NAME" ]; + 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" From a8a92ba0799a0f013ad86921ed28a3f323337045 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 00:03:01 -0600 Subject: [PATCH 35/52] Changed help function to match README --- src/includes/help.sns.sh | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/includes/help.sns.sh b/src/includes/help.sns.sh index 7cd4981..8f26e97 100644 --- a/src/includes/help.sns.sh +++ b/src/includes/help.sns.sh @@ -1,18 +1,14 @@ function help { - echo "" - echo "usage: sns [-ce] NAME NOTEBOOK SECTION" - echo " sns [-d ] NAME NOTEBOOK SECTION" - echo " sns [-lp] NOTEBOOK" - echo " sns [-w ]" - echo " sns [-h ]" + printf "\n%s" "usage: sns [-cedp] NAME NOTEBOOK SECTION" + printf "\n%s" " sns [-l] NOTEBOOK" + printf "\n%s" " sns [-hi ]" - echo "" - echo " -c | --create : Create note" - echo " -d | --delete : Delete note" - echo " -e | --edit : Open note for editing" - echo " -h | --help : Display this message" - echo " -p | --print : Print note to console" - echo " -l | --list : List all notes in NOTEBOOK" - echo " -i | --init : Write default config and initalize SNS store" - echo "" + printf "\n%s" " -c | --create : Create note" + printf "\n%s" " -d | --delete : Delete note" + printf "\n%s" " -e | --edit : Open note for editing" + printf "\n%s" " -h | --help : Display this message" + printf "\n%s" " -p | --print : Print note to console" + printf "\n%s" " -l | --list : List all notes in NOTEBOOK" + printf "\n%s" " -i | --init : Write default config and initalize SNS store" + printf "\n" } From 3664b3b4296a62701a2ec6116347d5130380537f Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 00:08:21 -0600 Subject: [PATCH 36/52] Fixed a bug where verify_store would create a " directory tree. --- src/includes/verify_store.sns.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/includes/verify_store.sns.sh b/src/includes/verify_store.sns.sh index 9604d8d..31a59b9 100644 --- a/src/includes/verify_store.sns.sh +++ b/src/includes/verify_store.sns.sh @@ -1,7 +1,7 @@ function verify_store { - ETC_DIR="$(dirname \"$CONFIG_FILE\")" + ETC_DIR=$(dirname "$CONFIG_FILE") STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") - for DIR in ${STORE_DIRS[@]}; do + for DIR in "${STORE_DIRS[@]}"; do mkdir -p "$DIR" done } From d11c2597c4047e04847e5ee8346749f12f4c15f0 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 00:20:50 -0600 Subject: [PATCH 37/52] Formatting changes --- build.sh | 1 + header.sh | 5 ++++- src/includes/init_store.sns.sh | 2 +- src/main/stage1.sns.sh | 4 +--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index d23b4e5..3a306e3 100755 --- a/build.sh +++ b/build.sh @@ -24,4 +24,5 @@ cat ./src/main/stage1.sns.sh >> "$S" cat ./src/main/stage2.sns.sh >> "$S" cat ./src/main/stage3.sns.sh >> "$S" +chmod u+x "$S" exit diff --git a/header.sh b/header.sh index 454afb9..9ffc69b 100644 --- a/header.sh +++ b/header.sh @@ -12,10 +12,13 @@ cat << EOF # Prevent freak accidents involving the root directory if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi -PROD_STR="$PROD_STR" +readonly PROD_STR="$PROD_STR" readonly VER_STR="$VER_STR" readonly ROOT_DIR="\$HOME"/.config/sns readonly NOTES_DIR="\$ROOT_DIR"/notes readonly TMP_DIR="\$ROOT_DIR"/tmp readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" + +printf "%s\n" "\$PROD_STR" +printf "%s\n" "------------------" EOF diff --git a/src/includes/init_store.sns.sh b/src/includes/init_store.sns.sh index c58654b..40a4f0d 100644 --- a/src/includes/init_store.sns.sh +++ b/src/includes/init_store.sns.sh @@ -24,7 +24,7 @@ EOF chmod 600 "$CONFIG_FILE" -printf " - %s\n" "Rewrote Default Configuration" +printf "\n - %s\n" "Rewrote Default Configuration" if [ "$WILL_INIT" == "TRUE" ]; then printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR" diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index b2ddef2..dc3e962 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -4,6 +4,7 @@ #============================================================================== # Stage 1: Read Configuration / Verify Integrity #============================================================================== + if [ -r "$CONFIG_FILE" ]; then source "$CONFIG_FILE" else @@ -24,14 +25,11 @@ 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 From 2b77e325ae7305cfc2a072fea495e2dd3ea223b4 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 00:40:36 -0600 Subject: [PATCH 38/52] Changed old argument parser to more sensible case statement; began work to recognize any path as a valid note path. --- src/main/stage2.sns.sh | 90 ++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 10cbc02..3ddb324 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -1,35 +1,57 @@ - #============================================================================== - # 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"; OP="TRUE" - elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" - elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then init_store; 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 +#============================================================================== +# Stage 2: Argument Parsing +#============================================================================== +NOTE="" +if [ -z "$1" ]; then help; exit 20 +else +for ARG in "$@"; do + case "$ARG" in + -c|--create) + CREATE="TRUE" + OP="TRUE" + ;; + -d|--delete) + DELETE="TRUE" + OP="TRUE" + ;; + -e|--edit) + EDIT="TRUE" + OP="TRUE" + ;; + -ce|-ec) + CREATE="TRUE" + EDIT="TRUE" + OP="TRUE" + ;; + -l|--list) + LIST="TRUE" + OP="TRUE" + ;; + -p|--print) + PRINT="TRUE" + OP="TRUE" + ;; + -h|--help) + help + exit 0 + ;; + -i|--init-store) + init_store + exit 0 + ;; + *) + NOTE="$ARG" + break; + ;; + esac +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. +# w_conf and help are called here to avoid excess stage 3 code. From faab86dff29faa19a296974177c9f750eb6cc942 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 00:55:29 -0600 Subject: [PATCH 39/52] Continued work on loosening note definition; added framework for color in errors. --- errors.ref | 6 ++-- header.sh | 3 ++ src/main/stage1.sns.sh | 63 +++++++++++++++++------------------ src/main/stage3.sns.sh | 74 +++++++++++++++++++++--------------------- 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/errors.ref b/errors.ref index 28754c8..eb46e38 100644 --- a/errors.ref +++ b/errors.ref @@ -3,12 +3,12 @@ Error Code Reference General------------------------------------------------------------------------- ERR_NO_ARGS 10 No arguments were specified -ERR_NO_OP 20 -ERR_NO_NOTEBOOK 30 A required argument was not provided +ERR_NO_OP 20 No operation was specified +ERR_NO_NOTE 30 A required argument was not provided Encryption---------------------------------------------------------------------- ERR_NO_GPG 100 Encryption is enabled, but GPG is not installed ERR_NO_KEY 110 Encryption is enabled, but no recipient was specified Create-------------------------------------------------------------------------- -ERR_NOTE_EXiSTS 200 The specified note already exists \ No newline at end of file +ERR_NOTE_EXiSTS 200 The specified note already exists diff --git a/header.sh b/header.sh index 9ffc69b..63d8c87 100644 --- a/header.sh +++ b/header.sh @@ -19,6 +19,9 @@ readonly NOTES_DIR="\$ROOT_DIR"/notes readonly TMP_DIR="\$ROOT_DIR"/tmp 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" "------------------" EOF diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index dc3e962..77d5008 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -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 diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 673b184..3f813f0 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -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 +#============================================================================== From 037fd9c2fa81e25ac37a236287ea7e1bcdc36e35 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 01:18:44 -0600 Subject: [PATCH 40/52] Made changes to create and delete functions reflecting recent design decisions --- src/includes/create.sns.sh | 30 +++++++++++++++++------------- src/includes/delete.sns.sh | 11 ++++++----- src/main/stage3.sns.sh | 17 ++++------------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index a0549ed..228bad0 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -1,18 +1,21 @@ function create(){ # Depends : p_header - # Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME + # Requires: $NOTE, $NOTE_DIR, # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt # Given a valid setup, create writes the standard note header as specified # by p_header, to $NOTE. # 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 + if [ -e "$NOTE_DIR/$NOTE" ]; then + printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Note already exists"\ + "Hint: use -e to edit the note." + exit 200 + fi + + # If the note's notebook/section does not exist, + # create the appropriate folders. + mkdir -p "$NOTE_DIR"/$(dirname "$NOTE") # Write the standard note header if [ "$ENCRYPTION" == "TRUE" ]; then @@ -20,12 +23,13 @@ function create(){ p_header > "$TMP_NOTE" encrypt else - p_header > "$NOTE" + p_header > "$NOTE_DIR/$NOTE" fi - # Make sure the note exists, and inform the user. - if [ -e "$NOTE" ]; then - echo "Created note: $NOTEBOOK/$SECTION/$NAME." + # Make sure the note exists, and inform the user of the result. + if [ -e "$NOTE_DIR/$NOTE" ]; then + printf " - %s\n" "Created note: ${NOTE%.*}" else - printf "%s\n" "Something went wrong." + printf " $RED_COLOR!$RESET_COLOR%s\n"\ + "Something went wrong, and the note was not created." fi } diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index 696d9d1..a8aefed 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -1,10 +1,11 @@ function delete(){ - #Requires: $NOTE, $NOTEBOOK, $SECTION, $NAME + # Requires: $NOTE, $NOTE_DIR # Given a valid $NOTE, delete removes $NOTE from sns. - if [ -e "$NOTE" ]; then - rm "$NOTE" - printf "\n%s\n" "Deleted note: $NOTEBOOK/$SECTION/$NAME." + + if [ -e "$NOTE_DIR/$NOTE" ]; then + rm "$NOTE_DIR/$NOTE" + printf " - %s\n" "Deleted note: ${NOTE%.*}." else - printf "\n%s\n" "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." + printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." fi } diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 3f813f0..ca3c262 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -9,29 +9,20 @@ # 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" + printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified." exit 30 fi 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" + readonly NOTE="$NOTE.$EXT.gpg" else - readonly NOTE="$NOTE_DIR/$NAME.$EXT" + readonly NOTE="$NOTE.$EXT" fi +if [ "$LIST" == "TRUE" ]; then list; exit 0; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$CREATE" == "TRUE" ]; then create; fi From 7085a46ef3eb320956f5dd07afb4354b2e58c45d Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 11:24:57 -0600 Subject: [PATCH 41/52] Sweeping refinements and formatting changes --- build.sh | 3 +- errors.md | 21 +++++++ errors.ref | 14 ----- header.sh | 5 +- src/includes/create.sns.sh | 4 +- src/includes/delete.sns.sh | 2 +- src/includes/edit.sns.sh | 33 ++++++++--- src/includes/init_store.sns.sh | 6 +- src/includes/libencryption.sns.sh | 8 +-- src/includes/list.sns.sh | 8 +-- src/includes/pause.sns.sh | 4 -- src/includes/print.sns.sh | 21 ++++--- src/includes/verify_store.sns.sh | 6 +- src/main/stage1.sns.sh | 35 ++++-------- src/main/stage2.sns.sh | 91 ++++++++++++++----------------- src/main/stage3.sns.sh | 9 +-- 16 files changed, 133 insertions(+), 137 deletions(-) mode change 100644 => 100755 build.sh create mode 100644 errors.md delete mode 100644 errors.ref delete mode 100644 src/includes/pause.sns.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 3a306e3..cb5e42d --- a/build.sh +++ b/build.sh @@ -10,7 +10,6 @@ bash header.sh > "$S" echo -e "\n# Section: Functions" >> "$S" cat ./src/includes/init_store.sns.sh >> "$S" cat ./src/includes/verify_store.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.sns.sh >> "$S" @@ -19,7 +18,7 @@ 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 "%s\n" "# End Section: Functions" >> "$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.md b/errors.md new file mode 100644 index 0000000..edde651 --- /dev/null +++ b/errors.md @@ -0,0 +1,21 @@ +# Simple Note System, version 2 +## Error Code Reference + +### General Codes +| Name | Code | Meaning | +|-------------|------|--------------------------------------| +| ERR_NO_ARGS | 10 | No arguments were specified | +| ERR_NO_OP | 20 | No operation was specified | +| ERR_NO_NOTE | 30 | A required argument was not provided | + +### Encryption-related codes +|Name | Code | Meaning | +|------------|------|-------------------------------------------------------| +| ERR_NO_GPG | 100 | Encryption is enabled, but GPG is not installed | +| ERR_NO_KEY | 110 | Encryption is enabled, but no recipient was specified | + +### Creation-related codes +|Name | Code | Meaning | +|-----------------|------|-----------------------------------| +| ERR_NOTE_EXiSTS | 200 | The specified note already exists | +| ERR_NOTE_NO_READ| 205 | The specified note cannot be read | diff --git a/errors.ref b/errors.ref deleted file mode 100644 index eb46e38..0000000 --- a/errors.ref +++ /dev/null @@ -1,14 +0,0 @@ -Simple Note System, version 2 -Error Code Reference - -General------------------------------------------------------------------------- -ERR_NO_ARGS 10 No arguments were specified -ERR_NO_OP 20 No operation was specified -ERR_NO_NOTE 30 A required argument was not provided - -Encryption---------------------------------------------------------------------- -ERR_NO_GPG 100 Encryption is enabled, but GPG is not installed -ERR_NO_KEY 110 Encryption is enabled, but no recipient was specified - -Create-------------------------------------------------------------------------- -ERR_NOTE_EXiSTS 200 The specified note already exists diff --git a/header.sh b/header.sh index 63d8c87..d3c6c8f 100644 --- a/header.sh +++ b/header.sh @@ -1,5 +1,5 @@ PROD_STR="Simple Note System" -VER_STR="v2.0a8" +VER_STR="v2.0a9" YEAR=2016 cat << EOF @@ -12,6 +12,7 @@ cat << EOF # Prevent freak accidents involving the root directory if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi +# Store files and locations readonly PROD_STR="$PROD_STR" readonly VER_STR="$VER_STR" readonly ROOT_DIR="\$HOME"/.config/sns @@ -19,9 +20,11 @@ readonly NOTES_DIR="\$ROOT_DIR"/notes readonly TMP_DIR="\$ROOT_DIR"/tmp readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" +#Color codes for error reporting readonly RED_COLOR='\033[1;31m' readonly RESET_COLOR='\033[0m' +#Print the program header to stdout printf "%s\n" "\$PROD_STR" printf "%s\n" "------------------" EOF diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 228bad0..2a9d6a6 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -7,7 +7,7 @@ function create(){ # Refuse to overwrite a note if [ -e "$NOTE_DIR/$NOTE" ]; then - printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Note already exists"\ "Hint: use -e to edit the note." exit 200 @@ -29,7 +29,7 @@ function create(){ if [ -e "$NOTE_DIR/$NOTE" ]; then printf " - %s\n" "Created note: ${NOTE%.*}" else - printf " $RED_COLOR!$RESET_COLOR%s\n"\ + >&2 printf " $RED_COLOR!$RESET_COLOR%s\n"\ "Something went wrong, and the note was not created." fi } diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index a8aefed..4404f95 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -6,6 +6,6 @@ function delete(){ rm "$NOTE_DIR/$NOTE" printf " - %s\n" "Deleted note: ${NOTE%.*}." else - printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." fi } diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index 54702c5..a12ab5d 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -4,29 +4,46 @@ function edit(){ # Verify an editor was specified if [ -z "$EDITOR" ]; then - >&2 echo "Error no editor specified in environment." + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ + "No editor specified in environment." exit # Verify the note exists elif [ ! -r "$NOTE" ]; then - echo "ERROR: Note cannot be opened for editing." + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ + "Note cannot be opened for editing." exit 40; fi -# When encryption is enabled, decrypt $NOTE to a temp file + +# If encryption is enabled, decrypt $NOTE to a temp file, otherwise +# operate on the note directly. if [ "$ENCRYPTION" == "TRUE" ]; then 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 +else + TMP_NOTE="$NOTE"; +fi +# Write an ammendment header +if [ -z "$CREATE" ]; then + printf "\n %s\n" "edit - $(date)" >> "$TMP_NOTE" + printf "\n %s\n" "===================================" >> "$TMP_NOTE" +fi -if [ -z "$CREATE" ]; then printf "\nEDIT %s" "$(date)" >> "$TMP_NOTE"; fi - +# Call the editor +printf " - %s\n" "editing ${NOTE%.*}" "$EDITOR" "$TMP_NOTE" +# If the file was previously decrypted, encrypt it back if [ "$ENCRYPTION" == "TRUE" ]; then rm "$NOTE" encrypt; - if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi + if [ ! -r "$NOTE" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved." + cp "$NOTE.bk" "$NOTE" + else + rm "$NOTE.bk"; + fi fi + } diff --git a/src/includes/init_store.sns.sh b/src/includes/init_store.sns.sh index 40a4f0d..9a2c20d 100644 --- a/src/includes/init_store.sns.sh +++ b/src/includes/init_store.sns.sh @@ -24,11 +24,11 @@ EOF chmod 600 "$CONFIG_FILE" -printf "\n - %s\n" "Rewrote Default Configuration" +printf " - %s\n" "Rewrote Default Configuration" if [ "$WILL_INIT" == "TRUE" ]; then - printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR" + printf " - %s\n" "Environment initialized in $ROOT_DIR" else - printf " - %s\n" "Store already initialized." + printf " - %s\n" "Store already initialized." fi } diff --git a/src/includes/libencryption.sns.sh b/src/includes/libencryption.sns.sh index 71b1181..04ba8b3 100644 --- a/src/includes/libencryption.sns.sh +++ b/src/includes/libencryption.sns.sh @@ -1,6 +1,6 @@ function encrypt(){ # 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 +# output file, $NOTE, will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private # GPG key. gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE" @@ -8,8 +8,8 @@ function encrypt(){ } function decrypt(){ -# 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. +# This function, given a file to decrypt, will attempt to decrypt the file +# against the specified recipient's private key, and print the result to +# stdout. gpg -d "$NOTE" } diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index d65d4f7..2869286 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,8 +1,4 @@ function list(){ - 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 - fi + # This function, given a folder, $NOTE, will list the contents of $NOTE. + ls "$NOTE" } diff --git a/src/includes/pause.sns.sh b/src/includes/pause.sns.sh deleted file mode 100644 index ace9b99..0000000 --- a/src/includes/pause.sns.sh +++ /dev/null @@ -1,4 +0,0 @@ -function pause { - read -rp " Press [Enter] to continue." - echo "" -} diff --git a/src/includes/print.sns.sh b/src/includes/print.sns.sh index a24cd2b..fba75a4 100644 --- a/src/includes/print.sns.sh +++ b/src/includes/print.sns.sh @@ -1,13 +1,12 @@ function print(){ - if [ -r "$NOTE" ]; then - if [ -z "$CREATE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then - decrypt - else - cat "$NOTE" - fi - else - printf "\nERROR: Note cannot be found.\n" - fi - fi +# Given an existing file, $NOTE, print prints the contents of $NOTE to stdout. + +if [ -r "$NOTE" ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout + else cat "$NOTE" fi +else + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Note cannot be found." + exit 205 #ERR_NOTE_NO_READ +fi } diff --git a/src/includes/verify_store.sns.sh b/src/includes/verify_store.sns.sh index 31a59b9..ef0e9f6 100644 --- a/src/includes/verify_store.sns.sh +++ b/src/includes/verify_store.sns.sh @@ -1,7 +1,11 @@ function verify_store { + ETC_DIR=$(dirname "$CONFIG_FILE") + STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") for DIR in "${STORE_DIRS[@]}"; do - mkdir -p "$DIR" + if [ ! -d "$DIR" ]; then + mkdir -p "$DIR" + fi done } diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 77d5008..40cbd1e 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -4,33 +4,20 @@ if [ -r "$CONFIG_FILE" ]; then source "$CONFIG_FILE" + verify_store else - init_store - source "$CONFIG_FILE" -fi - -verify_store - -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"; } + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Configuration note found. Please run sns -i." fi if [ "$ENCRYPTION" == "TRUE" ]; then - if [ ! -d "$ROOT_DIR"/tmp ]; then - mkdir -p "$ROOT_DIR"/tmp + if [ ! -r $(which gpg) ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Encryption was specified, but GPG is not installed." + exit 100 + elif [ -z "$PUBKEY" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "No GPG recipient was provided in $CONFIG_FILE. " + exit 110 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 diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 3ddb324..4423feb 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -4,54 +4,45 @@ NOTE="" if [ -z "$1" ]; then help; exit 20 else -for ARG in "$@"; do - case "$ARG" in - -c|--create) - CREATE="TRUE" - OP="TRUE" - ;; - -d|--delete) - DELETE="TRUE" - OP="TRUE" - ;; - -e|--edit) - EDIT="TRUE" - OP="TRUE" - ;; - -ce|-ec) - CREATE="TRUE" - EDIT="TRUE" - OP="TRUE" - ;; - -l|--list) - LIST="TRUE" - OP="TRUE" - ;; - -p|--print) - PRINT="TRUE" - OP="TRUE" - ;; - -h|--help) - help - exit 0 - ;; - -i|--init-store) - init_store - exit 0 - ;; - *) - NOTE="$ARG" - break; - ;; - esac -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="" + for ARG in "$@"; do + case "$ARG" in + -c|--create) + CREATE="TRUE" + OP="TRUE" + ;; + -d|--delete) + DELETE="TRUE" + OP="TRUE" + ;; + -e|--edit) + EDIT="TRUE" + OP="TRUE" + ;; + -ce|-ec) + CREATE="TRUE" + EDIT="TRUE" + OP="TRUE" + ;; + -l|--list) + LIST="TRUE" + OP="TRUE" + ;; + -p|--print) + PRINT="TRUE" + OP="TRUE" + ;; + -h|--help) + help + exit 0 + ;; + -i|--init-store) + init_store + exit 0 + ;; + *) + NOTE="$ARG" + break; + ;; + esac + done fi -fi - -# 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 ca3c262..2880385 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -13,8 +13,6 @@ if [ -z "$NOTE" ]; then exit 30 fi -NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION" - if [ "$ENCRYPTION" == "TRUE" ]; then SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename readonly NOTE="$NOTE.$EXT.gpg" @@ -22,12 +20,11 @@ else readonly NOTE="$NOTE.$EXT" fi -if [ "$LIST" == "TRUE" ]; then list; exit 0; fi -if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi +if [ "$LIST" == "TRUE" ]; then list ; exit 0; 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 [ "$EDIT" == "TRUE" ]; then edit ; fi #============================================================================== # End Section: Actions / Stage 3 #============================================================================== From ca398122f37a6931ca8655628ed6e5c97b90a6d6 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 11:36:08 -0600 Subject: [PATCH 42/52] Script was modified to pass shellcheck --- src/includes/create.sns.sh | 8 ++++---- src/includes/delete.sns.sh | 4 ++-- src/includes/print.sns.sh | 2 +- src/main/stage1.sns.sh | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 2a9d6a6..2303d23 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -6,7 +6,7 @@ function create(){ # by p_header, to $NOTE. # Refuse to overwrite a note - if [ -e "$NOTE_DIR/$NOTE" ]; then + if [ -e "$NOTES_DIR/$NOTE" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Note already exists"\ "Hint: use -e to edit the note." @@ -15,7 +15,7 @@ function create(){ # If the note's notebook/section does not exist, # create the appropriate folders. - mkdir -p "$NOTE_DIR"/$(dirname "$NOTE") + mkdir -p "$NOTES_DIR"/"$(dirname "$NOTE")" # Write the standard note header if [ "$ENCRYPTION" == "TRUE" ]; then @@ -23,10 +23,10 @@ function create(){ p_header > "$TMP_NOTE" encrypt else - p_header > "$NOTE_DIR/$NOTE" + p_header > "$NOTES_DIR/$NOTE" fi # Make sure the note exists, and inform the user of the result. - if [ -e "$NOTE_DIR/$NOTE" ]; then + if [ -e "$NOTES_DIR/$NOTE" ]; then printf " - %s\n" "Created note: ${NOTE%.*}" else >&2 printf " $RED_COLOR!$RESET_COLOR%s\n"\ diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index 4404f95..5c5ee49 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -2,8 +2,8 @@ function delete(){ # Requires: $NOTE, $NOTE_DIR # Given a valid $NOTE, delete removes $NOTE from sns. - if [ -e "$NOTE_DIR/$NOTE" ]; then - rm "$NOTE_DIR/$NOTE" + if [ -e "$NOTES_DIR/$NOTE" ]; then + rm "$NOTES_DIR/$NOTE" printf " - %s\n" "Deleted note: ${NOTE%.*}." else >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." diff --git a/src/includes/print.sns.sh b/src/includes/print.sns.sh index fba75a4..7b6d2eb 100644 --- a/src/includes/print.sns.sh +++ b/src/includes/print.sns.sh @@ -3,7 +3,7 @@ function print(){ if [ -r "$NOTE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout - else cat "$NOTE" fi + else cat "$NOTE"; fi else >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Note cannot be found." diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 40cbd1e..26ec031 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -11,7 +11,7 @@ else fi if [ "$ENCRYPTION" == "TRUE" ]; then - if [ ! -r $(which gpg) ]; then + if [ ! -r "$(which gpg)" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Encryption was specified, but GPG is not installed." exit 100 From 069280106934681ab3cad0e066c386bc5492f206 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 11:38:03 -0600 Subject: [PATCH 43/52] Fixed a bug where sns does not exit in the abscence of an existing store --- errors.md | 11 +- sns.sh | 317 +++++++++++++++++++++++++++++++++++++++++ src/main/stage1.sns.sh | 1 + 3 files changed, 324 insertions(+), 5 deletions(-) create mode 100755 sns.sh diff --git a/errors.md b/errors.md index edde651..9e13a94 100644 --- a/errors.md +++ b/errors.md @@ -2,11 +2,12 @@ ## Error Code Reference ### General Codes -| Name | Code | Meaning | -|-------------|------|--------------------------------------| -| ERR_NO_ARGS | 10 | No arguments were specified | -| ERR_NO_OP | 20 | No operation was specified | -| ERR_NO_NOTE | 30 | A required argument was not provided | +| Name | Code | Meaning | +|--------------|------|---------------------------------------| +| ERR_NO_STORE | 5 | the SNS store needs to be initialized | +| ERR_NO_ARGS | 10 | No arguments were specified | +| ERR_NO_OP | 20 | No operation was specified | +| ERR_NO_NOTE | 30 | A required argument was not provided | ### Encryption-related codes |Name | Code | Meaning | diff --git a/sns.sh b/sns.sh new file mode 100755 index 0000000..9c7bd71 --- /dev/null +++ b/sns.sh @@ -0,0 +1,317 @@ +#!/bin/bash +#========================================================== +# Simple Note System, v2.0a9 +# Copyright 2016, Xenese Labs/Sicron-Perion XNF +#========================================================== + +# Prevent freak accidents involving the root directory +if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi + +# Store files and locations +readonly PROD_STR="Simple Note System" +readonly VER_STR="v2.0a9" +readonly ROOT_DIR="$HOME"/.config/sns +readonly NOTES_DIR="$ROOT_DIR"/notes +readonly TMP_DIR="$ROOT_DIR"/tmp +readonly CONFIG_FILE="$ROOT_DIR/sns.conf" + +#Color codes for error reporting +readonly RED_COLOR='\033[1;31m' +readonly RESET_COLOR='\033[0m' + +#Print the program header to stdout +printf "%s\n" "$PROD_STR" +printf "%s\n" "------------------" + +# Section: Functions +function init_store { + +if [ ! -d "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi +if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi + + +cat > "$CONFIG_FILE" << EOF +# This file contains directives for the Simple Note System. + +EXT=note # File extension to use (for listing notes) + +#EDITOR= # Preferred Editor: + # If you would like to specify a different editor for + # sns to use, you may do so here. + +ENCRYPTION="FALSE" # Main Encryption Toggle: + # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST + # Change this to TRUE to enable encryption. + +PUBKEY="" # Public Key + # Encryption is done using GPG. You must enter your + # public key's identifier here. +EOF + +chmod 600 "$CONFIG_FILE" + +printf " - %s\n" "Rewrote Default Configuration" + +if [ "$WILL_INIT" == "TRUE" ]; then + printf " - %s\n" "Environment initialized in $ROOT_DIR" +else + printf " - %s\n" "Store already initialized." +fi +} +function verify_store { + + ETC_DIR=$(dirname "$CONFIG_FILE") + + STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") + for DIR in "${STORE_DIRS[@]}"; do + if [ ! -d "$DIR" ]; then + mkdir -p "$DIR" + fi + done +} +function help { + printf "\n%s" "usage: sns [-cedp] NAME NOTEBOOK SECTION" + printf "\n%s" " sns [-l] NOTEBOOK" + printf "\n%s" " sns [-hi ]" + + printf "\n%s" " -c | --create : Create note" + printf "\n%s" " -d | --delete : Delete note" + printf "\n%s" " -e | --edit : Open note for editing" + printf "\n%s" " -h | --help : Display this message" + printf "\n%s" " -p | --print : Print note to console" + printf "\n%s" " -l | --list : List all notes in NOTEBOOK" + printf "\n%s" " -i | --init : Write default config and initalize SNS store" + printf "\n" +} +function p_header(){ + printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" +} +function encrypt(){ +# 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(){ +# This function, given a file to decrypt, will attempt to decrypt the file +# against the specified recipient's private key, and print the result to +# stdout. + gpg -d "$NOTE" +} +function create(){ + # Depends : p_header + # Requires: $NOTE, $NOTE_DIR, + # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt + # Given a valid setup, create writes the standard note header as specified + # by p_header, to $NOTE. + + # Refuse to overwrite a note + if [ -e "$NOTES_DIR/$NOTE" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Note already exists"\ + "Hint: use -e to edit the note." + exit 200 + fi + + # If the note's notebook/section does not exist, + # create the appropriate folders. + mkdir -p "$NOTES_DIR"/"$(dirname "$NOTE")" + + # Write the standard note header + if [ "$ENCRYPTION" == "TRUE" ]; then + TMP_NOTE="$TMP_DIR"/"$SESSION_ID" + p_header > "$TMP_NOTE" + encrypt + else + p_header > "$NOTES_DIR/$NOTE" + fi + # Make sure the note exists, and inform the user of the result. + if [ -e "$NOTES_DIR/$NOTE" ]; then + printf " - %s\n" "Created note: ${NOTE%.*}" + else + >&2 printf " $RED_COLOR!$RESET_COLOR%s\n"\ + "Something went wrong, and the note was not created." + fi +} +function delete(){ + # Requires: $NOTE, $NOTE_DIR + # Given a valid $NOTE, delete removes $NOTE from sns. + + if [ -e "$NOTES_DIR/$NOTE" ]; then + rm "$NOTES_DIR/$NOTE" + printf " - %s\n" "Deleted note: ${NOTE%.*}." + else + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." + fi +} +function edit(){ +# Requires: $EDITOR, $NOTE +# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt + +# Verify an editor was specified +if [ -z "$EDITOR" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ + "No editor specified in environment." + exit +# Verify the note exists +elif [ ! -r "$NOTE" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ + "Note cannot be opened for editing." + exit 40; +fi + +# If encryption is enabled, decrypt $NOTE to a temp file, otherwise +# operate on the note directly. +if [ "$ENCRYPTION" == "TRUE" ]; then + cp "$NOTE" "$NOTE".bk #Insurance + TMP_NOTE="$TMP_DIR/$SESSION_ID" + decrypt > "$TMP_NOTE" +else + TMP_NOTE="$NOTE"; +fi + +# Write an ammendment header +if [ -z "$CREATE" ]; then + printf "\n %s\n" "edit - $(date)" >> "$TMP_NOTE" + printf "\n %s\n" "===================================" >> "$TMP_NOTE" +fi + +# Call the editor +printf " - %s\n" "editing ${NOTE%.*}" +"$EDITOR" "$TMP_NOTE" + +# If the file was previously decrypted, encrypt it back +if [ "$ENCRYPTION" == "TRUE" ]; then + rm "$NOTE" + encrypt; + if [ ! -r "$NOTE" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved." + cp "$NOTE.bk" "$NOTE" + else + rm "$NOTE.bk"; + fi +fi + +} +function print(){ +# Given an existing file, $NOTE, print prints the contents of $NOTE to stdout. + +if [ -r "$NOTE" ]; then + if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout + else cat "$NOTE"; fi +else + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Note cannot be found." + exit 205 #ERR_NOTE_NO_READ +fi +} +function list(){ + # This function, given a folder, $NOTE, will list the contents of $NOTE. + ls "$NOTE" +} +# End Section: Functions +#============================================================================== +# Stage 1: Read Configuration / Verify Integrity +#============================================================================== + +if [ -r "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" + verify_store +else + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Configuration note found. Please run sns -i." + exit 5 #ERR_NO_STORE +fi + +if [ "$ENCRYPTION" == "TRUE" ]; then + if [ ! -r "$(which gpg)" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "Encryption was specified, but GPG is not installed." + exit 100 + elif [ -z "$PUBKEY" ]; then + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + "No GPG recipient was provided in $CONFIG_FILE. " + exit 110 + fi +fi +#============================================================================== +# Stage 2: Argument Parsing +#============================================================================== +NOTE="" +if [ -z "$1" ]; then help; exit 20 +else + for ARG in "$@"; do + case "$ARG" in + -c|--create) + CREATE="TRUE" + OP="TRUE" + ;; + -d|--delete) + DELETE="TRUE" + OP="TRUE" + ;; + -e|--edit) + EDIT="TRUE" + OP="TRUE" + ;; + -ce|-ec) + CREATE="TRUE" + EDIT="TRUE" + OP="TRUE" + ;; + -l|--list) + LIST="TRUE" + OP="TRUE" + ;; + -p|--print) + PRINT="TRUE" + OP="TRUE" + ;; + -h|--help) + help + exit 0 + ;; + -i|--init-store) + init_store + exit 0 + ;; + *) + NOTE="$ARG" + break; + ;; + esac + done +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 + +if [ "$ENCRYPTION" == "TRUE" ]; then + SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename + readonly NOTE="$NOTE.$EXT.gpg" +else + readonly NOTE="$NOTE.$EXT" +fi + +if [ "$LIST" == "TRUE" ]; then list ; exit 0; 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 +#============================================================================== diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index 26ec031..ede1d7d 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -8,6 +8,7 @@ if [ -r "$CONFIG_FILE" ]; then else >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Configuration note found. Please run sns -i." + exit 5 #ERR_NO_STORE fi if [ "$ENCRYPTION" == "TRUE" ]; then From e7dbc219546d88f16701d9c7313292514fb47d68 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 15:17:49 -0600 Subject: [PATCH 44/52] Fixed a bug where the program would stop before the init command could take effect --- src/main/stage1.sns.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index ede1d7d..1ddfc3c 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -5,9 +5,9 @@ if [ -r "$CONFIG_FILE" ]; then source "$CONFIG_FILE" verify_store -else +elif [ $1 != "-i" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Configuration note found. Please run sns -i." + "Configuration not found. Please run sns -i." exit 5 #ERR_NO_STORE fi From 5a594b71cff626d4d83e3f5ebcbeac4ea36bc0e1 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 15:20:32 -0600 Subject: [PATCH 45/52] Fixed a bug where the list function does not look in $NOTES_DIR --- src/includes/list.sns.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh index 2869286..5a39dec 100644 --- a/src/includes/list.sns.sh +++ b/src/includes/list.sns.sh @@ -1,4 +1,4 @@ function list(){ # This function, given a folder, $NOTE, will list the contents of $NOTE. - ls "$NOTE" + ls "$NOTES_DIR/${NOTE%.*}" } From bc3cc7661c88246d48451cdbae804219d40f62d1 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 15:28:53 -0600 Subject: [PATCH 46/52] Fixed a bug where the p_header function would not fill in the title. --- src/includes/p_header.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/includes/p_header.sh b/src/includes/p_header.sh index f3b1156..b42dfd6 100644 --- a/src/includes/p_header.sh +++ b/src/includes/p_header.sh @@ -1,3 +1,3 @@ function p_header(){ - printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" + printf "# %s\n## Date: %s\n" "$(basename ${NOTE%.*})" "$(date)" } From 0be408290d98a95181dbac13281fefb03c58b24a Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 15:58:26 -0600 Subject: [PATCH 47/52] Added licensing information (GPLv2) and began importing completion code from pass. --- LICENSE | 278 ++++++++++++++++++++++++++++++++++ header.sh | 20 ++- sns.sh | 317 --------------------------------------- src/bash-completion/sns | 94 ++++++++++++ src/includes/edit.sns.sh | 14 +- 5 files changed, 395 insertions(+), 328 deletions(-) create mode 100644 LICENSE delete mode 100755 sns.sh create mode 100644 src/bash-completion/sns diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4619a0f --- /dev/null +++ b/LICENSE @@ -0,0 +1,278 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. diff --git a/header.sh b/header.sh index d3c6c8f..5a27ea1 100644 --- a/header.sh +++ b/header.sh @@ -4,10 +4,22 @@ YEAR=2016 cat << EOF #!/bin/bash -#========================================================== -# $PROD_STR, $VER_STR -# Copyright $YEAR, Xenese Labs/Sicron-Perion XNF -#========================================================== +# Simple Note System +# Copyright (C) 2016, Jon Lewis +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Prevent freak accidents involving the root directory if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi diff --git a/sns.sh b/sns.sh deleted file mode 100755 index 9c7bd71..0000000 --- a/sns.sh +++ /dev/null @@ -1,317 +0,0 @@ -#!/bin/bash -#========================================================== -# Simple Note System, v2.0a9 -# Copyright 2016, Xenese Labs/Sicron-Perion XNF -#========================================================== - -# Prevent freak accidents involving the root directory -if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi - -# Store files and locations -readonly PROD_STR="Simple Note System" -readonly VER_STR="v2.0a9" -readonly ROOT_DIR="$HOME"/.config/sns -readonly NOTES_DIR="$ROOT_DIR"/notes -readonly TMP_DIR="$ROOT_DIR"/tmp -readonly CONFIG_FILE="$ROOT_DIR/sns.conf" - -#Color codes for error reporting -readonly RED_COLOR='\033[1;31m' -readonly RESET_COLOR='\033[0m' - -#Print the program header to stdout -printf "%s\n" "$PROD_STR" -printf "%s\n" "------------------" - -# Section: Functions -function init_store { - -if [ ! -d "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi -if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi - - -cat > "$CONFIG_FILE" << EOF -# This file contains directives for the Simple Note System. - -EXT=note # File extension to use (for listing notes) - -#EDITOR= # Preferred Editor: - # If you would like to specify a different editor for - # sns to use, you may do so here. - -ENCRYPTION="FALSE" # Main Encryption Toggle: - # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST - # Change this to TRUE to enable encryption. - -PUBKEY="" # Public Key - # Encryption is done using GPG. You must enter your - # public key's identifier here. -EOF - -chmod 600 "$CONFIG_FILE" - -printf " - %s\n" "Rewrote Default Configuration" - -if [ "$WILL_INIT" == "TRUE" ]; then - printf " - %s\n" "Environment initialized in $ROOT_DIR" -else - printf " - %s\n" "Store already initialized." -fi -} -function verify_store { - - ETC_DIR=$(dirname "$CONFIG_FILE") - - STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") - for DIR in "${STORE_DIRS[@]}"; do - if [ ! -d "$DIR" ]; then - mkdir -p "$DIR" - fi - done -} -function help { - printf "\n%s" "usage: sns [-cedp] NAME NOTEBOOK SECTION" - printf "\n%s" " sns [-l] NOTEBOOK" - printf "\n%s" " sns [-hi ]" - - printf "\n%s" " -c | --create : Create note" - printf "\n%s" " -d | --delete : Delete note" - printf "\n%s" " -e | --edit : Open note for editing" - printf "\n%s" " -h | --help : Display this message" - printf "\n%s" " -p | --print : Print note to console" - printf "\n%s" " -l | --list : List all notes in NOTEBOOK" - printf "\n%s" " -i | --init : Write default config and initalize SNS store" - printf "\n" -} -function p_header(){ - printf "TITLE: %s\nDATE: %s\n" "$NAME" "$(date)" -} -function encrypt(){ -# 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(){ -# This function, given a file to decrypt, will attempt to decrypt the file -# against the specified recipient's private key, and print the result to -# stdout. - gpg -d "$NOTE" -} -function create(){ - # Depends : p_header - # Requires: $NOTE, $NOTE_DIR, - # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt - # Given a valid setup, create writes the standard note header as specified - # by p_header, to $NOTE. - - # Refuse to overwrite a note - if [ -e "$NOTES_DIR/$NOTE" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Note already exists"\ - "Hint: use -e to edit the note." - exit 200 - fi - - # If the note's notebook/section does not exist, - # create the appropriate folders. - mkdir -p "$NOTES_DIR"/"$(dirname "$NOTE")" - - # Write the standard note header - if [ "$ENCRYPTION" == "TRUE" ]; then - TMP_NOTE="$TMP_DIR"/"$SESSION_ID" - p_header > "$TMP_NOTE" - encrypt - else - p_header > "$NOTES_DIR/$NOTE" - fi - # Make sure the note exists, and inform the user of the result. - if [ -e "$NOTES_DIR/$NOTE" ]; then - printf " - %s\n" "Created note: ${NOTE%.*}" - else - >&2 printf " $RED_COLOR!$RESET_COLOR%s\n"\ - "Something went wrong, and the note was not created." - fi -} -function delete(){ - # Requires: $NOTE, $NOTE_DIR - # Given a valid $NOTE, delete removes $NOTE from sns. - - if [ -e "$NOTES_DIR/$NOTE" ]; then - rm "$NOTES_DIR/$NOTE" - printf " - %s\n" "Deleted note: ${NOTE%.*}." - else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." - fi -} -function edit(){ -# Requires: $EDITOR, $NOTE -# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt - -# Verify an editor was specified -if [ -z "$EDITOR" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ - "No editor specified in environment." - exit -# Verify the note exists -elif [ ! -r "$NOTE" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ - "Note cannot be opened for editing." - exit 40; -fi - -# If encryption is enabled, decrypt $NOTE to a temp file, otherwise -# operate on the note directly. -if [ "$ENCRYPTION" == "TRUE" ]; then - cp "$NOTE" "$NOTE".bk #Insurance - TMP_NOTE="$TMP_DIR/$SESSION_ID" - decrypt > "$TMP_NOTE" -else - TMP_NOTE="$NOTE"; -fi - -# Write an ammendment header -if [ -z "$CREATE" ]; then - printf "\n %s\n" "edit - $(date)" >> "$TMP_NOTE" - printf "\n %s\n" "===================================" >> "$TMP_NOTE" -fi - -# Call the editor -printf " - %s\n" "editing ${NOTE%.*}" -"$EDITOR" "$TMP_NOTE" - -# If the file was previously decrypted, encrypt it back -if [ "$ENCRYPTION" == "TRUE" ]; then - rm "$NOTE" - encrypt; - if [ ! -r "$NOTE" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved." - cp "$NOTE.bk" "$NOTE" - else - rm "$NOTE.bk"; - fi -fi - -} -function print(){ -# Given an existing file, $NOTE, print prints the contents of $NOTE to stdout. - -if [ -r "$NOTE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout - else cat "$NOTE"; fi -else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Note cannot be found." - exit 205 #ERR_NOTE_NO_READ -fi -} -function list(){ - # This function, given a folder, $NOTE, will list the contents of $NOTE. - ls "$NOTE" -} -# End Section: Functions -#============================================================================== -# Stage 1: Read Configuration / Verify Integrity -#============================================================================== - -if [ -r "$CONFIG_FILE" ]; then - source "$CONFIG_FILE" - verify_store -else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Configuration note found. Please run sns -i." - exit 5 #ERR_NO_STORE -fi - -if [ "$ENCRYPTION" == "TRUE" ]; then - if [ ! -r "$(which gpg)" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Encryption was specified, but GPG is not installed." - exit 100 - elif [ -z "$PUBKEY" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "No GPG recipient was provided in $CONFIG_FILE. " - exit 110 - fi -fi -#============================================================================== -# Stage 2: Argument Parsing -#============================================================================== -NOTE="" -if [ -z "$1" ]; then help; exit 20 -else - for ARG in "$@"; do - case "$ARG" in - -c|--create) - CREATE="TRUE" - OP="TRUE" - ;; - -d|--delete) - DELETE="TRUE" - OP="TRUE" - ;; - -e|--edit) - EDIT="TRUE" - OP="TRUE" - ;; - -ce|-ec) - CREATE="TRUE" - EDIT="TRUE" - OP="TRUE" - ;; - -l|--list) - LIST="TRUE" - OP="TRUE" - ;; - -p|--print) - PRINT="TRUE" - OP="TRUE" - ;; - -h|--help) - help - exit 0 - ;; - -i|--init-store) - init_store - exit 0 - ;; - *) - NOTE="$ARG" - break; - ;; - esac - done -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 - -if [ "$ENCRYPTION" == "TRUE" ]; then - SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename - readonly NOTE="$NOTE.$EXT.gpg" -else - readonly NOTE="$NOTE.$EXT" -fi - -if [ "$LIST" == "TRUE" ]; then list ; exit 0; 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 -#============================================================================== diff --git a/src/bash-completion/sns b/src/bash-completion/sns new file mode 100644 index 0000000..4a6cd7d --- /dev/null +++ b/src/bash-completion/sns @@ -0,0 +1,94 @@ +#!/bin/bash +# Simple Note System, bash completion file +# ======================================== +# Copyright (C) 2016, Jon Lewis +# Simple Note System is licensed under the GPLv2. Please see LICENSE for more +# information. +# +# **Notice** +# This file was adapted from pass, the standard unix password manager under the +# terms of the GPLv2 license. Pass may be found at https://passwordstore.org. +# +# The original file bore the following copyright notice: +# +# Copyright (C) 2012 - 2014 Jason A. Donenfeld and +# Brian Mattern . All Rights Reserved. +# This file is licensed under the GPLv2+. Please see COPYING for more information. + +_sns_complete_entries () { + prefix="${SNS_STORE_DIR:-$HOME/.config/sns/notes/}" + suffix=".note" + autoexpand=${1:-0} + + local IFS=$'\n' + local items=($(compgen -f $prefix$cur)) + for item in ${items[@]}; do + [[ $item =~ /\.[^/]*$ ]] && continue + + # if there is a unique match, and it is a directory with one entry + # autocomplete the subentry as well (recursively) + if [[ ${#items[@]} -eq 1 && $autoexpand -eq 1 ]]; then + while [[ -d $item ]]; do + local subitems=($(compgen -f "$item/")) + local filtereditems=( ) + for item2 in "${subitems[@]}"; do + [[ $item2 =~ /\.[^/]*$ ]] && continue + filtereditems+=( "$item2" ) + done + if [[ ${#filtereditems[@]} -eq 1 ]]; then + item="${filtereditems[0]}" + else + break + fi + done + fi + + # append / to directories + [[ -d $item ]] && item="$item/" + + item="${item%$suffix}" + COMPREPLY+=("${item#$prefix}") + done +} + +_sns_complete_folders () { + prefix="${SNS_STORE_DIR:-$HOME/.config/sns/notes/}" + + local IFS=$'\n' + local items=($(compgen -d $prefix$cur)) + for item in ${items[@]}; do + [[ $item == $prefix.* ]] && continue + COMPREPLY+=("${item#$prefix}/") + done +} + +_sns_complete_keys () { + local IFS=$'\n' + # Extract names and email addresses from gpg --list-keys + local keys="$(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')" + COMPREPLY+=($(compgen -W "${keys}" -- ${cur})) +} + +_sns() +{ + COMPREPLY=() + local cur="${COMP_WORDS[COMP_CWORD]}" + local commands="--create --delete --edit --help --print --list --init" + if [[ $COMP_CWORD -gt 1 ]]; then + local lastarg="${COMP_WORDS[$COMP_CWORD-1]}" + case "${COMP_WORDS[1]}" in + --list) + _sns_complete_folders + --edit|--print) + _sns_complete_entries + ;; + *) + ;; + esac + else + COMPREPLY+=($(compgen -W "${commands}" -- ${cur})) + + fi +} + +complete -o filenames -o nospace -F _sns sns diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index a12ab5d..2953e5e 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -8,7 +8,7 @@ if [ -z "$EDITOR" ]; then "No editor specified in environment." exit # Verify the note exists -elif [ ! -r "$NOTE" ]; then +elif [ ! -r "$NOTES_DIR/$NOTE" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ "Note cannot be opened for editing." exit 40; @@ -17,17 +17,17 @@ fi # If encryption is enabled, decrypt $NOTE to a temp file, otherwise # operate on the note directly. if [ "$ENCRYPTION" == "TRUE" ]; then - cp "$NOTE" "$NOTE".bk #Insurance + cp "$NOTES_DIR/$NOTE" "$NOTES_DIR$/$NOTE".bk #Insurance TMP_NOTE="$TMP_DIR/$SESSION_ID" decrypt > "$TMP_NOTE" else - TMP_NOTE="$NOTE"; + TMP_NOTE="$NOTES_DIR/$NOTE"; fi # Write an ammendment header if [ -z "$CREATE" ]; then printf "\n %s\n" "edit - $(date)" >> "$TMP_NOTE" - printf "\n %s\n" "===================================" >> "$TMP_NOTE" + printf "%s\n" "===================================" >> "$TMP_NOTE" fi # Call the editor @@ -36,13 +36,13 @@ printf " - %s\n" "editing ${NOTE%.*}" # If the file was previously decrypted, encrypt it back if [ "$ENCRYPTION" == "TRUE" ]; then - rm "$NOTE" + rm "$NOTES_DIR/$NOTE" encrypt; if [ ! -r "$NOTE" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved." - cp "$NOTE.bk" "$NOTE" + cp "$NOTES_DIR/$NOTE.bk" "$NOTES_DIR/$NOTE" else - rm "$NOTE.bk"; + rm "$NOTES_DIR/$NOTE.bk"; fi fi From d1140974f40550b4079e7ca4cb8da68a8cfbd072 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 16:22:14 -0600 Subject: [PATCH 48/52] Added functionality to remove empty notebooks/sections --- src/includes/delete.sns.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh index 5c5ee49..f8aa791 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -5,6 +5,13 @@ function delete(){ if [ -e "$NOTES_DIR/$NOTE" ]; then rm "$NOTES_DIR/$NOTE" printf " - %s\n" "Deleted note: ${NOTE%.*}." + #Cleanup empty notebooks/sections] + find "$NOTES_DIR" -mindepth 1 -type d | tac |\ + while read -r DIR ; do + if [ ! "$(ls -A $DIR)" ]; then + rmdir "$DIR" + fi + done else >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." fi From 051546691fa96f3f13f27218f70daceb96b6986b Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 16:23:01 -0600 Subject: [PATCH 49/52] Further bash-completion work --- src/bash-completion/sns | 9 +++++---- src/main/stage3.sns.sh | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bash-completion/sns b/src/bash-completion/sns index 4a6cd7d..1ede6c3 100644 --- a/src/bash-completion/sns +++ b/src/bash-completion/sns @@ -22,7 +22,7 @@ _sns_complete_entries () { local IFS=$'\n' local items=($(compgen -f $prefix$cur)) - for item in ${items[@]}; do + for item in "${items[@]}"; do [[ $item =~ /\.[^/]*$ ]] && continue # if there is a unique match, and it is a directory with one entry @@ -56,7 +56,7 @@ _sns_complete_folders () { local IFS=$'\n' local items=($(compgen -d $prefix$cur)) - for item in ${items[@]}; do + for item in "${items[@]}"; do [[ $item == $prefix.* ]] && continue COMPREPLY+=("${item#$prefix}/") done @@ -77,9 +77,10 @@ _sns() if [[ $COMP_CWORD -gt 1 ]]; then local lastarg="${COMP_WORDS[$COMP_CWORD-1]}" case "${COMP_WORDS[1]}" in - --list) + --list|-l) _sns_complete_folders - --edit|--print) + ;; + --edit|-e|--print|-p|--delete|-d) _sns_complete_entries ;; *) diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index 2880385..b090f4b 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -15,7 +15,7 @@ fi if [ "$ENCRYPTION" == "TRUE" ]; then SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename - readonly NOTE="$NOTE.$EXT.gpg" + readonly NOTE="$NOTE.gpg.$EXT" else readonly NOTE="$NOTE.$EXT" fi From 69bbd0694826d909503f29a5c207c1466facee77 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 16:30:49 -0600 Subject: [PATCH 50/52] Added support for custom date formats --- src/includes/edit.sns.sh | 2 +- src/includes/init_store.sns.sh | 7 ++++++- src/includes/p_header.sh | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index 2953e5e..f2e88f7 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -26,7 +26,7 @@ fi # Write an ammendment header if [ -z "$CREATE" ]; then - printf "\n %s\n" "edit - $(date)" >> "$TMP_NOTE" + printf "\n%s\n" "edit - $(date $DATE_FMT)" >> "$TMP_NOTE" printf "%s\n" "===================================" >> "$TMP_NOTE" fi diff --git a/src/includes/init_store.sns.sh b/src/includes/init_store.sns.sh index 9a2c20d..40552b7 100644 --- a/src/includes/init_store.sns.sh +++ b/src/includes/init_store.sns.sh @@ -11,7 +11,12 @@ EXT=note # File extension to use (for listing notes) #EDITOR= # Preferred Editor: # If you would like to specify a different editor for - # sns to use, you may do so here. + # sns to use, you may do so here, otherwise, sns will + # use the editor specified in the environment. + +DATE_FMT="+%D %T" # Date Format: + # If you would like to modify the date format, you may + # specify one appropriate to the `date` command. ENCRYPTION="FALSE" # Main Encryption Toggle: # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST diff --git a/src/includes/p_header.sh b/src/includes/p_header.sh index b42dfd6..65a1abf 100644 --- a/src/includes/p_header.sh +++ b/src/includes/p_header.sh @@ -1,3 +1,3 @@ function p_header(){ - printf "# %s\n## Date: %s\n" "$(basename ${NOTE%.*})" "$(date)" + printf "# %s\n## Date: %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")" } From 6105190e78629534d98582b625ce90d338c7cc17 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 18:48:56 -0600 Subject: [PATCH 51/52] Fixed critical issues relating to encryption, including misplaced files and failure to erase temporary files. --- src/bash-completion/sns | 1 + src/includes/create.sns.sh | 2 +- src/includes/edit.sns.sh | 8 +++++--- src/includes/init_store.sns.sh | 2 +- src/includes/libencryption.sns.sh | 4 ++-- src/includes/p_header.sh | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/bash-completion/sns b/src/bash-completion/sns index 1ede6c3..1d49269 100644 --- a/src/bash-completion/sns +++ b/src/bash-completion/sns @@ -47,6 +47,7 @@ _sns_complete_entries () { [[ -d $item ]] && item="$item/" item="${item%$suffix}" + item="${item%.gpg}" COMPREPLY+=("${item#$prefix}") done } diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh index 2303d23..6b1f04e 100644 --- a/src/includes/create.sns.sh +++ b/src/includes/create.sns.sh @@ -29,7 +29,7 @@ function create(){ if [ -e "$NOTES_DIR/$NOTE" ]; then printf " - %s\n" "Created note: ${NOTE%.*}" else - >&2 printf " $RED_COLOR!$RESET_COLOR%s\n"\ + >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ "Something went wrong, and the note was not created." fi } diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index f2e88f7..79ebc47 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -17,7 +17,7 @@ fi # If encryption is enabled, decrypt $NOTE to a temp file, otherwise # operate on the note directly. if [ "$ENCRYPTION" == "TRUE" ]; then - cp "$NOTES_DIR/$NOTE" "$NOTES_DIR$/$NOTE".bk #Insurance + cp "$NOTES_DIR/$NOTE" "$NOTES_DIR/$NOTE.bk" #Insurance TMP_NOTE="$TMP_DIR/$SESSION_ID" decrypt > "$TMP_NOTE" else @@ -26,7 +26,7 @@ fi # Write an ammendment header if [ -z "$CREATE" ]; then - printf "\n%s\n" "edit - $(date $DATE_FMT)" >> "$TMP_NOTE" + printf "\n%s\n" "edit - $(date "$DATE_FMT")" >> "$TMP_NOTE" printf "%s\n" "===================================" >> "$TMP_NOTE" fi @@ -36,9 +36,11 @@ printf " - %s\n" "editing ${NOTE%.*}" # If the file was previously decrypted, encrypt it back if [ "$ENCRYPTION" == "TRUE" ]; then + echo "reencrypting" rm "$NOTES_DIR/$NOTE" encrypt; - if [ ! -r "$NOTE" ]; then + rm "$TMP_NOTE" + if [ ! -r "$NOTES_DIR/$NOTE" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved." cp "$NOTES_DIR/$NOTE.bk" "$NOTES_DIR/$NOTE" else diff --git a/src/includes/init_store.sns.sh b/src/includes/init_store.sns.sh index 40552b7..b3095de 100644 --- a/src/includes/init_store.sns.sh +++ b/src/includes/init_store.sns.sh @@ -16,7 +16,7 @@ EXT=note # File extension to use (for listing notes) DATE_FMT="+%D %T" # Date Format: # If you would like to modify the date format, you may - # specify one appropriate to the `date` command. + # specify one appropriate to the \`date\` command. ENCRYPTION="FALSE" # Main Encryption Toggle: # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST diff --git a/src/includes/libencryption.sns.sh b/src/includes/libencryption.sns.sh index 04ba8b3..2906341 100644 --- a/src/includes/libencryption.sns.sh +++ b/src/includes/libencryption.sns.sh @@ -3,7 +3,7 @@ function encrypt(){ # output file, $NOTE, will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private # GPG key. - gpg -r "$PUBKEY" -o "$NOTE" -e "$TMP_NOTE" + gpg -r "$PUBKEY" -o "$NOTES_DIR/$NOTE" -e "$TMP_NOTE" } @@ -11,5 +11,5 @@ function decrypt(){ # This function, given a file to decrypt, will attempt to decrypt the file # against the specified recipient's private key, and print the result to # stdout. - gpg -d "$NOTE" + gpg -d "$NOTES_DIR/$NOTE" } diff --git a/src/includes/p_header.sh b/src/includes/p_header.sh index 65a1abf..6fc43d6 100644 --- a/src/includes/p_header.sh +++ b/src/includes/p_header.sh @@ -1,3 +1,3 @@ function p_header(){ - printf "# %s\n## Date: %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")" + printf "# %s\n## %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")" } From 167ec440087c961e9b6aa0678e9cb1c4877317ee Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 19:41:29 -0600 Subject: [PATCH 52/52] Preparations for GitHub --- README.md | 36 ++++++++++++++++++++++++++++++++++ build.sh | 27 -------------------------- install.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 27 deletions(-) delete mode 100755 build.sh create mode 100755 install.sh diff --git a/README.md b/README.md index 2cfb451..d9c134f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Simple Note System ================== +## About The Simple Note System is a shell script partially inspired by [pass], in that it stores notes as normal, plaintext, files in normal folders. It uses the environment-specified editor, and can be configured to use GPG encryption. @@ -27,5 +28,40 @@ was almost entirely rewritten as SNSv2. -l | --list : List all notes in NOTEBOOK -i | --init : Write default config and initalize SNS store" +## Installing +To install, place `sns.sh` in your path, and copy `src/bash-completion/sns` +to `/usr/share/bash-completion/completions/sns`. + +Or simply run `./install.sh`. + +To uninstall, remove the files you copied, or run `./install.sh --uninstall` + +Once installed, SNS will require you to run `sns -i`, to indicate you would like +to create its note store and write its default configuration. + +By default, SNS will set itself up in `~/.config/sns`, with `~/.config/sns/sns.conf` +as its configuration file. + +## Configuration +In SNS's configuration file, you can change the editor SNS uses, along with +the date format used in notes, and whether or not to use GPG encryption. + +**A word about encryption**: Enabling encryption will cause problems if +previously un-encrypted notes exist. In the future, I'd like to resolve these, +however for the time being it's best to decide when you install SNS if you'd +like to enable encryption or not. + +## Credits +The majority of the code here is my own, however the bash completion +code comes from [pass], the standard UNIX package manager, along with some +design and feature ideas. + +## License +Simple Note System is licensed under the terms of the GNU General Public License +Version 2, as detailed in `LICENSE`. + +## Bugs +If something seems off, or just doesn't work, please open an issue and I'll look +into it. [pass]: http://passwordstore.org diff --git a/build.sh b/build.sh deleted file mode 100755 index cb5e42d..0000000 --- a/build.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#========================================================== -# Simple Note System - Build Script -# Copyright 2016, Xenese Labs/Sicron-Perion XNF -#========================================================== - -S=sns.sh - -bash header.sh > "$S" -echo -e "\n# Section: Functions" >> "$S" -cat ./src/includes/init_store.sns.sh >> "$S" -cat ./src/includes/verify_store.sns.sh >> "$S" -cat ./src/includes/help.sns.sh >> "$S" -cat ./src/includes/p_header.sh >> "$S" -cat ./src/includes/libencryption.sns.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" "# End Section: Functions" >> "$S" -cat ./src/main/stage1.sns.sh >> "$S" -cat ./src/main/stage2.sns.sh >> "$S" -cat ./src/main/stage3.sns.sh >> "$S" - -chmod u+x "$S" -exit diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..68485f2 --- /dev/null +++ b/install.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Simple Note System - Install Script +# Copyright (C) 2016, Jon Lewis +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +if [ "$1" == "--uninstall" ]; then + rm /bin/sns + rm /usr/share/bash-completion/completions/sns + exit +fi + +mkdir build + +S=build/sns.sh + +bash header.sh > "$S" +echo -e "\n# Section: Functions" >> "$S" +cat ./src/includes/init_store.sns.sh >> "$S" +cat ./src/includes/verify_store.sns.sh >> "$S" +cat ./src/includes/help.sns.sh >> "$S" +cat ./src/includes/p_header.sh >> "$S" +cat ./src/includes/libencryption.sns.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" "# End Section: Functions" >> "$S" +cat ./src/main/stage1.sns.sh >> "$S" +cat ./src/main/stage2.sns.sh >> "$S" +cat ./src/main/stage3.sns.sh >> "$S" + +chmod u+x "$S" +# Install SNS +if [ ! -r "/bin/sns" ] || [ grep "Simple Note System" < "/bin/sns" ]; + sudo cp "$S" > "/bin/sns" +fi +# Install Bash completion +if [ ! -r "/usr/share/bash-completion/completions/sns" ]\ + || [ grep "Simple Note System" < "/usr/share/bash-completion/completions/sns" ]; then + sudo cp "src/bash-completion/sns" >\ + "/usr/share/bash-completion/completions/sns" +fi +exit