%global _smp_mflags -j1


%global sname deepin-daemon
%global repo dde-daemon
%global release_name server-industry

Name:           dde-daemon
Version:        5.13.85.8
Release:        3
Summary:        Daemon handling the DDE session settings
License:        GPLv3
URL:            http://shuttle.corp.deepin.com/cache/tasks/18802/unstable-amd64/
Source0:        %{name}-%{version}.tar.gz

Patch0001:      0001-to-fix-a-potential-crash-issue-in-the-control-center.patch

BuildRequires:  python3

BuildRequires:  gocode

BuildRequires:  compiler(go-compiler)
BuildRequires:  deepin-gettext-tools
BuildRequires:  fontpackages-devel
BuildRequires:  librsvg2-tools
BuildRequires:  pam-devel >= 1.3.1
BuildRequires:  glib2-devel
BuildRequires:  gtk3-devel
BuildRequires:  systemd-devel
BuildRequires:  alsa-lib-devel
BuildRequires:  pulseaudio-libs-devel
BuildRequires:  gdk-pixbuf2-xlib-devel
BuildRequires:  libnl3-devel
BuildRequires:  libgudev-devel
BuildRequires:  libinput-devel
BuildRequires:  librsvg2-devel
BuildRequires:  libXcursor-devel
BuildRequires:  pkgconfig(sqlite3)
BuildRequires:  go-lib-devel
BuildRequires:  libX11-devel
BuildRequires:  dde-api-devel
BuildRequires:  golang-github-linuxdeepin-go-x11-client-devel
BuildRequires:  golang-github-linuxdeepin-go-dbus-factory-devel
BuildRequires:  golang(gir/gio-2.0)
BuildRequires:  golang(gir/glib-2.0)
BuildRequires:  golang(gir/gobject-2.0)
BuildRequires:  golang(gir/gudev-1.0)

Requires:       bluez-libs
Requires:       deepin-desktop-base
Requires:       deepin-desktop-schemas
Requires:       dde-polkit-agent
Requires:       rfkill
Requires:       gvfs
Requires:       iw
# Requires:       xdotool
# Requires:       gnome-keyring-pam
Requires:       imwheel
# Requires:       proxychains-ng
# Requires:       deepin-proxy

Recommends:     iso-codes
Recommends:     mobile-broadband-provider-info
Recommends:     google-noto-mono-fonts
Recommends:     google-noto-sans-fonts

%description
Daemon handling the DDE session settings

%prep
%autosetup -p1 -n %{name}-%{version}
patch langselector/locale.go < rpm/locale.go.patch
patch accounts/users/passwd.go < rpm/passwd.go.patch

# Fix library exec path
sed -i '/deepin/s|lib|libexec|' Makefile
sed -i '/systemd/s|lib|usr/lib|' Makefile
sed -i 's:/lib/udev/rules.d:%{_udevrulesdir}:' Makefile
sed -i '/${DESTDIR}\/usr\/lib\/deepin-daemon\/service-trigger/s|${DESTDIR}/usr/lib/deepin-daemon/service-trigger|${DESTDIR}/usr/libexec/deepin-daemon/service-trigger|g' Makefile
sed -i '/${DESTDIR}${PREFIX}\/lib\/deepin-daemon/s|${DESTDIR}${PREFIX}/lib/deepin-daemon|${DESTDIR}${PREFIX}/usr/libexec/deepin-daemon|g' Makefile
sed -i 's|lib/NetworkManager|libexec|' network/utils_test.go

for file in $(grep "/usr/lib/deepin-daemon" * -nR |awk -F: '{print $1}')
do
    sed -i 's|/usr/lib/deepin-daemon|/usr/libexec/deepin-daemon|g' $file
done

# Fix grub.cfg path
sed -i 's|boot/grub|boot/grub2|' grub2/{grub2,grub_params,theme}.go

# Fix activate services failed (Permission denied)
# dbus service
pushd misc/system-services/
sed -i '$aSystemdService=deepin-accounts-daemon.service' com.deepin.system.Power.service \
    com.deepin.daemon.{Accounts,Apps,Daemon}.service \
    com.deepin.daemon.{Gesture,SwapSchedHelper,Timedated}.service
sed -i '$aSystemdService=dbus-com.deepin.dde.lockservice.service' com.deepin.dde.LockService.service
popd
# systemd service
cat > misc/systemd/services/dbus-com.deepin.dde.lockservice.service <<EOF
[Unit]
Description=Deepin Lock Service
Wants=user.slice dbus.socket
After=user.slice dbus.socket

[Service]
Type=dbus
BusName=com.deepin.dde.LockService
ExecStart=%{_libexecdir}/%{sname}/dde-lockservice

[Install]
WantedBy=graphical.target
EOF

