changeset 2:eb4d7d34889e

Removed old files
author Eris Caffee <discordia@eldalin.com>
date Tue, 17 May 2011 22:09:59 -0500
parents 1217ea1da6d7
children 58e218e2b4ac
files notes shell-script
diffstat 2 files changed, 0 insertions(+), 121 deletions(-) [+]
line diff
     1.1 --- a/notes	Tue May 17 05:00:54 2011 -0500
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,26 +0,0 @@
     1.4 -What does this need to do?
     1.5 -
     1.6 -
     1.7 -Detect when you are attempting to delete anything other than something _under_ a subdirectory of /home and ask for confirmation before proceeding.
     1.8 -
     1.9 -Examples safe to delete
    1.10 -
    1.11 -	 /home/user/file
    1.12 -	 /home/user/dir
    1.13 -	 /home/user/dir/dir/file
    1.14 -
    1.15 -Example that require confirmation
    1.16 -
    1.17 -	/home/dir
    1.18 -	/home/file
    1.19 -	/etc
    1.20 -	/
    1.21 -
    1.22 -
    1.23 -
    1.24 -Implementation:
    1.25 -
    1.26 -Preferably it should be implemented in a way that will be transparent to scripts.  We do not want to have to recode any scripts that call rm.
    1.27 -
    1.28 -A shell function loaded only in interactive shells therefore comes to mind.
    1.29 -
     2.1 --- a/shell-script	Tue May 17 05:00:54 2011 -0500
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,95 +0,0 @@
     2.4 -# -*- sh -*-
     2.5 -#
     2.6 -#
     2.7 -# Giving up on this version.  The kind of pattern matching I really want to
     2.8 -# do against the filespces needs regular expressions, so I might was well use
     2.9 -# use perl
    2.10 -#
    2.11 -#
    2.12 -#
    2.13 -#
    2.14 -# safe-rm
    2.15 -#
    2.16 -# Put this in /root/.bashrc to help prevent accidental data loss.
    2.17 -# In any interactive shell, it aliases the rm command to a shell function
    2.18 -# that checks the arguments.  Any attempt to delete something not in 
    2.19 -# a subdirectory of /home will generate a warning message and prompt to 
    2.20 -# continue.  This should help to prevent accidentally deleting /etc or other
    2.21 -# important system files.
    2.22 -#
    2.23 -# Since the function and alias are only set for interactive shells, existing
    2.24 -# scripts will not need to be modified in any way.
    2.25 -#
    2.26 -# Also, if a user really needs to do a lot of deletion outside /home and gets
    2.27 -# annoyed by the prompt, s/he can either unalias rm  or call /bin/rm directly.
    2.28 -#
    2.29 -# When installing this, be sure it comes _after_ any other "alias rm" command
    2.30 -# or else you will not be safe.
    2.31 -#
    2.32 -
    2.33 -
    2.34 -if [ ! -z "$PS1" ] ; then
    2.35 -
    2.36 -    function safe-rm {
    2.37 -
    2.38 -	Proceed=yes
    2.39 -	Opts=""
    2.40 -
    2.41 -	while : ; do
    2.42 -	    case $# in
    2.43 -		0)
    2.44 -		    break
    2.45 -		    ;;
    2.46 -	    esac
    2.47 -
    2.48 -	    Option=$1
    2.49 -	    shift
    2.50 -
    2.51 -	    case ${Option} in
    2.52 -		-*)
    2.53 -		    # ignore option switches
    2.54 -		    Opts="${Opts} ${Option}"
    2.55 -		    ;;
    2.56 -		*)
    2.57 -		    # Found a filespec
    2.58 -		    Opts="$Opts ${Option}"
    2.59 -		    Parent=$(dirname $(readlink -m ${Option}))
    2.60 -		    echo "Parent = ${Parent}"
    2.61 -		    if [ "${Parent%${Parent#/home}}" != "/home" ] ; then
    2.62 -			Proceed=no
    2.63 -		    fi
    2.64 -		    ;;
    2.65 -	    esac
    2.66 -	done
    2.67 -
    2.68 -	if [ "${Proceed}" = "no" ] ; then
    2.69 -	    echo "
    2.70 -
    2.71 -============ WARNING! ========== WARNING! ========== WARNING! =================
    2.72 -
    2.73 -You are about to delete files or directories that are not in a users home
    2.74 -directory.  Please review the rm command for any typos before proceeding.
    2.75 -
    2.76 -Type \"yes\" to continue.
    2.77 -
    2.78 -
    2.79 -"
    2.80 -	    read Proceed
    2.81 -	fi
    2.82 -
    2.83 -	if [ "${Proceed}" = "yes" ] ; then
    2.84 -	    echo "/bin/rm ${Opts}"
    2.85 -	fi
    2.86 -    }
    2.87 -
    2.88 -    RM_Opts=""
    2.89 -    alias | grep -q "alias rm="
    2.90 -    if [ $? -eq 0 ] ; then
    2.91 -	RM_Opts=$(alias | awk '/alias rm=/ { sub(/^rm /, "", $2); print $2}' FS="'")
    2.92 -    fi
    2.93 -
    2.94 -    unalias rm 2> /dev/null
    2.95 -    alias rm="safe-rm ${RM_Opts}"
    2.96 -
    2.97 -fi
    2.98 -