%define pkg_version 1.2.5001
%define pkg_release 1%{?_dist_release}

Summary:Summary:     An integrated development environment (IDE) for R
Summary(ja): Rのための統合開発環境（サーバ版）
Name:        rstudio-server
Version:     %{pkg_version}
Release:     %{pkg_release}

License: AGPLv3
Group:   Applications/Edutainment
URL:     https://www.rstudio.com/
Source0: rstudio-%{version}.tar.gz
Source1: rserver.conf
Source2: rsession.conf

Source11: core-dictionaries.zip
Source12: mathjax-26.zip

# patch to avoid download necessary files
Patch1: rstudio-1.2-dependencies_common_not_download.patch

# patches to use system pandoc
Patch2: rstudio-1.2-rsession-dev.conf.patch
Patch3: rstudio-1.2-SessionOptions.cpp.patch
Patch4: rstudio-1.2-session_CMakeLists.txt.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root

BuildRequires: cmake
BuildRequires: rstudio-gwt >= 1.2
BuildRequires: R >= 3.6
BuildRequires: pandoc pandoc-citeproc

# java-1.8.0-openjdk-devel is needed
BuildRequires: java-1.8.0-openjdk-devel
BuildRequires: ant >= 1.9
BuildRequires: xml-commons-apis
BuildRequires: libuuid-devel
BuildRequires: openssl-devel
BuildRequires: pam-devel
BuildRequires: pango-devel
BuildRequires: bzip2-devel zlib-devel

# libboost >= 1.63.0
BuildRequires: libboost-devel
BuildRequires: libboost
BuildRequires: libboost-atomic
BuildRequires: libboost-date-time
BuildRequires: libboost-filesystem
BuildRequires: libboost-iostreams
BuildRequires: libboost-program-options
BuildRequires: libboost-random
BuildRequires: libboost-regex
BuildRequires: libboost-signals
BuildRequires: libboost-system
BuildRequires: libboost-thread
BuildRequires: libboost-chrono

Requires: R
Requires: pandoc pandoc-citeproc
Requires: java-1.8.0-openjdk


Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
RStudio Server enables you to provide a browser based interface
(the RStudio IDE) to a version of R running on a remote Linux server.
Deploying R and RStudio on a server has a number of benefits, including:
- The ability to access your R workspace from any computer in any location;
  Easy sharing of code, data, and other files with colleagues;
- Allowing multiple users to share access to
  the more powerful compute resources (memory, processors, etc.)
  available on a well equipped server; and Centralized installation and
  configuration of R, R packages, TeX, and other supporting libraries.

%description -l ja
RStudio Serverは離れた場所にあるLinuxサーバ上で走っている
Rのバージョンに対してブラウザベースのインタフェイス(the RStudio IDE)
を提供します。
サーバ上にRとRStudioを配置すると以下のような数多くの利点があります：
- あなたのRの作業スペースにどんな場所にあるどんなコンピュータからも
  アクセスできます。
  同僚とたやすくコードやデータその他のファイルを共有できます。
- 複数のユーザが十分な装備を備えたサーバ上で利用可能な、
  より強力な計算資源（メモリ、CPUなど）を共有できます。
  RやRパッケージ、TeXその他のサポートライブラリを集権的にインストール、
  設定することができます。


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q -n rstudio-%{version}

# patch to avoid download necessary files
%patch1

# patches to use system pandoc
%patch2
%patch3
%patch4

%{__cp} /usr/src/rstudio-gwt/* \
 %{_builddir}/rstudio-%{version}/dependencies/common

%{__cp} \
 %{SOURCE11} %{SOURCE12} \
 %{_builddir}/rstudio-%{version}/dependencies/common

pushd dependencies/common
 sh install-gwt;
 sh install-dictionaries;
 sh install-mathjax;
popd

%build
%{__mkdir_p} build
pushd build
cmake .. \
      -DRSTUDIO_TARGET=Server \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=%{_libdir}/rstudio-server
%{__make} %{?_smp_mflags}
popd

%install
pushd build
%{make_install}
popd

# make symbolic link
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_sbindir}
%{__ln_s} %{_libdir}/rstudio-server/bin/rstudio-server \
 ${RPM_BUILD_ROOT}%{_sbindir}/

# RStudio setting files
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_sysconfdir}/rstudio
%{__cp} %{SOURCE1} %{SOURCE2} ${RPM_BUILD_ROOT}%{_sysconfdir}/rstudio/

# PAM setting
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_sysconfdir}/pam.d
%{__cp} ${RPM_BUILD_ROOT}%{_libdir}/rstudio-server/extras/pam/rstudio \
 ${RPM_BUILD_ROOT}%{_sysconfdir}/pam.d/

# init.d setting
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_sysconfdir}/init.d/
%{__cp} ${RPM_BUILD_ROOT}%{_libdir}/rstudio-server/extras/init.d/redhat/rstudio-server \
 ${RPM_BUILD_ROOT}%{_sysconfdir}/init.d/

%clean
%{__rm} -rf ${RPM_BUILD_ROOT}

%pre
if [ "$1" -eq 1 ]; then
  /usr/sbin/useradd rstudio-server -M -s /sbin/nologin >/dev/null 2>&1 || :;
fi;

%post
%{_syssbindir}/chkconfig --add rstudio-server
%{__mkdir_p} %{_var}/{run,lock,log,lib}/rstudio-server
%{__chmod} 600 %{_var}/{run,lock,log,lib}/rstudio-server
%{__chown} rstudio-server:rstudio-server \
 %{_var}/{run,lock,log,lib}/rstudio-server

%preun
if [ "$1" -eq 0 ]; then
   %{_syssbindir}/service rstudio-server stop >/dev/null 2>&1 || :
   %{_syssbindir}/chkconfig --del rstudio-server ||:
fi

%postun
%{__rm} -rf /var/{run,lock,log,lib}/rstudio-server


%files
%defattr(-, root, root)
%doc COPYING NOTICE *.md
%{_sysconfdir}/init.d/rstudio-server
%{_sysconfdir}/pam.d/rstudio
%{_sysconfdir}/rstudio/
%{_libdir}/rstudio-server
%{_sbindir}/


%changelog
* Mon Oct 28 2019 Toshiaki Ara <ara_t@384.jp> 1.2.5000-1
- update to 1.2.5001

* Fri Nov 16 2018 Toshiaki Ara <ara_t@384.jp> 1.1.463-1
- new upstream release

* Thu Nov 01 2018 Toshiaki Ara <ara_t@384.jp> 1.1.456-2
- rebuild with openssl-1.1.1

* Sun Aug 19 2018 Toshiaki Ara <ara_t@384.jp> 1.1.456-1
- new upstream release
- drop SOURCE13 and SOURCE14

* Fri Jan 12 2018 Toshiaki Ara <ara_t@384.jp> 1.1.412-1
- new upstream release
- add BuildRequires: libboost-random
- update Patches

* Fri Aug 05 2016 Toshiaki Ara <ara_t@384.jp> 0.99.1274-1
- new package

