Formatting changes
This commit is contained in:
15
build.sh
15
build.sh
@@ -1,3 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#==========================================================
|
||||||
|
# Simple Note System - Build Script
|
||||||
|
# Copyright 2016, Xenese Labs/Sicron-Perion XNF
|
||||||
|
#==========================================================
|
||||||
|
|
||||||
S=sns.sh
|
S=sns.sh
|
||||||
|
|
||||||
bash header.sh > "$S"
|
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/print.sns.sh >> "$S"
|
||||||
cat ./src/includes/list.sns.sh >> "$S"
|
cat ./src/includes/list.sns.sh >> "$S"
|
||||||
printf "%s\n\n\n\n" "# End Section: Functions" >> "$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/stage1.sns.sh >> "$S"
|
||||||
cat ./src/main/stage2.sns.sh >> "$S"
|
cat ./src/main/stage2.sns.sh >> "$S"
|
||||||
cat ./src/main/stage3.sns.sh >> "$S"
|
cat ./src/main/stage3.sns.sh >> "$S"
|
||||||
|
|||||||
@@ -10,3 +10,6 @@ ERR_INSUFFICIENT_ARGS 30 A required argument was not provided
|
|||||||
Encryption----------------------------------------------------------------------
|
Encryption----------------------------------------------------------------------
|
||||||
ERR_NO_GPG 100 GPG is not installed
|
ERR_NO_GPG 100 GPG is not installed
|
||||||
ERR_NO_KEY 110 No recipient specified
|
ERR_NO_KEY 110 No recipient specified
|
||||||
|
|
||||||
|
Create--------------------------------------------------------------------------
|
||||||
|
ERR_NOTE_EXiSTS 200 The specified note already exists
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
PROD_STR="Simple Note System"
|
PROD_STR="Simple Note System"
|
||||||
VER_STR="v2.0a8"
|
VER_STR="v2.0a8"
|
||||||
|
YEAR=2016
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#==========================================================
|
#==========================================================
|
||||||
# $PROD_STR, $VER_STR
|
# $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
|
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 TMP_DIR="\$ROOT_DIR"/tmp
|
||||||
readonly CONFIG_FILE="\$ROOT_DIR/sns.conf"
|
readonly CONFIG_FILE="\$ROOT_DIR/sns.conf"
|
||||||
|
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
141
sns.sh
141
sns.sh
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#==========================================================
|
#==========================================================
|
||||||
# Simple Note System, v2.0a8
|
# 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
|
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"
|
readonly CONFIG_FILE="$ROOT_DIR/sns.conf"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Section: Functions
|
# Section: Functions
|
||||||
function create_sns_root {
|
function create_sns_root {
|
||||||
|
|
||||||
@@ -112,7 +113,6 @@ function create(){
|
|||||||
if [ -e "$NOTE" ]; then
|
if [ -e "$NOTE" ]; then
|
||||||
echo "Created note: $NOTEBOOK/$SECTION/$NAME."
|
echo "Created note: $NOTEBOOK/$SECTION/$NAME."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
function delete(){
|
function delete(){
|
||||||
if [ "$DELETE" == "TRUE" ]; then
|
if [ "$DELETE" == "TRUE" ]; then
|
||||||
@@ -180,24 +180,20 @@ function list(){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
###############################################################################
|
# Entry Point
|
||||||
#==============================================================================
|
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
# Begin Main Program
|
#==============================================================================
|
||||||
#==============================================================================
|
# Stage 1: Read Configuration
|
||||||
###############################################################################
|
#==============================================================================
|
||||||
|
if [ -r "$CONFIG_FILE" ]; then
|
||||||
#==============================================================================
|
|
||||||
# Section: Configuration / Stage 1
|
|
||||||
#==============================================================================
|
|
||||||
if [ -r "$CONFIG_FILE" ]; then
|
|
||||||
source "$CONFIG_FILE"
|
source "$CONFIG_FILE"
|
||||||
else
|
else
|
||||||
create_sns_root
|
create_sns_root
|
||||||
source "$CONFIG_FILE"
|
source "$CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
if [ -z "$PUBKEY" ]; then
|
if [ -z "$PUBKEY" ]; then
|
||||||
ERR_NO_KEY="TRUE"
|
ERR_NO_KEY="TRUE"
|
||||||
ENCRYPTION="FALSE"
|
ENCRYPTION="FALSE"
|
||||||
@@ -205,38 +201,32 @@ if [ "$ENCRYPTION" == "TRUE" ]; then
|
|||||||
|
|
||||||
command -v gpg >/dev/null 2>&1 ||\
|
command -v gpg >/dev/null 2>&1 ||\
|
||||||
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
|
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
PROD_STR="Simple Note System (Encryption Enabled)"
|
PROD_STR="Simple Note System (Encryption Enabled)"
|
||||||
if [ ! -d "$ROOT_DIR"/tmp ]; then
|
if [ ! -d "$ROOT_DIR"/tmp ]; then
|
||||||
mkdir -p "$ROOT_DIR"/tmp
|
mkdir -p "$ROOT_DIR"/tmp
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$PROD_STR, $VER_STR"
|
echo "$PROD_STR, $VER_STR"
|
||||||
|
|
||||||
if [ -n "$ERR_NO_GPG" ]; then
|
if [ -n "$ERR_NO_GPG" ]; then
|
||||||
>&2 echo " Error: Encryption was specified, but GPG is not installed."
|
>&2 echo " Error: Encryption was specified, but GPG is not installed."
|
||||||
exit 100
|
exit 100
|
||||||
elif [ -n "$ERR_NO_KEY" ]; then
|
elif [ -n "$ERR_NO_KEY" ]; then
|
||||||
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
|
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
|
||||||
exit 110
|
exit 110
|
||||||
fi
|
fi
|
||||||
|
#==============================================================================
|
||||||
|
# Stage 2: Argument Parsing
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
# End Section: Configuration / Stage 1
|
NAME=""
|
||||||
#==============================================================================
|
NOTEBOOK=""
|
||||||
#==============================================================================
|
SECTION=""
|
||||||
# Section: Argument Parsing / Stage 2
|
if [ -z "$1" ]; then help; exit 20
|
||||||
#==============================================================================
|
else
|
||||||
|
|
||||||
NAME=""
|
|
||||||
NOTEBOOK=""
|
|
||||||
SECTION=""
|
|
||||||
if [ -z "$1" ]; then help; exit 20
|
|
||||||
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"
|
||||||
@@ -246,7 +236,7 @@ else
|
|||||||
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"
|
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"
|
||||||
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"
|
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"
|
||||||
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0
|
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
|
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"
|
||||||
@@ -255,56 +245,49 @@ else
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
|
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
|
||||||
# If we got a note title above, but no notebook, and the list option
|
# If a note title was specified, but no notebook, and the list option
|
||||||
# was specified, we assume that the detected note title is actually a
|
# was specified, assume that the detected note title is actually the
|
||||||
# notebook name.
|
# name of a notebook
|
||||||
NOTEBOOK="$NAME"
|
NOTEBOOK="$NAME"
|
||||||
NAME=""
|
NAME=""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
# w_conf and help are called here to avoid excess stage 3 code.
|
||||||
# Note: w_conf and help have highest priority, as they are the only functions
|
#==============================================================================
|
||||||
# that can work without any arguments.
|
# Section: Actions / Stage 3
|
||||||
|
#==============================================================================
|
||||||
#==============================================================================
|
# All options not requiring at least a notebook to be specified have been dealt
|
||||||
# End Section: Argument Parsing / Stage 2
|
# with; if one isn't specified, throw code 30.
|
||||||
#==============================================================================
|
if [ -z "$NOTEBOOK" ]; then
|
||||||
#==============================================================================
|
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
|
||||||
# Section: Actions / Stage 3
|
|
||||||
#==============================================================================
|
|
||||||
# List only requires a notebook, and is exclusive.
|
|
||||||
if [ -z "$NOTEBOOK" ]; then
|
|
||||||
echo " ERROR: Insufficient arguments:"
|
|
||||||
echo " Notebook not specified"
|
|
||||||
exit 30
|
exit 30
|
||||||
fi
|
fi
|
||||||
|
# List is the only option requiring only a notebook.
|
||||||
if [ -n "$LIST" ]; then
|
# If list isn't the selected option and no note name was specified, throw code 30.
|
||||||
|
if [ "$LIST" == TRUE ]; then
|
||||||
list
|
list
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
elif [ -z "$NAME" ]; then
|
||||||
|
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
|
||||||
#All other functions require a note title and notebook.
|
|
||||||
|
|
||||||
if [ -z "$NAME" ]; then
|
|
||||||
echo " ERROR: Insufficient arguments:"
|
|
||||||
echo " Title not specified"
|
|
||||||
exit 30
|
exit 30
|
||||||
fi
|
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
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
else readonly NOTE="$NOTE_DIR""$NAME"."$EXT"
|
SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename
|
||||||
fi
|
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
|
if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
|
||||||
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
|
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
|
||||||
if [ "$CREATE" == "TRUE" ]; then create; fi
|
if [ "$CREATE" == "TRUE" ]; then create; fi
|
||||||
if [ "$EDIT" == "TRUE" ]; then edit; fi
|
if [ "$EDIT" == "TRUE" ]; then edit; fi
|
||||||
|
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
# End Section: Actions / Stage 3
|
# End Section: Actions / Stage 3
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
|||||||
@@ -15,11 +15,12 @@
|
|||||||
5D22D6A81AFC4F5A0036DC52 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.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>"; };
|
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>"; };
|
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>"; };
|
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.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>"; };
|
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>"; };
|
||||||
@@ -47,8 +48,9 @@
|
|||||||
5D22D6A81AFC4F5A0036DC52 /* p_header.sh */,
|
5D22D6A81AFC4F5A0036DC52 /* p_header.sh */,
|
||||||
5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */,
|
5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */,
|
||||||
5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */,
|
5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */,
|
||||||
5D22D6AB1AFC4F5A0036DC52 /* create_sns_root.sns.sh */,
|
5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */,
|
||||||
5D22D6B01AFC5B100036DC52 /* libencryption.sh */,
|
5D22D6B01AFC5B100036DC52 /* libencryption.sh */,
|
||||||
|
5D75D24F1C5F13DF001E7B33 /* verify_store.sh */,
|
||||||
);
|
);
|
||||||
path = includes;
|
path = includes;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|||||||
BIN
sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate
generated
Normal file
BIN
sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate
generated
Normal file
Binary file not shown.
@@ -1,22 +1,31 @@
|
|||||||
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
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
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#!/bin/sh
|
function verify_store {
|
||||||
|
STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR")
|
||||||
# verify_store.sh
|
for DIR in ${STORE_DIRS[]}; do
|
||||||
# sns
|
mkdir -p "$DIR"
|
||||||
#
|
done
|
||||||
# Created by Jon-William Lewis on 1/31/16.
|
}
|
||||||
#
|
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
#==============================================================================
|
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
# Section: Configuration / Stage 1
|
# Entry Point
|
||||||
#==============================================================================
|
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
if [ -r "$CONFIG_FILE" ]; then
|
#==============================================================================
|
||||||
|
# Stage 1: Read Configuration / Verify Integrity
|
||||||
|
#==============================================================================
|
||||||
|
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
|
||||||
|
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
verify_store
|
||||||
|
|
||||||
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
if [ -z "$PUBKEY" ]; then
|
if [ -z "$PUBKEY" ]; then
|
||||||
ERR_NO_KEY="TRUE"
|
ERR_NO_KEY="TRUE"
|
||||||
ENCRYPTION="FALSE"
|
ENCRYPTION="FALSE"
|
||||||
@@ -16,26 +21,21 @@ if [ "$ENCRYPTION" == "TRUE" ]; then
|
|||||||
|
|
||||||
command -v gpg >/dev/null 2>&1 ||\
|
command -v gpg >/dev/null 2>&1 ||\
|
||||||
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
|
{ ERR_NO_GPG="TRUE"; ENCRYPTION="FALSE"; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
PROD_STR="Simple Note System (Encryption Enabled)"
|
PROD_STR="Simple Note System (Encryption Enabled)"
|
||||||
if [ ! -d "$ROOT_DIR"/tmp ]; then
|
if [ ! -d "$ROOT_DIR"/tmp ]; then
|
||||||
mkdir -p "$ROOT_DIR"/tmp
|
mkdir -p "$ROOT_DIR"/tmp
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$PROD_STR, $VER_STR"
|
echo "$PROD_STR, $VER_STR"
|
||||||
|
|
||||||
if [ -n "$ERR_NO_GPG" ]; then
|
if [ -n "$ERR_NO_GPG" ]; then
|
||||||
>&2 echo " Error: Encryption was specified, but GPG is not installed."
|
>&2 echo " Error: Encryption was specified, but GPG is not installed."
|
||||||
exit 100
|
exit 100
|
||||||
elif [ -n "$ERR_NO_KEY" ]; then
|
elif [ -n "$ERR_NO_KEY" ]; then
|
||||||
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
|
>&2 echo " Error: No GPG recipient was provided in $CONFIG_FILE. "
|
||||||
exit 110
|
exit 110
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
#==============================================================================
|
|
||||||
# End Section: Configuration / Stage 1
|
|
||||||
#==============================================================================
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#==============================================================================
|
#==============================================================================
|
||||||
# Section: Argument Parsing / Stage 2
|
# Stage 2: Argument Parsing
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
NAME=""
|
||||||
NAME=""
|
NOTEBOOK=""
|
||||||
NOTEBOOK=""
|
SECTION=""
|
||||||
SECTION=""
|
if [ -z "$1" ]; then help; exit 20
|
||||||
if [ -z "$1" ]; then help; exit 20
|
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"
|
||||||
@@ -25,17 +24,11 @@ else
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
|
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then
|
||||||
# If we got a note title above, but no notebook, and the list option
|
# If a note title was specified, but no notebook, and the list option
|
||||||
# was specified, we assume that the detected note title is actually a
|
# was specified, assume that the detected note title is actually the
|
||||||
# notebook name.
|
# name of a notebook
|
||||||
NOTEBOOK="$NAME"
|
NOTEBOOK="$NAME"
|
||||||
NAME=""
|
NAME=""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
# w_conf and help are called here to avoid excess stage 3 code.
|
||||||
# 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
|
|
||||||
#==============================================================================
|
|
||||||
|
|||||||
@@ -1,39 +1,37 @@
|
|||||||
#==============================================================================
|
#==============================================================================
|
||||||
# Section: Actions / Stage 3
|
# 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
|
||||||
if [ -z "$NOTEBOOK" ]; then
|
# with; if one isn't specified, throw code 30.
|
||||||
echo " ERROR: Insufficient arguments:"
|
if [ -z "$NOTEBOOK" ]; then
|
||||||
echo " Notebook not specified"
|
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
|
||||||
exit 30
|
exit 30
|
||||||
fi
|
fi
|
||||||
|
# List is the only option requiring only a notebook.
|
||||||
if [ -n "$LIST" ]; then
|
# If list isn't the selected option and no note name was specified, throw code 30.
|
||||||
|
if [ "$LIST" == TRUE ]; then
|
||||||
list
|
list
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
elif [ -z "$NAME" ];
|
||||||
|
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
|
||||||
#All other functions require a note title and notebook.
|
|
||||||
|
|
||||||
if [ -z "$NAME" ]; then
|
|
||||||
echo " ERROR: Insufficient arguments:"
|
|
||||||
echo " Title not specified"
|
|
||||||
exit 30
|
exit 30
|
||||||
fi
|
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
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
else readonly NOTE="$NOTE_DIR""$NAME"."$EXT"
|
SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename
|
||||||
fi
|
readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg"
|
||||||
|
else
|
||||||
|
readonly NOTE="$NOTE_DIR/$NAME.$EXT"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
|
if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
|
||||||
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
|
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
|
||||||
if [ "$CREATE" == "TRUE" ]; then create; fi
|
if [ "$CREATE" == "TRUE" ]; then create; fi
|
||||||
if [ "$EDIT" == "TRUE" ]; then edit; fi
|
if [ "$EDIT" == "TRUE" ]; then edit; fi
|
||||||
|
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
# End Section: Actions / Stage 3
|
# End Section: Actions / Stage 3
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user