#!/bin/bash

# get new astap version from mercury repository at sourceforge

HG=`command -v hg`
UNZIP=`command -v unzip`
REPO="http://hg.code.sf.net/p/astap-program/code"

if [ -z "$HG" ]; then
  echo "E: hg not found"
  exit 1
fi
if [ -z "$UNZIP" ]; then
  echo "E: unzip not found"
  exit 1
fi

mkdir astap-upstream
cd astap-upstream
$HG clone $REPO
cd code
version=`LANG=C $HG log|grep summary|head -1|awk -F"'" '{printf("%s",$2)}'|tr -d "v"`
echo "I: version: $version"
cd ..
# prepare orig source
sourcedir=astap_$version.orig

mv code $sourcedir
cd $sourcedir
  # remove some stuff not needed for astap package
  rm -rf bayer_test_pattern command-line_version dcraw_modification debian_package_scripts documentation inno_scripts libraw_mod
  rm -rf .hg
  cd star_database_creation
    $UNZIP *
    rm *.zip
  cd ..
cd ..

tar -czf $sourcedir.tar.gz $sourcedir



