%define mattermost_user mattermost
%define mattermost_group mattermost
%define mattermost_home /var/lib/mattermost
%define debug_package %{nil}

Name:		mattermost-plugin-matterpoll
Version:	1.4.0
Release:	1%{?dist}
URL:		https://github.com/matterpoll/matterpoll
Summary:	Plugin for Mattermost and Github
License:	Apache
BuildRequires:	golang
Requires:	mattermost


%description


%prep
%setup -q -T -c %{name}-%{version}
export GOPATH=`pwd`
mkdir -p src/github.com/matterpoll/
pushd src/github.com/matterpoll/
git clone https://github.com/matterpoll/matterpoll
popd
mkdir -p src/github.com/mattermost/
pushd src/github.com/mattermost/
git clone https://github.com/mattermost/mattermost-utilities
popd


%build
export GOPATH=`pwd`
export PATH="bin:"$PATH
cd src/github.com/matterpoll/matterpoll
go build -o plugin.exe ./server
pushd webapp
npm install
npm run build
popd


%install
mkdir -p %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/{server,webapp}
cp -rv src/github.com/matterpoll/matterpoll/plugin.json %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/
sed 's/"executables": {/"executable": "server\/plugin.exe"/' -i %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/plugin.json
sed '/"darwin-amd64"/d' -i %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/plugin.json
sed '/"linux-amd64"/d' -i %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/plugin.json
sed '/"windows-amd64"/d' -i %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/plugin.json
sed '/\t },"/d' -i %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/plugin.json
cp -rv src/github.com/matterpoll/matterpoll/plugin.exe %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/server/
cp -rv src/github.com/matterpoll/matterpoll/webapp/dist/ %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/webapp/
cp -rv src/github.com/matterpoll/matterpoll/assets/ %{buildroot}%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/


%files
%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/plugin.json
%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/server/plugin.exe
%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/webapp/dist/main.js
%{mattermost_home}/plugins/com.github.matterpoll.matterpoll/assets/


%changelog