# Replace reference of google-chrome to chromium-browser
sed -i 's/google-chrome/chromium-browser/g' misc/dde-daemon/mime/data.json

%build
%ifarch loongarch64
export CGO_ENABLED=1
export GOOS=linux
%endif

BUILDID="0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n')"
export GOPATH=/usr/share/gocode
%make_build GO_BUILD_FLAGS=-trimpath GOBUILD="go build -compiler gc -ldflags \"-B $BUILDID\""

%install
%ifarch loongarch64
export CGO_ENABLED=1
export GOOS=linux
%endif

BUILDID="0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n')"
export GOPATH=/usr/share/gocode
%make_install GOBUILD="go build -compiler gc -ldflags \"-B $BUILDID\""


install -Dm0644 rpm/85-deepin-accounts-daemon.preset -t %{buildroot}/%{_presetdir}

# fix systemd/logind config
install -d %{buildroot}/usr/lib/systemd/logind.conf.d/
cat > %{buildroot}/usr/lib/systemd/logind.conf.d/10-%{sname}.conf <<EOF
[Login]
HandlePowerKey=ignore
HandleSuspendKey=ignore
EOF


%find_lang %{name}

%post
if [ $1 -ge 1 ]; then
  systemd-sysusers %{sname}.conf
  %{_sbindir}/alternatives --install %{_bindir}/x-terminal-emulator \
    x-terminal-emulator %{_libexecdir}/%{sname}/default-terminal 30
fi
%systemd_post deepin-accounts-daemon.service
if [ $1 -eq 2 ] ; then
        # Upgrade installation
        systemctl --no-reload preset deepin-accounts-daemon.service  &>/dev/null || :
fi

%preun
if [ $1 -eq 0 ]; then
  %{_sbindir}/alternatives --remove x-terminal-emulator \
    %{_libexecdir}/%{sname}/default-terminal
fi
%systemd_preun deepin-accounts-daemon.service


%postun
if [ $1 -eq 0 ]; then
  rm -f /var/cache/deepin/mark-setup-network-services
  rm -f /var/log/deepin.log
fi
%systemd_postun_with_restart deepin-accounts-daemon.service

%files -f %{name}.lang
%doc README.md
%license LICENSE
%{_sysconfdir}/pam.d/deepin-auth-keyboard
%{_sysconfdir}/NetworkManager/conf.d/deepin.dde.daemon.conf
%{_libexecdir}/%{sname}/
%{_prefix}/lib/systemd/logind.conf.d/10-%{sname}.conf
%{_datadir}/dbus-1/services/*.service
%{_datadir}/dbus-1/system-services/*.service
%{_datadir}/dbus-1/system.d/*.conf
%{_datadir}/icons/hicolor/*/status/*
%{_datadir}/%{name}/
%{_datadir}/dde/
%{_datadir}/polkit-1/actions/*.policy
%{_var}/lib/polkit-1/localauthority/10-vendor.d/com.deepin.daemon.Accounts.pkla
%{_sysconfdir}/acpi/actions/deepin_lid.sh
%{_sysconfdir}/acpi/events/deepin_lid
%{_sysconfdir}/lightdm/deepin/xsettingsd.conf
# This directory is not provided by any other package.
%dir %{_sysconfdir}/pulse/daemon.conf.d
%{_sysconfdir}/pulse/daemon.conf.d/10-deepin.conf
%{_udevrulesdir}/80-deepin-fprintd.rules
%{_var}/lib/polkit-1/localauthority/10-vendor.d/com.deepin.daemon.Fprintd.pkla
%{_unitdir}/dbus-com.deepin.dde.lockservice.service
%{_unitdir}/deepin-accounts-daemon.service
%{_presetdir}/85-deepin-accounts-daemon.preset
%{_sysconfdir}/default/grub.d/10_deepin.cfg
%{_sysconfdir}/grub.d/35_deepin_gfxmode
%{_var}/lib/polkit-1/localauthority/10-vendor.d/com.deepin.daemon.Grub2.pkla

%changelog
* Mon Dec 18 2023 liuzhilin <liuzhilin@uniontech.com> - 5.13.85.8-3
- fix-a-potential-crash-issue-in-the-control-center

* Tue Nov 28 2023 hanshuang <hanshuang@uniontech.com> - 5.13.85.8-2
- modify spec remove openeuler info

* Wed Sep 2 2020 chenbo pan <panchenbo@uniontech.com> - 5.10.0.23-8
- fix requires golang devel

* Wed Aug 19 2020 openEuler Buildteam <buildteam@openeuler.org> - 5.10.0.23-7
- change python37 to python3

* Thu Jul 30 2020 openEuler Buildteam <buildteam@openeuler.org> - 5.10.0.23-6
- remove golang devel

* Thu Jul 30 2020 openEuler Buildteam <buildteam@openeuler.org> - 5.10.0.23-5
- Package init
