#/bin/sh
# This script checks if downloaded clouds are correct jpeg files
# (because often enough they were damaged and ugly looking)
# ...and I don't understand why it still fails sometimes :(

cloud_file_name=$XPHOME/clouds_2048.jpg;

# Checking before calling the actual download script:
if !(convert $cloud_file_name  -scale 10x5 /dev/null); then
  echo "Damaged cloud file! - deleting";
  rm $cloud_file_name;
fi

# this works, because download_clouds.pl only returns (0) when
# it really downloads new clouds:
if (perl $XPHOME/download_clouds.pl); then
  echo -n "Downloaded new clouds - checking...";
  if !(convert $cloud_file_name  -scale 10x5 /dev/null); then
    echo "damaged cloud file! - deleting...";
    rm $cloud_file_name;
  else
    echo "ok";
  fi;
fi;

