File fetch-et-linux-2.60.x86.sh.in of Package enemy-territory-data

#!/bin/sh

EULA="http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/licenses/RTCW-ETEULA"

POST_MESSAGE="/var/adm/update-messages/__NAME__-__VERSION__-__RELEASE__-1"

SERVER=" \
ftp.gwdg.de/pub/misc/ftp.idsoftware.com/idstuff/et/linux    \
ftp5.gwdg.de/pub/misc/ftp.idsoftware.com/idstuff/et/linux   \
ftp.idsoftware.com/idstuff/et/linux     \
"

CURL_OPTIONS="-L -s --speed-limit 3500 --speed-time 15"

if [ ! -f /usr/bin/id -o ! -f /usr/bin/md5sum ]; then
 echo "Running in non-chrooted (install into directory) mode... Exit safely."
 exit 0
fi

if [ "`id -u`" != "0" ]; then
 echo "error: You must be root to use this program!"
 exit 1
fi

if [ ! -x /usr/bin/md5sum ]; then
  echo "error: md5sum missing! Please install package md5sum first."
  exit 2
fi

. /etc/sysconfig/proxy

if test "$PROXY_ENABLED" != "no"; then
  if test -n "$HTTP_PROXY" ; then
    export http_proxy="$HTTP_PROXY"
  fi
fi

if [ -z $http_proxy ]; then
  echo 
  echo "note: No proxy is used. Please set the environment variable \"http_proxy\""
  echo "note: to your favorite proxy, if you want to use a proxy for the download."
  echo "note:"
  echo "note:   bash: export http_proxy=\"http://proxy.example.com:3128/\""
  echo "note:   tcsh: setenv http_proxy \"http://proxy.example.com:3128/\""
fi

echo "EULA:"
echo -n "  Fetching   ... "
curl $CURL_OPTIONS -o /usr/share/doc/enemy-territory/RTCW-ETEULA $EULA || \
  rm -f /usr/share/doc/enemy-territory/RTCW-ETEULA
echo "done"

tmpname=`basename $0`
tmpdir=`mktemp -d /tmp/$tmpname.XXXXXX`
trap "rm -rf $tmpdir" EXIT
if [ $? -ne 0 ]; then
  echo "$0: Can't create temp dir, exiting..."
  exit 4
fi

pushd $tmpdir &> /dev/null

echo
echo "Trying to find the fastest server:"
besttime=1000

for server in $SERVER; do
  echo -n " $server ... "
  start=$SECONDS
  curl $CURL_OPTIONS --connect-timeout 10 -o et-linux-2.60-update.x86.run \
    http://$server/et-linux-2.60-update.x86.run
  if [ $? -ne 0 ]; then
    echo "too slow (aborted)"
    continue
  fi
  stop=$SECONDS
  time=$((stop - start))
  echo "$time sec"
  if [ $time -lt $besttime ]; then 
    besttime=$time
    useserver=$server
  fi
done

rm -f et-linux-2.60-update.x86.run
if [ -n "$useserver" ]; then
  echo "The winner is: >> $useserver <<"
  echo
else
  echo "Connection too slow or no server available. Aborting ... "
  exit 5
fi

for i in $useserver $SERVER; do
  archive=http://$i/et-linux-2.60.x86.run
  file=`echo $archive|awk -F "/" '{print $NF}'`
  rm -f $file
  echo "$file ($archive):"
  echo -n "  Fetching   ... "
  curl $CURL_OPTIONS -o $file $archive
  if [ $? -ne 0 ]; then
    rm -f $file
    echo "failed ... deleted!"
    continue
  fi
  success=true
  echo done
  break
done

if [ "x$success" != "x" ]; then 
  chmod +x et-linux-2.60.x86.run
  # Extract data from installer
  ./et-linux-2.60.x86.run --noexec --nox11 --keep --target enemy-territory
  # Remove shipped binaries and scripts
  rm enemy-territory/etmain/*.so
  rm -r enemy-territory/bin
  rm -r enemy-territory/pb
  # Remove misplaced and outdated documentation
  rm -rf enemy-territory/Docs/
  rm enemy-territory/README
  rm enemy-territory/CHANGES
  # remove the installer
  rm -r enemy-territory/setup.{data,sh}
  rm et-linux-2.60.x86.run
  cp -r enemy-territory /usr/lib
  rm -rf enemy-territory
  echo "*** Enemy Territory content files installed. ***" | tee $POST_MESSAGE
else
  echo "*** No Enemy Territory content files installed. ***" | tee $POST_MESSAGE
fi

test -f /usr/share/doc/enemy-territory/RTCW-ETEULA && w3m -dump /usr/share/doc/enemy-territory/RTCW-ETEULA | tee $POST_MESSAGE

popd &> /dev/null
openSUSE Build Service is sponsored by