#!/bin/bash # # Helper script for install-assist package. # arguments 1:package name, 2 and on: download url # # NOTE: To avoid scriptlet failure during rpm transaction, # This script should always return 0 even if there is an error. TEXTDOMAIN=self-build-setup TEXTDOMAINDIR=/usr/share/locale _NAME=$1 _QUEDIR=/var/cache/self-build _ARCHIVEDIR=/var/cache/apt/archives . /etc/self-build.conf # create temporary directory to save downloaded file(s) if ! _TOPDIR=`mktemp -d $TEMP_DIR/$_NAME.XXXXXX`; then echo -n " " echo $"*ERROR: can't crete temporary directory." exit 0 fi # get target package echo -n " " echo $"Downloading rpm files..." shift 1 for u in $@; do # if you already downloaded rpm files, # then copy these from archived directory _TGT=$_TOPDIR/$(basename $u) _ARCHIVEDTGT=$_ARCHIVEDIR/$(basename $u) if [ "$CACHE_DOWNLOADED_FILES" = "yes" ]; then [ -s $_ARCHIVEDTGT ] && cp -af $_ARCHIVEDTGT $_TGT fi [ -s $_TGT ] && continue if [ ! $DL_SHOW_PROGRESS = "yes" ]; then # run quiet, no GUI wget -q -P $_TOPDIR $u RESULT=$? elif [ -z `pgrep -n synaptic` ]; then # run verbose, no GUI (because no synaptic running) wget -P $_TOPDIR $u RESULT=$? else # run verbose with GUI (zenity) wget -P $_TOPDIR $u 2>&1 | \ sed -u 's/.* \+\([0-9]\+%\).*$/\1/' 2>/dev/null | \ zenity --auto-close --progress \ --title $"Download files" \ --text $"Downloading $(basename $u)..." & # workaround for killing remaining wget process when cancel button pressed. WGETPID=`pgrep -f "wget -P $_TOPDIR $u"` ZENITYPID=$! # last child pid = zenity pid RESULT=0 # hold exit status of zenity RUNNING=0 while [ $RUNNING -eq 0 ] do sleep 1 if [ -z `ps -p $ZENITYPID -o pid=` ]; then if [ `ps -p $WGETPID -o pid=` ]; then # if zenity exited but wget still running, # then we suppose that zenity is cancelled by user. sleep 3 kill -KILL $WGETPID RESULT=1 fi RUNNING=1 fi done fi [ $RESULT -ne 0 -a -e $_TGT ] && rm -f $_TGT done for f in $(echo $@|xargs -r -n1 basename|sort -u); do if [ ! -s $_TOPDIR/$f ]; then echo -n " " echo $"*ERROR: can't download rpm files."": $f" rm -rf $_TOPDIR exit 0 fi done echo -n " " echo $"Rpm files downloaded successfully." # move rpm to que directory and remove temporary diractory mv -f $_TOPDIR/* $_QUEDIR rm -rf $_TOPDIR exit 0