Testing:
Print function works
This commit is contained in:
Jon-William Lewis
2015-03-18 14:53:05 -05:00
parent 45717e33b5
commit a0ad2e7d48
16 changed files with 389 additions and 398 deletions

View File

@@ -1,34 +1,35 @@
S=sns.sh S=sns.sh
PROD_STR="Simple Note System" PROD_STR="Simple Note System"
VER_STR=v2.0a2 VER_STR=v2.0a3
cat > $S << EOF cat > $S << EOF
#!/bin/bash #!/bin/bash
#========================================================== #==========================================================
# Simple Note System, v2.0a1 # $PROD_STR, $VER_STR
# Copyright 2014, Xenese Labs/Sicron-Perion XNF # Copyright 2014, Xenese Labs/Sicron-Perion XNF
#========================================================== #==========================================================
PROD_STR=$PROD_STR PROD_STR="$PROD_STR"
VER_STR=$VER_STR VER_STR="$VER_STR"
EOF EOF
cat functions/wconf.sns.sh >> $S echo "# Section: Functions" >> $S
cat functions/help.sns.sh >> $S cat ./functions/init_default_config.sns.sh >> $S
cat ./functions/wconf.sns.sh >> $S
cat ./functions/pause.sns.sh >> $S
cat ./functions/help.sns.sh >> $S
cat ./functions/create.sns.sh >> $S
cat ./functions/delete.sns.sh >> $S
cat ./functions/edit.sns.sh >> $S
cat ./functions/print.sns.sh >> $S
cat ./functions/list.sns.sh >> $S
echo "# End Section: Functions" >> $S
cat ./init/stage1.sns.sh >> $S cat ./init/stage1.sns.sh >> $S
cat ./init/stage2.sns.sh >> $S cat ./init/stage2.sns.sh >> $S
cat ./init/stage3.sns.sh >> $S cat ./init/stage3.sns.sh >> $S
cat ./functions/create.sns.sh >> $S
cat ./functions/delete.sns.sh >> $S
cat ./functions/edit.sns.sh >> $S
cat ./functions/print.sns.sh >> $S
cat ./functions/list.sns.sh >> $S
exit exit

12
errors.ref Normal file
View File

@@ -0,0 +1,12 @@
Simple Note System, version 2
Error Code Reference
General-------------------------------------------------------------------------
ERR_NO_ARGS 10 No arguments were specified
ERR_NO_OP 20
ERR_INSUFFICIENT_ARGS 30 A required argument was not provided
Encryption----------------------------------------------------------------------
ERR_NO_SSL 100 Cannot execute openssl
ERR_NO_KEY 110 No encryption key in sns.conf

View File

@@ -1,33 +1,28 @@
#========================================================================== function create(){
# Subection: Create if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit
#========================================================================== help
if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit exit
help elif [ "$CREATE" == "TRUE" ]; then
exit if [ -e $NOTE -o -e ${NOTE%.*} ]; then
else 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 [ "$CREATE" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
if [ -e $NOTE -o -e ${NOTE%.*} ]; then if [ $EDIT == "FALSE" ]; then
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
echo "" fi
echo "ERROR: Note already exists" fi
echo "Hint: use -e to edit the note." fi
echo "" fi
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
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
fi
fi
fi
fi

View File

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

View File

@@ -1,30 +1,27 @@
#========================================================================== function edit (){
# Subection: Edit if [ "$EDIT" == "TRUE" ]; then
#========================================================================== if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then
if [ "$EDIT" == "TRUE" ]; then if [ -z "$CREATE" ]; then
if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
if [ -z "$CREATE" ]; then TMP_NAME=$ROOTDIR/tmp/$RANDOM
if [ "$ENCRYPTION" == "TRUE" ]; then openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME
TMP_NAME=$ROOTDIR/tmp/$RANDOM echo "" >> $TMP_NAME
openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME echo "EDIT $(date)" >> $TMP_NAME
echo "" >> $TMP_NAME else
echo "EDIT $(date)" >> $TMP_NAME echo "" >> $NOTE
else echo "EDIT $(date)" >> $NOTE
echo "" >> $NOTE fi
echo "EDIT $(date)" >> $NOTE fi
fi $EDITOR $NOTE
fi if [ "$ENCRYPTION" == "TRUE" ]; then
$EDITOR $NOTE openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
if [ "$ENCRYPTION" == "TRUE" ]; then rm $NOTE
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY fi
rm $NOTE
fi
else else
echo "" echo ""
echo "ERROR: Note cannot be opened for editting." echo "ERROR: Note cannot be opened for editting."
echo "" echo ""
fi fi
fi fi
}
fi

