105 lines
3.5 KiB
RPMSpec
105 lines
3.5 KiB
RPMSpec
%define debug_package %{nil}
|
|
|
|
Name: %(make name)
|
|
Version: %(make version)
|
|
Release: %(make release)
|
|
Summary: %(make summary)
|
|
License: %(make license)
|
|
URL: %(make url)
|
|
|
|
Source0: %(make source0)
|
|
Buildarch: %(make arch)
|
|
BuildRequires: make
|
|
Requires: netoik-rp netoik-db netoik-cache php php-cli php-gd php-mbstring php-intl php-pecl-apcu php-mysqlnd php-opcache php-json php-zip php-redis php-imagick php-fpm
|
|
|
|
%description
|
|
Install the cloud server called Nextcloud.
|
|
|
|
%prep
|
|
%autosetup -v
|
|
|
|
%install
|
|
%make_install
|
|
|
|
%post
|
|
# Display commands and exit on error
|
|
set -xe
|
|
|
|
# Create nextcloud user
|
|
if ! id nextcloud >/dev/null 2>&1; then
|
|
useradd --base-dir %{_sharedstatedir} --create-home --shell $SHELL --system nextcloud
|
|
fi
|
|
runuser --user=nextcloud -- mkdir --parents %{_sharedstatedir}/nextcloud/data
|
|
|
|
# Create config file
|
|
if ! -f %{_sysconfdir}/nextcloud/config.php; then
|
|
export INSTANCE_ID=$(openssl rand -hex 16)
|
|
export PASSWORD_SALT=$(openssl rand -hex 16)
|
|
export SECRET=$(openssl rand -hex 16)
|
|
envsubst < %{_sysconfdir}/nextcloud/config.php.tpl > %{_sysconfdir}/nextcloud/config.php
|
|
chown root:nextcloud %{_sysconfdir}/nextcloud/config.php
|
|
chmod 640 %{_sysconfdir}/nextcloud/config.php
|
|
fi
|
|
|
|
# Add nextcloud to postgres and valkey groups
|
|
usermod --groups postgres,valkey --append nextcloud
|
|
|
|
# Create postgres user and db
|
|
if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\du' | grep --quiet nextcloud; then
|
|
runuser --user=postgres -- createuser nextcloud
|
|
fi
|
|
if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\l' | grep --quiet nextcloud; then
|
|
runuser --user=postgres -- createdb --owner=nextcloud nextcloud
|
|
fi
|
|
|
|
# Download nextcloud latest release
|
|
if ! -d /var/www/nextcloud; then
|
|
wget --output-document %{_tmppath}/nextcloud-latest.tar.bz2 https://download.nextcloud.com/server/releases/latest.tar.bz2
|
|
wget --output-document %{_tmppath}/nextcloud-latest.tar.bz2.asc https://download.nextcloud.com/server/releases/latest.tar.bz2.asc
|
|
wget --output-document %{_tmppath}/nextcloud.asc https://nextcloud.com/nextcloud.asc
|
|
gpg --import %{_tmppath}/nextcloud.asc
|
|
gpg --verify %{_tmppath}/nextcloud-latest.tar.bz2.asc %{_tmppath}/nextcloud-latest.tar.bz2
|
|
tar --extract --file=%{_tmppath}/nextcloud-latest.tar.bz2 --directory=/var/www
|
|
fi
|
|
|
|
# Change rights and owner
|
|
chown --recursive nextcloud:nextcloud /var/www/nextcloud
|
|
chmod 755 /var/www/nextcloud
|
|
|
|
# Create symbolic link to config
|
|
runuser --user=nextcloud -- ln --symbolic --force %{_sysconfdir}/nextcloud/config.php /var/www/nextcloud/config/config.php
|
|
|
|
# Restart services
|
|
systemctl daemon-reload
|
|
systemctl reenable nginx.service php-fpm.service
|
|
systemctl restart nginx.service php-fpm.service
|
|
|
|
%postun
|
|
# Display commands and exit on error
|
|
set -xe
|
|
|
|
# If uninstalling, then delete user and db
|
|
if [ $1 == 0 ]; then
|
|
if id nextcloud >/dev/null 2>&1; then
|
|
userdel --force --remove nextcloud
|
|
fi
|
|
if runuser --user=postgres -- psql --quiet --tuples-only --command='\l' | grep --quiet nextcloud; then
|
|
runuser --user=postgres -- dropdb nextcloud
|
|
fi
|
|
if runuser --user=postgres -- psql --quiet --tuples-only --command='\du' | grep --quiet nextcloud; then
|
|
runuser --user=postgres -- dropuser nextcloud
|
|
fi
|
|
rm --recursive --force /var/www/nextcloud
|
|
fi
|
|
|
|
%files
|
|
%dir %attr(755, root, root) %{_sysconfdir}/nextcloud
|
|
%attr(644, root, root) %{_sysconfdir}/nextcloud/config.php.tpl
|
|
|
|
%attr(644, root, root) %{_sysconfdir}/nginx/conf.d/cloud.netoik.io.conf
|
|
|
|
%attr(644, root, root) %{_sysconfdir}/php-fpm.d/nextcloud.conf
|
|
|
|
%changelog
|
|
%autochangelog
|