Code cleanup

This commit is contained in:
Jon-William Lewis
2016-02-11 00:22:34 -06:00
parent 7e1655402b
commit 993a6508d3
13 changed files with 135 additions and 112 deletions

View File

@@ -8,11 +8,12 @@ S=sns.sh
bash header.sh > "$S" bash header.sh > "$S"
echo -e "\n# Section: Functions" >> "$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/pause.sns.sh >> "$S"
cat ./src/includes/help.sns.sh >> "$S" cat ./src/includes/help.sns.sh >> "$S"
cat ./src/includes/p_header.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/create.sns.sh >> "$S"
cat ./src/includes/delete.sns.sh >> "$S" cat ./src/includes/delete.sns.sh >> "$S"
cat ./src/includes/edit.sns.sh >> "$S" cat ./src/includes/edit.sns.sh >> "$S"

View File

@@ -4,12 +4,11 @@ Error Code Reference
General------------------------------------------------------------------------- General-------------------------------------------------------------------------
ERR_NO_ARGS 10 No arguments were specified ERR_NO_ARGS 10 No arguments were specified
ERR_NO_OP 20 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---------------------------------------------------------------------- Encryption----------------------------------------------------------------------
ERR_NO_GPG 100 GPG is not installed ERR_NO_GPG 100 Encryption is enabled, but GPG is not installed
ERR_NO_KEY 110 No recipient specified ERR_NO_KEY 110 Encryption is enabled, but no recipient was specified
Create-------------------------------------------------------------------------- Create--------------------------------------------------------------------------
ERR_NOTE_EXiSTS 200 The specified note already exists ERR_NOTE_EXiSTS 200 The specified note already exists

View File

@@ -9,14 +9,13 @@ cat << EOF
# Copyright $YEAR, Xenese Labs/Sicron-Perion XNF # Copyright $YEAR, Xenese Labs/Sicron-Perion XNF
#========================================================== #==========================================================
# Prevent freak accidents involving the root directory
if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi
PROD_STR="$PROD_STR" PROD_STR="$PROD_STR"
readonly VER_STR="$VER_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 NOTES_DIR="\$ROOT_DIR"/notes
readonly TMP_DIR="\$ROOT_DIR"/tmp readonly TMP_DIR="\$ROOT_DIR"/tmp
readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" readonly CONFIG_FILE="\$ROOT_DIR/sns.conf"
EOF EOF

128
sns.sh
View File

