#!/bin/bash

if [ -z "$1" ]; then
  #echo "Usage: $0 version"
  #echo "Example: $0 2012_05_14"
  #exit 0
  version=`wget -q -O - http://boot.salstar.sk/pmagic.ipxe | grep ^item | head -1 | cut -d" " -f2`
  echo VERSION: $version
  sleep 1s
else
  version="$1"
fi

sfurl="https://sourceforge.net/projects/partedmagic/files/partedmagic"

update() {
  pushd $1
  if [ -f pmagic_pxe_$version/pmagic/bzImage ]; then
    popd
    return
  fi
  wget -c $sfurl/Parted%20Magic%20$version/pmagic_pxe_$version$2.zip/download \
    -O pmagic_pxe_$version$2.zip
  unzip pmagic_pxe_$version$2.zip
  popd
}

update . ""
update i686 _i686
update i586 _i586
#update x86_64 _x86_64

rm -f pmagic_pxe_$version*.zip */pmagic_pxe_$version*.zip
