%global __cmake_builddir %{!?__cmake_in_source_build:%{_vpath_builddir}}%{?__cmake_in_source_build:.}

Name:           calamares
Version:        3.3.7
Release:        1
Summary:        Installer from a live CD/DVD/USB to disk

License:        GPL-3.0-or-later
URL:            https://calamares.io/
Source0:        calamares-3.3.7.tar.gz
Source2:        show.qml
# Run:
# lupdate-qt6 show.qml -ts calamares-auto_fr.ts
# then translate the template in linguist-qt6.
Source3:        calamares-auto_fr.ts
# Run:
# lupdate-qt6 show.qml -ts calamares-auto_de.ts
# then translate the template in linguist-qt6.
Source4:        calamares-auto_de.ts
# Run:
# lupdate-qt6 show.qml -ts calamares-auto_it.ts
# then translate the template in linguist-qt6.
Source5:        calamares-auto_it.ts
Source6:        calamares.service
# Backports from upstream

#image:binary file:svg,png,svgz
Source7:        squid.png
Source8:        Biglogo.svgz
Source9:        Biglogo.svg
Source10:       Biglogo.png
Source11:       Minimal-Install.png
Source12:       gnome.png
Source13:       Slide1.png
Source14:       Slide2.png
Source15:       Slide3.png
Source16:       information.svgz
Source17:       openEuler.png
Source18:       openEulerWord-blus.png
Source19:       openEulerWord.png

# patch
Patch0:         0001-branding-patch.patch
Patch1:         0002-lang.patch
Patch2:         0003-calamares.patch
Patch3:         0004-libcalamares.patch
Patch4:         0005-libcalamaresui.patch
Patch5:         0006-modules-file.patch
Patch6:         0007-root.patch
Patch7:         0008-progromTree.patch
Patch8:         0009-qss.patch
# Calamares is only supported where live images (and GRUB) are. (#1171380)
# This list matches the arches where grub2-efi is used to boot the system
ExclusiveArch:  %{ix86} x86_64 aarch64 riscv64

# Macros
BuildRequires:  git-core
BuildRequires:  kf5-rpm-macros

# Compilation tools
BuildRequires:  cmake >= 3.16
BuildRequires:  extra-cmake-modules
BuildRequires:  extra-cmake-modules
BuildRequires:  gcc-c++ >= 9.0.0
BuildRequires:  pkgconfig
BuildRequires:  make
##
### Other build-time tools
BuildRequires:  desktop-file-utils
BuildRequires:  gettext
##
### Qt 5
BuildRequires:  cmake(Qt5Concurrent)
BuildRequires:  cmake(Qt5Core)
BuildRequires:  cmake(Qt5DBus)
BuildRequires:  cmake(Qt5Gui)
BuildRequires:  cmake(Qt5LinguistTools)
BuildRequires:  cmake(Qt5Network)
BuildRequires:  cmake(Qt5Svg)
BuildRequires:  cmake(Qt5Widgets)
BuildRequires:  cmake(Qt5Quick)
BuildRequires:  cmake(Qt5QuickWidgets)
BuildRequires:  polkit-qt5-1-devel
##
### KF5
BuildRequires:  cmake(KF5CoreAddons)
BuildRequires:  cmake(KF5Config)
BuildRequires:  cmake(KF5Crash)
BuildRequires:  cmake(KF5DBusAddons)
BuildRequires:  cmake(KF5I18n)
BuildRequires:  cmake(KF5Package)
BuildRequires:  cmake(KF5Parts)
BuildRequires:  cmake(KF5Service)
BuildRequires:  cmake(KF5WidgetsAddons)
##
### Plasma
#BuildRequires:  cmake(Plasma)
##
### KPMcore
BuildRequires:  cmake(KPMcore) >= 4.2.0
##
### Python 3
BuildRequires:  python3-devel >= 3.3
BuildRequires:  python3-jsonschema
BuildRequires:  python3-pyyaml
BuildRequires:  boost-devel >= 1.55.0
##%global __python %{__python3}
##
### Other libraries
BuildRequires:  cmake(AppStreamQt)
BuildRequires:  libpwquality-devel
BuildRequires:  libxcrypt-devel
BuildRequires:  parted-devel
BuildRequires:  yaml-cpp-devel >= 0.5.1

# for automatic branding setup
Requires(post): system-release
Requires(post): system-logos
Requires:       system-logos

Requires:       python3-devel
Requires:       boost-devel
Requires:       coreutils
Requires:       util-linux
Requires:       upower
Requires:       NetworkManager
Requires:       dracut
Requires:       grub2
%ifarch x86_64 aarch64 riscv64
%ifarch x86_64
# For x86 systems
Requires:       grub2-efi-x64
Recommends:     grub2-efi-ia32
%else
# For all non-x86 arches
Requires:       grub2-efi
%endif
Requires:       efibootmgr
%endif
Requires:       console-setup
Requires:       setxkbmap
Requires:       os-prober
Requires:       e2fsprogs
Requires:       dosfstools
Requires:       ntfsprogs
Requires:       gawk
Requires:       systemd
Requires:       rsync
Requires:       shadow-utils
Requires:       dnf
Requires:       kdesu
Requires:       hicolor-icon-theme

Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
# webview module is no longer available
Obsoletes:      %{name}-webview < 3.0.0~


