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

Name:		mattermost-plugin-webrtc
Version:	1.0.3
Release:	1%{?dist}
URL:            https://github.com/niklabh/mattermost-plugin-webrtc-video
Summary:	Plugin for Mattermost for a WebRTC Video Call
License:	Apache
BuildRequires:	golang
Requires:	mattermost


%description


%prep
%setup -q -T -c %{name}-%{version}
export GOPATH=`pwd`
mkdir -p src/github.com/niklabh/
cd src/github.com/niklabh/
git clone https://github.com/niklabh/mattermost-plugin-webrtc-video/


%build
export GOPATH=`pwd`
export PATH="bin:"$PATH
export GO111MODULE=on
cd src/github.com/niklabh/mattermost-plugin-webrtc-video/
git checkout tags/%{version}
pushd webapp
npm install
npm run build
popd
go build -o plugin.exe ./server


%install
mkdir -p %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/{server,webapp}
cp -rv src/github.com/niklabh/mattermost-plugin-webrtc-video/plugin.json %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/
sed 's/"executables": {/"executable": "server\/plugin.exe"/' -i %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/plugin.json
sed '/"darwin-amd64"/d' -i %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/plugin.json
sed '/"linux-amd64"/d' -i %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/plugin.json
sed -e '/"windows-amd64"/,+1d' -i %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/plugin.json
cp -rv src/github.com/niklabh/mattermost-plugin-webrtc-video/plugin.exe %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/server/
cp -rv src/github.com/niklabh/mattermost-plugin-webrtc-video/webapp/dist/main.js %{buildroot}%{mattermost_home}/plugins/mattermost-webrtc-video/webapp/


%files
%{mattermost_home}/plugins/mattermost-webrtc-video/plugin.json
%{mattermost_home}/plugins/mattermost-webrtc-video/server/plugin.exe
%{mattermost_home}/plugins/mattermost-webrtc-video/webapp/main.js


%changelog