@@ -8,51 +8,53 @@ if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi
PROD_STR="Simple Note System" PROD_STR="Simple Note System"
readonly VER_STR="v2.0a8" 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 NOTES_DIR="$ROOT_DIR"/notes
readonly TMP_DIR="$ROOT_DIR"/tmp readonly TMP_DIR="$ROOT_DIR"/tmp
readonly CONFIG_FILE="$ROOT_DIR/sns.conf" readonly CONFIG_FILE="$ROOT_DIR/sns.conf"
# Section: Functions # 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 if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi
cat > "$CONFIG_FILE" << EOF cat > "$CONFIG_FILE" << EOF
#========================================================== # This file contains directives for the Simple Note System.
# Simple Note System Config, v2.0a8
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
#==========================================================
#File extension to use (for listing notes) EXT=note # File extension to use (for listing notes)
EXT=note
#Preferred Editor #EDITOR= # Preferred Editor:
if [ -z "$EDITOR" ]; then # If you would like to specify a different editor for
EDITOR=vim # sns to use, you may do so here.
fi
#Encryption ENCRYPTION="FALSE" # Main Encryption Toggle:
#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST
# Change this to TRUE to enable encryption.
#ENCRYPTION="TRUE" PUBKEY="" # Public Key
ENCRYPTION="FALSE" # Encryption is done using GPG. You must enter your
# public key's identifier here.
PUBKEY=""
EOF EOF
chmod 600 "$CONFIG_FILE" chmod 600 "$CONFIG_FILE"
printf " - %s\n" "Rewrote Default Configuration"
if [ "$WILL_INIT" == "TRUE" ]; then if [ "$WILL_INIT" == "TRUE" ]; then
printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR"
else else
printf "%s\n" "Environment already initialized." printf " - %s\n" "Store already initialized."
fi 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 { function pause {
read -rp " Press [Enter] to continue." read -rp " Press [Enter] to continue."
echo "" echo ""
@@ -72,7 +74,7 @@ function help {
echo " -h | --help : Display this message" echo " -h | --help : Display this message"
echo " -p | --print : Print note to console" echo " -p | --print : Print note to console"
echo " -l | --list : List all notes in NOTEBOOK" 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 "" echo ""
} }
function p_header(){ function p_header(){
@@ -94,52 +96,63 @@ function decrypt(){
gpg -d "$NOTE" gpg -d "$NOTE"
} }
function create(){ 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 if [ -e "$NOTE" ]; then
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
exit exit 200
else # If the notebook doesn't exist, create it.
elif [ ! -d "$NOTE_DIR" ]; then
mkdir -p "$NOTE_DIR" mkdir -p "$NOTE_DIR"
fi fi
if [ -z "$ENCRYPTION" ]; then # Write the standard note header
echo "TITLE: $NAME" > "$NOTE" if [ "$ENCRYPTION" == "TRUE" ]; then
echo "DATE: $(date)" >> "$NOTE"
elif [ "$ENCRYPTION" == "TRUE" ]; then
TMP_NOTE="$TMP_DIR"/"$SESSION_ID" TMP_NOTE="$TMP_DIR"/"$SESSION_ID"
p_header > "$TMP_NOTE" p_header > "$TMP_NOTE"
encrypt encrypt
else
p_header > "$NOTE"
fi fi
# Make sure the note exists, and inform the user.
if [ -e "$NOTE" ]; then if [ -e "$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME." echo "Created note: $NOTEBOOK/$SECTION/$NAME."
else
printf "%s\n" "Something went wrong."
fi fi
} }
function delete(){ function delete(){
if [ "$DELETE" == "TRUE" ]; then #Requires: $NOTE, $NOTEBOOK, $SECTION, $NAME
# Given a valid $NOTE, delete removes $NOTE from sns.
if [ -e "$NOTE" ]; then if [ -e "$NOTE" ]; then
rm "$NOTE" rm "$NOTE"
echo "" printf "\n%s\n" "Deleted note: $NOTEBOOK/$SECTION/$NAME."
echo "Deleted note: $NOTEBOOK/$SECTION/$NAME."
exit
else else
echo "" printf "\n%s\n" "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
echo "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist."
exit
fi
fi fi
} }
function edit(){ function edit(){
# Requires: $EDITOR, $NOTE
# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt
# Verify an editor was specified
if [ -z "$EDITOR" ]; then if [ -z "$EDITOR" ]; then
>&2 echo "Error no editor specified in environment." >&2 echo "Error no editor specified in environment."
exit exit
# Verify the note exists
elif [ ! -r "$NOTE" ]; then elif [ ! -r "$NOTE" ]; then
echo "ERROR: Note cannot be opened for editing." echo "ERROR: Note cannot be opened for editing."
exit 40; exit 40;
fi fi
# When encryption is enabled, decrypt $NOTE to a temp file
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk cp "$NOTE" "$NOTE".bk #Insurance
if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi if [ ! -d "$TMP_DIR" ]; then mkdir "$TMP_DIR"; fi
TMP_NOTE="$TMP_DIR/$SESSION_ID" TMP_NOTE="$TMP_DIR/$SESSION_ID"
decrypt > "$TMP_NOTE" decrypt > "$TMP_NOTE"
else TMP_NOTE="$NOTE"; fi else TMP_NOTE="$NOTE"; fi
@@ -184,15 +197,17 @@ function list(){
# Entry Point # Entry Point
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#============================================================================== #==============================================================================
# Stage 1: Read Configuration # Stage 1: Read Configuration / Verify Integrity
#============================================================================== #==============================================================================
if [ -r "$CONFIG_FILE" ]; then if [ -r "$CONFIG_FILE" ]; then
source "$CONFIG_FILE" source "$CONFIG_FILE"
else else
create_sns_root init_store
source "$CONFIG_FILE" source "$CONFIG_FILE"
fi fi
verify_store
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
if [ -z "$PUBKEY" ]; then if [ -z "$PUBKEY" ]; then
ERR_NO_KEY="TRUE" ERR_NO_KEY="TRUE"
@@ -229,14 +244,14 @@ function list(){
else else
ARGS=( "$@" ) ARGS=( "$@" )
for ARG in "${ARGS[@]}"; do for ARG in "${ARGS[@]}"; do
if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE" if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"; OP="TRUE"
elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE" elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE"
elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE" elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE"
elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE" elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE"
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE" elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE" elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE"
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 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 else
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG"
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"
@@ -252,12 +267,18 @@ function list(){
NAME="" NAME=""
fi fi
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.
#============================================================================== #==============================================================================
# Section: Actions / Stage 3 # 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 # 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 if [ -z "$NOTEBOOK" ]; then
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30 exit 30
@@ -267,7 +288,7 @@ function list(){
if [ "$LIST" == TRUE ]; then if [ "$LIST" == TRUE ]; then
list list
exit 0 exit 0
elif [ -z "$NAME" ]; then elif [ -z "$NAME" ];
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30 exit 30
fi fi
@@ -280,7 +301,6 @@ function list(){
readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg" readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg"
else else
readonly NOTE="$NOTE_DIR/$NAME.$EXT" readonly NOTE="$NOTE_DIR/$NAME.$EXT"
echo "$NOTE"
fi fi
if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi

View File

@@ -19,8 +19,8 @@
5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.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>"; }; 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>"; }; 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>"; }; 5D22D6B01AFC5B100036DC52 /* libencryption.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = libencryption.sns.sh; sourceTree = "<group>"; };
5D75D24F1C5F13DF001E7B33 /* verify_store.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = verify_store.sh; sourceTree = "<group>"; }; 5D75D24F1C5F13DF001E7B33 /* verify_store.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = verify_store.sns.sh; sourceTree = "<group>"; };
5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.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>"; }; 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>"; }; 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = "<group>"; };
@@ -49,8 +49,8 @@
5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */,
5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */, 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */,
5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */, 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */,
5D22D6B01AFC5B100036DC52 /* libencryption.sh */, 5D22D6B01AFC5B100036DC52 /* libencryption.sns.sh */,
5D75D24F1C5F13DF001E7B33 /* verify_store.sh */, 5D75D24F1C5F13DF001E7B33 /* verify_store.sns.sh */,
); );
path = includes; path = includes;
sourceTree = "<group>"; sourceTree = "<group>";

View File

@@ -13,6 +13,6 @@ function help {
echo " -h | --help : Display this message" echo " -h | --help : Display this message"
echo " -p | --print : Print note to console" echo " -p | --print : Print note to console"
echo " -l | --list : List all notes in NOTEBOOK" 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 "" echo ""
} }

View File

@@ -1,37 +1,34 @@
function init_store { 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 if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi
cat > "$CONFIG_FILE" << EOF cat > "$CONFIG_FILE" << EOF
#========================================================== # This file contains directives for the Simple Note System.
# Simple Note System Config, v2.0a8
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
#==========================================================
#File extension to use (for listing notes) EXT=note # File extension to use (for listing notes)
EXT=note
#Preferred Editor #EDITOR= # Preferred Editor:
if [ -z "$EDITOR" ]; then # If you would like to specify a different editor for
EDITOR=vim # sns to use, you may do so here.
fi
#Encryption ENCRYPTION="FALSE" # Main Encryption Toggle:
#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST
# Change this to TRUE to enable encryption.
#ENCRYPTION="TRUE" PUBKEY="" # Public Key
ENCRYPTION="FALSE" # Encryption is done using GPG. You must enter your
# public key's identifier here.
PUBKEY=""
EOF EOF
chmod 600 "$CONFIG_FILE" chmod 600 "$CONFIG_FILE"
printf " - %s\n" "Rewrote Default Configuration"
if [ "$WILL_INIT" == "TRUE" ]; then if [ "$WILL_INIT" == "TRUE" ]; then
printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" printf " - %s %s\n" "Environment initialized in" "$ROOT_DIR"
else else
printf "%s\n" "Environment already initialized." printf " - %s\n" "Store already initialized."
fi fi
} }

View File

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

View File

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

View File

@@ -8,14 +8,14 @@
else else
ARGS=( "$@" ) ARGS=( "$@" )
for ARG in "${ARGS[@]}"; do for ARG in "${ARGS[@]}"; do
if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE" if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"; OP="TRUE"
elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE" elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE"
elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE" elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE"
elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE" elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE"
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE" elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE" elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE"
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 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 else
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG"
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"
@@ -31,4 +31,5 @@
NAME="" NAME=""
fi fi
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.

View File

@@ -1,8 +1,13 @@
#============================================================================== #==============================================================================
# Section: Actions / Stage 3 # 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 # 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 if [ -z "$NOTEBOOK" ]; then
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified" printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30 exit 30