source: projects/self-build-setup/trunk/get-binary-rpm.sh @ 434

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

updated self-build-rpm.sh, get-binary-rpm.sh: keep/check downloaded files to/from cache directory

  • 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    [ -s $_ARCHIVEDTGT ] && cp -af $_ARCHIVEDTGT $_TGT
35    [ -s $_TGT ] && continue
36
37    if [ ! $DL_SHOW_PROGRESS = "yes" ]; then
38        # run quiet, no GUI
39        wget -q -P $_TOPDIR $u
40        RESULT=$?
41    elif [ -z `pgrep -n synaptic` ]; then
42        # run verbose, no GUI (because no synaptic running)
43        wget -P $_TOPDIR $u
44        RESULT=$?
45    else
46        # run verbose with GUI (zenity)
47        wget -P $_TOPDIR $u 2>&1 | \
48             sed -u 's/.* \+\([0-9]\+%\).*$/\1/' 2>/dev/null | \
49             zenity --auto-close --progress \
50                     --title $"Download files" \
51                     --text $"Downloading $(basename $u)..." &
52
53        # workaround for killing remaining wget process when cancel button pressed.
54        WGETPID=`pgrep -f "wget -P $_TOPDIR $u"`
55        ZENITYPID=$!                        # last child pid = zenity pid
56        RESULT=0                            # hold exit status of zenity
57
58        RUNNING=0
59        while [ $RUNNING -eq 0 ]
60        do
61            sleep 1
62            if [ -z `ps -p $ZENITYPID -o pid=` ]; then
63                if [ `ps -p $WGETPID -o pid=` ]; then
64                    # if zenity exited but wget still running,
65                    # then we suppose that zenity is cancelled by user.
66                    sleep 3
67                    kill -KILL $WGETPID
68                    RESULT=1
69                fi
70            RUNNING=1
71            fi
72        done
73    fi
74    [ $RESULT -ne 0 -a -e $_TGT ] && rm -f $_TGT   
75done
76for f in $(echo $@|xargs -r -n1 basename|sort -u); do
77    if [ ! -s $_TOPDIR/$f ]; then
78        echo -n "     "
79        echo $"*ERROR: can't download rpm files."": $f"
80        rm -rf $_TOPDIR
81        exit 0
82    fi
83done
84
85echo -n "     "
86echo $"Rpm files downloaded successfully."
87
88# move rpm to que directory and remove temporary diractory
89mv -f $_TOPDIR/* $_QUEDIR
90rm -rf $_TOPDIR
91
92exit 0
Note: See TracBrowser for help on using the repository browser.