From 7438806847813e364ec18d185374a51c2a057d7f Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Thu, 11 Aug 2016 16:02:08 -0500 Subject: [PATCH] Cleanup --- README.md | 23 ++- install.sh | 220 ++++++++++++++++++---------- install.sh.gpg | Bin 1207 -> 0 bytes src/includes/create.sns.sh | 6 +- src/includes/delete.sns.sh | 6 +- src/includes/edit.sns.sh | 10 +- header.sh => src/includes/header.sh | 22 +-- src/includes/help.sns.sh | 5 +- src/includes/init_store.sns.sh | 23 ++- src/includes/p_header.sh | 2 +- src/includes/print.sns.sh | 2 +- src/main/stage1.sns.sh | 10 +- src/main/stage3.sns.sh | 2 +- 13 files changed, 198 insertions(+), 133 deletions(-) delete mode 100644 install.sh.gpg rename header.sh => src/includes/header.sh (74%) diff --git a/README.md b/README.md index f9c0b8d..e444ec7 100644 --- a/README.md +++ b/README.md @@ -73,12 +73,23 @@ properties of SNS: SNS requires the identifier of a GPG public key for encryption to function. -**A word about encryption**: Enabling encryption will cause problems if -previously un-encrypted notes exist. In the future, I'd like to resolve these, -however for the time being it's best to decide when you install SNS if you'd -like to enable encryption or not. -**Encryption amendment**: As of SNS 2a10, experimental support is in place for -migrating between encrypted and unencrypted note stores. +* Version Control program + SNS can be configured to use a version control program such as Git, + Mercurial, Subversion, etc. When configured, SNS can pass commands through + to the specified program in the context of SNS's store. For example, if Git + was configured here, then `sns git init` would initialize a Git repository + for your notes; `sns git remote add` could be used to add a remote repo, and + `sns git push` could push committed changes to the notes store to that + remote. + + +**A word about encryption:** +When editing an encrypted note, SNS will decrypt +the note to a temporary file inside its store. The temporary file will have a +random name, but a predictable location. It can only be read by the user and +root, and is deleted after editing, but can be recovered by forensic utilities. +SNS's encryption is mainly useful when the store is being _transferred over a +network_. ## Tips and Tricks * To list all notes in all notebooks, use `sns -l .` diff --git a/install.sh b/install.sh index 65e8ef8..7c749ba 100755 --- a/install.sh +++ b/install.sh @@ -19,19 +19,33 @@ # Color codes for messages readonly RED_COLOR='\033[1;31m' readonly YELLOW_COLOR='\033[1;33m' +readonly BLUE_COLOR='\033[1;34m' readonly RESET_COLOR='\033[0m' -if [ "$(id -u)" != "0" ]; then - printf "$RED_COLOR!$RESET_COLOR - %s\n"\ - "Please run as root or specify a PREFIX= you have write access to." - exit + +# Set variables for header +PROD_STR="Simple Note System" +PROD_SUB="Install Script" +# Set default build directory if none specified +if [ ! -d "$BUILD_ROOT" ]; then BUILD_ROOT="build"; fi + +# Set default install prefix according to platform +if [ -z "$INSTALL_DIR" ]; then + case "$(uname)" in + "Darwin" ) + INSTALL_ROOT=/usr/local/opt + ;; + *) + INSTALL_ROOT=/opt + ;; + esac + INSTALL_DIR="$INSTALL_ROOT/sns" fi -S="build/sns.sh" - -function build { - bash header.sh - echo -e "\n# Section: Functions" +function sns_out { + # Compile SNS from source files and print the resulting script to stdout + cat ./src/includes/header.sh + printf "%s\n" "# Section: Functions" cat ./src/includes/init_store.sns.sh cat ./src/includes/verify_store.sns.sh cat ./src/includes/help.sns.sh @@ -47,129 +61,173 @@ function build { cat ./src/main/stage2.sns.sh cat ./src/main/stage3.sns.sh } +function clean { + if [ -d "$BUILD_ROOT" ]; then rm -rf "$BUILD_ROOT"; fi +} +function build_sns { + clean + if [ ! -d ."$BUILD_ROOT" ]; then mkdir $BUILD_ROOT; fi + sns_out > "$BUILD_ROOT/sns" + cp -f src/bash-completion/sns ./build/bash-completion +} -function install { - mkdir -p "$PREFIX/bin" - mkdir -p "$PREFIX/etc/bash-completion.d" - chmod +x "$S" +function check_install_dir_perms { + STATS=( $(stat -c "%a %u %g" "$INSTALL_ROOT")) + O=$(echo "${STATS[1]}" | cut -c 1) + G=$(echo "${STATS[1]}" | cut -c 2) + E=$(echo "${STATS[1]}" | cut -c 3) - cp -f "$S" "$PREFIX/bin/sns" - cp -f ./build/bash-completion "$PREFIX/etc/bash-completion.d/sns" + USER=$(id -u) + GROUP=$(id -g) + if [ "${STATS[2]}" == "$USER" ] && [ "$O" == "7" ]; then WRITE="1"; + elif [ "${STATS[3]}" == "$GROUP" ] && [ "$G" == "7" ]; then WRITE="1"; + elif [ "$E" == "7" ]; then WRITE="1"; + else WRITE="0"; + fi + + if [ "$(id -u)" == "0" ]; then WRITE=1; fi +} +function install_sns { + # Make sure we can write to "$INSTALL_DIR" + check_install_dir_perms + if [ "$WRITE" == "0" ]; then + printf "$RED_COLOR!$RESET_COLOR - %s %s\n"\ + "Superuser permissions required to install to" "$INSTALL_DIR." + printf "$YELLOW_COLOR!$RESET_COLOR - %s\n"\ + "Will use sudo as necessary." + USE_SUDO="sudo" + else + USE_SUDO="" + fi + # Prepare target environment + "$USE_SUDO" mkdir -p "$INSTALL_DIR" + "$USE_SUDO" mkdir -p "$INSTALL_DIR/bin" + "$USE_SUDO" mkdir -p "$INSTALL_DIR/etc/bash-completion.d" + + # Install files from "$BUILD_ROOT" to "$INSTALL_DIR" + "$USE_SUDO" install -m 0755 "$BUILD_ROOT/sns" "$INSTALL_DIR/bin/sns" + "$USE_SUDO" install -m 0644 "$BUILD_ROOT/bash-completion" "$INSTALL_DIR/etc/bash-completion.d/sns" } function verify { - if [ ! -r "$PREFIX/bin/sns" ]; then + if [ ! -r "$INSTALL_DIR/bin/sns" ]; then printf "$RED_COLOR!$RESET_COLOR - %s\n"\ - "could not write to $PREFIX/bin/sns" + "could not write to $INSTALL_DIR/bin/sns" exit 15 - elif [ ! -r "$PREFIX"/etc/bash-completion.d/sns ]; then - printf "$RED_COLOR!$RESET_COLOR - %s\n"\ - "could not write to $PREFIX/etc/bash-completion.d/sns" - exit 15 - fi - - if [ -z "$(which sns)" ]; then - printf "$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\ - "sns was not found in PATH. Please add"\ - "export PATH=$PREFIX/bin:\$PATH"\ - "to your ~/.bashrc or ~/.bash_profile" - elif [ "$(which sns)" != "$PREFIX/bin/sns" ]; then - printf "$RED_COLOR!$RESET_COLOR - %s\n\t%s\n %s\n\n"\ - "Another installation of sns "\ - "($(which sns))"\ - " is conflicting with this one." else - printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\ - "Simple Note System was installed to $PREFIX/bin/sns successfully." - printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\ - "Bash completion was installed to $PREFIX/etc/bash-completion.d/sns successfully." - + printf "$YELLOW_COLOR*$RESET_COLOR - %s $BLUE_COLOR%s$RESET_COLOR\n"\ + "Simple Note System was installed to" "$INSTALL_DIR/bin/sns." + SNS_INSTALLED=1 fi - if grep "source $PREFIX/etc/bash-completion.d/sns" < "$BASH_SETTINGS" > /dev/null; then + + if [ ! -r "$INSTALL_DIR/etc/bash-completion.d/sns" ]; then + printf "$RED_COLOR!$RESET_COLOR - %s\n"\ + "could not write to $INSTALL_DIR/etc/bash-completion.d/sns" + exit 15 + else + printf "$YELLOW_COLOR*$RESET_COLOR - %s $BLUE_COLOR%s$RESET_COLOR\n"\ + "Bash completion was installed to" "$INSTALL_DIR/etc/bash-completion.d/sns." + fi + + DEFAULT_SNS="$(which sns 2>/dev/null)" + if [ -n "$DEFAULT_SNS" ] && [ "$DEFAULT_SNS" != "$INSTALL_DIR/bin/sns" ]; then + printf "$RED_COLOR!$RESET_COLOR - %s %s %s\n"\ + "Another installation of sns"\ + "($DEFAULT_SNS)"\ + "was detected." + fi + if [ -z "$DEFAULT_SNS" ]; then + printf "\n$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\ + "sns was not found in PATH. Please add"\ + "export PATH=$INSTALL_DIR/bin:\$PATH"\ + " to your ~/.bashrc or ~/.bash_profile" + fi + if grep "source $INSTALL_DIR/etc/bash-completion.d/sns" < "$BASH_SETTINGS" > /dev/null; then SNS_BASH_COMPLETION=1; else SNS_BASH_COMPLETION=0; fi if [ "$SNS_BASH_COMPLETION" != "1" ]; then - printf "$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\ - "to enable bash completion, add"\ - "source $PREFIX/etc/bash-completion.d/sns"\ - "to your ~/.bashrc or ~/.bash_profile" + printf "\n$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\ + "To enable bash completion, add"\ + "source $INSTALL_DIR/etc/bash-completion.d/sns"\ + " to your ~/.bashrc or ~/.bash_profile" else printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\ "Bash completion already enabled." fi + if [ "$SNS_INSTALLED" == "1" ]; then + printf "$YELLOW_COLOR*$RESET_COLOR - %s $BLUE_COLOR%s$RESET_COLOR %s\n"\ + "Installation succeeded. You should run" "sns -i" "now." + fi } function print_help { - printf "\n%s" "usage: ./install [bchiu]" + printf " %s" "usage: ./install [bchiu]" printf "\n%s" " -b | --build-only : build, but do not install sns" - printf "\n%s" " -c | --clean : clean build directory" - printf "\n%s" " -h | --help : Print this information" - printf "\n%s" " -i | --install : build and install sns" - printf "\n%s" " -u | --uninstall : remove sns from the system (will not remove notes)" - printf "\n" + printf "\n%s" " -c | --clean : clean build directory" + printf "\n%s" " -h | --help : Print this information" + printf "\n%s" " -i | --install : build and install sns" + printf "\n%s" " -u | --uninstall : remove sns from the system (will not remove notes)" + printf "\n\n%s" "Run Variables:" + printf "\n %s %s" "BUILD_DIR= " "Directory to build SNS in" + printf "\n %s %s" "INSTALL_DIR=" "Directory to install SNS to" + printf "\n\n" } -# Platform detection -if [ -z "$PREFIX" ]; then - case "$(uname)" in - "Darwin" ) - PREFIX=/usr/local/opt/sns - ;; - *) - PREFIX=/opt/sns - ;; - esac -fi - # Sanity check -if [ -z "$PREFIX" ]; then +if [ -z "$INSTALL_DIR" ]; then printf "$RED_COLOR!$RESET_COLOR - %s\n"\ - "Failed to determine an install prefix please specify with PREFIX=\n" + "Failed to guess optimal install directory please specify with INSTALL_DIR=\n" exit 10 fi - -if [ -r "$HOME"/.bash_profile ]; then - BASH_SETTINGS="$HOME/.bash_profile" -elif [ -r "$HOME"/.bashrc ]; then +if [ -r "$HOME"/.bashrc ]; then BASH_SETTINGS="$HOME/.bashrc" +elif [ -r "$HOME"/.bash_profile ]; then + BASH_SETTINGS="$HOME/.bash_profile" else printf "$RED_COLOR!$RESET_COLOR - %s\n"\ "Failed to determine bash settings file (e.g. ~/.bashrc)" exit 13 fi -#Argument Parsing +# Print header +printf "\n %s\n" "$PROD_STR" +printf " %s\n" "$PROD_SUB" +printf "%s\n\n" "--------------------" +# Argument Parsing for ARG in "$@"; do case "$ARG" in - -h|--help) - print_help - exit - ;; -b|--build-only) - if [ ! -d ./build ]; then mkdir ./build; fi - build > "$S"; chmod +x "$S" - cp src/bash-completion/sns ./build/bash-completion + build_sns + printf "\n" exit ;; -c|--clean) - if [ -d ./build ]; then rm -rf build; fi + clean exit ;; -u|--uninstall) - rm -rf $PREFIX + check_install_dir_perms + if [ "$WRITE" == "1" ]; then + rm -rf "$INSTALL_DIR" + else + sudo rm -rf "$INSTALL_DIR" + fi exit ;; -i|--install) - if [ ! -d ./build ]; then mkdir ./build; fi - build > "$S" - cp src/bash-completion/sns ./build/bash-completion - install + build_sns + install_sns verify + printf "\n" + exit + ;; + -h|--help) + print_help exit ;; esac diff --git a/install.sh.gpg b/install.sh.gpg deleted file mode 100644 index 81deee203e9b49cef21edd7857d33bb6352edff8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1207 zcmV;o1W5aZ0Sp5*K@@3rRMLO}2m1zbiH4{LE5tFkjIu-`Mw!^evzK{+7iK9`6M?WJ z9$^3RYNr{gGNJkb==85?Xoq1Yxgz;GE?B~OR}uZo0!pd<*SsF2%=I8j%%^?hyB1-s zvlUhSJY|`brZQW3kZCSkvia+8Q1lsT$W}(x2VDk8^I$Wd#VCc}xF( z<-hn(BD&e%aX<^L3+m;qc5bFT8cO>?G9c@r6njhOb^kzxlQ+fZXe%f;;lNWxas-JC zvuCsiihMv!KQ3LRMzlaFU{fFuhUj^_4?k|j$?U>DQYSC$_S?j+-8KQmGR|zi9s{^p z!U(3IxmDx=AbbyIXaJ|qPhryO0UXaj=ep+hEm&d%J83!P3Nll09`vI^r2!8?K4w=@LzhZ!jYu&M{ARw2J z1?;;^BO7bFubka&yW`>iuHzNbvLLC1DUK*3nSW(OI##@@J3AD1$M<`qX6jF0J|nIo zzdg0r_WC36@d2}dOwhCqh2cYvO~*;^i@mW{`6yhDzyzsL(@bJY$Ote4_aV8C%L6p; z{fwYC3jFZR7vG)0i_QeKVPuH5WUcWR>|LV3t3+l53`Ygv6PVzbQ5E+~v!xOdb-5O(3M%mag>bDGpf==eyM=`Oqm(`e%&)5DuF-?>4XRZu8y%XoD7crJ_@4=`7z zn33JanHA1+>iTxTl3`h+BFubahR&D5M2sSzEz2ljQ=4tZoc-H@XgeDCtp76ahmM zP)b2{8bJdK)^=Czz~qsrr5lWS%^u1T5BwF2b^N{~X(K&OpahnMU0%p8MWGeCL(X~A zk^d=wFkzl%pYr7LdM4XIDTP&+(uQTI4bMv7E^{^3rr>i3T*q67o!2uvM(F22%TpSCp?NBmI77o(-r>lG79K3# z42n85{WUGl4Wz0VGo$tIiy|5HA6?Qh6v`ojc-}Zbby7{D z&_xL5KdQ;4Qg5`!lK$t8Aq^u4$~e*>5A#nMr^REHZnd0H<&f89@n(i@(4VvXGt=u; zf#^x~oY}TO&CL&nKx^WgfhEpLu>04k5WJSV>UOttnl8XcX>e7^BhBkmy4kqppQc52 zLO+mwfR+(ikfgQvmnluToudK>HtNhuELP{tKrWIXhPe8~BVeBA&si?-5xqR=EBZ0- VvoD$giw)uCHzL+7*=g&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + >&2 printf "$RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Note already exists"\ "Hint: use -e to edit the note." exit 200 @@ -27,9 +27,9 @@ function create(){ 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%.*}" + printf "%s\n" "- Created note: ${NOTE%.*}" else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ + >&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 index f8aa791..cb24a6c 100644 --- a/src/includes/delete.sns.sh +++ b/src/includes/delete.sns.sh @@ -4,15 +4,15 @@ function delete(){ if [ -e "$NOTES_DIR/$NOTE" ]; then rm "$NOTES_DIR/$NOTE" - printf " - %s\n" "Deleted note: ${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 + if [ ! "$(ls -A "$DIR")" ]; then rmdir "$DIR" fi done else - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist." + >&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 index ee2a9df..330ce8d 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -4,12 +4,12 @@ function edit(){ # Verify an editor was specified if [ -z "$EDITOR" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n"\ + >&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"\ + >&2 printf "$RED_COLOR!$RESET_COLOR %s\n"\ "Note cannot be opened for editing." exit 40; fi @@ -31,17 +31,17 @@ if [ -z "$CREATE" ]; then fi # Call the editor -printf " - %s\n" "editing ${NOTE%.*}" +printf "%s\n" "- editing ${NOTE%.*}" "$EDITOR" "$TMP_NOTE" # If the file was previously decrypted, encrypt it back if [ "$ENCRYPTION" == "TRUE" ]; then - printf " - %s\n" "encrypting ${NOTE%.*}" + printf "%s\n" "- encrypting ${NOTE%.*}" 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." + >&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"; diff --git a/header.sh b/src/includes/header.sh similarity index 74% rename from header.sh rename to src/includes/header.sh index a2a87a9..5fec337 100644 --- a/header.sh +++ b/src/includes/header.sh @@ -1,8 +1,3 @@ -PROD_STR="Simple Note System" -VER_STR="v2.0a11" -YEAR=2016 - -cat << EOF #!/bin/bash # Simple Note System # Copyright (C) 2016, Jon Lewis @@ -22,15 +17,15 @@ cat << EOF # 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 +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"/.local/sns -readonly NOTES_DIR="\$ROOT_DIR"/notes -readonly TMP_DIR="\$ROOT_DIR"/tmp -readonly CONFIG_FILE="\$ROOT_DIR/sns.conf" +readonly PROD_STR="Simple Note System" +readonly VER_STR="v2.0a12" +readonly ROOT_DIR="$HOME"/.local/sns +readonly NOTES_DIR="$ROOT_DIR"/notes +readonly TMP_DIR="$ROOT_DIR"/tmp +readonly CONFIG_FILE="$ROOT_DIR/sns.conf" #Color codes for messages readonly RED_COLOR='\033[1;31m' @@ -38,6 +33,5 @@ readonly YELLOW_COLOR='\033[1;33m' readonly RESET_COLOR='\033[0m' #Print the program header to stdout -printf "%s\n" "\$PROD_STR" +printf "%s\n" "$PROD_STR" printf "%s\n" "------------------" -EOF diff --git a/src/includes/help.sns.sh b/src/includes/help.sns.sh index ff15469..6c079b6 100644 --- a/src/includes/help.sns.sh +++ b/src/includes/help.sns.sh @@ -1,5 +1,8 @@ function help { printf "\n%s" "usage: sns [-cedlp] " + if [ -z "$VCTL" ]; then + printf "\n%s%s%s" "usage: sns " "$VCTL" " ..." + fi printf "\n%s" " sns [-hi ]" printf "\n%s" " -c | --create : Create note" @@ -9,5 +12,5 @@ function help { 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" + printf "\n\n" } diff --git a/src/includes/init_store.sns.sh b/src/includes/init_store.sns.sh index 5a5cbdd..dcf0fe6 100644 --- a/src/includes/init_store.sns.sh +++ b/src/includes/init_store.sns.sh @@ -4,6 +4,7 @@ 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 "$NOTES_DIR" ]; then mkdir -p "$NOTES_DIR"; fi +if [ ! -r "$CONFIG_FILE" ]; then cat > "$CONFIG_FILE" << EOF # This file contains directives for the Simple Note System. @@ -26,21 +27,19 @@ PUBKEY="" # Public Key # Encryption is done using GPG. You must enter your # public key's identifier here. -#VCTL="" # Version Control program +#VCTL="" # Version Control Program # Set this to the name of your preferred version control - # program to use it in SNS. For example, if VCTL is Set - # to `git`, `sns git ...`` will call `git ...` in SNS's - # store. This can be used to revert changes, or to sync - # across computers. + # program to use it in SNS. Examples: git, hg, svn EOF - chmod 600 "$CONFIG_FILE" - -printf " - %s\n" "Rewrote Default Configuration" - -if [ "$WILL_INIT" == "TRUE" ]; then - printf " - %s\n" "Environment initialized in $ROOT_DIR" +printf "%s\n" "- Rewrote Default Configuration" else - printf " - %s\n" "Store already initialized." + printf "$RED_COLOR!$RESET_COLOR - %s" "Refusing to overwrite existing config" +fi + +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/p_header.sh b/src/includes/p_header.sh index 6fc43d6..4a5f947 100644 --- a/src/includes/p_header.sh +++ b/src/includes/p_header.sh @@ -1,3 +1,3 @@ function p_header(){ - printf "# %s\n## %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")" + printf "# %s\n## %s\n" "$(basename "${NOTE%.*}")" "$(date "$DATE_FMT")" } diff --git a/src/includes/print.sns.sh b/src/includes/print.sns.sh index 7b6d2eb..180d65d 100644 --- a/src/includes/print.sns.sh +++ b/src/includes/print.sns.sh @@ -5,7 +5,7 @@ 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"\ + >&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/main/stage1.sns.sh b/src/main/stage1.sns.sh index 6e8f1ac..188be53 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -6,7 +6,7 @@ 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"\ + >&2 printf "$RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Configuration not found. Please run sns -i." exit 5 #ERR_NO_STORE fi @@ -19,12 +19,12 @@ if [ "$ENCRYPTION" == "TRUE" ]; then fi # Check if GPG is installed. if [ ! -r "$(which gpg)" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + >&2 printf "$RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Encryption was specified, but GPG is not installed." exit 100 # Check if we have a GPG recipient elif [ -z "$PUBKEY" ]; then - >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ + >&2 printf "$RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "No GPG recipient was provided in $CONFIG_FILE. " exit 110 # All is good. If any previously unencrypted notes exist, encrypt them. @@ -34,7 +34,7 @@ if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="${TMP_NOTE%.$EXT}.gpg.$EXT" encrypt if [ -r "$NOTE" ]; then - printf " $YELLOW_COLOR!$RESET_COLOR %s\n" "Encrypted ${NOTE%.$EXT}" + printf "$YELLOW_COLOR!$RESET_COLOR %s\n" "Encrypted ${NOTE%.$EXT}" rm "$TMP_NOTE" fi done @@ -57,7 +57,7 @@ else --decrypt "$NOTE" if [ -r "${NOTE%.gpg.note}.note" ]; then - printf " $YELLOW_COLOR!$RESET_COLOR %s\n"\ + printf "$YELLOW_COLOR!$RESET_COLOR %s\n"\ "De-encrypted ${NOTE%.gpg.$EXT}" rm "$NOTE"; fi diff --git a/src/main/stage3.sns.sh b/src/main/stage3.sns.sh index b090f4b..5bef5e8 100644 --- a/src/main/stage3.sns.sh +++ b/src/main/stage3.sns.sh @@ -9,7 +9,7 @@ # 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." + printf "$RED_COLOR!$RESET_COLOR %s\n" "No note specified." exit 30 fi