SafeDelete 1.3
--------------

SafeDelete is a set of commands which are meant to safely delete files
and allow them to be undeleted.  It is intended to be a shell enhancement
to the /bin/rm command.

COMMANDS:

safedelete - The main program which, when invoked, makes a compressed copy
             of the file(s) specified on the command line and places them 
             in a preselected directory under a program-generated file
             name.  It then updates a log file to keep track of the original
             file name as well as the generated file name.

             Only regular files and symbolic links are processed by safedelete.
             Special files, etc are ignored.  Hard links are processed like 
             regular files.

undelete   - This command undeletes files by scanning the log, created by
             the safedelete command, for the file name specified on the 
             command line.  Once found,  the file is restored by decompressing
             the program-generated file name then copying it back to its 
             original location (along with the original permissions, dates,
             etc).

             A file name on the command line is optional, if none is specified
             a full-screen scrollable list is displayed (using ncurses) 
             allowing the user to select which file(s) to undelete.

safedelchk - Scans the directory containing the users safedeleted files and
             deletes those that are older than a preset maximum number of
             days.  The users log file is also updated to reflect which files
             can still be undeleted.

safecnvt   - Converts a users .safedelete.log from other formats to the format 
             required by release 1.3.  It also copies the files that they
             currently have safedeleted from the directory used by release 1.0
             to the new directory used in release 1.3.  If you are using releases
	     1.1 or 1.2 the files are already in the proper location and are not
	     moved.

There are also a complete set of man pages describing the options for each of
these commands.



FILES:

.safedelete.log - Each user has one in their $HOME directory.  It is basically
             a cross-reference between the original file names and their 
             generated file names.  It also contains the original inode
             information for each file.

.safedelete.lock - this file is created dynamically to control access to the
             .safedelete.log.  Each program first tries to acquire the lock
             before performing any processing.  The lockbusy option in the
             .Safedelrc file describes what action should be taken if the lock
             cannot be acquired.

