| | #!/bin/sh |
---|
| | # trm.sh - Safer 'rm' |
---|
| | # trm.sh - Safer 'rm' And Backup Utility |
---|
| | # Copyright (c) 2016 TundraWare Inc., Des Plaines, IL USA |
---|
| | # All Rights Reserved |
---|
| | # Permission granted for the free use of this program without restriction |
---|
| | |
---|
| |
---|
| | |
---|
| | # Process arguments |
---|
| | |
---|
| | shift $((OPTIND-1)) |
---|
| | for arg in $* |
---|
| | while [ $# -gt 0 ] |
---|
| | do |
---|
| | |
---|
| | # Symlinks require special care |
---|
| | if [ -L $arg ] |
---|
| | # Symlinks require special care |
---|
| | if [ -L "$1" ] |
---|
| | then |
---|
| | |
---|
| | # Bare symlink itelf |
---|
| | REALPATH=$(readlink -f $(dirname "$1")) |
---|
| | if [ "${REALPATH}" = '/' ] |
---|
| | then |
---|
| | |
---|
| | # Bare symlink itelf |
---|
| | REALPATH=$(readlink -f $(dirname $arg)) |
---|
| | if [ ${REALPATH} = '/' ] |
---|
| | then |
---|
| | REALPATH="" |
---|
| | fi |
---|
| | |
---|
| | REALPATH=${REALPATH}/$(basename $arg) |
---|
| | |
---|
| | # Process normal files and directories |
---|
| | else |
---|
| | REALPATH=$(readlink -f $arg) |
---|
| | REALPATH="" |
---|
| | fi |
---|
| | |
---|
| | # See if we want serial numbers |
---|
| | SERIAL="" |
---|
| | if [ -n "${SERIALNO}" ] |
---|
| | then |
---|
| | SERIAL=".$(date +%Y%m%d%H%M%S)" |
---|
| | fi |
---|
| | REALPATH="${REALPATH}"/$(basename "$1") |
---|
| | |
---|
| | SRCDIR=$(dirname $REALPATH) |
---|
| | if [ ${SRCDIR} = '/' ] |
---|
| | then |
---|
| | SRCDIR="" |
---|
| | fi |
---|
| | SRCFIL=$(basename $REALPATH) |
---|
| | DESDIR=${GRAVEYARD}${SRCDIR} |
---|
| | DESFIL="${SRCFIL}${SERIAL}" |
---|
| | # Process normal files and directories |
---|
| | else |
---|
| | REALPATH=$(readlink -f "$1") |
---|
| | fi |
---|
| | |
---|
| | CMD="${OPERATOR} $VERBOSE '${REALPATH}' '${DESDIR}/${DESFIL}'" |
---|
| | if [ -n "${TESTMODE}" ] |
---|
| | then |
---|
| | echo ${TESTMODE} |
---|
| | echo ${CMD} |
---|
| | else |
---|
| | mkdir -p ${DESDIR} |
---|
| | eval ${CMD} |
---|
| | fi |
---|
| | # See if we want serial numbers |
---|
| | SERIAL="" |
---|
| | if [ -n "${SERIALNO}" ] |
---|
| | then |
---|
| | SERIAL=".$(date +%Y%m%d%H%M%S)" |
---|
| | fi |
---|
| | |
---|
| | SRCDIR=$(dirname "${REALPATH}") |
---|
| | if [ "${SRCDIR}" = '/' ] |
---|
| | then |
---|
| | SRCDIR="" |
---|
| | fi |
---|
| | |
---|
| | SRCFIL=$(basename "${REALPATH}") |
---|
| | DESDIR="${GRAVEYARD}${SRCDIR}" |
---|
| | DESFIL="${SRCFIL}${SERIAL}" |
---|
| | |
---|
| | CMD="${OPERATOR} $VERBOSE '${REALPATH}' '${DESDIR}/${DESFIL}'" |
---|
| | if [ -n "${TESTMODE}" ] |
---|
| | then |
---|
| | echo ${TESTMODE} |
---|
| | echo ${CMD} |
---|
| | else |
---|
| | mkdir -p "${DESDIR}" |
---|
| | eval ${CMD} |
---|
| | fi |
---|
| | |
---|
| | shift |
---|
| | |
---|
| | done |
---|
| | |
---|
| | } |
---|
| | |
---|
| | trm $* |
---|
| | # Uncomment to invoke as a free standing utility |
---|
| | |
---|
| | # trm "$@" |
---|
| | |
---|
| | |