2.0a4 -> 2.0a5

Changed some filenames
Rewrote edit function to be more sane
Separated encryption and decryption functions from edit into libencryption.sh
Fixed a bug where an edit tag would be added regardless of create status
This commit is contained in:
Jon-William Lewis
2015-05-07 22:11:13 -05:00
parent 64e504ebcb
commit 3cb375f64b
22 changed files with 540 additions and 208 deletions

View File

@@ -0,0 +1,44 @@
#function create(){
#
# #Check if note exists
# if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then
# echo ""
# echo "ERROR: Note already exists"
# echo "Hint: use -e to edit the note."
# echo ""
# exit
# else
# #Create any necessary folders
# mkdir -p $NOTEDIR
#
# #Fill in title
# echo "TITLE: $NAME" > $NOTE
# #Fill the second line with the date
# echo "DATE: $(date)" >> $NOTE
#
# if [ "$ENCRYPTION" == "TRUE" ]; then
# if [ "$EDIT" == "FALSE" ]; then
# echo " openssl enc -aes-256-cbc -salt -in $NOTE -out $NOTE.enc -pass pass:$ENC_KEY"
# fi
# fi
# fi
#}
function create(){
if [ -e "$NOTE" -o -e ${NOTE%.*} ]; then
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
exit
else
mkdir -p "$NOTEDIR"
fi
if [ -z "$ENCRYPTION" ]; then
echo "TITLE: $NAME" > $NOTE
echo "DATE: $(date)" >> $NOTE
elif [ "$ENCRYPTION" == "TRUE" ]; then
touch "$NOTE"
echo "$(p_header)" | openssl enc -aes-256-cbc -salt -out "$NOTE"\
-pass pass:$ENC_KEY
fi
echo "$NOTE"
}

19
src/includes/defaults.sh Normal file
View File

@@ -0,0 +1,19 @@
function init_default_config() {
if [ -z "$ROOTDIR" ]; then
ROOTDIR=$HOME/.sns
fi
if [ -z "$BASEDIR" ]; then
BASEDIR=$ROOTDIR/notes
fi
if [ -z "$EXT" ]; then
EXT=note
fi
if [ -z "$EDITOR" ]; then
EDITOR=vim
fi
if [ -z "$ENC_KEY" ]; then
ENCRYPTION="FALSE"
else
ENCRYPTION="TRUE"
fi
}

View File

@@ -0,0 +1,18 @@
function delete(){
if [ "$DELETE" == "TRUE" ]; then
if [ -e $NOTE -o -e ${NOTE%.*} ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then
rm ${NOTE%.*}
else
rm $NOTE
fi
echo ""
echo "Deleted note: $NOTEBOOK/$SECTION$NAME."
exit
else
echo ""
echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist."
exit
fi
fi
}

21
src/includes/edit.sns.sh Normal file
View File

@@ -0,0 +1,21 @@
function edit(){
if [ ! -r "$NOTE" ]; then
echo "ERROR: Note cannot be opened for editing."
exit 40;
fi
if [ "$ENCRYPTION" == "TRUE" ]; then decrypt
else TARGET="$NOTE"; fi
if [ -z "$CREATE" ]; then printf "\nEDIT $(date)" >> "$TARGET"; fi
"$EDITOR" "$TARGET"
if [ "$ENCRYPTION" == "TRUE" ]; then encrypt; fi
}

18
src/includes/help.sns.sh Normal file
View File

@@ -0,0 +1,18 @@
function help {
echo ""
echo "usage: sns [-ce] NAME NOTEBOOK SECTION"
echo " sns [-d ] NAME NOTEBOOK SECTION"
echo " sns [-lp] NOTEBOOK"
echo " sns [-w ]"
echo " sns [-h ]"
echo ""
echo " -c | --create : Create note"
echo " -d | --delete : Delete note"
echo " -e | --edit : Open note for editing"
echo " -h | --help : Display this message"
echo " -p | --print : Print note to console"
echo " -l | --list : List all notes in NOTEBOOK"
echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)"
echo ""
}

View File

@@ -0,0 +1,8 @@
function encrypt(){
openssl enc -aes-256-cbc -salt -in "$TARGET" -out "$NOTE" -pass pass:"$ENC_KEY"
}
function decrypt(){
TARGET="$ROOTDIR"/tmp/"$RANDOM"
openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET"
}

29
src/includes/list.sns.sh Normal file
View File

@@ -0,0 +1,29 @@
function list(){
if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then
echo ""
printf "Notes in $(basename $NOTEBOOK):"
echo ""
NOTES=( $(find $BASEDIR/$NOTEBOOK -name "*.$EXT" -print0 | sed s:$BASEDIR/$NOTEBOOK/:" ":g | sed -e s:".$EXT"::g | tr "/" " ") )
let i=0
for NOTE in ${NOTES[@]}; do
if [ -d $BASEDIR/$NOTEBOOK/$NOTE ]; then
if [ "$LAST_SECTION" != "$NOTE" ]; then
printf " Section: $NOTE\n"
fi
LAST_SECTION=$NOTE
else
#if [ $(($i % 1)) -eq 0 ]; then
# printf "\n "
#fi
printf " $NOTE\n"
fi
let i++
done
printf "\n"
else
echo ""
echo "ERROR: Notebook $NOTEBOOK does not exist."
echo ""
fi
}

3
src/includes/p_header.sh Normal file
View File

@@ -0,0 +1,3 @@
function p_header(){
printf "TITLE: $NAME\nDATE: $(date)\n"
}

View File

@@ -0,0 +1,4 @@
function pause {
read -p " Press [Enter] to continue."
echo ""
}

19
src/includes/print.sns.sh Normal file
View File

@@ -0,0 +1,19 @@
function print(){
if [ "$PRINT" == "TRUE" ]; then
if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then
if [ -z "$CREATE" ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then
openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY
else
cat $NOTE
echo "" >> $NOTE
fi
else
echo ""
echo "ERROR: Note cannot be found."
echo ""
fi
fi
fi
}

View File

@@ -0,0 +1,27 @@
function w_conf {
cat > $HOME/.sns/sns.conf << EOF
#==========================================================
# Simple Note System Config, v2.0a1
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
#==========================================================
#Directory where notes will be stored
ROOTDIR=$HOME/.sns
BASEDIR=$ROOTDIR/notes
#File extension to use (for listing notes)
EXT=note
#Preferred Editor
if [ -z "$EDITOR" ]; then
EDITOR=vim
fi
#Encryption
#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST
ENCRYPTION="FALSE"
ENC_KEY=""
EOF
chmod 600 $ROOTDIR/sns.conf
}