#!/bin/sh # # Show a progress bar. # # If kdialog/zenity are available they are used. # Progress data is read from the created pipe, echoing "quit" to the pipe will # cause the script to terminate, as will the progress reaching 100% # # Pressing cancle on a zenity dialog will terminate right away, kdialog will # only terminate when the next line of data is read from the pipe. # ISKDE=`pidof -x -s kdeinit` KDIALOG=`which kdialog` ISGNOME=`pidof -x -s gnome-panel` ZENITY=`which zenity` CAPTION=${1} FILESIZE=${2} progresswindow="" TYPE="" PIPE="progresspipe_${$}" retval="1" readprogress() { data="" input="" while [ -e ${PIPE} ]; do if [ "${TYPE}" = "KDE" ]; then if [ `dcop ${progresswindow} wasCancelled` = "true" ]; then break; fi fi; input=`cat "${PIPE}"` if [ "${input}" == "quit" ]; then break; elif [ "${input}" != "" ]; then data=${input} input="" res=`echo "scale=4 ; (${data}/${FILESIZE})*100" | bc` val=${res%%.*} if [ "${val}" = "" ]; then val=0 fi; if [ "${TYPE}" = "KDE" ]; then dcop ${progresswindow} setProgress ${val} if [ ${?} -ne 0 ]; then break; fi; elif [ "${TYPE}" = "GNOME" ]; then echo ${val} if [ $? -ne 0 ] ; then break; fi else if [ $((${val} % 2)) -eq 0 ]; then echo "-> "${val}"%" fi; fi; if [ "${val}" = "100" ]; then retval="0" break; fi; fi; done; } if [ "" = "${CAPTION}" -o "" = ${FILESIZE} ]; then echo "Insufficient Parameters." echo "Usage: ${0}