View File

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

View File

@@ -0,0 +1,7 @@
function init_default_config() {
ROOTDIR=$HOME/.sns
BASEDIR=$ROOTDIR/notes
EXT=note
EDITOR=vim
ENCRYPTION="FALSE"
}

View File

@@ -1,39 +1,29 @@
# list.sns.sh function list(){
if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then
echo ""
printf "Notes in $(basename $NOTEBOOK):"
echo ""
if [ -n "$LIST" ]; then NOTES=( $(find $BASEDIR/$NOTEBOOK -name "*.$EXT" -print0 | sed s:$BASEDIR/$NOTEBOOK/:" ":g | sed -e s:".$EXT"::g | tr "/" " ") )
NOTEBOOK="$NAME" #In case of a list command, arg parsing fails. let i=0
if [ -z "$NOTEBOOK" ]; then for NOTE in ${NOTES[@]}; do
echo " ERROR: Insufficient arguments" if [ -d $BASEDIR/$NOTEBOOK/$NOTE ]; then
help if [ "$LAST_SECTION" != "$NOTE" ]; then
exit printf " Section: $NOTE\n"
else fi
if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then LAST_SECTION=$NOTE
else
echo "" #if [ $(($i % 1)) -eq 0 ]; then
printf "Notes in $(basename $NOTEBOOK):" # printf "\n "
echo "" #fi
NOTES=( $(find $BASEDIR/$NOTEBOOK -name "*.$EXT" -print0 | sed s:$BASEDIR/$NOTEBOOK/:" ":g | sed -e s:".$EXT"::g | tr "/" " ") ) printf " $NOTE\n"
let i=0 fi
for NOTE in ${NOTES[@]}; do let i++
if [ -d $BASEDIR/$NOTEBOOK/$NOTE ]; then done
if [ "$LAST_SECTION" != "$NOTE" ]; then printf "\n"
printf " Section: $NOTE\n" else
fi echo ""
LAST_SECTION=$NOTE echo "ERROR: Notebook $NOTEBOOK does not exist."
else echo ""
#if [ $(($i % 1)) -eq 0 ]; then fi
# printf "\n " }
#fi
printf " $NOTE\n"
fi
let i++
done
printf "\n"
else
echo ""
echo "ERROR: Notebook $NOTEBOOK does not exist."
echo ""
fi
fi
exit
fi

4
functions/pause.sns.sh Normal file
View File

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

View File

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

View File

@@ -1,6 +1,3 @@
#==============================================================================
# Section: Helper Functions
#==============================================================================
function writeconf { function writeconf {
cat > $HOME/.sns/sns.conf << EOF cat > $HOME/.sns/sns.conf << EOF
#========================================================== #==========================================================
@@ -26,10 +23,3 @@ EOF
chmod 600 $ROOTDIR/sns.conf chmod 600 $ROOTDIR/sns.conf
} }
function pause {
read -p " Press [Enter] to continue."
echo ""
}

View File

@@ -2,12 +2,9 @@
# Section: Configuration # Section: Configuration
#============================================================================== #==============================================================================
if [ -r $HOME/.sns/sns.conf ]; then if [ -r $HOME/.sns/sns.conf ]; then
source $HOME/.sns/sns.conf source $HOME/.sns/sns.conf
else else
ROOTDIR=$HOME/.sns init_default_config
BASEDIR=$ROOTDIR/notes
EDITOR=vim
EXT=note
fi fi
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then

View File