%description
Calamares is a distribution-independent installer framework, designed to install
from a live CD/DVD/USB environment to a hard disk. It includes a graphical
installation program based on Qt 6. This package includes the Calamares
framework and the required configuration files to produce a working replacement
for Anaconda's liveinst.


%package        libs
Summary:        Calamares runtime libraries
Requires:       %{name} = %{version}-%{release}

%description    libs
%{summary}.


%package        interactiveterminal
Summary:        Calamares interactiveterminal module
Requires:       %{name} = %{version}-%{release}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description    interactiveterminal
Optional interactiveterminal module for the Calamares installer, based on the
KonsolePart (from Konsole 6)


%package        plasmalnf
Summary:        Calamares plasmalnf module
Requires:       %{name} = %{version}-%{release}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description    plasmalnf
Optional plasmalnf module for the Calamares installer, based on the KDE Plasma
Desktop Workspace and its KDE Frameworks (KConfig, KPackage, Plasma)


%package        devel
Summary:        Development files for %{name}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       cmake

%description    devel
The %{name}-devel package contains libraries and header files for
developing custom modules for Calamares.


%prep
%autosetup -p1

# 配置文件与资源文件的准备
mkdir -p %{_builddir}/calamares-3.3.7/data/config-appimage/branding/default
install -Dm 0644 %{SOURCE7} %{_builddir}/calamares-3.3.7/data/config-appimage/branding/default/squid.png

mkdir -p %{_builddir}/calamares-3.3.7/data/images
install -Dm 0644 %{SOURCE8} %{_builddir}/calamares-3.3.7/data/images/Biglogo.svgz
install -Dm 0644 %{SOURCE9} %{_builddir}/calamares-3.3.7/data/images/Biglogo.svg
install -Dm 0644 %{SOURCE16} %{_builddir}/calamares-3.3.7/data/images/information.svgz
mkdir -p %{_builddir}/calamares-3.3.7/src/modules/packagechooser/images
install -Dm 0644 %{SOURCE10} %{_builddir}/calamares-3.3.7/src/branding/default/Biglogo.png
install -Dm 0644 %{SOURCE11} %{_builddir}/calamares-3.3.7/src/modules/packagechooser/images/Minimal-Install.png
install -Dm 0644 %{SOURCE9} %{_builddir}/calamares-3.3.7/src/branding/default/Biglogo.svg
install -Dm 0644 %{SOURCE8} %{_builddir}/calamares-3.3.7/src/branding/default/Biglogo.svgz
install -Dm 0644 %{SOURCE7} %{_builddir}/calamares-3.3.7/src/branding/default/squid.png
install -Dm 0644 %{SOURCE12} %{_builddir}/calamares-3.3.7/src/modules/packagechooser/images/gnome.png
install -Dm 0644 %{SOURCE13} %{_builddir}/calamares-3.3.7/src/branding/default/Slide1.png
install -Dm 0644 %{SOURCE14} %{_builddir}/calamares-3.3.7/src/branding/default/Slide2.png
install -Dm 0644 %{SOURCE15} %{_builddir}/calamares-3.3.7/src/branding/default/Slide3.png
install -Dm 0644 %{SOURCE17} %{_builddir}/calamares-3.3.7/src/branding/default/openEuler.png
install -Dm 0644 %{SOURCE18} %{_builddir}/calamares-3.3.7/src/branding/default/openEulerWord-blus.png
install -Dm 0644 %{SOURCE19} %{_builddir}/calamares-3.3.7/src/branding/default/openEulerWord.png
%build
mkdir build
cd build
cmake .. -DINSTALL_CONFIG=ON
make -j 2

%install
cd build
%make_install

# 创建auto branding目录并安装相关文件
mkdir -p %{buildroot}%{_datadir}/calamares/branding/auto
touch %{buildroot}%{_datadir}/calamares/branding/auto/branding.desc
install -p -m 644 %{SOURCE2} %{buildroot}%{_datadir}/calamares/branding/auto/show.qml

# 翻译文件
mkdir -p %{buildroot}%{_datadir}/calamares/branding/auto/lang
lrelease-qt5 %{SOURCE3} -qm %{buildroot}%{_datadir}/calamares/branding/auto/lang/calamares-auto_fr.qm
lrelease-qt5 %{SOURCE4} -qm %{buildroot}%{_datadir}/calamares/branding/auto/lang/calamares-auto_de.qm
lrelease-qt5 %{SOURCE5} -qm %{buildroot}%{_datadir}/calamares/branding/auto/lang/calamares-auto_it.qm

