#!/bin/sh

PACKAGE=conquest-dicom-server

VERSION=`dpkg-parsechangelog | sed -n -e 's/^Version: \(.*\)-[^-]*$/\1/p'`

TARFILE=${PACKAGE}_${VERSION}.orig.tar.gz
UPSTREAM=conquestlinux1417d.tar.gz

FOLDER=${PACKAGE}-${VERSION}

wget -c -O /tmp/$UPSTREAM ftp://ftp-rt.nki.nl/outbox/MarcelVanHerk/dicomserver/${UPSTREAM}

mkdir ${FOLDER}
tar xvf /tmp/${UPSTREAM} -C ${FOLDER}

# cleanup
# conv copy of libjasper (sigh)
#rm -rf ${FOLDER}/jasper-1.900.1-6ct/
# conv copy of libjpeg 6c:
#rm -rf ${FOLDER}/jpeg-6c/
# conv copy of lua 5.1.4
rm -rf ${FOLDER}/lua_*
# conv copy of sqlite3
rm ${FOLDER}/sqlite3.*
# ZeroBraneStudio
rm -rf ${FOLDER}/ZeroBraneStudio*
# clibs windows
rm -rf ${FOLDER}/clibs*
# logs
rm -f ${FOLDER}/*.log
# mak* files
rm -f ${FOLDER}/mak*
# conquest-pacs.sh
rm -rf ${FOLDER}/conquest-pacs.sh
# remove non-free file
rm -f ${FOLDER}/jasper-1.900.1-6ct/data/colorprofiles/srgb.icm

# remove DICOM test files:
rm -rf ${FOLDER}/data/samples/

# Unused PDFs
rm ${FOLDER}/jasper-1.900.1-6ct/doc/*.pdf

# zip file:
rm ${FOLDER}/jpeg-6c/jpeg-6c-changesmvh2.zip

# vc80.pdb ?
find ${FOLDER} -name vc80.pdb -delete

# remove executable bit from files (except configure script)
find ${FOLDER} -type f -not -name "*configure" -exec chmod a-x {} \;

# 
rm ${FOLDER}/data/dbase/conquest.db3

# webserver dir
rm -rf ${FOLDER}/webserver

# make distclean
(cd ${FOLDER}/jasper-1.900.1-6ct && make distclean)
(cd ${FOLDER}/jpeg-6c && make distclean)

GZIP="--best --no-name" tar cvfz ${TARFILE} ${FOLDER} 
rm -rf ${FOLDER}
