SafeDelete 1.1
--------------

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 the release 1.0 format to 
             that required by release 1.1.  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.1.

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.

.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.

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


INSTALLATION:

1. Update the Makefile with the following values:

   SAFEDIR  -  The location where safedeleted files will be stored.
               This directory will have the user's $HOME prefixed to it.
               For example, if SAFEDIR is "/.Safedelete", the safedeleted
               files for user "foo" will be placed in foo's directory
               "$HOME/.Safedelete".  The directory is created the first time
               the user issues the safedelete command.
               The default is:  /.Safedelete

   MAXDAYS  -  The system-wide maximum number of days to keep safedeleted
               files.  This value is used by the safedelchk command as an
               absolute upper limit for determining when safedeleted files
               should be removed.  Values in the .Safedelrc which are 
               larger than MAXDAYS are reduced to MAXDAYS.
               The default is:  30 days

   MAXFILES  -  The maximum number of files to allow in the ncurses full
                screen list.  Files beyond this number for any user will
                not be displayed.
                The default is:  1000 files

   BINDIR  -  The directory where the commands will be installed.
              The default is:  /usr/local/bin

   MANDIR  -  The directory where the manual pages will be placed.
              The default is:  /usr/local/man 

2. After updating the Makefile, just issue the command
     make
   
   This will compile all the source code and create the executables.

3. Issue this command as root:
     make install

   This copies the executables and the manual pages to their proper locations.

4. Each user that has any files currently safedeleted should issue the command
     safecnvt

   to convert their .safedelete.log to the new format required by this release
   of SafeDelete.  The original .safedelete.log will be renamed to 
   .safedelete.log.old.  Those that do not have any safedeleted files can skip
   this step.

5. Anyone wishing to use the .Safedelrc file feature should copy the sample
   file .Safedelrc.samp to their $HOME directory and modify it to meet their
   requirements.

6. Update either /etc/profile or each users .bash_profile with the following
   lines:
 
   alias rm='<BINDIR>/safedelete'
   alias purge='/bin/rm'
   export SAFEDAYS=xx
   safedelchk

   where xx is between 1 and MAXDAYS.  

   If you wish to use safedelete from an xterm, you'll also need to define
   the aliases in your .bashrc.

   On my Linux system I have these lines in my .bash_profile:

      alias rm='/usr/local/bin/safedelete'
      alias purge='/bin/rm'
      export SAFEDAYS=7
      safedelchk

   I also have the two alias commands in my .bashrc so my xterm sessions
   will use safedelete.

7. Set up a crontab entry, if needed, to have safedelchk perform periodic checks
   of the safedelete directories.  Make sure you create the crontab entry as
   root, otherwise you'll just end up checking your own files.



HOW THIS THING 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.

Currently all of the options for the rm command are handled by safedelete with
the exception of the -d and -r/-R options.  The reasons are that safedelete is
meant to safely delete files, not directories.  Also, I assume that if you use
these options you know what you are doing and have a reason for doing it.



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 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 
- Allow filname patterns on the undelete command
- Support the -d and -r/-R options
