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

Revision 419, 2.5 KB checked in by munepi, 14 years ago (diff)

added self-build-setup

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