1#!/bin/bash
2dirname=${PWD##*/}
3if ! [[ "$dirname" =~ ^lazpaint-[0-9]+(\.[0-9]+)*$ ]]; then
4    echo "Parent folder name must be \"lazpaint-#[.#][.#]\" but is \"$dirname\" instead"
5    echo "where #[.#][.#] is the app version number"
6    exit 1
7fi
8if ! [ -d bgrabitmap ] || ! [ -d bgracontrols ]; then
9    echo "Cannot find bgrabitmap or bgracontrols subdirectories."
10    exit 1
11fi
12if [ -d bgrabitmap/test ] || [ -d lazpaint/release/windows ]; then
13    echo "Lazarus custom packages have not been pruned. Call ./prune_lpk first"
14    exit 1
15fi
16archive=${dirname/-/_}.orig.tar.gz
17read -p "Create \"../${archive}\" file (y/n)?" -n 1 -r
18echo
19if [[ $REPLY =~ ^[Yy]$ ]]
20then
21    make distclean
22
23    cd ..
24    tar --exclude=./${dirname}/debian --exclude-vcs -zcvf ${archive} ./${dirname}
25    cd "$dirname"
26    echo "Done creating ../${archive}"
27    echo
28    read -p "Launch \"debuild -us -uc\" on the package now (y/n)?" -n 1 -r
29    echo
30    if [[ $REPLY =~ ^[Yy]$ ]]
31    then
32    	debuild -us -uc
33    fi
34fi
35
36