[419] | 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 | |
---|
| 9 | TEXTDOMAIN=self-build-setup |
---|
| 10 | TEXTDOMAINDIR=/usr/share/locale |
---|
| 11 | |
---|
| 12 | _NAME=$1 |
---|
| 13 | _QUEDIR=/var/cache/self-build |
---|
[434] | 14 | _ARCHIVEDIR=/var/cache/apt/archives |
---|
[419] | 15 | |
---|
| 16 | . /etc/self-build.conf |
---|
| 17 | |
---|
| 18 | # create temporary directory to save downloaded file(s) |
---|
| 19 | if ! _TOPDIR=`mktemp -d $TEMP_DIR/$_NAME.XXXXXX`; then |
---|
| 20 | echo -n " " |
---|
| 21 | echo $"*ERROR: can't crete temporary directory." |
---|
| 22 | exit 0 |
---|
| 23 | fi |
---|
| 24 | |
---|
| 25 | # get target package |
---|
| 26 | echo -n " " |
---|
| 27 | echo $"Downloading rpm files..." |
---|
| 28 | shift 1 |
---|
| 29 | for u in $@; do |
---|
[434] | 30 | # if you already downloaded rpm files, |
---|
| 31 | # then copy these from archived directory |
---|
[419] | 32 | _TGT=$_TOPDIR/$(basename $u) |
---|
[434] | 33 | _ARCHIVEDTGT=$_ARCHIVEDIR/$(basename $u) |
---|
[439] | 34 | if [ "$CACHE_DOWNLOADED_FILES" = "yes" ]; then |
---|
| 35 | [ -s $_ARCHIVEDTGT ] && cp -af $_ARCHIVEDTGT $_TGT |
---|
| 36 | fi |
---|
[419] | 37 | [ -s $_TGT ] && continue |
---|
| 38 | |
---|
| 39 | if [ ! $DL_SHOW_PROGRESS = "yes" ]; then |
---|
| 40 | # run quiet, no GUI |
---|
[545] | 41 | wget -q -O $_TOPDIR/$(basename $u) $u |
---|
[419] | 42 | RESULT=$? |
---|
| 43 | elif [ -z `pgrep -n synaptic` ]; then |
---|
| 44 | # run verbose, no GUI (because no synaptic running) |
---|
[545] | 45 | wget -O $_TOPDIR/$(basename $u) $u |
---|
[419] | 46 | RESULT=$? |
---|
| 47 | else |
---|
| 48 | # run verbose with GUI (zenity) |
---|
[478] | 49 | DLSTAT=0 |
---|
[545] | 50 | DLSTAT=(`wget -O $_TOPDIR/$(basename $u) $u 2>&1 | \ |
---|
[419] | 51 | sed -u 's/.* \+\([0-9]\+%\).*$/\1/' 2>/dev/null | \ |
---|
[478] | 52 | zenity --auto-close --progress --auto-kill \ |
---|
[419] | 53 | --title $"Download files" \ |
---|
[478] | 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 |
---|
[419] | 63 | fi |
---|
| 64 | [ $RESULT -ne 0 -a -e $_TGT ] && rm -f $_TGT |
---|
| 65 | done |
---|
| 66 | for 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 |
---|
| 73 | done |
---|
| 74 | |
---|
| 75 | echo -n " " |
---|
| 76 | echo $"Rpm files downloaded successfully." |
---|
| 77 | |
---|
| 78 | # move rpm to que directory and remove temporary diractory |
---|
| 79 | mv -f $_TOPDIR/* $_QUEDIR |
---|
| 80 | rm -rf $_TOPDIR |
---|
| 81 | |
---|
| 82 | exit 0 |
---|