#!/bin/sh LOADFILE=$1 FILEPERM=$2 LOCALDR=$3 CONFFILE="downloader.cfg" CONFPATH="/mod/etc/conf/" if [ ! -r "$CONFPATH$CONFFILE" ]; then echo "Error[downloader]: not configured" 1>&2 exit 1 fi . $CONFPATH$CONFFILE ISFTP=$(echo $DOWNLOADER_SRVPRFX | grep -c ftp://) if [ $ISFTP -eq 1 ]; then if [ "$DOWNLOADER_SRVUSR" ]; then if [ "$DOWNLOADER_SRVPWD" ]; then SERVERSTR=ftp://$DOWNLOADER_SRVUSR:$DOWNLOADER_SRVPWD@$DOWNLOADER_SRVURL$DOWNLOADER_SRVDIR/ else SERVERSTR=ftp://$DOWNLOADER_SRVUSR@$DOWNLOADER_SRVURL$DOWNLOADER_SRVDIR/ fi else SERVERSTR=ftp://$DOWNLOADER_SRVURL$DOWNLOADER_SRVDIR/ fi else ISHTTP=$(echo $DOWNLOADER_SRVPRFX | grep -c http://) if [ $ISHTTP -eq 1 ]; then SERVERSTR=http://$DOWNLOADER_SRVURL$DOWNLOADER_SRVDIR/ else echo "$DOWNLOADER_SRVPRFX is wrong server prefix in $CONFPATH$CONFFILE" exit 1 fi fi echo "Downloading of $LOADFILE from $SERVERSTR:" LOADERROR=1 # define false II=1 while [ $II -le $DOWNLOADER_NREP ] do echo -n "1. Ping test $II of $DOWNLOADER_NREP for $DOWNLOADER_SRVURL ... " if (ping -c 1 $DOWNLOADER_SRVURL > /dev/null 2>&1); then echo "done" echo -n "1.1. $LOCALDR is being created ... " mkdir -p $LOCALDR echo -n "2. $LOADFILE.gz is downloading from $DOWNLOADER_SRVURL ... " wget -q -O $LOCALDR/$LOADFILE.gz $SERVERSTR$LOADFILE.gz LOADERROR=$? break else echo "failed" fi let II++ echo -n "1a. Waiting $DOWNLOADER_TWAIT secs ... " sleep $DOWNLOADER_TWAIT echo "done" done if [ $LOADERROR -eq 1 ]; then echo "failed" echo "file $LOADFILE.gz could not be loaded" echo "echo $LOADFILE does not exist" > $LOCALDR/$LOADFILE chmod $FILEPERM $LOCALDR/$LOADFILE exit $LOADERROR fi echo "done" if [ -e $LOCALDR/$LOADFILE ]; then echo -n "2a. $LOCALDR/$LOADFILE exists already. deleting $LOADFILE ... " chmod "777" $LOCALDR/$LOADFILE rm -f $LOCALDR/$LOADFILE LOADERROR=$? if [ $LOADERROR -eq 1 ]; then echo "failed" echo "file $LOCALDR/$LOADFILE could not be deleted" exit $LOADERROR fi echo "done" fi echo -n "3. unpacking $LOADFILE.gz ... " gzip -df $LOCALDR/$LOADFILE.gz LOADERROR=$? if [ $LOADERROR -eq 1 ]; then echo "failed" echo "file $LOADFILE.gz could not be unpacked" exit $LOADERROR fi echo "done" echo -n "4. setting permissions for $LOADFILE ... " chmod $FILEPERM $LOCALDR/$LOADFILE LOADERROR=$? if [ $LOADERROR -eq 1 ]; then echo "failed" echo "permissions for file $LOADFILE could not be set" exit $LOADERROR fi echo "done" exit 0