.Safedelrc - This is an optional file which the user can place in their $HOME
             directory.  It contains detail on items used by the SafeDelete
             commands.

             There are three sections in the .Safedelrc file.  Each section
             begins with a header label and ends with a trailer label.  The
             sections are:

             [safedays] -- contains filename patterns and the number of days
                           files matching the pattern should be kept.  The 
                           pattern must begin in column 1 and at least one
                           blank must separate the pattern from the number 
                           of days.  Multiple patterns can be specified on the
                           same line and must be separated by commas.  The 
                           pattern can contain at most 1 asterisk (for a 
                           wildcard character) or can be a complete filename.
                           Files not matching any of the patterns will use
                           the $SAFEDAYS variable to determine when the 
                           safedeleted file should be purged.  Specifying 0
                           for the number of days prevents files matching
                           the pattern from being safedeleted.

                           Syntax: <pattern>[,pattern][,...] <no. of days>

                           Example:

                           [safedays]
                           core,/tmp/* 0
                           *.c 7
                           test*.o 1
                           [endsection]

                           In the example, all core files and all files in the
                           /tmp directory will not be safedeleted.  All files
                           ending in .c will be safedeleted for 7 days and
                           files beginning with test and ending with .o will be
                           safedeleted for 1 day.


             [compression] -- contains filename patterns and the compression
                           commands to be used for each.  The special keyword 
                           "none" is recognized for files that should not be
                           compressed.  Both the compression and decompression 
                           commands must be specified for each pattern.  The 
                           commands must be separated by a forward slash "/".
                           Up to 40 characters can be used for each command.

                           The pattern must begin in column 1 with at least one
                           blank separating the pattern from the commands.

                           Syntax: <pattern>[,pattern][,...]
                                        <compress>/<decompress>

                           Example:

                           [compression]
                           *.gz,*.tgz,*.Z none
                           *.c gzip -9/gunzip
                           test* compress/uncompress
                           [endsection]

                           In the example, all files ending with .gz, .tgz and
                           .Z should not be compressed while those ending with
                           .c should be compressed with the gzip command and
                           decompressed with gunzip.  All files starting with
                           test should be compressed with compress and 
                           decompressed with uncompress.


             [suffix] ---- contains compression commands followed by the suffix
                           each adds to the filename.  Multiple commands,
                           separated by commas, can be entered on one
                           line and at least one blank must separate the 
                           commands from the suffix.

                           Each suffix can be at most 8 characters long (a dot
                           followed by up to 7 characters).

                           Syntax: <command>[,command][,...] <.suffix>

                           Example:

                           [suffix]
                           gzip .gz
                           compress .Z
                           [endsection]

                           In the example, the gzip command adds the .gz suffix
                           while the compress command adds the .Z suffix.

             [options] --- contains various options that affect the behavior
                           of the commands.

                           Syntax:

                           lockbusy <action> - what to do if the lock file is
                                               already in use.

                           where <action> is one of the following:

                               wait - wait until the lock file becomes available.
                                      a message is issued every 5 seconds indicating
                                      that the lock file is still busy.

                               prompt - issue a propmt every 5 seconds asking if the
                                      command should continue waiting for the lock
                                      file.  This is the default action.

                               quit - don't wait for the lock file, just terminate.

                            Example:
 
                            [options]
                            lockbusy wait
                            [endsection]

             See the safedelrc(5) man page on for complete details.



PROBLEM REPORTING:

If you encounter any bugs or have any questions or comments I can be reached
in the following ways:

e-mail: jrenicker@goodyear.com
voice:  (216) 796-3984
snailmail: Goodyear Tire & Rubber Co.
           1144 E. Market St.
           Akron, OH 44316
           ATTN: Jeff Renicker Dept. 659/9968



MY SYSTEM CONFIGURATION:

This package was built and tested on a Slackware 2.2.0.1 system
with the following configuration:

   Linux 1.2.3
   GCC 2.6.3
   libc 4.6.27
   ncurses 1.8.5



POSSIBLE FUTURE ENHANCEMENTS:

- Add additional options to the .Safedelrc file to allow
  various ways of sorting the ncurses display, different
  ways of displaying the dates (mm/dd/yy vs dd/mm/yy), etc
- Allow all ncurses options to be done from the command
  line (currently the remove and newname actions are not
  available on the command line)
- Add a character search option to the ncurses interface
- Allow the files to be sorted in various ways within
  the ncurses interface (without requiring the user to 
  exit then reenter)
- Allow the filename pattern to be changed within the
  ncurses interface
- Add support for page-up, page-down, home, and end keys
  in the ncurses interface
- Put all file movement and compression into a background
  process to improve the response time of safedelete
- Add mouse support to the ncurses undelete so files can 
  be selected with a mouse as well as the keyboard
- Have undelete run natively under X11 


================================================================================
You only need to read the following if you are really interested in how it works
================================================================================

This utility is patterned after the SmartCan utility from Symantec Corp.  When 
a file is deleted by the user a compressed copy of it is placed in a preselected
directory under a generated file name and removed from its original location.
Each user has a log file which keeps track of each file they have deleted and
cross-references them to the generated file names.  The log file name is 
.safedelete.log and is kept in the users home directory.  

To prevent the filesystem from filling up with user-deleted files the safedelchk 
command scans the users .safedelete.log and safedelete directory removing all
files older than a set number of days (see the MAXDAYS variable in the
Makefile).  The user's .safedelete.log is updated to reflect any files removed
from their safedelete directory.  Safedelchk also scans for inconsistencies
between the .safedelete.log and the directory reporting to the user any that
are found.

To allow some flexibility for the users a variable called SAFEDAYS can be set
in either /etc/profile or the .bash_profile for each user.  This variable is
used by both the safedelete and the safedelchk programs.  When safedelete starts
processing it checks to see if the variable is defined.  If $SAFEDAYS is not 
defined, or is defined and is non-zero, the files specified on the command line
are safedeleted as described above.  If $SAFEDAYS is defined and has a value of
zero, safedelete just invokes the /bin/rm command to remove the files, thus
turning off the safedelete function.  This can be handy if you know that the
files you'll be deleting will never be needed again.  Just set $SAFEDAYS to 0
and safedelete will ignore all requests to safely delete files.  Don't forget
to reset $SAFEDAYS to a non-zero value when you're done.

For more granularity at the filename level, each user can optionally have a
.Safedelrc file in their $HOME directory.  This file contains file names and
patterns which control the number of days a particular file should be kept
in the safedelete directory.  Any file name not matching a pattern in the 
.Safedelrc will be controlled by the $SAFEDAYS or the $MAXDAYS variable, 
whichever has the lower value.

Safedelchk is coded to run in two different modes, user mode and administrator
mode.  In user mode (i.e. invoked by the user) only those files in the user's
safedelete directory are scanned and removed.  In administrator mode 
(i.e. invoked by root) the files for all users are scanned and removed.
The reasoning for this way of doing things goes like this:

- safedelchk is really meant to be executed from either /etc/profile or from 
  each users .bash_profile.
- if executed from /etc/profile, no problem,  the users old safedeleted files
  will be removed to prevent a bunch of old files cluttering up the filesystem.
- if executed from the users .bash_profile the user has the option of never
  running safedelchk (they can just remove it from their .bash_profile).
- thus, setting a crontab entry from root to invoke safedelchk on a periodic
  basis enforces system policy for safedeleted files.  Invoking safedelchk as
  root defaults to running in administrator mode.  To run safedelchk in user
  mode as root you must use the -u option.

The undelete command undeletes the files that were previously removed with 
safedelete.  It has two modes, command and interactive.  In command mode, the
user specifies the name of the file on the command line (only one file at a
time, for now).  Undelete then scans the user's .safedelete.log looking for the
most recent occurence of that file (this allows multiple copies of the same file
to exist in the safedelete directory).  The file is then restored to its 
original location along with its original permissions and timestamps.  Some
safety checks are performed internally to make sure the file was successfully
undeleted.  Once the undelete process is verified the safedeleted copy of the 
file, and its corresponding log entry, are removed.

To enter interactive mode just issue the undelete command with no options.
This will display a scrollable list of files that the user currently has listed
in their .safedelete.log.  This display facility uses ncurses (the System V
curses, not the BSD curses).  This allows the user to pick and choose which
file(s) to undelete.  The actual undelete process is the same as for command
mode.
