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.
This commit is contained in:
Jon-William Lewis
2015-05-07 21:23:12 -05:00
parent a0ad2e7d48
commit 64e504ebcb
11 changed files with 170 additions and 109 deletions

3
build.sh Normal file → Executable file
View File

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

View File

@@ -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
if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
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
elif [ -z "$ENCRYPTION" ]; then
echo "TITLE: $NAME" > $NOTE
#Fill the second line with the date
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
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"
}

View File

@@ -1,27 +1,26 @@
function edit (){
if [ "$EDIT" == "TRUE" ]; then
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
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
fi
fi
$EDITOR $NOTE
fi
fi
#Post-Processing (Encryption)
if [ "$ENCRYPTION" == "TRUE" ]; then
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
rm $NOTE
openssl enc -aes-256-cbc -salt -in $TMP_NAME -out $NOTE -pass pass:$ENC_KEY
rm "$TMP_NAME"
fi
else
echo ""
echo "ERROR: Note cannot be opened for editting."
echo ""
fi
printf "\nERROR: Note cannot be opened for editting.\n"
fi
}

View File

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

3
functions/p_header.sh Normal file
View File

@@ -0,0 +1,3 @@
function p_header(){
printf "TITLE: $NAME\nDATE: $(date)\n"
}

View File

@@ -1,4 +1,4 @@
function writeconf {
function w_conf {
cat > $HOME/.sns/sns.conf << EOF
#==========================================================
# Simple Note System Config, v2.0a1

View File

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

View File

@@ -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.
#==============================================================================

View File

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

109
sns.sh Normal file → Executable file
View File

@@ -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
if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
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
elif [ -z "$ENCRYPTION" ]; then
echo "TITLE: $NAME" > $NOTE
#Fill the second line with the date
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
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
#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
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
fi
fi
$EDITOR $NOTE
fi
fi
#Post-Processing (Encryption)
if [ "$ENCRYPTION" == "TRUE" ]; then
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
rm $NOTE
openssl enc -aes-256-cbc -salt -in $TMP_NAME -out $NOTE -pass pass:$ENC_KEY
rm "$TMP_NAME"
fi
else
echo ""
echo "ERROR: Note cannot be opened for editting."
echo ""
fi
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

View File

@@ -7,6 +7,7 @@
objects = {
/* Begin PBXFileReference section */
5D5625481AC8A26500D6E1B5 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = "<group>"; };
5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
5DE839761AB9D42F006CB4F6 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = "<group>"; };
5DE839771AB9D52C006CB4F6 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = "<group>"; };
@@ -16,7 +17,7 @@
5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = "<group>"; };
5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = "<group>"; };
5DE839811AB9D7F8006CB4F6 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = "<group>"; };
5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = wconf.sns.sh; sourceTree = "<group>"; };
5DE839821AB9DAA6006CB4F6 /* w_conf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = w_conf.sns.sh; sourceTree = "<group>"; };
5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = "<group>"; };
5DE839841AB9FDF9006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = "<group>"; };
5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = "<group>"; };
@@ -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 */,
);