source: projects/self-build-setup/tags/0.9.7/get-binary-rpm.sh @ 439

Revision 439, 2.7 KB checked in by munepi, 14 years ago (diff)

added CACHE_DOWNLOADED_FILES option to cache downloaded files

  • Property svn:executable set to *
Line 
1#!/bin/bash
2#
3# Helper script for install-assist package.
4# arguments 1:package name, 2 and on: download url
5#
6# NOTE: To avoid scriptlet failure during rpm transaction,
7#       This script should always return 0 even if there is an error.
8
9TEXTDOMAIN=self-build-setup
10TEXTDOMAINDIR=/usr/share/locale
11
12_NAME=$1
13_QUEDIR=/var/cache/self-build
14_ARCHIVEDIR=/var/cache/apt/archives
15
16. /etc/self-build.conf
17
18# create temporary directory to save downloaded file(s)
19if ! _TOPDIR=`mktemp -d $TEMP_DIR/$_NAME.XXXXXX`; then
20    echo -n "     "
21    echo $"*ERROR: can't crete temporary directory."
22    exit 0
23fi
24
25# get target package
26echo -n "     "
27echo $"Downloading rpm files..."
28shift 1
29for u in $@; do
30    # if you already downloaded rpm files,
31    # then copy these from archived directory
32    _TGT=$_TOPDIR/$(basename $u)
33    _ARCHIVEDTGT=$_ARCHIVEDIR/$(basename $u)
34    if [ "$CACHE_DOWNLOADED_FILES" = "yes" ]; then
35        [ -s $_ARCHIVEDTGT ] && cp -af $_ARCHIVEDTGT $_TGT
36    fi
37    [ -s $_TGT ] && continue
38
39    if [ ! $DL_SHOW_PROGRESS = "yes" ]; then
40        # run quiet, no GUI
41        wget -q -P $_TOPDIR $u
42        RESULT=$?
43    elif [ -z `pgrep -n synaptic` ]; then
44        # run verbose, no GUI (because no synaptic running)
45        wget -P $_TOPDIR $u
46        RESULT=$?
47    else
48        # run verbose with GUI (zenity)
49        wget -P $_TOPDIR $u 2>&1 | \
50             sed -u 's/.* \+\([0-9]\+%\).*$/\1/' 2>/dev/null | \
51             zenity --auto-close --progress \
52                     --title $"Download files" \
53                     --text $"Downloading $(basename $u)..." &
54
55        # workaround for killing remaining wget process when cancel button pressed.
56        WGETPID=`pgrep -f "wget -P $_TOPDIR $u"`
57        ZENITYPID=$!                        # last child pid = zenity pid
58        RESULT=0                            # hold exit status of zenity
59
60        RUNNING=0
61        while [ $RUNNING -eq 0 ]
62        do
63            sleep 1
64            if [ -z `ps -p $ZENITYPID -o pid=` ]; then
65                if [ `ps -p $WGETPID -o pid=` ]; then
66                    # if zenity exited but wget still running,
67                    # then we suppose that zenity is cancelled by user.
68                    sleep 3
69                    kill -KILL $WGETPID
70                    RESULT=1
71                fi
72            RUNNING=1
73            fi
74        done
75    fi
76    [ $RESULT -ne 0 -a -e $_TGT ] && rm -f $_TGT   
77done
78for f in $(echo $@|xargs -r -n1 basename|sort -u); do
79    if [ ! -s $_TOPDIR/$f ]; then
80        echo -n "     "
81        echo $"*ERROR: can't download rpm files."": $f"
82        rm -rf $_TOPDIR
83        exit 0
84    fi
85done
86
87echo -n "     "
88echo $"Rpm files downloaded successfully."
89
90# move rpm to que directory and remove temporary diractory
91mv -f $_TOPDIR/* $_QUEDIR
92rm -rf $_TOPDIR
93
94exit 0
Note: See TracBrowser for help on using the repository browser.