This scripts show progress bar with ROX-Filer
1[EDIT] New version (1.1) now script use gtk progress bar, it's better because it uses GTK Theme
2[EDIT] no need recompile Rox, easy way : look my next message!
3[EDIT] 1.2 update script ! , better way
4[EDIT] fixed a bug with the cp command when an argument is missing
5[EDIT] My bad, I used "$1" "$2" too pass cp args, but "$@" better! update gtk_progress bar too / use rsync -ah = high speed
6[EDIT] You must have RSYNC version >= 3.1.1 (support for --info=progress2 option) and better secure off course
7[EDIT] update 2 scripts, now "--no-preserve=context,links" work, Thanks Mister Argolance for your patience.
Code: Select all
#!/bin/sh
#
# this script is called by ROX-Filer
#--------------$1 $2 $3
#--------------args / source / destination
# version 1.4 , correctif && soluce for --no-preserve=context,links args
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# you need rename /bin/cp as /bin/cp_original
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# copy this script in /bin and named it cp
# _______________________________________
# get pid of this script
p="$$"
cleanup () {
[ -f "/tmp/rsync.log" ] && rm /tmp/rsync.log
[ -f "/tmp/rsync_.log" ] && rm /tmp/rsync_.log
[ -f "/tmp/rsync_ok.log" ] && rm /tmp/rsync_ok.log
[ -f "/tmp/numeric" ] && rm /tmp/numeric
}
export -f cleanup
_term() {
# abort copy in ROX
cleanup
}
trap _term SIGTERM
# to be sure that it is ROX who calls
# get string name of process parent
proc=$(ps -p `ps -o ppid= -p $p` -o comm=)
# if it's ROX-filer caller
if [ "$proc" = "ROX-Filer" ] ; then
#check file size
[ -f "$3" ] && fz=$(du "$3" | awk -F " " '{print $1}' ) || fz=$(du "$2" | awk -F " " '{print $1}' )
# set limit = 70M, otherwise use standart cp binarie
limit="70000"
if [[ "$fz" -lt "$limit" ]] ; then
/bin/cp_original "$@"
exit 0
fi
if [ -f "/tmp/start_gtkbar" ] ; then
#always run
:
else
# start gtk
touch /tmp/rsync.log
touch /tmp/rsync_.log
# open gtk progress bar ->
/usr/local/bin/rsync_gtk.sh "$@" /dev/null 2>&1 &
fi
# check for '--no-preserve=context,links .... cp --args with comma ....'
if [ "$4" = "" ] ; then
rsync -ah --info=progress2 --append --inplace --partial -args --log-file="/tmp/rsync_.log" "$2" "$3" > /tmp/rsync.log
else
rsync -ah --info=progress2 --append --inplace --partial -args --log-file="/tmp/rsync_.log" "$3" "$4" > /tmp/rsync.log
fi
# force close gtk ->
echo "100%" >> /tmp/numeric
#cleanup log
cleanup
if [ -f "/tmp/start_gtkbar" ] ; then
rm /tmp/start_gtkbar
fi
# !! not ROX-filer , call original cp command !!
else
/bin/cp_original "$@"
fi
Code: Select all
#!/bin/sh
# rsync_gtk.sh
# show a progress bar and acces log from rsync
# version 1.4
# & just one progressbar, use GTK Theme!
# & update, kill tail from pid
# & update, force waiting to make sure it works.
# update title bar
# prevent multiple open
touch /tmp/start_gtkbar
# source name copy for title bar
if [ "$4" = "" ] ; then
title=`basename "$2"`
else
title=`basename "$3"`
fi
# food for progressbar
echo -e "[Start Copy]\n1%" > /tmp/numeric
# force wait because sometimes rsync log and gtkdialog operations take time so progressbar is froze
sleep 1
calculat () {
if [ -s "/tmp/rsync.log" ] ; then
tr '\r' '\n' < /tmp/rsync.log > /tmp/rsync_ok.log
i=$(cat /tmp/rsync_ok.log | tail -n 1 | awk -F " " '{print $2}' | tr -d '%')
x=$(tail -n 1 /tmp/rsync_ok.log | awk -F " " '{print "[" $3 " " $4 "]"}')
echo -e "$x \n $i%" >> /tmp/numeric
fi
}
export -f calculat
GTKDIALOG=gtkdialog
MAIN_DIALOG='
<window title="'$title'" icon_name="gtk-copy" resizable="true">
<progressbar sensitive="true">
<input>tail -f '"/tmp/numeric"' & echo "$!" > /tmp/rsync_gtk_pidnum</input>
<action function="closewindow">MAIN_DIALOG</action>
<action function="exit">Ready</action>
</progressbar>
<timer milliseconds="true" visible="false" interval="1000">
<action>calculat</action>
</timer>
</window>'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
# kill tail from pid
kill -9 `cat /tmp/rsync_gtk_pidnum`
rm /tmp/rsync_gtk_pidnum
[ -f "/tmp/start_gtkbar" ] && rm /tmp/start_gtkbar
[ -f "/tmp/rsync_gtk_pidnum" ] && rm /tmp/rsync_gtk_pidnum
...........................[ Preview ]