1#!/bin/bash
2
3set -x
4set -u
5set -e
6
7## Parameters
8TOKEN=$1
9ORGANIZATION="FreeFem"
10REPOSITORY="FreeFem-sources"
11VERSION=`grep AC_INIT configure.ac | cut -d"," -f2`
12RELEASE_TAG_NAME="v$VERSION"
13distrib=`uname -s`-`uname -r`
14
15DISTRIB="Ubuntu"
16
17DEB_NAME="freefem_${VERSION}-1_amd64"
18GH_DEB_NAME="FreeFEM_${VERSION}_${DISTRIB}_amd64.deb"
19
20## DEB build
21autoreconf -i
22./configure --enable-download --enable-optim --enable-generic
23./3rdparty/getall -a
24make -j4
25make -j4 install
26
27#create FreeFEM Debian package  with ff-petsc
28
29mkdir $DEB_NAME
30mkdir $DEB_NAME/DEBIAN
31touch $DEB_NAME/DEBIAN/control
32echo "Package: freefem" >> $DEB_NAME/DEBIAN/control
33echo "Version: "$VERSION >> $DEB_NAME/DEBIAN/control
34echo "Section: custom" >> $DEB_NAME/DEBIAN/control
35echo "Architecture: amd64" >> $DEB_NAME/DEBIAN/control
36echo "Depends: libc6 (>= 2.23), g++ (>= 7), gcc (>= 7), gfortran (>= 7), libgsl-dev (>=2.4), libhdf5-dev (>=1.10.0), liblapack-dev (>= 3.7), libopenmpi-dev (>=2.1.1) ,freeglut3-dev (>= 2.8.1) ">> $DEB_NAME/DEBIAN/control
37echo "Maintainer: FreeFEM, Frédéric Hecht <frederic.hecht@sorbonne-universite.fr> " >> $DEB_NAME/DEBIAN/control
38echo "Description: FreeFEM, Finite Element Language software" >> $DEB_NAME/DEBIAN/control
39echo "Homepage: https://freefem.org" >> $DEB_NAME/DEBIAN/control
40mkdir -p $DEB_NAME/usr/local
41mkdir -p $DEB_NAME/usr/local/share/FreeFEM
42mkdir -p $DEB_NAME/usr/local/bin
43mkdir -p $DEB_NAME/usr/local/lib/ff++
44mkdir -p $DEB_NAME/usr/share/doc/freefem
45
46cp -r /usr/local/lib/ff++/$VERSION $DEB_NAME/usr/local/lib/ff++/$VERSION
47cp -r /usr/local/share/FreeFEM/$VERSION $DEB_NAME/usr/local/share/FreeFEM/$VERSION
48cp -r /usr/local/bin/FreeFem++ $DEB_NAME/usr/local/bin/FreeFem++
49cp -r /usr/local/bin/FreeFem++-mpi $DEB_NAME/usr/local/bin/FreeFem++-mpi
50cp -r /usr/local/bin/FreeFem++-nw $DEB_NAME/usr/local/bin/FreeFem++-nw
51cp -r /usr/local/bin/bamg $DEB_NAME/usr/local/bin/bamg
52cp -r /usr/local/bin/cvmsh2 $DEB_NAME/usr/local/bin/cvmsh2
53cp -r /usr/local/bin/ff-c++ $DEB_NAME/usr/local/bin/ff-c++
54cp -r /usr/local/bin/ff-get-dep $DEB_NAME/usr/local/bin/ff-get-dep
55cp -r /usr/local/bin/ff-mpirun $DEB_NAME/usr/local/bin/ff-mpirun
56cp -r /usr/local/bin/ff-pkg-download $DEB_NAME/usr/local/bin/ff-pkg-download
57cp -r /usr/local/bin/ffglut $DEB_NAME/usr/local/bin/ffglut
58cp -r /usr/local/bin/ffmaster $DEB_NAME/usr/local/bin/ffmaster
59cp -r /usr/local/bin/ffmedit $DEB_NAME/usr/local/bin/ffmedit
60cp  AUTHORS $DEB_NAME/usr/share/doc/freefem/AUTHOR
61cp  README.md $DEB_NAME/usr/share/doc/freefem/README.md
62
63dpkg-deb --build $DEB_NAME/
64
65## Rename DEB to include Ubuntu version
66mv $DEB_NAME.deb $GH_DEB_NAME
67
68## Deploy in GitHub release
69RELEASE=`curl 'https://api.github.com/repos/'$ORGANIZATION'/'$REPOSITORY'/releases/tags/'$RELEASE_TAG_NAME`
70UPLOAD_URL=`printf "%s" "$RELEASE" | jq -r '.upload_url'`
71
72if [ -x $UPLOAD_URL ]
73then
74	echo "Release does not exists"
75	exit 1
76else
77  RESPONSE=`curl --data-binary "@$GH_DEB_NAME" -H "Authorization: token $TOKEN" -H "Content-Type: application/octet-stream" "$UPLOAD_URL=$GH_DEB_NAME"`
78fi
79
80# clean the VM
81rm -rf $DEB_NAME
82rm $GH_DEB_NAME
83
84. ./bin/uninstall-ff++
85