Skip to content

Commit 1b2c203

Browse files
committed
Added shred command. closes #26 #22
1 parent 9197926 commit 1b2c203

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

docs/notebook.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ be entered before copying the note to a new note title. The new notebook will be
8585
.SY "delete|rm notebook"
8686
.YS
8787
.OP notebook
88-
Delete a notebook with the included notes inside.
88+
Delete a notebook with the included notes inside. If GNU shred(1) is available notebook will use it to shred the files during deletion.
8989

9090
.SH NOTES
9191

docs/notes.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ will default to \fBnano\fP.
192192
By default notes creates it's notes directory in ~/.notes for the user. This can be
193193
changed by modifying the shell script.
194194

195+
Notes will find the GNU shred command if available using the options
196+
--remove=wipe. If shred is not installed then it will default to using
197+
the rm command.
198+
195199
.SH FILES
196200

197201
The following files are found in the notes directory (~/.notes by default):

notes

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ JOURNALDIR="${JOURNALDIR:-$DIRFORDIARY}"
2626
GPGKEY=''
2727
GPG_OPTS=" --quiet --yes --compress-algo=none --no-encrypt-to"
2828
GPG="gpg"
29-
SHREDCMD="rm"
3029
EDITOR="${EDITOR:-nano}"
3130
PAGER="${PAGER:-more}"
32-
#SHREDCMD="shred"
31+
32+
# Use shred if available
33+
SHRED="`which shred`"
34+
if [ $? = 0 ]; then
35+
SHREDCMD="${SHRED} --remove=wipe"
36+
else
37+
SHREDCMD="rm"
38+
fi
3339

