Cleanup
This commit is contained in:
23
README.md
23
README.md
@@ -73,12 +73,23 @@ properties of SNS:
|
|||||||
|
|
||||||
SNS requires the identifier of a GPG public key for encryption to function.
|
SNS requires the identifier of a GPG public key for encryption to function.
|
||||||
|
|
||||||
**A word about encryption**: Enabling encryption will cause problems if
|
* Version Control program
|
||||||
previously un-encrypted notes exist. In the future, I'd like to resolve these,
|
SNS can be configured to use a version control program such as Git,
|
||||||
however for the time being it's best to decide when you install SNS if you'd
|
Mercurial, Subversion, etc. When configured, SNS can pass commands through
|
||||||
like to enable encryption or not.
|
to the specified program in the context of SNS's store. For example, if Git
|
||||||
**Encryption amendment**: As of SNS 2a10, experimental support is in place for
|
was configured here, then `sns git init` would initialize a Git repository
|
||||||
migrating between encrypted and unencrypted note stores.
|
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
|
## Tips and Tricks
|
||||||
* To list all notes in all notebooks, use `sns -l .`
|
* To list all notes in all notebooks, use `sns -l .`
|
||||||
|
|||||||
220
install.sh
220
install.sh
@@ -19,19 +19,33 @@
|
|||||||
# Color codes for messages
|
# Color codes for messages
|
||||||
readonly RED_COLOR='\033[1;31m'
|
readonly RED_COLOR='\033[1;31m'
|
||||||
readonly YELLOW_COLOR='\033[1;33m'
|
readonly YELLOW_COLOR='\033[1;33m'
|
||||||
|
readonly BLUE_COLOR='\033[1;34m'
|
||||||
readonly RESET_COLOR='\033[0m'
|
readonly RESET_COLOR='\033[0m'
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
|
||||||
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
# Set variables for header
|
||||||
"Please run as root or specify a PREFIX= you have write access to."
|
PROD_STR="Simple Note System"
|
||||||
exit
|
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
|
fi
|
||||||
|
|
||||||
S="build/sns.sh"
|
function sns_out {
|
||||||
|
# Compile SNS from source files and print the resulting script to stdout
|
||||||
function build {
|
cat ./src/includes/header.sh
|
||||||
bash header.sh
|
printf "%s\n" "# Section: Functions"
|
||||||
echo -e "\n# Section: Functions"
|
|
||||||
cat ./src/includes/init_store.sns.sh
|
cat ./src/includes/init_store.sns.sh
|
||||||
cat ./src/includes/verify_store.sns.sh
|
cat ./src/includes/verify_store.sns.sh
|
||||||
cat ./src/includes/help.sns.sh
|
cat ./src/includes/help.sns.sh
|
||||||
@@ -47,129 +61,173 @@ function build {
|
|||||||
cat ./src/main/stage2.sns.sh
|
cat ./src/main/stage2.sns.sh
|
||||||
cat ./src/main/stage3.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 {
|
function check_install_dir_perms {
|
||||||
mkdir -p "$PREFIX/bin"
|
STATS=( $(stat -c "%a %u %g" "$INSTALL_ROOT"))
|
||||||
mkdir -p "$PREFIX/etc/bash-completion.d"
|
O=$(echo "${STATS[1]}" | cut -c 1)
|
||||||
chmod +x "$S"
|
G=$(echo "${STATS[1]}" | cut -c 2)
|
||||||
|
E=$(echo "${STATS[1]}" | cut -c 3)
|
||||||
|
|
||||||
cp -f "$S" "$PREFIX/bin/sns"
|
USER=$(id -u)
|
||||||
cp -f ./build/bash-completion "$PREFIX/etc/bash-completion.d/sns"
|
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 {
|
function verify {
|
||||||
if [ ! -r "$PREFIX/bin/sns" ]; then
|
if [ ! -r "$INSTALL_DIR/bin/sns" ]; then
|
||||||
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
||||||
"could not write to $PREFIX/bin/sns"
|
"could not write to $INSTALL_DIR/bin/sns"
|
||||||
exit 15
|
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
|
else
|
||||||
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\
|
printf "$YELLOW_COLOR*$RESET_COLOR - %s $BLUE_COLOR%s$RESET_COLOR\n"\
|
||||||
"Simple Note System was installed to $PREFIX/bin/sns successfully."
|
"Simple Note System was installed to" "$INSTALL_DIR/bin/sns."
|
||||||
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\
|
SNS_INSTALLED=1
|
||||||
"Bash completion was installed to $PREFIX/etc/bash-completion.d/sns successfully."
|
|
||||||
|
|
||||||
fi
|
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;
|
SNS_BASH_COMPLETION=1;
|
||||||
else
|
else
|
||||||
SNS_BASH_COMPLETION=0;
|
SNS_BASH_COMPLETION=0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$SNS_BASH_COMPLETION" != "1" ]; then
|
if [ "$SNS_BASH_COMPLETION" != "1" ]; then
|
||||||
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\
|
printf "\n$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\
|
||||||
"to enable bash completion, add"\
|
"To enable bash completion, add"\
|
||||||
"source $PREFIX/etc/bash-completion.d/sns"\
|
"source $INSTALL_DIR/etc/bash-completion.d/sns"\
|
||||||
"to your ~/.bashrc or ~/.bash_profile"
|
" to your ~/.bashrc or ~/.bash_profile"
|
||||||
else
|
else
|
||||||
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\
|
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\
|
||||||
"Bash completion already enabled."
|
"Bash completion already enabled."
|
||||||
fi
|
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 {
|
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" " -b | --build-only : build, but do not install sns"
|
||||||
printf "\n%s" " -c | --clean : clean build directory"
|
printf "\n%s" " -c | --clean : clean build directory"
|
||||||
printf "\n%s" " -h | --help : Print this information"
|
printf "\n%s" " -h | --help : Print this information"
|
||||||
printf "\n%s" " -i | --install : build and install sns"
|
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%s" " -u | --uninstall : remove sns from the system (will not remove notes)"
|
||||||
printf "\n"
|
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
|
# Sanity check
|
||||||
if [ -z "$PREFIX" ]; then
|
if [ -z "$INSTALL_DIR" ]; then
|
||||||
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
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
|
exit 10
|
||||||
fi
|
fi
|
||||||
|
if [ -r "$HOME"/.bashrc ]; then
|
||||||
if [ -r "$HOME"/.bash_profile ]; then
|
|
||||||
BASH_SETTINGS="$HOME/.bash_profile"
|
|
||||||
elif [ -r "$HOME"/.bashrc ]; then
|
|
||||||
BASH_SETTINGS="$HOME/.bashrc"
|
BASH_SETTINGS="$HOME/.bashrc"
|
||||||
|
elif [ -r "$HOME"/.bash_profile ]; then
|
||||||
|
BASH_SETTINGS="$HOME/.bash_profile"
|
||||||
else
|
else
|
||||||
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
||||||
"Failed to determine bash settings file (e.g. ~/.bashrc)"
|
"Failed to determine bash settings file (e.g. ~/.bashrc)"
|
||||||
exit 13
|
exit 13
|
||||||
fi
|
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
|
for ARG in "$@"; do
|
||||||
case "$ARG" in
|
case "$ARG" in
|
||||||
-h|--help)
|
|
||||||
print_help
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
-b|--build-only)
|
-b|--build-only)
|
||||||
if [ ! -d ./build ]; then mkdir ./build; fi
|
build_sns
|
||||||
build > "$S"; chmod +x "$S"
|
printf "\n"
|
||||||
cp src/bash-completion/sns ./build/bash-completion
|
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
-c|--clean)
|
-c|--clean)
|
||||||
if [ -d ./build ]; then rm -rf build; fi
|
clean
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
-u|--uninstall)
|
-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
|
exit
|
||||||
;;
|
;;
|
||||||
-i|--install)
|
-i|--install)
|
||||||
if [ ! -d ./build ]; then mkdir ./build; fi
|
build_sns
|
||||||
build > "$S"
|
install_sns
|
||||||
cp src/bash-completion/sns ./build/bash-completion
|
|
||||||
install
|
|
||||||
verify
|
verify
|
||||||
|
printf "\n"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
print_help
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
BIN
install.sh.gpg
BIN
install.sh.gpg
Binary file not shown.
@@ -7,7 +7,7 @@ function create(){
|
|||||||
|
|
||||||
# Refuse to overwrite a note
|
# Refuse to overwrite a note
|
||||||
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
||||||
>&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"\
|
"Note already exists"\
|
||||||
"Hint: use -e to edit the note."
|
"Hint: use -e to edit the note."
|
||||||
exit 200
|
exit 200
|
||||||
@@ -27,9 +27,9 @@ function create(){
|
|||||||
fi
|
fi
|
||||||
# Make sure the note exists, and inform the user of the result.
|
# Make sure the note exists, and inform the user of the result.
|
||||||
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
||||||
printf " - %s\n" "Created note: ${NOTE%.*}"
|
printf "%s\n" "- Created note: ${NOTE%.*}"
|
||||||
else
|
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."
|
"Something went wrong, and the note was not created."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ function delete(){
|
|||||||
|
|
||||||
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
if [ -e "$NOTES_DIR/$NOTE" ]; then
|
||||||
rm "$NOTES_DIR/$NOTE"
|
rm "$NOTES_DIR/$NOTE"
|
||||||
printf " - %s\n" "Deleted note: ${NOTE%.*}."
|
printf "%s\n" "- Deleted note: ${NOTE%.*}."
|
||||||
#Cleanup empty notebooks/sections]
|
#Cleanup empty notebooks/sections]
|
||||||
find "$NOTES_DIR" -mindepth 1 -type d | tac |\
|
find "$NOTES_DIR" -mindepth 1 -type d | tac |\
|
||||||
while read -r DIR ; do
|
while read -r DIR ; do
|
||||||
if [ ! "$(ls -A $DIR)" ]; then
|
if [ ! "$(ls -A "$DIR")" ]; then
|
||||||
rmdir "$DIR"
|
rmdir "$DIR"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ function edit(){
|
|||||||
|
|
||||||
# Verify an editor was specified
|
# Verify an editor was specified
|
||||||
if [ -z "$EDITOR" ]; then
|
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."
|
"No editor specified in environment."
|
||||||
exit
|
exit
|
||||||
# Verify the note exists
|
# Verify the note exists
|
||||||
elif [ ! -r "$NOTES_DIR/$NOTE" ]; then
|
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."
|
"Note cannot be opened for editing."
|
||||||
exit 40;
|
exit 40;
|
||||||
fi
|
fi
|
||||||
@@ -31,17 +31,17 @@ if [ -z "$CREATE" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Call the editor
|
# Call the editor
|
||||||
printf " - %s\n" "editing ${NOTE%.*}"
|
printf "%s\n" "- editing ${NOTE%.*}"
|
||||||
"$EDITOR" "$TMP_NOTE"
|
"$EDITOR" "$TMP_NOTE"
|
||||||
|
|
||||||
# If the file was previously decrypted, encrypt it back
|
# If the file was previously decrypted, encrypt it back
|
||||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||||
printf " - %s\n" "encrypting ${NOTE%.*}"
|
printf "%s\n" "- encrypting ${NOTE%.*}"
|
||||||
rm "$NOTES_DIR/$NOTE"
|
rm "$NOTES_DIR/$NOTE"
|
||||||
encrypt;
|
encrypt;
|
||||||
rm "$TMP_NOTE"
|
rm "$TMP_NOTE"
|
||||||
if [ ! -r "$NOTES_DIR/$NOTE" ]; then
|
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"
|
cp "$NOTES_DIR/$NOTE.bk" "$NOTES_DIR/$NOTE"
|
||||||
else
|
else
|
||||||
rm "$NOTES_DIR/$NOTE.bk";
|
rm "$NOTES_DIR/$NOTE.bk";
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
PROD_STR="Simple Note System"
|
|
||||||
VER_STR="v2.0a11"
|
|
||||||
YEAR=2016
|
|
||||||
|
|
||||||
cat << EOF
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Simple Note System
|
# Simple Note System
|
||||||
# Copyright (C) 2016, Jon Lewis
|
# Copyright (C) 2016, Jon Lewis
|
||||||
@@ -22,15 +17,15 @@ cat << EOF
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
# Prevent freak accidents involving the root directory
|
# 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
|
# Store files and locations
|
||||||
readonly PROD_STR="$PROD_STR"
|
readonly PROD_STR="Simple Note System"
|
||||||
readonly VER_STR="$VER_STR"
|
readonly VER_STR="v2.0a12"
|
||||||
readonly ROOT_DIR="\$HOME"/.local/sns
|
readonly ROOT_DIR="$HOME"/.local/sns
|
||||||
readonly NOTES_DIR="\$ROOT_DIR"/notes
|
readonly NOTES_DIR="$ROOT_DIR"/notes
|
||||||
readonly TMP_DIR="\$ROOT_DIR"/tmp
|
readonly TMP_DIR="$ROOT_DIR"/tmp
|
||||||
readonly CONFIG_FILE="\$ROOT_DIR/sns.conf"
|
readonly CONFIG_FILE="$ROOT_DIR/sns.conf"
|
||||||
|
|
||||||
#Color codes for messages
|
#Color codes for messages
|
||||||
readonly RED_COLOR='\033[1;31m'
|
readonly RED_COLOR='\033[1;31m'
|
||||||
@@ -38,6 +33,5 @@ readonly YELLOW_COLOR='\033[1;33m'
|
|||||||
readonly RESET_COLOR='\033[0m'
|
readonly RESET_COLOR='\033[0m'
|
||||||
|
|
||||||
#Print the program header to stdout
|
#Print the program header to stdout
|
||||||
printf "%s\n" "\$PROD_STR"
|
printf "%s\n" "$PROD_STR"
|
||||||
printf "%s\n" "------------------"
|
printf "%s\n" "------------------"
|
||||||
EOF
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
function help {
|
function help {
|
||||||
printf "\n%s" "usage: sns [-cedlp] <notebook/section/name>"
|
printf "\n%s" "usage: sns [-cedlp] <notebook/section/name>"
|
||||||
|
if [ -z "$VCTL" ]; then
|
||||||
|
printf "\n%s%s%s" "usage: sns " "$VCTL" " ..."
|
||||||
|
fi
|
||||||
printf "\n%s" " sns [-hi ]"
|
printf "\n%s" " sns [-hi ]"
|
||||||
|
|
||||||
printf "\n%s" " -c | --create : Create note"
|
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" " -i | --init : Write default config and initalize SNS store"
|
||||||
printf "\n%s" " -l | --list : List all notes in NOTEBOOK"
|
printf "\n%s" " -l | --list : List all notes in NOTEBOOK"
|
||||||
printf "\n%s" " -p | --print : Print note to console"
|
printf "\n%s" " -p | --print : Print note to console"
|
||||||
printf "\n"
|
printf "\n\n"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi
|
||||||
if [ ! -d "$NOTES_DIR" ]; then mkdir -p "$NOTES_DIR"; fi
|
if [ ! -d "$NOTES_DIR" ]; then mkdir -p "$NOTES_DIR"; fi
|
||||||
|
|
||||||
|
if [ ! -r "$CONFIG_FILE" ]; then
|
||||||
cat > "$CONFIG_FILE" << EOF
|
cat > "$CONFIG_FILE" << EOF
|
||||||
# This file contains directives for the Simple Note System.
|
# 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
|
# Encryption is done using GPG. You must enter your
|
||||||
# public key's identifier here.
|
# public key's identifier here.
|
||||||
|
|
||||||
#VCTL="" # Version Control program
|
#VCTL="" # Version Control Program
|
||||||
# Set this to the name of your preferred version control
|
# Set this to the name of your preferred version control
|
||||||
# program to use it in SNS. For example, if VCTL is Set
|
# program to use it in SNS. Examples: git, hg, svn
|
||||||
# to `git`, `sns git ...`` will call `git ...` in SNS's
|
|
||||||
# store. This can be used to revert changes, or to sync
|
|
||||||
# across computers.
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
chmod 600 "$CONFIG_FILE"
|
chmod 600 "$CONFIG_FILE"
|
||||||
|
printf "%s\n" "- Rewrote Default Configuration"
|
||||||
printf " - %s\n" "Rewrote Default Configuration"
|
else
|
||||||
|
printf "$RED_COLOR!$RESET_COLOR - %s" "Refusing to overwrite existing config"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$WILL_INIT" == "TRUE" ]; then
|
if [ "$WILL_INIT" == "TRUE" ]; then
|
||||||
printf " - %s\n" "Environment initialized in $ROOT_DIR"
|
printf "%s\n" "- Environment initialized in $ROOT_DIR"
|
||||||
else
|
else
|
||||||
printf " - %s\n" "Store already initialized."
|
printf "%s\n" "- Store already initialized."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
function p_header(){
|
function p_header(){
|
||||||
printf "# %s\n## %s\n" "$(basename ${NOTE%.*})" "$(date "$DATE_FMT")"
|
printf "# %s\n## %s\n" "$(basename "${NOTE%.*}")" "$(date "$DATE_FMT")"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ if [ -r "$NOTE" ]; then
|
|||||||
if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout
|
if [ "$ENCRYPTION" == "TRUE" ]; then decrypt #to stdout
|
||||||
else cat "$NOTE"; fi
|
else cat "$NOTE"; fi
|
||||||
else
|
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."
|
"Note cannot be found."
|
||||||
exit 205 #ERR_NOTE_NO_READ
|
exit 205 #ERR_NOTE_NO_READ
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ if [ -r "$CONFIG_FILE" ]; then
|
|||||||
source "$CONFIG_FILE"
|
source "$CONFIG_FILE"
|
||||||
verify_store
|
verify_store
|
||||||
elif [ "$1" != "-i" ]; then
|
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."
|
"Configuration not found. Please run sns -i."
|
||||||
exit 5 #ERR_NO_STORE
|
exit 5 #ERR_NO_STORE
|
||||||
fi
|
fi
|
||||||
@@ -19,12 +19,12 @@ if [ "$ENCRYPTION" == "TRUE" ]; then
|
|||||||
fi
|
fi
|
||||||
# Check if GPG is installed.
|
# Check if GPG is installed.
|
||||||
if [ ! -r "$(which gpg)" ]; then
|
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."
|
"Encryption was specified, but GPG is not installed."
|
||||||
exit 100
|
exit 100
|
||||||
# Check if we have a GPG recipient
|
# Check if we have a GPG recipient
|
||||||
elif [ -z "$PUBKEY" ]; then
|
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. "
|
"No GPG recipient was provided in $CONFIG_FILE. "
|
||||||
exit 110
|
exit 110
|
||||||
# All is good. If any previously unencrypted notes exist, encrypt them.
|
# 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"
|
NOTE="${TMP_NOTE%.$EXT}.gpg.$EXT"
|
||||||
encrypt
|
encrypt
|
||||||
if [ -r "$NOTE" ]; then
|
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"
|
rm "$TMP_NOTE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -57,7 +57,7 @@ else
|
|||||||
--decrypt "$NOTE"
|
--decrypt "$NOTE"
|
||||||
|
|
||||||
if [ -r "${NOTE%.gpg.note}.note" ]; then
|
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}"
|
"De-encrypted ${NOTE%.gpg.$EXT}"
|
||||||
rm "$NOTE";
|
rm "$NOTE";
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
# All options not requiring a note to be specified have been dealt
|
# All options not requiring a note to be specified have been dealt
|
||||||
# with; if one isn't specified, exit on ERR_NO_NOTE.
|
# with; if one isn't specified, exit on ERR_NO_NOTE.
|
||||||
if [ -z "$NOTE" ]; then
|
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
|
exit 30
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user