#!/bin/bash
#**********************************************************************
#* Auteur : Martin VINCENT (MVincent) [email protected]
#* Fichier : rm.scp
#* Répertoire : localhost:/home/vincenma/bin/
#* Créé le : 23 janvier 2001 11:30:16 (-0500)
#* Modifié le : 5 février 2014 18:45:07 (-0500) par : mvincent
#* Sauvegarde # : 50
#* Ver. CVS GMT : $Id: rm.scp,v 1.6 2014/02/05 18:45:07 admin Exp $
#**********************************************************************
TRASH=$HOME/poubelle
CONFIRM=0
VERSION="1.5" #1.4 : reation de poubelle/ si inexistant
#DATE=`date -d"+${1:-0} day" +"%d%b%Y_%Hh%Mm%Ss" | tr \'[:upper:]\' \'[:lower:]\' `
PROMPT=`echo $PS1`
# detect OS
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
OS='osx'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under Linux platform
OS='linux'
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
# Do something under Windows NT platform
OS='windows'
fi
if [ $# -lt 1 ]; then
echo "R v.${VERSION}"
echo "-----------------------------------------------------"
echo "USAGE: ${0} [-fhip] fichiers"
echo "Options (mutuellement exclusive):"
echo " -f: Suppression d�finitive"
echo " -h: Aide"
echo " -i: Avec confirmations"
echo " -p: Vider la ${TRASH}"
exit 0
fi
if [ $1 = "-h" ]; then
echo "R v.${VERSION}"
echo "-----------------------------------------------------"
echo "USAGE: ${0} [-fhip] fichiers"
echo "Options (mutuellement exclusive):"
echo " -f: Suppression d�finitive"
echo " -h: Aide"
echo " -i: Avec confirmations"
echo " -p: Vider la ${TRASH}"
exit 0
fi
### function cecho : outputs echo with color
if [ "$OS" == "osx" ]; then
black='\033[30m'
red='\033[31m'
green='\033[32m'
yellow='\033[33m'
blue='\033[34m'
magenta='\033[35m'
cyan='\033[36m'
white='\033[37m'
bold="\033[1m"
NONE="\033[m"
elif [ "$OS" == "linux" ]; then
black='\E[30;40m'
red='\E[31;40m'
green='\E[32;40m'
yellow='\E[33;40m'
blue='\E[34;40m'
magenta='\E[35;40m'
cyan='\E[36;40m'
white='\E[37;40m'
bold="\033[1m"
NONE="\033[0;38m"
fi
# \[\e[0;96m\]/\u@\[\e[0;31m\]192.168.1.180\[\e[0;96m\]:\w/ \[\e[0m\]
# > \e[1mBold Text\e[m\n\
# > \e[4mUnderline Text\e[m\n\
# > \e[5mBlink Text\e[m\n\
# > \e[7mInverse Text\e[m\]\n\
# > Should be normal text
# \e[0;30m30: Black
# > \e[0;31m31: Red
# > \e[0;32m32: Green
# > \e[0;33m33: Yellow\Orange
# > \e[0;34m34: Blue
# > \e[0;35m35: Magenta
# > \e[0;36m36: Cyan
# > \e[0;37m37: Light Gray\Black
# > \e[0;39m39: Default
# > Bright foreground colors:
# > \e[1;30m30: Dark Gray
# > \e[1;31m31: Red
# > \e[1;32m32: Green
# > \e[1;33m33: Yellow
# > \e[1;34m34: Blue
# > \e[1;35m35: Magenta
# > \e[1;36m36: Cyan
# > \e[1;37m37: White
# > \e[0;39m39: Default
# > \e[m\]Background colors:
# > \[\e[1;37m\e[40m40: Black\e[0;49m
# > \e[41m41: Red\e[0;49m
# > \e[42m42: Green\e[0;49m
# > \e[43m43: Yellow\Orange\e[0;49m
# > \e[44m44: Blue\e[0;49m
# > \e[45m45: Magenta\e[0;49m
# > \e[46m46: Cyan\e[0;49m
# > \e[47m47: Light Gray\Black\e[0;49m
# > \e[49m49: Default\e[m\]
cecho ()
# Color-echo.
# Argument $1 = message
# Argument $2 = color
# Argument $3 = bold colr code if wanted
{
local default_msg="No message passed."
# Doesn't really need to be a local variable.
local noCarriageReturn=""
local boldBoolean=""
message=${1:-$default_msg} # Defaults to default message.
color=${2:-$white} # Defaults to black, if not specified.
boldBoolean=${3:-""} # Defaults to no $noBold
# carriageReturn=${3:-$noCarriageReturn} # Defaults to no $noCarriageReturn
#echo $carriageReturn -e "$bold$color"
#echo $carriageReturn "$message"
echo -n -e "$boldBoolean$color"
echo $carriageReturn "$message"
echo -n -e $NONE
return
}
### MAIN
if [ "-p" = ${1} ]; then
echo "INFO : Voulez-vous vider la ${TRASH} ?[on] \c"
read answer
if [ "$answer" = o ]; then
rm -Rf ${TRASH}/*
fi
exit 0
fi
if [[ "-f" = $1 || "$PWD" = "$TRASH" ]]; then
rm -R $@
exit 0
fi
if [ "-i" = $1 ]; then
shift
CONFIRM=1
fi
for file in $@
do
nopath=`echo $file | awk '{ x=split($1,y,"/"); print y[x]}'`
if [ -f $file -o -d $file ]; then
if [ ${CONFIRM} -eq 1 ]; then
cecho "INFO : suppresion de $file [on]?" $green
read answer
echo
if [ "$answer" = o ]; then
cecho "INFO : suppression de $file ..." $blue
if [ -f ${TRASH}/${nopath} -o -d ${TRASH}/${nopath} ]; then
mv ${TRASH}/${nopath} ${TRASH}/${nopath}.old
fi
mv $file ${TRASH}/${nopath}
touch -m ${TRASH}/${nopath}
else
cecho "INFO : ok, on saute $file" $yellow
fi
else
if [ ! -d ${TRASH} ]; then
cecho "INFO : repertoire ${TRASH} inexsitant...creation de ${TRASH} ..." $green
mkdir -p ${TRASH}
fi
if [ -f ${TRASH}/$file -o -d ${TRASH}/$file ]; then
cecho "INFO : copie de ${TRASH}/${nopath} vers ${TRASH}/${nopath}.old ..." $red
mv ${TRASH}/${nopath} ${TRASH}/${nopath}.old
fi
cecho "INFO : suppression de $file ..." $white
mv $file ${TRASH}/${nopath}
touch -m ${TRASH}/${nopath}
fi
else
cecho "ERREUR : fichier(s) inexistant : $file" $red $bold
echo -n
exit -1
fi
done
exit 0
mercredi 5 février 2014
rm.scp
Inscription à :
Articles (Atom)