diff --git a/CMakeLists.txt b/CMakeLists.txt index 52472952f..74d20378f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -253,17 +253,19 @@ set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY} applications driver by real-time connected data.") # RPM specific -set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /var /var/lib /var/log /etc/logrotate.d /lib /lib/systemd /lib/systemd/system) -set(CPACK_RPM_PACKAGE_REQUIRES_PRE "shadow-utils,systemd") -# set(CPACK_RPM_USER_BINARY_SPECFILE "${CMAKE_SOURCE_DIR}/release/rpm/memgraph.spec.in") -set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/release/rpm/preinst") -set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/release/rpm/postinst") -set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/release/rpm/prerm") +set(CPACK_RPM_PACKAGE_URL https://memgraph.com) +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION + /var /var/lib /var/log /etc/logrotate.d + /lib /lib/systemd /lib/systemd/system /lib/systemd/system/memgraph.service) +set(CPACK_RPM_PACKAGE_REQUIRES_PRE "shadow-utils") +# NOTE: user specfile has a bug in cmake 3.7.2, this needs to be patched +# manually in: ~/cmake/share/cmake-3.7/Modules/CPackRPM.cmake line 2273 +# Or newer cmake version used +set(CPACK_RPM_USER_BINARY_SPECFILE "${CMAKE_SOURCE_DIR}/release/rpm/memgraph.spec.in") # Description formatting is important, no line must be greater than 80 characters. set(CPACK_RPM_PACKAGE_DESCRIPTION "Contains Memgraph, the graph database. - : It aims to deliver developers the speed, simplicity and scale - : required to build the next generation of applications driver by - : real-time connected data.") +It aims to deliver developers the speed, simplicity and scale required to build +the next generation of applications driver by real-time connected data.") # All variables must be set before including. include(CPack) diff --git a/release/arch-pkg/memgraph.install b/release/arch-pkg/memgraph.install index 80ea851cc..7e8d992ac 100644 --- a/release/arch-pkg/memgraph.install +++ b/release/arch-pkg/memgraph.install @@ -1,11 +1,9 @@ post_install() { # Add the 'memgraph' user and group and set permissions on # 'var/*/memgraph' directories. - useradd --system memgraph - res=$? - if [[ "$res" != "0" && "$res" != "9" ]]; then - exit 1 - fi + getent group memgraph >/dev/null || groupadd -r memgraph || exit 1 + getent passwd memgraph >/dev/null || \ + useradd -r -g memgraph -d /var/lib/memgraph memgraph || exit 1 chown memgraph:memgraph /var/lib/memgraph || exit 1 chmod 750 /var/lib/memgraph || exit 1 chown memgraph:adm /var/log/memgraph || exit 1 diff --git a/release/debian/postinst b/release/debian/postinst index 8692c45a5..b589521ce 100644 --- a/release/debian/postinst +++ b/release/debian/postinst @@ -21,7 +21,7 @@ case "$1" in configure) # Add the 'memgraph' user and group and set permissions on # 'var/*/memgraph' directories. - adduser --quiet --system --group --no-create-home --shell /bin/bash memgraph || exit 1 + adduser --quiet --system --group --home /var/lib/memgraph --no-create-home --shell /bin/bash memgraph || exit 1 echo "Don't forget to switch to the 'memgraph' user to use Memgraph" || exit 1 chown memgraph:memgraph /var/lib/memgraph || exit 1 chmod 750 /var/lib/memgraph || exit 1 diff --git a/release/rpm/memgraph.spec.in b/release/rpm/memgraph.spec.in new file mode 100644 index 000000000..c6d3c4d53 --- /dev/null +++ b/release/rpm/memgraph.spec.in @@ -0,0 +1,108 @@ +# -*- rpm-spec -*- +BuildRoot: %_topdir/@CPACK_PACKAGE_FILE_NAME@@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH@ +Summary: @CPACK_RPM_PACKAGE_SUMMARY@ +Name: @CPACK_RPM_PACKAGE_NAME@ +Version: @CPACK_RPM_PACKAGE_VERSION@ +Release: @CPACK_RPM_PACKAGE_RELEASE@ +License: @CPACK_RPM_PACKAGE_LICENSE@ +# Group field is deprecated +# Group: @CPACK_RPM_PACKAGE_GROUP@ +Vendor: @CPACK_RPM_PACKAGE_VENDOR@ +BuildRequires: systemd + +@TMP_RPM_URL@ +@TMP_RPM_REQUIRES@ +@TMP_RPM_REQUIRES_PRE@ +@TMP_RPM_REQUIRES_POST@ +@TMP_RPM_REQUIRES_PREUN@ +@TMP_RPM_REQUIRES_POSTUN@ +@TMP_RPM_PROVIDES@ +@TMP_RPM_OBSOLETES@ +@TMP_RPM_CONFLICTS@ +@TMP_RPM_AUTOPROV@ +@TMP_RPM_AUTOREQ@ +@TMP_RPM_AUTOREQPROV@ +@TMP_RPM_BUILDARCH@ +@TMP_RPM_PREFIXES@ + +@TMP_RPM_DEBUGINFO@ + +%define _rpmdir %_topdir/RPMS +%define _srcrpmdir %_topdir/SRPMS +@FILE_NAME_DEFINE@ +%define _unpackaged_files_terminate_build 0 +@TMP_RPM_SPEC_INSTALL_POST@ +@CPACK_RPM_SPEC_MORE_DEFINE@ +@CPACK_RPM_COMPRESSION_TYPE_TMP@ + +%description +@CPACK_RPM_PACKAGE_DESCRIPTION@ + +# This is a shortcutted spec file generated by CMake RPM generator +# we skip _install step because CPack does that for us. +# We do only save CPack installed tree in _prepr +# and then restore it in build. +%prep +# Put the systemd unit where it is expected on this system +mkdir -p $RPM_BUILD_ROOT/%{_unitdir} +mv $RPM_BUILD_ROOT/lib/systemd/system/memgraph.service $RPM_BUILD_ROOT/%{_unitdir} +rm -rf $RPM_BUILD_ROOT/lib +# Fix the incorrect directory permissions set by cpack (this is fixed in CMake 3.11) +find $RPM_BUILD_ROOT -type d | xargs chmod 755 +# After setting up custom prep, continue with CMake's default +mv $RPM_BUILD_ROOT %_topdir/tmpBBroot + +%install +if [ -e $RPM_BUILD_ROOT ]; +then + rm -rf $RPM_BUILD_ROOT +fi +mv %_topdir/tmpBBroot $RPM_BUILD_ROOT + +@TMP_RPM_DEBUGINFO_INSTALL@ + +%clean + +%post +# memgraph user and group must be set in preinst +chown memgraph:memgraph /var/lib/memgraph || exit 1 +chmod 750 /var/lib/memgraph || exit 1 +chown memgraph:adm /var/log/memgraph || exit 1 +chmod 750 /var/log/memgraph || exit 1 +# Make examples directory immutable (optional) +chattr +i -R /usr/share/memgraph/examples || true +@RPM_SYMLINK_POSTINSTALL@ +@CPACK_RPM_SPEC_POSTINSTALL@ + +%postun +@CPACK_RPM_SPEC_POSTUNINSTALL@ + +%pre +# Add the 'memgraph' user and group +getent group memgraph >/dev/null || groupadd -r memgraph || exit 1 +getent passwd memgraph >/dev/null || \ + useradd -r -g memgraph -d /var/lib/memgraph -s /bin/bash memgraph || exit 1 +echo "Don't forget to switch to the 'memgraph' user to use Memgraph" || exit 1 +@CPACK_RPM_SPEC_PREINSTALL@ + +%preun +# Remove optional immutability from examples directory to allow removal +chattr -i -R /usr/share/memgraph/examples || true +@CPACK_RPM_SPEC_PREUNINSTALL@ + +%files +%defattr(@TMP_DEFAULT_FILE_PERMISSIONS@,@TMP_DEFAULT_USER@,@TMP_DEFAULT_GROUP@,@TMP_DEFAULT_DIR_PERMISSIONS@) +@CPACK_RPM_INSTALL_FILES@ +# Since we moved the memgraph.service file, declare it explicitly here. +# NOTE: memgraph.service must not be marked as configuration file. +%{_unitdir}/memgraph.service + +# Override CPACK_RPM_ABSOLUTE_INSTALL_FILES with our %config(noreplace), cpack +# uses plain %config. +%config(noreplace) "/etc/memgraph/memgraph.conf" +%config(noreplace) "/etc/logrotate.d/memgraph" + +@CPACK_RPM_USER_INSTALL_FILES@ + +%changelog +@CPACK_RPM_SPEC_CHANGELOG@ diff --git a/release/rpm/postinst b/release/rpm/postinst deleted file mode 100644 index aaf05dc53..000000000 --- a/release/rpm/postinst +++ /dev/null @@ -1,10 +0,0 @@ -# Hackish way to get the sytemd unit at the right place -mv /lib/systemd/system/memgraph.service %{_unitdir} -# memgraph user and group must be set in preinst -chown memgraph:memgraph /var/lib/memgraph || exit 1 -chmod 750 /var/lib/memgraph || exit 1 -chown memgraph:adm /var/log/memgraph || exit 1 -chmod 750 /var/log/memgraph || exit 1 -# Make examples directory immutable (optional) -chattr +i -R /usr/share/memgraph/examples || true - diff --git a/release/rpm/preinst b/release/rpm/preinst deleted file mode 100644 index 877c097d9..000000000 --- a/release/rpm/preinst +++ /dev/null @@ -1,6 +0,0 @@ -# Add the 'memgraph' user and group -getent group memgraph >/dev/null || groupadd -r memgraph || exit 1 -getent passwd memgraph >/dev/null || \ - useradd -r -g memgraph -d /var/lib/memgraph -s /bin/bash memgraph || exit 1 -echo "Don't forget to switch to the 'memgraph' user to use Memgraph" || exit 1 - diff --git a/release/rpm/prerm b/release/rpm/prerm deleted file mode 100644 index 7c1f0df15..000000000 --- a/release/rpm/prerm +++ /dev/null @@ -1,2 +0,0 @@ -# Remove optional immutability from examples directory to allow removal -chattr -i -R /usr/share/memgraph/examples || true diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 987fd6ec7..2ecd0fe76 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -126,6 +126,11 @@ endif() # Everything here is under "memgraph" install component. set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "memgraph") +# TODO: Default directory permissions to 755 +# NOTE: This is added in CMake 3.11, so enable it then +#set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS +# OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ) + # Install and rename executable to just 'memgraph' Since we have to rename, # we cannot use the recommended `install(TARGETS ...)`. install(PROGRAMS $<TARGET_FILE:memgraph>