# 系统配置目录
mkdir -p %{buildroot}%{_sysconfdir}/calamares/modules
mkdir -p %{buildroot}%{_sysconfdir}/calamares/branding
mkdir -p %{buildroot}%{_sysconfdir}/systemd/system
install -p -m 644 %{SOURCE6} %{buildroot}%{_sysconfdir}/systemd/system/calamares.service

# 额外资源文件/data/
mkdir -p %{buildroot}/data/config-appimage/branding/default
install -Dm 0644 %{SOURCE7} %{buildroot}/data/config-appimage/branding/default/squid.png

mkdir -p %{buildroot}/data/images
install -Dm 0644 %{SOURCE8}  %{buildroot}/data/images/Biglogo.svgz
install -Dm 0644 %{SOURCE9}  %{buildroot}/data/images/Biglogo.svg
install -Dm 0644 %{SOURCE16} %{buildroot}/data/images/information.svgz

# calamares模块图片目录
mkdir -p %{buildroot}%{_datadir}/calamares/modules/packagechooser/images
install -Dm 0644 %{SOURCE10} %{buildroot}%{_datadir}/calamares/branding/default/Biglogo.png
install -Dm 0644 %{SOURCE11} %{buildroot}%{_datadir}/calamares/modules/packagechooser/images/Minimal-Install.png
install -Dm 0644 %{SOURCE9} %{buildroot}%{_datadir}/calamares/branding/default/Biglogo.svg
install -Dm 0644 %{SOURCE8} %{buildroot}%{_datadir}/calamares/branding/default/Biglogo.svgz
install -Dm 0644 %{SOURCE7} %{buildroot}%{_datadir}/calamares/branding/default/squid.png
install -Dm 0644 %{SOURCE12} %{buildroot}%{_datadir}/calamares/modules/packagechooser/images/gnome.png
install -Dm 0644 %{SOURCE13} %{buildroot}%{_datadir}/calamares/branding/default/Slide1.png
install -Dm 0644 %{SOURCE14} %{buildroot}%{_datadir}/calamares/branding/default/Slide2.png
install -Dm 0644 %{SOURCE15} %{buildroot}%{_datadir}/calamares/branding/default/Slide3.png
install -Dm 0644 %{SOURCE17} %{buildroot}%{_datadir}/calamares/branding/default/openEuler.png
install -Dm 0644 %{SOURCE18} %{buildroot}%{_datadir}/calamares/branding/default/openEulerWord-blus.png
install -Dm 0644 %{SOURCE19} %{buildroot}%{_datadir}/calamares/branding/default/openEulerWord.png

%files
%doc AUTHORS
%license LICENSES/*
%{_bindir}/calamares
%{_datadir}/calamares/
%{_datadir}/calamares/settings.conf
%{_datadir}/calamares/branding/default/
%{_datadir}/calamares/branding/auto/
%ghost %{_datadir}/calamares/branding/auto/branding.desc
%{_datadir}/calamares/branding/auto/show.qml
%{_datadir}/calamares/branding/auto/lang/
%{_datadir}/calamares/modules/
%{_datadir}/calamares/qml/
%{_datadir}/applications/calamares.desktop
%{_datadir}/icons/hicolor/scalable/apps/calamares.svg
%{_mandir}/man8/calamares.8*
%{_sysconfdir}/calamares/
%{_datadir}/locale/
%{_datadir}/polkit-1/
%{_sysconfdir}/systemd/system/calamares.service
%{_datadir}/bash-completion/completions/calamares
%dir /data/
%dir /data/images/
/data/images/Biglogo.svgz
/data/images/Biglogo.svg
/data/images/information.svgz
%dir /data/config-appimage/
%dir /data/config-appimage/branding/
%dir /data/config-appimage/branding/default/
/data/config-appimage/branding/default/squid.png
%{_datadir}/calamares/branding/default/squid.png
%{_datadir}/calamares/branding/default/Biglogo.svg
%{_datadir}/calamares/branding/default/Biglogo.svgz
%{_datadir}/calamares/branding/default/openEulerWord-blus.png
%{_datadir}/calamares/branding/default/openEulerWord.png
%{_datadir}/calamares/branding/default/openEuler.png

%files libs
%{_libdir}/libcalamares.so.*
%{_libdir}/libcalamaresui.so.*
%{_libdir}/calamares/
%exclude %{_libdir}/calamares/modules/interactiveterminal/

%files interactiveterminal
%{_datadir}/calamares/modules/interactiveterminal.conf
%{_libdir}/calamares/modules/interactiveterminal/

%files devel
%{_includedir}/libcalamares/
%{_libdir}/libcalamares.so
%{_libdir}/libcalamaresui.so
%{_libdir}/cmake/Calamares/

%clean
cd %{_builddir} || exit 0
rm -rf %{buildroot}

%changelog
* Wed Oct 9 2024 Li Ping <liping136@huawei.com> - 3.3.7-1
- Initial package
