File wechat-universal-bwrap.spec of Package wechat-universal-bwrap

#
# spec file for package wechat-universal-bwrap
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%global __requires_exclude libbz2.so.1.0

%define _NAME wechat-universal
%define INSTALL_PREFIX /opt
%define INSTALL_ROOTDIR %{INSTALL_PREFIX}/%{_NAME}
%define INSTALL_RUNENV %{INSTALL_ROOTDIR}/RunEnv
%define INSTALL_BINDIR %{INSTALL_RUNENV}%{_bindir}
%define INSTALL_ETCDIR %{INSTALL_RUNENV}%{_sysconfdir}
%define INSTALL_LIBDIR %{INSTALL_RUNENV}/usr/lib

Name:           %{_NAME}-bwrap
Version:        4.1.0.13
Release:        0
Summary:        WeChat Qt, the so-called universal version
License:        NonFree
URL:            https://linux.weixin.qq.com
Group:          Productivity/Networking/Instant Messenger
Source0:        %{_NAME}_%{version}_%{_arch}.deb
Source1:        wechat-universal.sh
Source2:        wechat-universal.desktop
Source3:        icons.tar.gz

Source1000:     wechat-universal-bwrap.rpmlintrc
# flag to ensure that src.rpm can be rebuilt
Source1001:     %{_NAME}_%{version}_x86_64.deb
Source1002:     %{_NAME}_%{version}_aarch64.deb

BuildRequires:  bsdtar
BuildRequires:  execstack
BuildRequires:  fdupes
BuildRequires:  patchelf
BuildRequires:  update-desktop-files
Requires:       bubblewrap
Requires:       flatpak-xdg-utils
Requires:       iproute2
Requires:       libbz2-1
Requires:       (gawk or awk)

Conflicts:      wechat-universal

%description
WeChat Qt, the so-called universal version

%prep
mkdir -p %{_builddir}/%{name}-%{version}%{INSTALL_PREFIX}
bsdtar -xOf %{S:0} ./data.tar.xz | xz -cd > data.tar
tar -xf data.tar
mv opt/wechat %{_builddir}/%{name}-%{version}%{INSTALL_ROOTDIR}
rm -f %{_builddir}/%{name}-%{version}%{INSTALL_ROOTDIR}/libuosdevicea.so
rm -f data.tar

###############################################################################
# From https://github.com/7Ji-PKGBUILDs/wechat-universal-bwrap
cd %{_builddir}/%{name}-%{version}%{INSTALL_ROOTDIR}
# Remove non-essential executable permissions
find . -type f -perm /111 | while read _file; do
    if [[ $(file --brief "${_file}") == 'ELF '* ]]; then
        continue
    fi
    stat --printf '  %A => ' "${_file}"
    chmod u-x,g-x,o-x "${_file}"
    stat --format '%A %n' "${_file}"
done

# Modify the run path of the dynamic library
patchelf --set-rpath '$ORIGIN' 'libwxtrans.so'
cd vlc_plugins
find . -type f | while read _file; do
    patchelf --set-rpath '$ORIGIN:$ORIGIN/../..' "${_file}"
done
cd ..

# Remove executable stack marking to fix permission denied error
find ./ -type f -name "*.so" |xargs execstack -c

###############################################################################

%build

%install
install -d %{buildroot}%{_datadir}
tar -zxf %{S:3} -C %{buildroot}%{_datadir}/
find %{buildroot}%{_datadir}/icons -type f -name "*.png" |xargs chmod 644

install -d %{buildroot}%{INSTALL_ROOTDIR}
cp -r %{_builddir}/%{name}-%{version}%{INSTALL_ROOTDIR}/* %{buildroot}%{INSTALL_ROOTDIR}/

install -d %{buildroot}%{INSTALL_RUNENV}
install -d %{buildroot}%{INSTALL_BINDIR}
install -Dm 755 %{S:1} %{buildroot}%{INSTALL_BINDIR}/common.sh
# Fix Install Path
sed -i "s|INSTALL_RUNENV|%{INSTALL_RUNENV}|g" \
    %{buildroot}%{INSTALL_BINDIR}/common.sh
sed -i "s|INSTALL_ROOTDIR|%{INSTALL_ROOTDIR}|g" \
    %{buildroot}%{INSTALL_BINDIR}/common.sh
ln -sf ./common.sh %{buildroot}%{INSTALL_BINDIR}/start.sh
ln -sf ./common.sh %{buildroot}%{INSTALL_BINDIR}/stop.sh

printf '%s\n' '#!/bin/bash' 'exec %{INSTALL_BINDIR}/start.sh "$@"' |\
    install -DTm 755 /dev/stdin %{buildroot}%{_bindir}/%{_NAME}

install -Dm 644 %{S:2} %{buildroot}%{_datadir}/applications/%{_NAME}.desktop
# Fix Install Path
sed -i "s|WECHAT_START|%{_NAME}|g" \
    %{buildroot}%{_datadir}/applications/%{_NAME}.desktop
sed -i "s|WECHAT_STOP|%{INSTALL_BINDIR}/stop.sh|g" \
    %{buildroot}%{_datadir}/applications/%{_NAME}.desktop
%suse_update_desktop_file %{_NAME}

%fdupes -s %{buildroot}

export NO_BRP_CHECK_RPATH=true

%check

%files
%{_bindir}/%{_NAME}
%dir %{INSTALL_ROOTDIR}
%{INSTALL_ROOTDIR}/*
%{_datadir}/applications/%{_NAME}.desktop
%{_datadir}/icons/*

%changelog
openSUSE Build Service is sponsored by