From c410a2a69f644d7d4313bd432fdd203fa0f874b5 Mon Sep 17 00:00:00 2001 From: Jon Lewis Date: Tue, 20 Dec 2016 14:59:45 -0600 Subject: [PATCH 1/4] Began refactoring for sns v2a --- sns.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 sns.sh diff --git a/sns.sh b/sns.sh new file mode 100755 index 0000000..1bbdf8c --- /dev/null +++ b/sns.sh @@ -0,0 +1,63 @@ +#!/bin/bash +XL_PRODUCT="Simple Note System" +XL_VER="v2.1" + +#Environment +SNS_STORE="$HOME/.local/sns" +SNS_KEYFILE="$SNS_STORE/.pubkey" +SNS_DEPS=("gpg" "tree" "git") + +declare -f sns_checkDeps # Checks the system for dependencies +declare -f sns_initStore # Initializes the SNS Store ( -i) +declare -f sns_printHelp # Prints help page ( -h) +declare -f sns_list # Lists all notes in `tree` format ( *) +declare -f sns_create # Creates note; calls sns_edit() ( -c) +declare -f sns_edit # Decrypts note to /tmp, calls editor, re-encrypts note ( -e) +declare -f sns_print # Prints note to stdout ( -p) +declare -f sns_rm # Deletes note from store ( -d) +declare -f sns_gitPassthrough # Passes through all instructions to git (git) + +function sns_checkDeps(){ + for DEP in "${SNS_DEPS[@]}"; do + if test ! -e "$(which gpg 2>/dev/null)"; then + echo "Dependency missing: $DEP" + fi + done +} +function sns_initStore(){ + mkdir -p "$SNS_STORE" + mkdir -p "$SNS_STORE/notes" + echo "$1" > "$SNS_KEYFILE" +} +function sns_printHelp(){ + printf "%s" "Import helpfile from sns v2" +} +function sns_list(){ + tree -C --noreport "$1" +} +function sns_create(){ + gpg -r "$SNS_PUBKEY" -o "$1" < /dev/null + sns_edit "$1" +} +function sns_print(){ + gpg -d "$1" +} +function sns_rm(){ + rm -f "$1" +} +function sns_gitPassthrough(){ + git "$@" +} +# Entry Point +printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER" +while getopts ":ihc:e:p:d:git:" OPT; do + case "$OPT" in + *) + if [ -d "$SNS_STORE/notes/$OPTARG" ]; then + sns_list "$SNS_STORE/notes/$OPTARG" + else + sns_list "$SNS_STORE/notes/*" + fi + ;; + esac +done From 207db67b683b07c01abad928eb2e5006a47f50cc Mon Sep 17 00:00:00 2001 From: Jon Lewis Date: Tue, 27 Dec 2016 14:54:06 -0600 Subject: [PATCH 2/4] Started work on v2a rewrite --- errors.md | 22 --- header.sh | 42 ------ install.sh | 57 -------- sns.sh | 7 +- sns.xcodeproj/project.pbxproj | 132 ------------------ .../contents.xcworkspacedata | 7 - .../UserInterfaceState.xcuserstate | Bin 15437 -> 0 bytes .../WorkspaceSettings.xcsettings | 10 -- src/bash-completion/sns | 96 ------------- src/includes/create.sns.sh | 35 ----- src/includes/delete.sns.sh | 18 --- src/includes/edit.sns.sh | 51 ------- src/includes/help.sns.sh | 14 -- src/includes/init_store.sns.sh | 39 ------ src/includes/libencryption.sns.sh | 15 -- src/includes/list.sns.sh | 4 - src/includes/p_header.sh | 3 - src/includes/print.sns.sh | 12 -- src/includes/verify_store.sns.sh | 11 -- src/main/stage1.sns.sh | 24 ---- src/main/stage2.sns.sh | 48 ------- src/main/stage3.sns.sh | 30 ---- 22 files changed, 5 insertions(+), 672 deletions(-) delete mode 100644 errors.md delete mode 100644 header.sh delete mode 100755 install.sh delete mode 100644 sns.xcodeproj/project.pbxproj delete mode 100644 sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate delete mode 100644 sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/WorkspaceSettings.xcsettings delete mode 100644 src/bash-completion/sns delete mode 100644 src/includes/create.sns.sh delete mode 100644 src/includes/delete.sns.sh delete mode 100644 src/includes/edit.sns.sh delete mode 100644 src/includes/help.sns.sh delete mode 100644 src/includes/init_store.sns.sh delete mode 100644 src/includes/libencryption.sns.sh delete mode 100644 src/includes/list.sns.sh delete mode 100644 src/includes/p_header.sh delete mode 100644 src/includes/print.sns.sh delete mode 100644 src/includes/verify_store.sns.sh delete mode 100644 src/main/stage1.sns.sh delete mode 100644 src/main/stage2.sns.sh delete mode 100644 src/main/stage3.sns.sh diff --git a/errors.md b/errors.md deleted file mode 100644 index 9e13a94..0000000 --- a/errors.md +++ /dev/null @@ -1,22 +0,0 @@ -# Simple Note System, version 2 -## Error Code Reference - -### General Codes -| Name | Code | Meaning | -|--------------|------|---------------------------------------| -| ERR_NO_STORE | 5 | the SNS store needs to be initialized | -| ERR_NO_ARGS | 10 | No arguments were specified | -| ERR_NO_OP | 20 | No operation was specified | -| ERR_NO_NOTE | 30 | A required argument was not provided | - -### Encryption-related codes -|Name | Code | Meaning | -|------------|------|-------------------------------------------------------| -| ERR_NO_GPG | 100 | Encryption is enabled, but GPG is not installed | -| ERR_NO_KEY | 110 | Encryption is enabled, but no recipient was specified | - -### Creation-related codes -|Name | Code | Meaning | -|-----------------|------|-----------------------------------| -| ERR_NOTE_EXiSTS | 200 | The specified note already exists | -| ERR_NOTE_NO_READ| 205 | The specified note cannot be read | diff --git a/header.sh b/header.sh deleted file mode 100644 index 5a27ea1..0000000 --- a/header.sh +++ /dev/null @@ -1,42 +0,0 @@ -PROD_STR="Simple Note System" -VER_STR="v2.0a9" -YEAR=2016 - -cat << EOF -#!/bin/bash -# Simple Note System -# Copyright (C) 2016, Jon Lewis -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Prevent freak accidents involving the root directory -if [ -z "\$HOME" ]; then HOME=/home/"\$(whoami)"; fi - -# Store files and locations -readonly PROD_STR="$PROD_STR" -readonly VER_STR="$VER_STR" -readonly ROOT_DIR="\$HOME"/.config/sns -readonly NOTES_DIR="\$ROOT_DIR"/notes -readonly TMP_DIR="\$ROOT_DIR"/tmp -readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" - -#Color codes for error reporting -readonly RED_COLOR='\033[1;31m' -readonly RESET_COLOR='\033[0m' - -#Print the program header to stdout -printf "%s\n" "\$PROD_STR" -printf "%s\n" "------------------" -EOF diff --git a/install.sh b/install.sh deleted file mode 100755 index 68485f2..0000000 --- a/install.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -# Simple Note System - Install Script -# Copyright (C) 2016, Jon Lewis -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -if [ "$1" == "--uninstall" ]; then - rm /bin/sns - rm /usr/share/bash-completion/completions/sns - exit -fi - -mkdir build - -S=build/sns.sh - -bash header.sh > "$S" -echo -e "\n# Section: Functions" >> "$S" -cat ./src/includes/init_store.sns.sh >> "$S" -cat ./src/includes/verify_store.sns.sh >> "$S" -cat ./src/includes/help.sns.sh >> "$S" -cat ./src/includes/p_header.sh >> "$S" -cat ./src/includes/libencryption.sns.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" -printf "%s\n" "# 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" - -chmod u+x "$S" -# Install SNS -if [ ! -r "/bin/sns" ] || [ grep "Simple Note System" < "/bin/sns" ]; - sudo cp "$S" > "/bin/sns" -fi -# Install Bash completion -if [ ! -r "/usr/share/bash-completion/completions/sns" ]\ - || [ grep "Simple Note System" < "/usr/share/bash-completion/completions/sns" ]; then - sudo cp "src/bash-completion/sns" >\ - "/usr/share/bash-completion/completions/sns" -fi -exit diff --git a/sns.sh b/sns.sh index 1bbdf8c..fda8edb 100755 --- a/sns.sh +++ b/sns.sh @@ -1,6 +1,6 @@ #!/bin/bash XL_PRODUCT="Simple Note System" -XL_VER="v2.1" +XL_VER="v2a" #Environment SNS_STORE="$HOME/.local/sns" @@ -26,7 +26,6 @@ function sns_checkDeps(){ } function sns_initStore(){ mkdir -p "$SNS_STORE" - mkdir -p "$SNS_STORE/notes" echo "$1" > "$SNS_KEYFILE" } function sns_printHelp(){ @@ -50,6 +49,10 @@ function sns_gitPassthrough(){ } # Entry Point printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER" +if [ -d "$SNS_STORE" ] && [ "$1" != "-i" ]; then + printf "%s\n" "Please run \`sns -i\` to initialize sns." + exit +fi while getopts ":ihc:e:p:d:git:" OPT; do case "$OPT" in *) diff --git a/sns.xcodeproj/project.pbxproj b/sns.xcodeproj/project.pbxproj deleted file mode 100644 index 0c77465..0000000 --- a/sns.xcodeproj/project.pbxproj +++ /dev/null @@ -1,132 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXFileReference section */ - 5D22D6A21AFC4F5A0036DC52 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = ""; }; - 5D22D6A31AFC4F5A0036DC52 /* delete.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = delete.sns.sh; sourceTree = ""; }; - 5D22D6A41AFC4F5A0036DC52 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = ""; }; - 5D22D6A51AFC4F5A0036DC52 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = ""; }; - 5D22D6A71AFC4F5A0036DC52 /* list.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = list.sns.sh; sourceTree = ""; }; - 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = p_header.sh; sourceTree = ""; }; - 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = ""; }; - 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = ""; }; - 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = init_store.sns.sh; sourceTree = ""; }; - 5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = ""; }; - 5D22D6AE1AFC4F5A0036DC52 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = ""; }; - 5D22D6AF1AFC4F5A0036DC52 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = ""; }; - 5D22D6B01AFC5B100036DC52 /* libencryption.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = libencryption.sns.sh; sourceTree = ""; }; - 5D75D24F1C5F13DF001E7B33 /* verify_store.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = verify_store.sns.sh; sourceTree = ""; }; - 5D7E611F1AB74D33001D49B9 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = ""; }; - 5D7E91FB1B27FB620030B30D /* header.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = header.sh; sourceTree = ""; }; - 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = ""; }; - 5DE839881ABA04DD006CB4F6 /* errors.ref */ = {isa = PBXFileReference; lastKnownFileType = text; path = errors.ref; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXGroup section */ - 5D22D6A01AFC4F5A0036DC52 /* src */ = { - isa = PBXGroup; - children = ( - 5D22D6A11AFC4F5A0036DC52 /* includes */, - 5D22D6AC1AFC4F5A0036DC52 /* main */, - ); - path = src; - sourceTree = ""; - }; - 5D22D6A11AFC4F5A0036DC52 /* includes */ = { - isa = PBXGroup; - children = ( - 5D22D6A21AFC4F5A0036DC52 /* create.sns.sh */, - 5D22D6A31AFC4F5A0036DC52 /* delete.sns.sh */, - 5D22D6A41AFC4F5A0036DC52 /* edit.sns.sh */, - 5D22D6A51AFC4F5A0036DC52 /* help.sns.sh */, - 5D22D6A71AFC4F5A0036DC52 /* list.sns.sh */, - 5D22D6A81AFC4F5A0036DC52 /* p_header.sh */, - 5D22D6A91AFC4F5A0036DC52 /* pause.sns.sh */, - 5D22D6AA1AFC4F5A0036DC52 /* print.sns.sh */, - 5D22D6AB1AFC4F5A0036DC52 /* init_store.sns.sh */, - 5D22D6B01AFC5B100036DC52 /* libencryption.sns.sh */, - 5D75D24F1C5F13DF001E7B33 /* verify_store.sns.sh */, - ); - path = includes; - sourceTree = ""; - }; - 5D22D6AC1AFC4F5A0036DC52 /* main */ = { - isa = PBXGroup; - children = ( - 5D22D6AD1AFC4F5A0036DC52 /* stage1.sns.sh */, - 5D22D6AE1AFC4F5A0036DC52 /* stage2.sns.sh */, - 5D22D6AF1AFC4F5A0036DC52 /* stage3.sns.sh */, - ); - path = main; - sourceTree = ""; - }; - 5D7E61181AB74D11001D49B9 = { - isa = PBXGroup; - children = ( - 5D22D6A01AFC4F5A0036DC52 /* src */, - 5DE839881ABA04DD006CB4F6 /* errors.ref */, - 5DE839831AB9DACE006CB4F6 /* sns.sh */, - 5D7E611F1AB74D33001D49B9 /* build.sh */, - 5D7E91FB1B27FB620030B30D /* header.sh */, - ); - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXProject section */ - 5D7E61191AB74D11001D49B9 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0700; - }; - buildConfigurationList = 5D7E611C1AB74D11001D49B9 /* Build configuration list for PBXProject "sns" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 5D7E61181AB74D11001D49B9; - projectDirPath = ""; - projectRoot = ""; - targets = ( - ); - }; -/* End PBXProject section */ - -/* Begin XCBuildConfiguration section */ - 5D7E611D1AB74D11001D49B9 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ENABLE_TESTABILITY = YES; - ONLY_ACTIVE_ARCH = YES; - }; - name = Debug; - }; - 5D7E611E1AB74D11001D49B9 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 5D7E611C1AB74D11001D49B9 /* Build configuration list for PBXProject "sns" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5D7E611D1AB74D11001D49B9 /* Debug */, - 5D7E611E1AB74D11001D49B9 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 5D7E61191AB74D11001D49B9 /* Project object */; -} diff --git a/sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index dccdea5..0000000 --- a/sns.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate b/sns.xcodeproj/project.xcworkspace/xcuserdata/xilmwa.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index df0db656877e336bd9f922a0891aabdacbe362db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15437 zcmc(G349a9`}fT3Ztpgmq)nUjO7Gl9?{Y{BEjQ)p0p$v58%iK;N|HhgEzY8X9EvC) zq9`pO0)l`CA}S~%Dxx5VB8vPJ6;VJD1@Ct@+l1C%eP8|H`~SlSn(WMcpJ$$V?%7s1 zI_z$b$#eohfB*$(z<>Z|0yA-3>MWbfZFe?|OLbOHx7B#uRjF22%``iCT%PK2Hc9|o zu2ASZU;-iO0Wv71?$0LumL;)o&cO;V=S|xDG-O03WJZ~&59*6OXb;+l4x%^FyXYkP7@b9*pfAw{ z^cDIJT}9ucYZRg=il!JUfC{7{sTfL5#Zw7XGL=GQP%27C=_xanN##;`RBx&eRY(<4 zCDbr#IMqsFilgqL7Ep_+CDbzNK57NEl6r_*Lp@48My;ndP)|^sscqDDY8Ul1wVQgL zdXajGdWCwGdYw8%9j4x@a}hBTrnnx+{# zfDWXkbR-=`%jje}g-)f@XfvHjXVKYoAzeiGrw7m@=~47(dJH|8w$M{(D_u`F&`!FM zZl&AkdGzh{5_&0p4}CAahJKiSgkDQ;rnk^r=_l#u={@ud^j`W9{RaIeeUd&!zfXTa zpQk^kzo5UQzo)O!KQNF%48_n4%ZM2XBV{6)C`QIaGbv0elg6YonM@Xw&EznBnIfh? zGmsg?jATYJqnR;GSw(6?lf!Ww1cML|3c`R0NXC|y8D`j8+~dj5PD`pxt#Mf0?hX(R zA~3>K2Vj91)A$sww6Li;CUbHB?4n$KW|lcepIwkWKwp%foukjqE9#$J+&?!nr@&-k zBZm~1jC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HA^%rG;1|m zG*4@u)$G>n(d^Z{ra7c}OY^qoUClAghnmkc-)Mf)A}y^A&<1Hkv{J21E7!(q6SPXL zTAQiutsSf#tu515Xvb=+wAEUhcA9p&wqEPhHf!f=muOdO+qLVp8?~FXo3*>N&uX97 zzMy?cyHERu_L%lV?U&kbwO6&*v_EQZ=%9|)1?qxzVY&!iv@S`f)#dAobOUrHxbB{2=yvJ$>JI1*>psx^ zNB5cTbKRG^uXI;+Kj?1ge%Ae_`$He37wZ-J482KDeosuFtIyXL>5KJ)^h5N+^`-i; z`YHN){VaX6evZCXKTp3Oat*(Vx|y z(|@M_Tz^@A!+;DTLySRTh%+P@lm@jyXD}MfhHOKwp`T%}p~5iPFvU=9s5MMAI1MgC zlVP@Dj-l0Xm*HN+gN6-;ZH66&rwz{;_849@95lRPc*}6a@UG#aQEW^!4l<51RvD{} zPGhrijs^rh*V=_k{#ra#QI zInW$p4l_&4a&xj-YtA?KH5Zx(m - - - - HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges - - SnapshotAutomaticallyBeforeSignificantChanges - - - diff --git a/src/bash-completion/sns b/src/bash-completion/sns deleted file mode 100644 index 1d49269..0000000 --- a/src/bash-completion/sns +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash -# Simple Note System, bash completion file -# ======================================== -# Copyright (C) 2016, Jon Lewis -# Simple Note System is licensed under the GPLv2. Please see LICENSE for more -# information. -# -# **Notice** -# This file was adapted from pass, the standard unix password manager under the -# terms of the GPLv2 license. Pass may be found at https://passwordstore.org. -# -# The original file bore the following copyright notice: -# -# Copyright (C) 2012 - 2014 Jason A. Donenfeld and -# Brian Mattern . All Rights Reserved. -# This file is licensed under the GPLv2+. Please see COPYING for more information. - -_sns_complete_entries () { - prefix="${SNS_STORE_DIR:-$HOME/.config/sns/notes/}" - suffix=".note" - autoexpand=${1:-0} - - local IFS=$'\n' - local items=($(compgen -f $prefix$cur)) - for item in "${items[@]}"; do - [[ $item =~ /\.[^/]*$ ]] && continue - - # if there is a unique match, and it is a directory with one entry - # autocomplete the subentry as well (recursively) - if [[ ${#items[@]} -eq 1 && $autoexpand -eq 1 ]]; then - while [[ -d $item ]]; do - local subitems=($(compgen -f "$item/")) - local filtereditems=( ) - for item2 in "${subitems[@]}"; do - [[ $item2 =~ /\.[^/]*$ ]] && continue - filtereditems+=( "$item2" ) - done - if [[ ${#filtereditems[@]} -eq 1 ]]; then - item="${filtereditems[0]}" - else - break - fi - done - fi - - # append / to directories - [[ -d $item ]] && item="$item/" - - item="${item%$suffix}" - item="${item%.gpg}" - COMPREPLY+=("${item#$prefix}") - done -} - -_sns_complete_folders () { - prefix="${SNS_STORE_DIR:-$HOME/.config/sns/notes/}" - - local IFS=$'\n' - local items=($(compgen -d $prefix$cur)) - for item in "${items[@]}"; do - [[ $item == $prefix.* ]] && continue - COMPREPLY+=("${item#$prefix}/") - done -} - -_sns_complete_keys () { - local IFS=$'\n' - # Extract names and email addresses from gpg --list-keys - local keys="$(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')" - COMPREPLY+=($(compgen -W "${keys}" -- ${cur})) -} - -_sns() -{ - COMPREPLY=() - local cur="${COMP_WORDS[COMP_CWORD]}" - local commands="--create --delete --edit --help --print --list --init" - if [[ $COMP_CWORD -gt 1 ]]; then - local lastarg="${COMP_WORDS[$COMP_CWORD-1]}" - case "${COMP_WORDS[1]}" in - --list|-l) - _sns_complete_folders - ;; - --edit|-e|--print|-p|--delete|-d) - _sns_complete_entries - ;; - *) - ;; - esac - else - COMPREPLY+=($(compgen -W "${commands}" -- ${cur})) - - fi -} - -complete -o filenames -o nospace -F _sns sns diff --git a/src/includes/create.sns.sh b/src/includes/create.sns.sh deleted file mode 100644 index 6b1f04e..0000000 --- a/src/includes/create.sns.sh +++ /dev/null @@ -1,35 +0,0 @@ -function create(){ - # Depends : p_header - # Requires: $NOTE, $NOTE_DIR, - # 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 "$NOTES_DIR/$NOTE" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Note already exists"\ - "Hint: use -e to edit the note." - exit 200 - fi - - # If the note's notebook/section does not exist, - # create the appropriate folders. - mkdir -p "$NOTES_DIR"/"$(dirname "$NOTE")" - - # Write the standard note header - if [ "$ENCRYPTION" == "TRUE" ]; then - TMP_NOTE="$TMP_DIR"/"$SESSION_ID" - p_header > "$TMP_NOTE" - encrypt - else - p_header > "$NOTES_DIR/$NOTE" - fi - # Make sure the note exists, and inform the user of the result. - if [ -e "$NOTES_DIR/$NOTE" ]; then - printf " - %s\n" "Created note: ${NOTE%.*}" - else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ - "Something went wrong, and the note was not created." - fi -} diff --git a/src/includes/delete.sns.sh b/src/includes/delete.sns.sh deleted file mode 100644 index f8aa791..0000000 --- a/src/includes/delete.sns.sh +++ /dev/null @@ -1,18 +0,0 @@ -function delete(){ - # Requires: $NOTE, $NOTE_DIR - # Given a valid $NOTE, delete removes $NOTE from sns. - - if [ -e "$NOTES_DIR/$NOTE" ]; then - rm "$NOTES_DIR/$NOTE" - printf " - %s\n" "Deleted note: ${NOTE%.*}." - #Cleanup empty notebooks/sections] - find "$NOTES_DIR" -mindepth 1 -type d | tac |\ - while read -r DIR ; do - if [ ! "$(ls -A $DIR)" ]; then - rmdir "$DIR" - fi - done - else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." - fi -} diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh deleted file mode 100644 index 79ebc47..0000000 --- a/src/includes/edit.sns.sh +++ /dev/null @@ -1,51 +0,0 @@ -function edit(){ -# Requires: $EDITOR, $NOTE -# Optional: $ENCRYPTION, $TMP_DIR, $SESSION_ID, decrypt, encrypt - -# Verify an editor was specified -if [ -z "$EDITOR" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ - "No editor specified in environment." - exit -# Verify the note exists -elif [ ! -r "$NOTES_DIR/$NOTE" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ - "Note cannot be opened for editing." - exit 40; -fi - -# If encryption is enabled, decrypt $NOTE to a temp file, otherwise -# operate on the note directly. -if [ "$ENCRYPTION" == "TRUE" ]; then - cp "$NOTES_DIR/$NOTE" "$NOTES_DIR/$NOTE.bk" #Insurance - TMP_NOTE="$TMP_DIR/$SESSION_ID" - decrypt > "$TMP_NOTE" -else - TMP_NOTE="$NOTES_DIR/$NOTE"; -fi - -# Write an ammendment header -if [ -z "$CREATE" ]; then - printf "\n%s\n" "edit - $(date "$DATE_FMT")" >> "$TMP_NOTE" - printf "%s\n" "===================================" >> "$TMP_NOTE" -fi - -# Call the editor -printf " - %s\n" "editing ${NOTE%.*}" -"$EDITOR" "$TMP_NOTE" - -# If the file was previously decrypted, encrypt it back -if [ "$ENCRYPTION" == "TRUE" ]; then - echo "reencrypting" - rm "$NOTES_DIR/$NOTE" - encrypt; - rm "$TMP_NOTE" - if [ ! -r "$NOTES_DIR/$NOTE" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "error: note was not saved." - cp "$NOTES_DIR/$NOTE.bk" "$NOTES_DIR/$NOTE" - else - rm "$NOTES_DIR/$NOTE.bk"; - fi -fi - -} diff --git a/src/includes/help.sns.sh b/src/includes/help.sns.sh deleted file mode 100644 index 8f26e97..0000000 --- a/src/includes/help.sns.sh +++ /dev/null @@ -1,14 +0,0 @@ -function help { - printf "\n%s" "usage: sns [-cedp] NAME NOTEBOOK SECTION" - printf "\n%s" " sns [-l] NOTEBOOK" - printf "\n%s" " sns [-hi ]" - - printf "\n%s" " -c | --create : Create note" - printf "\n%s" " -d | --delete : Delete note" - printf "\n%s" " -e | --edit : Open note for editing" - printf "\n%s" " -h | --help : Display this message" - printf "\n%s" " -p | --print : Print note to console" - printf "\n%s" " -l | --list : List all notes in NOTEBOOK" - printf "\n%s" " -i | --init : Write default config and initalize SNS store" - printf "\n" -} diff --git a/src/includes/init_store.sns.sh b/src/includes/init_store.sns.sh deleted file mode 100644 index b3095de..0000000 --- a/src/includes/init_store.sns.sh +++ /dev/null @@ -1,39 +0,0 @@ -function init_store { - -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 - - -cat > "$CONFIG_FILE" << EOF -# This file contains directives for the Simple Note System. - -EXT=note # File extension to use (for listing notes) - -#EDITOR= # Preferred Editor: - # If you would like to specify a different editor for - # sns to use, you may do so here, otherwise, sns will - # use the editor specified in the environment. - -DATE_FMT="+%D %T" # Date Format: - # If you would like to modify the date format, you may - # specify one appropriate to the \`date\` command. - -ENCRYPTION="FALSE" # Main Encryption Toggle: - # WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST - # Change this to TRUE to enable encryption. - -PUBKEY="" # Public Key - # Encryption is done using GPG. You must enter your - # public key's identifier here. -EOF - -chmod 600 "$CONFIG_FILE" - -printf " - %s\n" "Rewrote Default Configuration" - -if [ "$WILL_INIT" == "TRUE" ]; then - printf " - %s\n" "Environment initialized in $ROOT_DIR" -else - printf " - %s\n" "Store already initialized." -fi -} diff --git a/src/includes/libencryption.sns.sh b/src/includes/libencryption.sns.sh deleted file mode 100644 index 2906341..0000000 --- a/src/includes/libencryption.sns.sh +++ /dev/null @@ -1,15 +0,0 @@ -function encrypt(){ -# This function, given a recipient, $PUBKEY; a file to encrypt, $TMP_NOTE; and an -# output file, $NOTE, will encrypt $TMP_NOTE to $NOTE against $PUBKEY's private -# GPG key. - - gpg -r "$PUBKEY" -o "$NOTES_DIR/$NOTE" -e "$TMP_NOTE" - -} - -function decrypt(){ -# This function, given a file to decrypt, will attempt to decrypt the file -# against the specified recipient's private key, and print the result to -# stdout. - gpg -d "$NOTES_DIR/$NOTE" -} diff --git a/src/includes/list.sns.sh b/src/includes/list.sns.sh deleted file mode 100644 index 5a39dec..0000000 --- a/src/includes/list.sns.sh +++ /dev/null @@ -1,4 +0,0 @@ -function list(){ - # This function, given a folder, $NOTE, will list the contents of $NOTE. - ls "$NOTES_DIR/${NOTE%.*}" -} diff --git a/src/includes/p_header.sh b/src/includes/p_header.sh deleted file mode 100644 index 6fc43d6..0000000 --- a/src/includes/p_header.sh +++ /dev/null @@ -1,3 +0,0 @@ -function p_header(){ - printf "# %s\n## %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")" -} diff --git a/src/includes/print.sns.sh b/src/includes/print.sns.sh deleted file mode 100644 index 7b6d2eb..0000000 --- a/src/includes/print.sns.sh +++ /dev/null @@ -1,12 +0,0 @@ -function print(){ -# Given an existing file, $NOTE, print prints the contents of $NOTE to stdout. - -if [ -r "$NOTE" ]; then - if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout - else cat "$NOTE"; fi -else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Note cannot be found." - exit 205 #ERR_NOTE_NO_READ -fi -} diff --git a/src/includes/verify_store.sns.sh b/src/includes/verify_store.sns.sh deleted file mode 100644 index ef0e9f6..0000000 --- a/src/includes/verify_store.sns.sh +++ /dev/null @@ -1,11 +0,0 @@ -function verify_store { - - ETC_DIR=$(dirname "$CONFIG_FILE") - - STORE_DIRS=("$ROOT_DIR" "$NOTES_DIR" "$TMP_DIR" "$ETC_DIR") - for DIR in "${STORE_DIRS[@]}"; do - if [ ! -d "$DIR" ]; then - mkdir -p "$DIR" - fi - done -} diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh deleted file mode 100644 index 1ddfc3c..0000000 --- a/src/main/stage1.sns.sh +++ /dev/null @@ -1,24 +0,0 @@ -#============================================================================== -# Stage 1: Read Configuration / Verify Integrity -#============================================================================== - -if [ -r "$CONFIG_FILE" ]; then - source "$CONFIG_FILE" - verify_store -elif [ $1 != "-i" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Configuration not found. Please run sns -i." - exit 5 #ERR_NO_STORE -fi - -if [ "$ENCRYPTION" == "TRUE" ]; then - if [ ! -r "$(which gpg)" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "Encryption was specified, but GPG is not installed." - exit 100 - elif [ -z "$PUBKEY" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ - "No GPG recipient was provided in $CONFIG_FILE. " - exit 110 - fi -fi diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh deleted file mode 100644 index 4423feb..0000000 --- a/src/main/stage2.sns.sh +++ /dev/null @@ -1,48 +0,0 @@ -#============================================================================== -# Stage 2: Argument Parsing -#============================================================================== -NOTE="" -if [ -z "$1" ]; then help; exit 20 -else - for ARG in "$@"; do - case "$ARG" in - -c|--create) - CREATE="TRUE" - OP="TRUE" - ;; - -d|--delete) - DELETE="TRUE" - OP="TRUE" - ;; - -e|--edit) - EDIT="TRUE" - OP="TRUE" - ;; - -ce|-ec) - CREATE="TRUE" - EDIT="TRUE" - OP="TRUE" - ;; - -l|--list) - LIST="TRUE" - OP="TRUE" - ;; - -p|--print) - PRINT="TRUE" - OP="TRUE" - ;; - -h|--help) - help - exit 0 - ;; - -i|--init-store) - init_store - exit 0 - ;; - *) - NOTE="$ARG" - break; - ;; - esac - done -fi diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh deleted file mode 100644 index b090f4b..0000000 --- a/src/main/stage3.sns.sh +++ /dev/null @@ -1,30 +0,0 @@ -#============================================================================== -# 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 a note to be specified have been dealt -# with; if one isn't specified, exit on ERR_NO_NOTE. -if [ -z "$NOTE" ]; then - printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified." - exit 30 -fi - -if [ "$ENCRYPTION" == "TRUE" ]; then - SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename - readonly NOTE="$NOTE.gpg.$EXT" -else - readonly NOTE="$NOTE.$EXT" -fi - -if [ "$LIST" == "TRUE" ]; then list ; exit 0; fi -if [ "$PRINT" == "TRUE" ]; then print ; exit 0; fi -if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi -if [ "$CREATE" == "TRUE" ]; then create; fi -if [ "$EDIT" == "TRUE" ]; then edit ; fi -#============================================================================== -# End Section: Actions / Stage 3 -#============================================================================== From 464c53f8453003a881a6a1af64c7f48f168be1df Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Fri, 30 Dec 2016 21:07:07 -0600 Subject: [PATCH 3/4] Continued work on rewrite v2a --- sns.sh | 127 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/sns.sh b/sns.sh index fda8edb..2c195ec 100755 --- a/sns.sh +++ b/sns.sh @@ -2,65 +2,106 @@ XL_PRODUCT="Simple Note System" XL_VER="v2a" -#Environment -SNS_STORE="$HOME/.local/sns" -SNS_KEYFILE="$SNS_STORE/.pubkey" -SNS_DEPS=("gpg" "tree" "git") +# Environment +readonly SNS_STORE="$HOME/.local/sns" +readonly SNS_KEYFILE="$SNS_STORE/.pubkey" +readonly SNS_DEPS=("gpg" "tree" "git") +readonly IFS=$'\n\t' +set -euo pipefail -declare -f sns_checkDeps # Checks the system for dependencies -declare -f sns_initStore # Initializes the SNS Store ( -i) -declare -f sns_printHelp # Prints help page ( -h) -declare -f sns_list # Lists all notes in `tree` format ( *) -declare -f sns_create # Creates note; calls sns_edit() ( -c) -declare -f sns_edit # Decrypts note to /tmp, calls editor, re-encrypts note ( -e) -declare -f sns_print # Prints note to stdout ( -p) -declare -f sns_rm # Deletes note from store ( -d) -declare -f sns_gitPassthrough # Passes through all instructions to git (git) +# Function Definitions +# sns_initStore Initializes the SNS Store ( -i) +# sns_printHelp Prints help page ( -h) +# sns_list Lists all notes in `tree` format ( *) +# sns_create Creates note; calls sns_edit() ( -c) +# sns_edit Decrypts note to /tmp, calls editor, re-encrypts note ( -e) +# sns_print Prints note to stdout ( -p) +# sns_rm Deletes note from store ( -d) +# sns_gitPassthrough Passes through all instructions to git (git) +# sns_checkDeps Checks the system for required dependencies +# sns_checkStore Checks if $SNS_STORE exists +# sns_sanityCheck Wrapper for sns_checkDeps and sns_checkStore -function sns_checkDeps(){ - for DEP in "${SNS_DEPS[@]}"; do - if test ! -e "$(which gpg 2>/dev/null)"; then - echo "Dependency missing: $DEP" - fi - done -} -function sns_initStore(){ +function sns_initStore { mkdir -p "$SNS_STORE" - echo "$1" > "$SNS_KEYFILE" + echo $* | awk '{print $1}' > "$SNS_KEYFILE" } function sns_printHelp(){ printf "%s" "Import helpfile from sns v2" } function sns_list(){ - tree -C --noreport "$1" + cd "$SNS_STORE" || exit + tree -C --noreport "$(echo $* | awk '{print $1}')" } function sns_create(){ - gpg -r "$SNS_PUBKEY" -o "$1" < /dev/null - sns_edit "$1" + gpg -r "$SNS_PUBKEY" -o "echo $* | awk '{print $1}'" < /dev/null + sns_edit "echo $* | awk '{print $1}'" } function sns_print(){ - gpg -d "$1" + gpg -d "echo $* | awk '{print $1}'" } function sns_rm(){ - rm -f "$1" + rm -f "echo $* | awk '{print $1}'" } function sns_gitPassthrough(){ - git "$@" + cd "$SNS_STORE" || exit; + git "$@"; } +function sns_checkDeps(){ + local SNS_RETURN="true"; + for DEP in "${SNS_DEPS[@]}"; do + if test ! -e "$(which gpg 2>/dev/null)"; then + echo "Dependency missing: $DEP"; + SNS_RETURN="false"; + fi + done + "$SNS_RETURN"; +} +function sns_checkStore(){ + if [ -d "$SNS_STORE" ]; then true; else false; fi +} +function sns_sanityCheck { + if ! sns_checkDeps; then + exit 10 + fi + if ! sns_checkStore; then + if [ "$(echo "$SNS_ACTION" | awk '{print $1;}')" != "sns_initStore" ]; then + printf "%s\n" "Please run \`sns -i\` to initialize sns." + exit 20 + fi + fi +} +function sns_argParse(){ + declare -ga SNS_ACTION=() + while getopts ":i:hc:e:p:d:" OPT; do + case "$OPT" in + i) + SNS_ACTION=("sns_initStore" "$OPTARG");; + h) + SNS_ACTION=("sns_printHelp");; + c) + SNS_ACTION=("sns_create $OPTARG");; + e) + SNS_ACTION=("sns_edit $OPTARG");; + p) + SNS_ACTION=("sns_print $OPTARG");; + d) + SNS_ACTION=("sns_rm $OPTARG");; + esac + done + if [ "${#SNS_ACTION[@]}" -eq 0 ]; then + if [ "$(echo "$@" | awk '{print $1}')" == "git" ]; then + SNS_ACTION=($@) + else + if [ -d "$SNS_STORE/$*" ]; then + SNS_ACTION=("sns_list" "./$*") + fi + fi + fi +} + # Entry Point printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER" -if [ -d "$SNS_STORE" ] && [ "$1" != "-i" ]; then - printf "%s\n" "Please run \`sns -i\` to initialize sns." - exit -fi -while getopts ":ihc:e:p:d:git:" OPT; do - case "$OPT" in - *) - if [ -d "$SNS_STORE/notes/$OPTARG" ]; then - sns_list "$SNS_STORE/notes/$OPTARG" - else - sns_list "$SNS_STORE/notes/*" - fi - ;; - esac -done +sns_argParse "$@" +sns_sanityCheck +"${SNS_ACTION[@]}" From a348f740bd04787b90c159ec36fa0b13575469ae Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Fri, 21 Apr 2017 05:17:27 -0500 Subject: [PATCH 4/4] Script appears complete --- errors.md | 28 ++++++++ sns.sh | 189 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 179 insertions(+), 38 deletions(-) create mode 100644 errors.md diff --git a/errors.md b/errors.md new file mode 100644 index 0000000..936ec07 --- /dev/null +++ b/errors.md @@ -0,0 +1,28 @@ +# Simple Note System, version 2 +## Error Code Reference + +### General Codes +| Name | Code | Meaning | +|--------------|------|---------------------------------------| +| ERR_NO_STORE | 5 | the SNS store needs to be initialized | +| | | | +| ERR_NO_OPTS | 10 | No mode argument was specified | +| | | | +| ERR_NO_ARGS | 11 | A mode requiring an argument was | +| | | specified without an argument | +| | | | + +### Encryption-related codes +|Name | Code | Meaning | +|------------|------|-----------------------------------------| +| ERR_NO_GPG | 100 | Encryption is enabled, but GPG is not | +| | | installed | +| | | | +| ERR_NO_KEY | 110 | Encryption is enabled, but no recipient | +| | | was specified | + +### Creation-related codes +|Name | Code | Meaning | +|-----------------|------|------------------------------------| +| ERR_NOTE_EXiSTS | 200 | The specified note already exists | +| ERR_NOTE_NO_READ| 205 | The specified note cannot be read | diff --git a/sns.sh b/sns.sh index 2c195ec..911c62d 100755 --- a/sns.sh +++ b/sns.sh @@ -2,14 +2,44 @@ XL_PRODUCT="Simple Note System" XL_VER="v2a" -# Environment +# Environment Constants readonly SNS_STORE="$HOME/.local/sns" readonly SNS_KEYFILE="$SNS_STORE/.pubkey" -readonly SNS_DEPS=("gpg" "tree" "git") +readonly SNS_DEPS=("gpg2" "tree" "git") readonly IFS=$'\n\t' set -euo pipefail +readonly SNS_RED_COLOR='\033[1;31m' +readonly SNS_YELLOW_COLOR='\033[1;33m' +readonly SNS_RESET_COLOR='\033[0m' + +# Erroneous Exit Constants + + # Invocation Errors + readonly SNS_ERR_NO_STORE=5 # The sns store needs to be initialized + readonly SNS_ERR_NO_OPTS=10 # No mode argument was specified + readonly SNS_ERR_NS_ARGS=11 # The specified mode requires an argument + + # Dependency Errors + readonly SNS_ERR_DEPS=20 # Base error - add the following codes + readonly SNS_ERR_NO_gpg2=1 # GPG is not installed + readonly SNS_ERR_NO_tree=2 # Tree is not installed + readonly SNS_ERR_NO_git=3 # Git is not installed + +# Global Variables +typeset -i SNS_SID="$RANDOM" +typeset -a SNS_ACTION=("") +typeset -a MISSING_DEPS +typeset -i SNS_EXIT=0 +declare SNS_PUBKEY= + # Function Definitions +# sns_printError Prints an error message +# sns_NoteHeader Prints standard note header to stdout +# sns_checkDeps Checks the system for required dependencies +# sns_checkStore Checks if $SNS_STORE exists +# sns_sanityCheck Wrapper for sns_checkDeps and sns_checkStore +# ---- # sns_initStore Initializes the SNS Store ( -i) # sns_printHelp Prints help page ( -h) # sns_list Lists all notes in `tree` format ( *) @@ -18,40 +48,18 @@ set -euo pipefail # sns_print Prints note to stdout ( -p) # sns_rm Deletes note from store ( -d) # sns_gitPassthrough Passes through all instructions to git (git) -# sns_checkDeps Checks the system for required dependencies -# sns_checkStore Checks if $SNS_STORE exists -# sns_sanityCheck Wrapper for sns_checkDeps and sns_checkStore -function sns_initStore { - mkdir -p "$SNS_STORE" - echo $* | awk '{print $1}' > "$SNS_KEYFILE" +function sns_printError(){ + printf "$SNS_RED_COLOR!$SNS_RESET_COLOR - %s\n" "$@" } -function sns_printHelp(){ - printf "%s" "Import helpfile from sns v2" -} -function sns_list(){ - cd "$SNS_STORE" || exit - tree -C --noreport "$(echo $* | awk '{print $1}')" -} -function sns_create(){ - gpg -r "$SNS_PUBKEY" -o "echo $* | awk '{print $1}'" < /dev/null - sns_edit "echo $* | awk '{print $1}'" -} -function sns_print(){ - gpg -d "echo $* | awk '{print $1}'" -} -function sns_rm(){ - rm -f "echo $* | awk '{print $1}'" -} -function sns_gitPassthrough(){ - cd "$SNS_STORE" || exit; - git "$@"; +function sns_NoteHeader(){ + printf "%s\n%s\n" "Title:" "Date:" } function sns_checkDeps(){ local SNS_RETURN="true"; for DEP in "${SNS_DEPS[@]}"; do - if test ! -e "$(which gpg 2>/dev/null)"; then - echo "Dependency missing: $DEP"; + if test ! -e "$(which "$DEP" 2>/dev/null)"; then + MISSING_DEPS+=("$DEP") SNS_RETURN="false"; fi done @@ -62,18 +70,112 @@ function sns_checkStore(){ } function sns_sanityCheck { if ! sns_checkDeps; then - exit 10 + SNS_EXIT="$SNS_ERR_DEPS" + for DEP in "${MISSING_DEPS[@]}"; do + local SNS_DEP_EC="\$ERR_NO_$DEP" + printError "Dependency %s not in path." "$DEP"; + SNS_EXIT+=${!SNS_DEP_EC} + done fi - if ! sns_checkStore; then - if [ "$(echo "$SNS_ACTION" | awk '{print $1;}')" != "sns_initStore" ]; then - printf "%s\n" "Please run \`sns -i\` to initialize sns." - exit 20 + + if [ -r "$SNS_STORE/.pubkey" ]; then + SNS_PUBKEY="$(cat "$SNS_STORE/.pubkey")" + elif ! sns_checkStore; then + if [ "$(echo "${SNS_ACTION[@]}" | awk '{print $1;}')" != "sns_initStore" ]; then + printError "The sns store does not exist." + printf " - %s\n" "Please run \`sns -i [gpg-key]\` to initialize sns." + SNS_EXIT="$SNS_ERR_NO_STORE" fi fi } +#---- +function sns_initStore { + mkdir -p "$SNS_STORE" + echo "$@" | awk '{print $1}' > "$SNS_KEYFILE" +} +function sns_printHelp(){ + printf "%s" "usage: sns [-cedlp] " + printf "\n%s%s%s" "usage: sns " "git" " ..." + printf "\n%s" " sns [-hi]" + + printf "\n%s" " -c | --create : Create note" + printf "\n%s" " -C | --config : Edit Config" + printf "\n%s" " -d | --delete : Delete note" + printf "\n%s" " -e | --edit : Open note for editing" + printf "\n%s" " -h | --help : Display this message" + printf "\n%s" " -i | --init : Write default config and initalize SNS store" + printf "\n%s" " -l | --list : List all notes in NOTEBOOK" + printf "\n%s" " -p | --print : Print note to console" + printf "\n\n" +} +function sns_list(){ + # Change directories to fix tree header + cd "$SNS_STORE" || exit; cd .. || exit; + # Print the tree + tree -C --noreport --prune "$(echo "$@" | awk '{print $1}')" +} +function sns_create(){ + # Make sure the note doesn't already exist + if [ -r "$SNS_STORE/$(echo "$@" | awk '{print $1}')" ]; then + sns_printError "Note already exists." + return + fi + + # Print the standard header to a temporary note + sns_NoteHeader > /tmp/"$SNS_SID" + + # Edit the new note + sns_edit "$(echo "$@" | awk '{print $1}')" +} +function sns_edit(){ + # Make the function more readable + local readonly SNS_NOTE="$SNS_STORE/$(echo "$@" | awk '{print $1}')" + + # Test if edit was called from create + if [ ! -r /tmp/"$SNS_SID" ]; then gpg2 -d -o /tmp/"$SNS_SID" "$SNS_NOTE"; fi + + # Edit the note + vim /tmp/"$SNS_SID" + + # Make sure the notebook/section exists + if [ ! -d "$(dirname "$SNS_NOTE")" ]; then mkdir -p "$(dirname "$SNS_NOTE")"; fi + + # If the note previously existed, make a backup. + if [ -r "$SNS_NOTE" ]; then mv "$SNS_NOTE" "$SNS_NOTE.bk"; fi + + # Re-encrypt it to the store + gpg2 -r "$SNS_PUBKEY" -o "$SNS_NOTE" -e /tmp/"$SNS_SID" + + # If all went well, remove the backup + if [ -r "$SNS_NOTE" ]; then rm "$SNS_NOTE.bk"; fi +} +function sns_print(){ + gpg2 -d "$SNS_STORE/$(echo "$@" | awk '{print $1}')" +} +function sns_rm(){ + rm -f "$SNS_STORE/$(echo "$@" | awk '{print $1}')" +} +function sns_gitPassthrough(){ + cd "$SNS_STORE" || exit; + git "$@"; +} +# ---- function sns_argParse(){ - declare -ga SNS_ACTION=() + ARGS=($@) + #echo "${#ARGS}" + SNS_ACTION=() while getopts ":i:hc:e:p:d:" OPT; do + + # If an option requiring an argument was passed without an argument, + # inform the user and set exit code to "$SNS_ERR_NS_ARGS" + case "${ARGS[!OPTIND]}" in + -i|-c|-e|-p|-d) + if [ "${#ARGS}" -lt 2 ]; then + printError "A required argument was not given." + SNS_EXIT="$SNS_ERR_NS_ARGS" + return + fi + esac case "$OPT" in i) SNS_ACTION=("sns_initStore" "$OPTARG");; @@ -89,12 +191,15 @@ function sns_argParse(){ SNS_ACTION=("sns_rm $OPTARG");; esac done + if [ "${#SNS_ACTION[@]}" -eq 0 ]; then if [ "$(echo "$@" | awk '{print $1}')" == "git" ]; then SNS_ACTION=($@) else if [ -d "$SNS_STORE/$*" ]; then - SNS_ACTION=("sns_list" "./$*") + SNS_ACTION=("sns_list" "sns/$@") + else + SNS_ACTION=("sns_list" "sns") fi fi fi @@ -102,6 +207,14 @@ function sns_argParse(){ # Entry Point printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER" +printf "\n" + sns_argParse "$@" sns_sanityCheck -"${SNS_ACTION[@]}" +if [ "$SNS_EXIT" -eq 0 ]; then + eval "${SNS_ACTION[@]}" +fi + +printf "\n" + +exit "$SNS_EXIT"