Made configuration directory static

Moved header variables to new file
Started sanitizing variable references
This commit is contained in:
Jon-William Lewis
2015-06-10 00:23:33 -05:00
parent 21b457c38c
commit 9334f3ba45
8 changed files with 51 additions and 95 deletions

View File

@@ -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

11
header.sh Normal file
View File

@@ -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"

45
sns.sh
View File

@@ -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

View File

@@ -11,7 +11,6 @@
5D22D6A31AFC4F5A0036DC52 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = "<group>"; };
5D22D6A41AFC4F5A0036DC52 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = "<group>"; };
5D22D6A51AFC4F5A0036DC52 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = "<group>"; };
5D22D6A61AFC4F5A0036DC52 /* defaults.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = defaults.sh; sourceTree = "<group>"; };
5D22D6A71AFC4F5A0036DC52 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = "<group>"; };
5D22D6A81AFC4F5A0036DC52 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = "<group>"; };
5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = "<group>"; };
@@ -22,6 +21,7 @@
5D22D6AF1AFC4F5A0036DC52 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = "<group>"; };
5D22D6B01AFC5B100036DC52 /* libencryption.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = libencryption.sh; sourceTree = "<group>"; };
5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
5D7E91FB1B27FB620030B30D /* header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = header.sh; sourceTree = "<group>"; };
5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = "<group>"; };
5DE839881ABA04DD006CB4F6 /* errors.ref */ = {isa = PBXFileReference; lastKnownFileType = text; path = errors.ref; sourceTree = "<group>"; };
/* 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 = "<group>";
};

View File

@@ -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
}

View File

@@ -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 ""
}

View File

@@ -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"
}

View File

@@ -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