source: projects/self-build-setup/tags/0.9.8/get-binary-rpm.sh @ 478

Revision 478, 2.3 KB checked in by kazutaka, 14 years ago (diff)

zenity でのプログレスの表示方法を self-build-rpm.sh に揃えた

  • 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        DLSTAT=0
50        DLSTAT=(`wget -P $_TOPDIR $u 2>&1 | \
51             sed -u 's/.* \+\([0-9]\+%\).*$/\1/' 2>/dev/null | \
52             zenity --auto-close --progress --auto-kill \
53                     --title $"Download files" \
54                     --text $"Downloading $(basename $u)..."; echo ${PIPESTATUS[0]}`)
55        RESULT=$?
56        # need to use string cpmparison for DLSTAT because PIPESTATUS[0] returns
57        # null value when wget is killed with zenity auto-kill function.
58        if [ "$DLSTAT" == "0" ] && [ $RESULT -eq 0 ]; then
59            RESULT=0
60        else
61            RESULT=1
62        fi
63    fi
64    [ $RESULT -ne 0 -a -e $_TGT ] && rm -f $_TGT   
65done
66for f in $(echo $@|xargs -r -n1 basename|sort -u); do
67    if [ ! -s $_TOPDIR/$f ]; then
68        echo -n "     "
69        echo $"*ERROR: can't download rpm files."": $f"
70        rm -rf $_TOPDIR
71        exit 0
72    fi
73done
74
75echo -n "     "
76echo $"Rpm files downloaded successfully."
77
78# move rpm to que directory and remove temporary diractory
79mv -f $_TOPDIR/* $_QUEDIR
80rm -rf $_TOPDIR
81
82exit 0
Note: See TracBrowser for help on using the repository browser.