#! /bin/sh

echo " *** RM OLD ENV"

rm dist/ -rf
rm linux-pamhyr-venv -rf

echo " *** SETUP ENV"

python3 -m venv linux-pamhyr-venv
. linux-pamhyr-venv/bin/activate
pip3 install -r ../requirements.txt

echo " *** PYINSTALL"

pyinstaller -y                                                          \
            --paths linux-pamhyr-venv/lib/python3.8/site-packages       \
            ../src/pamhyr.py

echo " *** MAKE QM"

# Update TS and build QM files
OLD_PWD=$PWD
cd ../src/lang/
./create_ts.sh
cd $OLD_PWD

echo " *** COPY DATA"

mkdir -p dist/pamhyr/View/ui
cp -r ../src/View/ui/ressources/ dist/pamhyr/View/ui/
cp -r ../src/View/ui/Widgets/*.ui dist/pamhyr/View/ui/
cp -r ../src/View/ui/*.ui dist/pamhyr/View/ui/

mkdir -p dist/pamhyr/lang
cp -r ../src/lang/*.qm dist/pamhyr/lang/

cp ../VERSION dist/pamhyr/
cp ../AUTHORS dist/pamhyr/

cp ../mage/src/build/mage dist/pamhyr/
cp ../mage/src/build/mage_extraire dist/pamhyr/
cp ../mage/src/build/mailleurPF dist/pamhyr/

echo " *** MAKE SRC PACKAGE"

OLD_PWD=$PWD
cd ../
git archive --format=tar.gz -o pamhyr-src.tar.gz HEAD
cd $OLD_PWD

mv ../pamhyr-src.tar.gz ./

echo " *** MAKE BIN PACKAGE"

OLD_PWD=$PWD
cd dist/
tar --xz -cf pamhyr-gnulinux-amd64.tar.xz pamhyr --checkpoint=.100
cd $OLD_PWD

mv dist/pamhyr-gnulinux-amd64.tar.xz ./

echo " *** DONE"
