From 467c466b7121a6c2fc62e5de1e538f3b1d95d562 Mon Sep 17 00:00:00 2001 From: Sebastian Schmelzer Date: Tue, 9 Jun 2009 19:22:30 +0000 Subject: add dialog based download script to preboot-scripts git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@2946 95ad53e4-c205-0410-b2fa-d234c58c8868 --- boot-env/preboot/preboot-scripts/dialog.functions | 81 +++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 boot-env/preboot/preboot-scripts/dialog.functions (limited to 'boot-env/preboot/preboot-scripts/dialog.functions') diff --git a/boot-env/preboot/preboot-scripts/dialog.functions b/boot-env/preboot/preboot-scripts/dialog.functions new file mode 100644 index 00000000..a9e76bdd --- /dev/null +++ b/boot-env/preboot/preboot-scripts/dialog.functions @@ -0,0 +1,81 @@ +# Copyright (c) 2009 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# dialog.functions +# provides shell scripts for dialog handling +# ----------------------------------------------------------------------------- + +# set -x + +if [ "x" == "x$DIALOG_HEIGHT" ]; then + DIALOG_HEIGHT="10" +fi + +if [ "x" == "x$DIALOG_WIDTH" ]; then + DIALOG_WIDTH="40" +fi + +_ddownload_checkpercentage () { + local lf=$1 + percentage=$(tail -n 5 $lf | sed 's/\.//g' | awk '{print $2}'| sed -n "s/%//p"| tail -n 1) + return $percentage +} + +ddownload () { + local dl_url=$1 + local dl_titel=$2 + local dl_outfile=$3 + local dl_logfile=$4 + + local dl_server=$(dirname $dl_url) + local dl_file=$(basename $dl_url) + + local dl_count + + if [ "x" == "x$dl_logfile" ]; then + dl_logfile="/tmp/logfile.$$" + fi + + if [ "x" == "x$dl_outfile" ]; then + dl_outfile="$dl_file" + fi + + if [ "x" == "x$dl_title" ]; then + dl_title="Downloading $dl_file .." + fi + + if [ -f "$dl_logfile" ]; then + rm $dl_logfile + fi + + # start wget in background + wget -v -b $dl_url -o "$dl_logfile" -O $dl_outfile + + sleep 0.1; + _ddownload_checkpercentage "$dl_logfile" + + dl_count=$? + + while [ $dl_count -le 99 ]; + do + echo $dl_count |dialog --gauge "$dl_title" $DIALOG_HEIGHT $DIALOG_WIDTH + sleep 0.5 + _ddownload_checkpercentage "$dl_logfile" + dl_count=$? + done + + local finished=0 + while [ ! $finished ]; do + finished=$(tail -n 4 $dl_logfile | grep -c "$dl_file"); + done + + echo 100 | dialog --gauge "$dl_title" $DIALOG_HEIGHT $DIALOG_WIDTH; + +} -- cgit v1.2.3-55-g7522