# HG changeset patch # User Eris Caffee # Date 1305688199 18000 # Node ID eb4d7d34889e86b5f80163c733047d7cd76b0aca # Parent 1217ea1da6d7b1fa6e964a6a44f9046a216a7126 Removed old files diff -r 1217ea1da6d7 -r eb4d7d34889e notes --- a/notes Tue May 17 05:00:54 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -What does this need to do? - - -Detect when you are attempting to delete anything other than something _under_ a subdirectory of /home and ask for confirmation before proceeding. - -Examples safe to delete - - /home/user/file - /home/user/dir - /home/user/dir/dir/file - -Example that require confirmation - - /home/dir - /home/file - /etc - / - - - -Implementation: - -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. - -A shell function loaded only in interactive shells therefore comes to mind. - diff -r 1217ea1da6d7 -r eb4d7d34889e shell-script --- a/shell-script Tue May 17 05:00:54 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -# -*- sh -*- -# -# -# Giving up on this version. The kind of pattern matching I really want to -# do against the filespces needs regular expressions, so I might was well use -# use perl -# -# -# -# -# safe-rm -# -# Put this in /root/.bashrc to help prevent accidental data loss. -# In any interactive shell, it aliases the rm command to a shell function -# that checks the arguments. Any attempt to delete something not in -# a subdirectory of /home will generate a warning message and prompt to -# continue. This should help to prevent accidentally deleting /etc or other -# important system files. -# -# Since the function and alias are only set for interactive shells, existing -# scripts will not need to be modified in any way. -# -# Also, if a user really needs to do a lot of deletion outside /home and gets -# annoyed by the prompt, s/he can either unalias rm or call /bin/rm directly. -# -# When installing this, be sure it comes _after_ any other "alias rm" command -# or else you will not be safe. -# - - -if [ ! -z "$PS1" ] ; then - - function safe-rm { - - Proceed=yes - Opts="" - - while : ; do - case $# in - 0) - break - ;; - esac - - Option=$1 - shift - - case ${Option} in - -*) - # ignore option switches - Opts="${Opts} ${Option}" - ;; - *) - # Found a filespec - Opts="$Opts ${Option}" - Parent=$(dirname $(readlink -m ${Option})) - echo "Parent = ${Parent}" - if [ "${Parent%${Parent#/home}}" != "/home" ] ; then - Proceed=no - fi - ;; - esac - done - - if [ "${Proceed}" = "no" ] ; then - echo " - -============ WARNING! ========== WARNING! ========== WARNING! ================= - -You are about to delete files or directories that are not in a users home -directory. Please review the rm command for any typos before proceeding. - -Type \"yes\" to continue. - - -" - read Proceed - fi - - if [ "${Proceed}" = "yes" ] ; then - echo "/bin/rm ${Opts}" - fi - } - - RM_Opts="" - alias | grep -q "alias rm=" - if [ $? -eq 0 ] ; then - RM_Opts=$(alias | awk '/alias rm=/ { sub(/^rm /, "", $2); print $2}' FS="'") - fi - - unalias rm 2> /dev/null - alias rm="safe-rm ${RM_Opts}" - -fi -