File regataos-store.spec of Package regataos-store

%define service_name regataos-store-selectlanguage
%define service_name2 regataos-store-clearcache
%define service_name3 capture-progress-download-snap

Name: regataos-store
%if 0%{?sle_version} == 150100 && 0%{?is_opensuse}
Version: 5.1
%else
Version: 5.3
%endif
Release: 0
Url: https://regataos.com.br/
Summary: Application store of Regata OS
Group: System/GUI/KDE
BuildRequires: xz
BuildRequires: desktop-file-utils
BuildRequires: update-desktop-files
BuildRequires: hicolor-icon-theme
BuildRequires:	-post-build-checks
%{?systemd_requires}
BuildRequires: systemd
BuildRequires: grep
License: MIT
Source1: regataos-store-%{version}.tar.xz
Requires: regataos-repo >= 5.0
Requires: xz
Requires: kdesudo
Requires: xdpyinfo
Requires: magma >= 5.50.2
Requires: zypper
Requires: snapd
Requires: flatpak
Requires: libflatpak0
Requires: typelib-1_0-Flatpak-1_0
Requires: xdg-desktop-portal
Requires: lsof
Requires: zenity
Requires: zenity-lang
Requires: pv
Requires: libnotify4
Requires: libnotify4-32bit
Requires: libnotify-tools
BuildRoot: %{_tmppath}/%{name}-%{version}-build

%description
Application store of Regata OS.

%build

%install
# Install the main store package
mkdir -p %{buildroot}/opt/regataos-base/
cp -f %{SOURCE1} %{buildroot}/opt/regataos-base/regataos-store-%{version}.tar.xz

%post
# Remove old files
if test -e /opt/regataos-store ; then
  rm -rf "/opt/regataos-store"
fi

# Extract store files at the root of the system
tar xf /opt/regataos-base/regataos-store-%{version}.tar.xz -C /

# Enable and start systemd service
%service_add_post %{service_name}.service
systemctl enable  %{service_name}.service || true
systemctl start   %{service_name}.service || true
systemctl restart %{service_name}.service || true

%service_add_post %{service_name2}.service
systemctl enable  %{service_name2}.service || true
systemctl start   %{service_name2}.service || true
systemctl restart %{service_name2}.service || true

%service_add_post %{service_name3}.service
systemctl enable  %{service_name3}.service || true
systemctl start   %{service_name3}.service || true
systemctl restart %{service_name3}.service || true

# Fix installed apps
if test -e "/tmp/regataos-store/config" ; then
	chmod 777 "/tmp/regataos-store/config"
else
	mkdir -p "/tmp/regataos-store/config"
	chmod 777 "/tmp/regataos-store/config"
fi

if test ! -e "/tmp/regataos-store/config/installed-apps.txt" ; then
	mkdir -p "/tmp/regataos-store/config"
	chmod 777 "/tmp/regataos-store/config"

    user=$(users | awk '{print $1}')
    mkdir -p "/home/$user/.config/regataos-store"
    chmod 777 "/home/$user/.config/regataos-store"
    echo "" >> "/home/$user/.config/regataos-store/installed-apps.txt"
    chmod 777 /home/$user/.config/regataos-store/*

	ln -sf "/home/$user/.config/regataos-store/installed-apps.txt" "/tmp/regataos-store/config/"
	chmod 777 /tmp/regataos-store/config/*
fi

# Create directory containing the list of installed apps
mkdir -p /opt/regataos-store/installed-apps/
chmod 777 /opt/regataos-store/installed-apps/

# Clear files from the old app store
user=$(users | awk '{print $1}')

if test -e "/home/$user/.config/autostart-scripts" ; then
  rm -f "/home/$user/.config/autostart-scripts/store-start-check-rpm"
  rm -f "/home/$user/.config/autostart-scripts/store-start-check-snap"
  rm -f "/home/$user/.config/autostart-scripts/store-start-check-zypper"
  rm -f "/home/*/.config/autostart-scripts/store-start-check-rpm"
  rm -f "/home/*/.config/autostart-scripts/store-start-check-snap"
  rm -f "/home/*/.config/autostart-scripts/store-start-check-zypper"
fi

rm -f "/etc/skel/.config/autostart-scripts/store-start-check-rpm"
rm -f "/etc/skel/.config/autostart-scripts/store-start-check-snap"
rm -f "/etc/skel/.config/autostart-scripts/store-start-check-zypper"
rm -f "/etc/xdg/autostart/regataos-store-check-rpm.desktop"
rm -f "/etc/xdg/autostart/regataos-store-check-snap.desktop"
rm -f "/etc/xdg/autostart/regataos-store-check-zypper.desktop"
rm -f "/etc/xdg/autostart/regataos-store-notify-queue.desktop"

systemctl stop regataos-store-checkapp-start.service
systemctl disable regataos-store-checkapp-start.service
systemctl stop regataos-store-checkapp-volta-button.service
systemctl disable regataos-store-checkapp-volta-button.service
systemctl stop store-autostart-scripts.service
systemctl disable store-autostart-scripts.service
systemctl stop store-stop-check-rpm.service
systemctl disable store-stop-check-rpm.service
systemctl stop store-stop-check-snap.service
systemctl disable store-stop-check-snap.service
systemctl stop store-stop-check-zypper.service
systemctl disable store-stop-check-zypper.service

update-desktop-database

%clean

%files
%defattr(-,root,root)
/opt/regataos-base
/opt/regataos-base/regataos-store-%{version}.tar.xz

%changelog
openSUSE Build Service is sponsored by