@@ -8,7 +8,7 @@ SECTION=""
if [ -z "$1" ]; then #If no input was given, print help if [ -z "$1" ]; then #If no input was given, print help
help help
exit exit 20
else #Assume the user wants to do something. else #Assume the user wants to do something.
ARGS=( "$@" ) ARGS=( "$@" )
for ARG in ${ARGS[@]};do for ARG in ${ARGS[@]};do
@@ -23,18 +23,22 @@ else #Assume the user wants to do something.
else else
if [ -z "$NAME" -a -n $ARG ]; then if [ -z "$NAME" -a -n $ARG ]; then
NAME=$ARG NAME=$ARG
echo "Name: $NAME"
elif [ -z "$NOTEBOOK" -a -n $ARG ]; then elif [ -z "$NOTEBOOK" -a -n $ARG ]; then
NOTEBOOK=$ARG NOTEBOOK=$ARG
echo "Notebook: $NOTEBOOK"
elif [ -z "$SECTION" -a -n $ARG ]; then elif [ -z "$SECTION" -a -n $ARG ]; then
SECTION=$ARG SECTION=$ARG
echo "Section: $SECTION"
fi fi
fi fi
done done
if [ -n "$NAME" -a -z "$NOTEBOOK" ]; then
NOTEBOOK="$NAME"
NAME=""
fi
fi fi
# Note: writeconf has highest priority, and it is the only function that can
# work without any parameters.
#============================================================================== #==============================================================================
# End Section: Argument Parsing # End Section: Argument Parsing
#============================================================================== #==============================================================================

View File

@@ -1,22 +1,30 @@
# Help requires no arguments, and is exclusive.
if [ -n "$HELP" ]; then help; exit 0; fi
# List only requires a notebook, and is exclusive.
if [ -z "$NOTEBOOK" ]; then
echo " ERROR: Insufficient arguments:"
echo " Notebook not specified"
exit 30
# If no name or notebook is specified, the create, edit, and print functions will not function properly.
# Check $NAME and $NOTEBOOK and exit if either are empty.
if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then;
echo " ERROR: Insufficient arguments";
help; #Remind the user how to use the script
exit 10;
fi fi
if [ -n "$LIST" ]; then
list
exit 0
fi
#All other functions require a note title and notebook.
if [ -z "$NAME" ]; then
echo " ERROR: Insufficient arguments:"
echo " Title not specified"
exit 30
fi
NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/
NOTE=$NOTEDIR$NAME.$EXT NOTE=$NOTEDIR$NAME.$EXT
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.tmp fi
NOTE=$NOTE.tmp
fi

371
sns.sh
View File

