Formatting changes

This commit is contained in:
Jon-William Lewis
2016-02-10 23:34:49 -06:00
parent be3871f859
commit 856b14242c
14 changed files with 267 additions and 282 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

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

View File

@@ -10,3 +10,6 @@ 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
Create--------------------------------------------------------------------------
ERR_NOTE_EXiSTS 200 The specified note already exists

View File

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

71
sns.sh
View File

@@ -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,15 +180,11 @@ function list(){
###############################################################################
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Entry Point
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#==============================================================================
# Begin Main Program
#==============================================================================
###############################################################################
#==============================================================================
# Section: Configuration / Stage 1
# Stage 1: Read Configuration
#==============================================================================
if [ -r "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
@@ -223,15 +219,9 @@ 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
# Stage 2: Argument Parsing
#==============================================================================
#==============================================================================
# Section: Argument Parsing / Stage 2
#==============================================================================
NAME=""
NOTEBOOK=""
SECTION=""
@@ -246,7 +236,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"
@@ -255,49 +245,42 @@ else
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.
# 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
# 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.
#==============================================================================
# Section: Actions / Stage 3
#==============================================================================
# List only requires a notebook, and is exclusive.
# 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
echo " ERROR: Insufficient arguments:"
echo " Notebook not specified"
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30
fi
if [ -n "$LIST" ]; then
# 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
fi
#All other functions require a note title and notebook.
if [ -z "$NAME" ]; then
echo " ERROR: Insufficient arguments:"
echo " Title not specified"
elif [ -z "$NAME" ]; then
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30
fi
SESSION_ID="$RANDOM"
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"
if [ "$ENCRYPTION" == "TRUE" ]; then readonly NOTE="$NOTE_DIR""$NAME"."$EXT".gpg
else readonly NOTE="$NOTE_DIR""$NAME"."$EXT"
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

View File

@@ -15,11 +15,12 @@
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>"; };
5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = "<group>"; };
5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create_sns_root.sns.sh; sourceTree = "<group>"; };
5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = init_store.sns.sh; sourceTree = "<group>"; };
5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = "<group>"; };
5D22D6AE1AFC4F5A0036DC52 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = "<group>"; };
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>"; };
5D75D24F1C5F13DF001E7B33 /* verify_store.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = verify_store.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>"; };
@@ -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 = "<group>";

View File

@@ -1,22 +1,31 @@
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
else
exit 200
# If the notebook doesn't exist, create it.
elif [ ! -d "$NOTE_DIR" ]; then
mkdir -p "$NOTE_DIR"
fi
if [ -z "$ENCRYPTION" ]; then
echo "TITLE: $NAME" > "$NOTE"
echo "DATE: $(date)" >> "$NOTE"
elif [ "$ENCRYPTION" == "TRUE" ]; then
# 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
}

View File

@@ -1,14 +1,10 @@
function delete(){
if [ "$DELETE" == "TRUE" ]; then
#Requires: $NOTE, $NOTEBOOK, $SECTION, $NAME
# Given a valid $NOTE, delete removes $NOTE from sns.
if [ -e "$NOTE" ]; then
rm "$NOTE"
echo ""
echo "Deleted note: $NOTEBOOK/$SECTION/$NAME."
exit
printf "\n%s\n" "Deleted note: $NOTEBOOK/$SECTION/$NAME."
else
echo ""
echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
exit
fi
printf "\n%s\n" "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
fi
}

View File

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

View File

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

View File

@@ -1,13 +1,18 @@
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Entry Point
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#==============================================================================
# Section: Configuration / Stage 1
# 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"
@@ -34,8 +39,3 @@ 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
#==============================================================================

View File

@@ -1,7 +1,6 @@
#==============================================================================
# Section: Argument Parsing / Stage 2
# Stage 2: Argument Parsing
#==============================================================================
NAME=""
NOTEBOOK=""
SECTION=""
@@ -25,17 +24,11 @@ else
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.
# 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
# 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.

View File

@@ -1,32 +1,30 @@
#==============================================================================
# Section: Actions / Stage 3
#==============================================================================
# List only requires a notebook, and is exclusive.
# 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
echo " ERROR: Insufficient arguments:"
echo " Notebook not specified"
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30
fi
if [ -n "$LIST" ]; then
# 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
fi
#All other functions require a note title and notebook.
if [ -z "$NAME" ]; then
echo " ERROR: Insufficient arguments:"
echo " Title not specified"
elif [ -z "$NAME" ];
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30
fi
SESSION_ID="$RANDOM"
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"/
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"
if [ "$ENCRYPTION" == "TRUE" ]; then readonly NOTE="$NOTE_DIR""$NAME"."$EXT".gpg
else readonly NOTE="$NOTE_DIR""$NAME"."$EXT"
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