3440
#
3541
# initialise notes system
@@ -122,7 +128,7 @@ validate_gpg_keyid () {
122128
echo Invalid GPG keyid
123129
cat $keyids
124130
echo \n\n Type 'gpg -k <keyid> to find out more about key'
125-
rm $keyids
131+
${SHREDCMD} $keyids
126132
exit 1
127133
else
128134
echo Valid key $testkey
@@ -133,7 +139,7 @@ validate_gpg_keyid () {
133139
echo Valid keys are ...
134140
cat $keyids
135141
echo \n\n Type 'gpg -k <keyid> to find out more about key'
136-
rm $keyids
142+
${SHREDCMD} $keyids
137143
exit 1;;
138144
esac
139145
}
@@ -147,7 +153,7 @@ note_add () {
147153
filen="$@"
148154
notefile="${USE_POINTER}/`echo ${filen} | tr ' ' '_'`"
149155

150-
if [ -f "$notefile.gpg" ] ; then
156+
if [ -f "$notefile.asc" ] ; then
151157
echo File exists ... cannot create. Try 'notes edit' instead.
152158
exit 1
153159
else
@@ -163,7 +169,7 @@ note_add () {
163169
# encrypt note file
164170
$GPG -ear $KEY $GPG_OPTS "$notefile"
165171

166-
rm "$notefile"
172+
${SHREDCMD} "$notefile"
167173
fi
168174
}
169175

@@ -176,7 +182,7 @@ note_import () {
176182
get_recipient
177183

178184
if [ -f "${toimport}" ] ; then
179-
$GPG -ear $KEY $GPG_OPTS -o "${USE_POINTER}/${target}.gpg" "${toimport}"
185+
$GPG -ear $KEY $GPG_OPTS -o "${USE_POINTER}/${target}.asc" "${toimport}"
180186
fi
181187
}
182188

@@ -188,8 +194,8 @@ note_view () {
188194

189195
if [ -f "${notefile}" ]; then
190196
gpg -d "${notefile}"
191-
elif [ -f "${notefile}.gpg" ]; then
192-
gpg -d "${notefile}.gpg"
197+
elif [ -f "${notefile}.asc" ]; then
198+
gpg -d "${notefile}.asc"
193199
else
194200
echo Note file does not exist
195201
exit 1
@@ -199,20 +205,20 @@ note_view () {
199205
note_edit () {
200206
notefile="`echo $@ | tr ' ' '_'`"
201207
notefile="${USE_POINTER}/${notefile}"
202-
decrypted="`echo ${notefile} | sed s/.gpg//`"
208+
decrypted="`echo ${notefile} | sed s/.asc//`"
203209

204210
get_recipient
205211

206212
if [ -f "$notefile" ]; then
207213
gpg -d -o "${decrypted}" "${notefile}"
208214
${EDITOR} "${decrypted}"
209215
$GPG -ear $KEY $GPG_OPTS "${decrypted}"
210-
rm ${decrypted}
211-
elif [ -f "${notefile}.gpg" ]; then
212-
gpg -d -o "${decrypted}" "${notefile}.gpg"
216+
${SHREDCMD} ${decrypted}
217+
elif [ -f "${notefile}.asc" ]; then
218+
gpg -d -o "${decrypted}" "${notefile}.asc"
213219
${EDITOR} "${decrypted}"
214220
$GPG -ear $KEY $GPG_OPTS "${decrypted}"
215-
rm ${decrypted}
221+
${SHREDCMD} ${decrypted}
216222
else
217223
echo Note file does not exist
218224
exit 1
@@ -228,9 +234,9 @@ note_delete () {
228234
notefile="${USE_POINTER}/${notefile}"
229235

230236
if [ -f "$notefile" ]; then
231-
rm -i "$notefile"
232-
elif [ -f "${notefile}.gpg" ]; then
233-
rm -i "${notefile}.gpg"
237+
${SHREDCMD} "$notefile"
238+
elif [ -f "${notefile}.asc" ]; then
239+
${SHREDCMD} "${notefile}.asc"
234240
else
235241
echo Note file does not exist
236242
fi
@@ -247,13 +253,13 @@ note_rename () {
247253

248254
case $notefile in
249255
*gpg) skip;;
250-
*) notefile="${notefile}.gpg"
256+
*) notefile="${notefile}.asc"
251257
esac
252258

253259
newnotefile="${USE_POINTER}/${newname}"
254260
case $newnotefile in
255261
*gpg) skip;;
256-
*) newnotefile="${newnotefile}.gpg"
262+
*) newnotefile="${newnotefile}.asc"
257263
esac
258264

259265
case $MVCP in
@@ -264,7 +270,7 @@ note_rename () {
264270
if [ -f "$notefile" ] ; then
265271
echo $notefile exists .... $processing
266272
$MVCP "$notefile" "$newnotefile"
267-
elif [ -f "${notefile}.gpg" ] ; then
273+
elif [ -f "${notefile}.asc" ] ; then
268274
echo $notefile exists .... $processing
269275
$MVCP "$notefile" "$newnotefile"
270276
else
@@ -297,7 +303,7 @@ notebook_delete () {
297303
exit 1
298304
else
299305
echo Deleting files from $notebook
300-
rm -if ${notebook}/*.gpg
306+
${SHREDCMD} ${notebook}/*.asc
301307

302308
if [ $? = 0 ] ; then
303309
rmdir "$notebook"
@@ -456,7 +462,7 @@ cmd_show () {
456462
cmd_find () {
457463
searchterm="$@"
458464

459-
for file in ${USE_POINTER}/*.gpg
465+
for file in ${USE_POINTER}/*.asc
460466
do
461467
gpg -d $file 2>/dev/null | grep -H --label ${file} "$searchterm"
462468
done
@@ -562,12 +568,12 @@ cmd_newkey () {
562568
get_gpg_keyid $mynewkey
563569

564570
# now recrypt files
565-
find ~/.notes -name \*.gpg | sed s/.gpg// | \
571+
find ~/.notes -name \*.asc | sed s/.asc// | \
566572

567573
while read filen ;
568574
do
569575
echo $filen;
570-
gpg -o "${filen}" --yes -d "${filen}.gpg"
576+
gpg -o "${filen}" --yes -d "${filen}.asc"
571577
gpg -r ${mynewkey} --yes -ea "${filen}" && ${SHREDCMD} "${filen}"
572578

573579
done

0 commit comments

Comments
 (0)