@@ -1,15 +1,20 @@
#!/bin/bash #!/bin/bash
#========================================================== #==========================================================
# Simple Note System, v2.0a1 # Simple Note System, v2.0a3
# Copyright 2014, Xenese Labs/Sicron-Perion XNF # Copyright 2014, Xenese Labs/Sicron-Perion XNF
#========================================================== #==========================================================
PROD_STR="Simple Note System" PROD_STR="Simple Note System"
VER_STR=v2.0a1 VER_STR="v2.0a3"
#============================================================================== # Section: Functions
# Section: Helper Functions function init_default_config() {
#============================================================================== ROOTDIR=$HOME/.sns
BASEDIR=$ROOTDIR/notes
EXT=note
EDITOR=vim
ENCRYPTION="FALSE"
}
function writeconf { function writeconf {
cat > $HOME/.sns/sns.conf << EOF cat > $HOME/.sns/sns.conf << EOF
#========================================================== #==========================================================
@@ -35,43 +40,157 @@ EOF
chmod 600 $ROOTDIR/sns.conf chmod 600 $ROOTDIR/sns.conf
} }
function pause { function pause {
read -p " Press [Enter] to continue." read -p " Press [Enter] to continue."
echo "" echo ""
} }
function help { function help {
echo "" echo ""
echo "usage: sns [-ce] NAME NOTEBOOK SECTION" echo "usage: sns [-ce] NAME NOTEBOOK SECTION"
echo " sns [-d ] NAME NOTEBOOK SECTION" echo " sns [-d ] NAME NOTEBOOK SECTION"
echo " sns [-l ] NOTEBOOK" echo " sns [-lp] NOTEBOOK"
echo " sns [-w ]" echo " sns [-w ]"
echo " sns [-h ]"
echo "" echo ""
echo " -c | --create : Create note" echo " -c | --create : Create note"
echo " -d | --delete : Delete note" echo " -d | --delete : Delete note"
echo " -e | --edit : Open note for editing" echo " -e | --edit : Open note for editing"
echo " -p | --print : Print note to console" echo " -h | --help : Display this message"
echo " -l | --list : List all notes in NOTEBOOK" echo " -p | --print : Print note to console"
echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)" echo " -l | --list : List all notes in NOTEBOOK"
echo "" echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)"
echo ""
} }
function create(){
if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit
help
exit
elif [ "$CREATE" == "TRUE" ]; then
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
# End Section: Helper Functions echo "TITLE: $NAME" > $NOTE
#============================================================================== #Fill the second line with the date
echo "DATE: $(date)" >> $NOTE
if [ "$ENCRYPTION" == "TRUE" ]; then
if [ $EDIT == "FALSE" ]; then
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
fi
fi
fi
fi
}
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
}
function edit (){
if [ "$EDIT" == "TRUE" ]; then
if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then
if [ -z "$CREATE" ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then
TMP_NAME=$ROOTDIR/tmp/$RANDOM
openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME
echo "" >> $TMP_NAME
echo "EDIT $(date)" >> $TMP_NAME
else
echo "" >> $NOTE
echo "EDIT $(date)" >> $NOTE
fi
fi
$EDITOR $NOTE
if [ "$ENCRYPTION" == "TRUE" ]; then
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
rm $NOTE
fi
else
echo ""
echo "ERROR: Note cannot be opened for editting."
echo ""
fi
fi
}
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
}
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
}
# End Section: Functions
#============================================================================== #==============================================================================
# Section: Configuration # Section: Configuration
#============================================================================== #==============================================================================
if [ -r $HOME/.sns/sns.conf ]; then if [ -r $HOME/.sns/sns.conf ]; then
source $HOME/.sns/sns.conf source $HOME/.sns/sns.conf
else else
ROOTDIR=$HOME/.sns init_default_config
BASEDIR=$ROOTDIR/notes
EDITOR=vim
EXT=note
fi fi
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
@@ -115,7 +234,7 @@ SECTION=""
if [ -z "$1" ]; then #If no input was given, print help if [ -z "$1" ]; then #If no input was given, print help
help help
exit exit 20
else #Assume the user wants to do something. else #Assume the user wants to do something.
ARGS=( "$@" ) ARGS=( "$@" )
for ARG in ${ARGS[@]};do for ARG in ${ARGS[@]};do
@@ -130,184 +249,52 @@ else #Assume the user wants to do something.
else else
if [ -z "$NAME" -a -n $ARG ]; then if [ -z "$NAME" -a -n $ARG ]; then
NAME=$ARG NAME=$ARG
echo "Name: $NAME"
elif [ -z "$NOTEBOOK" -a -n $ARG ]; then elif [ -z "$NOTEBOOK" -a -n $ARG ]; then
NOTEBOOK=$ARG NOTEBOOK=$ARG
echo "Notebook: $NOTEBOOK"
elif [ -z "$SECTION" -a -n $ARG ]; then elif [ -z "$SECTION" -a -n $ARG ]; then
SECTION=$ARG SECTION=$ARG
echo "Section: $SECTION"
fi fi
fi fi
done done
if [ -n "$NAME" -a -z "$NOTEBOOK" ]; then
NOTEBOOK="$NAME"
NAME=""
fi
fi fi
# Note: writeconf has highest priority, and it is the only function that can
# work without any parameters.
#============================================================================== #==============================================================================
# End Section: Argument Parsing # End Section: Argument Parsing
#============================================================================== #==============================================================================
# Help requires no arguments, and is exclusive.
if [ -n "$HELP" ]; then help; exit 0; fi
# List only requires a notebook, and is exclusive.
if [ -z "$NOTEBOOK" ]; then
echo " ERROR: Insufficient arguments:"
echo " Notebook not specified"
exit 30
# If no name or notebook is specified, the create, edit, and print functions will not function properly.
# Check $NAME and $NOTEBOOK and exit if either are empty.
if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then;
echo " ERROR: Insufficient arguments";
help; #Remind the user how to use the script
exit 10;
fi fi
if [ -n "$LIST" ]; then
list
exit 0
fi
#All other functions require a note title and notebook.
if [ -z "$NAME" ]; then
echo " ERROR: Insufficient arguments:"
echo " Title not specified"
exit 30
fi
NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/ NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION/
NOTE=$NOTEDIR$NAME.$EXT NOTE=$NOTEDIR$NAME.$EXT
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then NOTE=$NOTE.tmp fi
NOTE=$NOTE.tmp
fi
#==========================================================================
# Subection: Create
#==========================================================================
if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit
help
exit
else
if [ "$CREATE" == "TRUE" ]; then
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
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
fi
fi
fi
fi
# delete.sns.sh
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
#==========================================================================
# Subection: Edit
#==========================================================================
if [ "$EDIT" == "TRUE" ]; then
if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then
if [ -z "$CREATE" ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then
TMP_NAME=$ROOTDIR/tmp/$RANDOM
openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME
echo "" >> $TMP_NAME
echo "EDIT $(date)" >> $TMP_NAME
else
echo "" >> $NOTE
echo "EDIT $(date)" >> $NOTE
fi
fi
$EDITOR $NOTE
if [ "$ENCRYPTION" == "TRUE" ]; then
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
rm $NOTE
fi
else
echo ""
echo "ERROR: Note cannot be opened for editting."
echo ""
fi
fi
fi
#==========================================================================
# Subection: 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
# list.sns.sh
if [ -n "$LIST" ]; then
NOTEBOOK="$NAME" #In case of a list command, arg parsing fails.
if [ -z "$NOTEBOOK" ]; then
echo " ERROR: Insufficient arguments"
help
exit
else
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
fi
exit
fi

View File

@@ -13,18 +13,22 @@
5DE8397B1AB9D629006CB4F6 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = "<group>"; }; 5DE8397B1AB9D629006CB4F6 /* stage1.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage1.sns.sh; sourceTree = "<group>"; };
5DE8397C1AB9D64B006CB4F6 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = "<group>"; }; 5DE8397C1AB9D64B006CB4F6 /* stage2.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage2.sns.sh; sourceTree = "<group>"; };
5DE8397D1AB9D694006CB4F6 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = "<group>"; }; 5DE8397D1AB9D694006CB4F6 /* stage3.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = stage3.sns.sh; sourceTree = "<group>"; };
5DE8397E1AB9D72D006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = "<group>"; };
5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = "<group>"; }; 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create.sns.sh; sourceTree = "<group>"; };
5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = "<group>"; }; 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = edit.sns.sh; sourceTree = "<group>"; };
5DE839811AB9D7F8006CB4F6 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = "<group>"; }; 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = print.sns.sh; sourceTree = "<group>"; };
5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = wconf.sns.sh; sourceTree = "<group>"; }; 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = wconf.sns.sh; sourceTree = "<group>"; };
5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = "<group>"; }; 5DE839831AB9DACE006CB4F6 /* sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sns.sh; sourceTree = "<group>"; };
5DE839841AB9FDF9006CB4F6 /* help.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = help.sns.sh; sourceTree = "<group>"; };
5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = pause.sns.sh; sourceTree = "<group>"; };
5DE839861AB9FF14006CB4F6 /* init_default_config.sns.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = init_default_config.sns.sh; sourceTree = "<group>"; };
5DE839881ABA04DD006CB4F6 /* errors.ref */ = {isa = PBXFileReference; lastKnownFileType = text; path = errors.ref; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
5D7E61181AB74D11001D49B9 = { 5D7E61181AB74D11001D49B9 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
5DE839881ABA04DD006CB4F6 /* errors.ref */,
5DE839831AB9DACE006CB4F6 /* sns.sh */, 5DE839831AB9DACE006CB4F6 /* sns.sh */,
5DE839791AB9D5F8006CB4F6 /* init */, 5DE839791AB9D5F8006CB4F6 /* init */,
5D7E611F1AB74D33001D49B9 /* build.sh */, 5D7E611F1AB74D33001D49B9 /* build.sh */,
@@ -35,10 +39,12 @@
5DE839751AB9D41B006CB4F6 /* functions */ = { 5DE839751AB9D41B006CB4F6 /* functions */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
5DE839861AB9FF14006CB4F6 /* init_default_config.sns.sh */,
5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */, 5DE839821AB9DAA6006CB4F6 /* wconf.sns.sh */,
5DE839841AB9FDF9006CB4F6 /* help.sns.sh */,
5DE839851AB9FE1C006CB4F6 /* pause.sns.sh */,
5DE839761AB9D42F006CB4F6 /* list.sns.sh */, 5DE839761AB9D42F006CB4F6 /* list.sns.sh */,
5DE839771AB9D52C006CB4F6 /* delete.sns.sh */, 5DE839771AB9D52C006CB4F6 /* delete.sns.sh */,
5DE8397E1AB9D72D006CB4F6 /* help.sns.sh */,
5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */, 5DE8397F1AB9D7B9006CB4F6 /* create.sns.sh */,
5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */, 5DE839801AB9D7DD006CB4F6 /* edit.sns.sh */,
5DE839811AB9D7F8006CB4F6 /* print.sns.sh */, 5DE839811AB9D7F8006CB4F6 /* print.sns.sh */,