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