File zoom-appimage.spec of Package zoom-appimage

%define AppName "Zoom"
%define TITLE "%{AppName} AppImage"
%define executable zoom
%define executable_tag appimage
# option 1 = ON (true), 0 = OFF (false)
%define include_dummy_appimage 0
%define launcher %{executable}-%{executable_tag}
%define pkgname %{executable}-%{executable_tag}
# Get version from zsync file
# https://download.opensuse.org/repositories/home:/kimi:/zoom/AppImage/zoom-latest-x86_64.AppImage.zsync
# Filename: zoom-5.17.11.3835-lp155.155.1.Build103.1.glibc2.27-x86_64.AppImage
# zypper info zoom  | tr -d ' ' | grep Version | cut -d":" -f2 | cut -d"-" -f1
# %%define version %%(echo "$(awk '/ appVersion =/{ print $3 }' /filepath/values.txt" | sed 's/\"//g' | cut -d'-' -f1)
# %%define pkgver head -2 %%{_sourcedir}/VERSION | grep Filename | tr -d ' ' | cut -d"-" -f2
%define pkgver %(head -2 %{_sourcedir}/VERSION | grep %{executable} | cut -d"-" -f2)
%define packager Kimi
%define packagerEmail noreply@nodomain.org
%define architecture %(lscpu | awk '/Architecture:/{print $2}')
%define webDir "https://download.opensuse.org/repositories/home:/kimi:/zoom/AppImage/"
%define APPIMAGE "%{webDir}zoom-latest-%{architecture}.AppImage"
%define THISMONTHSHORT %(LC_TIME='en_US.UTF-8' date +%%b)
%define THISMONTHLONG %(LC_TIME='en_US.UTF-8' date +%%B)
%define THISYEAR %(date +%%Y)
%define DAYNUMBER %(LC_TIME='en_US.UTF-8' date +%%d)
%define DAYNAMESHORT %(LC_TIME='en_US.UTF-8' date +%%a)
%define today %{DAYNAMESHORT} %{THISMONTHSHORT} %{DAYNUMBER} %{THISYEAR}
Name:       %{pkgname}
Version:    %{pkgver}
Release:    0
# Fedora release look standard from OpenSUSE build service:
# Release:      <CI_CNT>.<B_CNT>
# Release:      %%{?release_prefix}.<CI_CNT>.<B_CNT>
# where rpm macro %%{release_prefix} is defined in spec file
# Normally it looks like:
# Release:      63.fc41 for Fedora packages which is scripted as:
# Release:      0%%{?dist}
# OpenSUSE build service allows for this variant:
# Release:      63.1.fc41
# Release:       <CI_CNT>.<B_CNT>%%{?dist}
#
# Add this to Project Config to tag Fedora packages with fcXX:
# ------------------------------
# # reset release name
# onepercentage%%if 0onepercentage%%{?fedora_version}
# Release: <CI_CNT>.<B_CNT> spec:<CI_CNT>.<B_CNT>twopercentage%%{?dist}
# onepercentage%%endif
# ------------------------------
Summary:    Cloud Meetings
License:    SUSE-NonFree
URL:        https://zoom.com
%if 0%{?fedora} > 1
Group:      Telephone
%endif
#%if 0%%{?suse_version} > 1600
%if 0%{?suse_version} 
Group:      Productivity/Telephony/SIP/Clients
%endif
#%%if 0%%{?sle_version} == 150600 && 0%%{?is_opensuse}
#Group:      Productivity/Telephony/SIP/Clients
#%%endif
#BuildArch:      noarch
#BuildArch:      %%{architecture}
BuildRequires:  wget
BuildRequires:  zypper
%if 0%{?suse_version}
BuildRequires: -post-build-checks
%endif
Provides:   %{name} = %{version}-%{release}
Obsoletes:  %{name} < %{version}-%{release}
Obsoletes:  %{executable}-appimage < %{version}-%{release}
# This app would benefit from being run in a firejail sandbox
Requires:   wget
Recommends: firejail >= 0.9.72
Recommends: firetools >= 0.9.72
Requires:   appimageupdatetool

%description
%{TITLE} Cloud Meetings
%{AppName} brings people together to connect and get things done.
%{AppName} provides video meetings and chat, with additional options for webinars and phone service.

%prep

%build

%install
echo
echo "--- Start section %%install ---"
ls %{_sourcedir}
echo
head -2 %{_sourcedir}/VERSION 
echo
head -2 %{_sourcedir}/VERSION | cut -d":" -f2 | cut -d"-" -f1 | tr -d ' '
echo
echo HOME=$HOME
ls -al $HOME 2>/dev/null
echo %%{_sourcedir}=%{_sourcedir}
ls -al %{_sourcedir} 2>/dev/null
srcdir=%{_sourcedir}
pkgdir_head=%{buildroot}
pkgdir=%{buildroot}
echo "----------------------------------------"
echo
echo "%{TITLE} releases"
echo "=================================="
echo
echo "Execute terminal command to open web page:"
echo
echo "xdg-open \"%{webDir}\""
echo
echo "----------------------------------------"
%if 0%{?include_dummy_appimage}
mkdir -p -v  "${pkgdir}/opt/appimages"
cat <<EOF > "${pkgdir}/opt/appimages/%{executable}.AppImage"
#!/usr/bin/bash
exit 0
EOF
chmod 755 "${pkgdir}/opt/appimages/%{executable}.AppImage"
%endif
# Create launcher
mkdir -p -v "${pkgdir}/usr/bin"
cp -r --no-preserve=mode,ownership "${srcdir}/%{executable}.sh" "${pkgdir}/usr/bin/%{launcher}"
chmod 755 "${pkgdir}/usr/bin/%{launcher}"
install -dm755 "${pkgdir}/usr/share/icons/hicolor/scalable/apps"
cat <<EOF > "${pkgdir}/usr/share/icons/hicolor/scalable/apps/%{pkgname}.svg"
<svg xmlns="http://www.w3.org/2000/svg" version="1.2" viewBox="0 0 128 128"><path fill="#fefefe" d="m58.347 126.765-4.154-.586A62.653 62.754 0 0 1 3.38 80.07a50.813 50.895 0 0 1-1.855-15.867c0-7.33.318-10.434 1.817-15.994A62.78 62.881 0 0 1 48.4 3.242c5.843-1.463 8.816-1.82 15.676-1.82 5.272 0 6.732.09 9.527.547a62.132 62.232 0 0 1 34.782 17.725 62.156 62.156 0 0 1 17.696 34.863c.495 3.143.635 6.337.546 9.517-.14 5.28-.318 9.836-1.817 15.74a62.78 62.881 0 0 1-44.893 45.093 53.392 53.478 0 0 1-14.863 1.858l-6.708-.039zm14.317-5.471a57.673 57.766 0 0 0 11.687-111.27A57.648 57.74 0 0 0 8.131 78.44a57.838 57.932 0 0 0 64.597 42.84ZM35.316 84.14a11.382 11.4 0 0 1-8.676-8.729c-.496-2.214-.56-29.226-.102-30.231.648-1.4-.101-1.375 21.85-1.336 21.9 0 22.13 0 24.733 1.297a12.106 12.126 0 0 1 4.485 4.263c1.562 2.646 1.6 2.926 1.6 19.073v14.53l-.711.713-.724.687H57.09c-11.395 0-21.177-.127-21.8-.254zm63.34.038c-.23-.063-4.193-2.926-8.817-6.26l-8.422-6.12V56.542l8.486-6.184a156.56 156.56 0 0 1 9.108-6.425 1.016 1.018 0 0 1 1.016.254c.356.37.42 2.125.42 19.913 0 17.406-.064 19.556-.382 19.875-.432.432-.724.496-1.397.203z"/><path fill="#e8ecea" d="M53.965 127.337A63.86 63.963 0 0 1 .839 74.241 56.492 56.583 0 0 1 .001 64.2c.127-5.456.609-10.52 2.134-16.22A64.088 64.192 0 0 1 48.11 2.046 67.328 67.436 0 0 1 64.077.01c3.264-.076 6.936.293 9.756.789a63.987 64.09 0 0 1 53.481 53.529c.457 2.837.686 6.515.686 9.772 0 3.27-.229 6.947-.686 9.785a63.987 64.09 0 0 1-53.15 53.49c-2.503.433-6.175.611-9.274.624-3.646.013-7.241-.09-10.925-.649zm19.97-1.158a62.78 62.881 0 0 0 50.876-46.365 65.537 65.642 0 0 0 1.957-15.74 62.208 62.309 0 0 0-18.382-44.38A61.967 62.067 0 0 0 73.579 1.969a53.443 53.53 0 0 0-9.502-.788c-5.272.127-9.82.56-15.676 2.06A62.78 62.881 0 0 0 3.329 48.196 59.515 59.611 0 0 0 1.22 64.19c.013 5.344.61 9.975 2.147 15.867a62.653 62.754 0 0 0 50.814 46.073c3.582.649 7.24.636 10.861.623 2.973-.013 6.479-.204 8.918-.585z"/><path fill="#558dfe" d="M59.326 121.777a57.737 57.83 0 1 1 13.338-.522c-3.646.548-10.086.815-13.338.484zm19.207-38.12.686-.726V68.426c0-16.083 0-16.414-1.626-19.022a12.106 12.126 0 0 0-4.459-4.263c-2.604-1.297-2.833-1.336-24.72-1.336-21.927 0-21.215-.063-21.825 1.298-.457 1.044-.432 28.056.064 30.308a11.382 11.4 0 0 0 8.676 8.704c.597.089 10.417.19 21.799.229h20.63zm21.532.318c.33-.319.394-2.469.394-19.875 0-17.788-.038-19.544-.42-19.938a.978.98 0 0 0-.977-.255c-.33.09-4.421 2.965-9.109 6.388l-8.524 6.247V71.76l8.46 6.133a298.63 299.112 0 0 0 8.779 6.285c.686.255.978.23 1.397-.203z" style="fill:#b200f8;fill-opacity:1"/></svg>EOF
EOF
# Create launcher
install -Dm644 "${srcdir}/launcher.desktop" "${pkgdir}/usr/share/applications/%{name}.desktop"

# Create a script to download Zoom AppImage
# Create script in /usr/local/bin/zoom-appimage-download
mkdir -p ${pkgdir}/usr/local/bin
scriptFile="${pkgdir}/usr/local/bin/%{executable}-%{executable_tag}-download"
echo "#!/usr/bin/bash" > $scriptFile
echo "echo \"Closing %{executable}.AppImage ...\"" >> $scriptFile
echo "pkill AppRun.wrapped" >> $scriptFile
echo "killall %{launcher}" >> $scriptFile
echo "echo \"wait a few seconds to terminate %{executable}.AppImage ...\"" >> $scriptFile
echo "sleep 5s" >> $scriptFile
echo "echo \"Download %{TITLE} file to /opt/appimages/\"" >> $scriptFile
echo "sudo wget -O /opt/appimages/%{executable}.AppImage %{APPIMAGE}" >> $scriptFile
echo "echo" >> $scriptFile
echo "echo \"Done.\"" >> $scriptFile
echo "exit 0" >> $scriptFile
# Make script executable
chmod +x "$scriptFile"

# Create a script to update Zoom AppImage
# Create script in /usr/local/bin/zoom-appimage-update
mkdir -p ${pkgdir}/usr/local/bin
scriptFile="${pkgdir}/usr/local/bin/%{executable}-%{executable_tag}-update"
echo "#!/usr/bin/bash" > $scriptFile
echo "echo \"Closing %{executable}.AppImage ...\"" >> $scriptFile
echo "pkill AppRun.wrapped" >> $scriptFile
echo "killall %{launcher}" >> $scriptFile
echo "echo \"wait a few seconds to terminate %{executable}.AppImage ...\"" >> $scriptFile
echo "sleep 5s" >> $scriptFile
echo "# Remove traces of unfinished downloads" >> $scriptFile
echo "sudo rm -f /opt/appimages/*.AppImage.part*" >> $scriptFile
echo "echo \"Download %{TITLE} file to /opt/appimages/\"" >> $scriptFile
echo "file=/opt/appimages/%{executable}.AppImage" >> $scriptFile
echo "minimumsize=90" >> $scriptFile
echo "if [ -f \$file ]; then" >> $scriptFile
echo "    echo found \$file" >> $scriptFile
echo "    actualsize=\$(du -k \$file | cut -f 1)" >> $scriptFile
echo "    if [ \$actualsize -ge \$minimumsize ]; then" >> $scriptFile
echo "        #echo size is over \$minimumsize kilobytes" >> $scriptFile
echo "        echo appimageupdatetool \$file" >> $scriptFile
echo "        sleep 1" >> $scriptFile
echo "        sudo appimageupdatetool \$file" >> $scriptFile
echo "        iFiles=\`ls /opt/appimages | grep '%{executable}.*\.AppImage' | wc -l\`" >> $scriptFile
echo "        if [ \$iFiles -gt 1 ]; then" >> $scriptFile
echo "            sudo rm -f \$file" >> $scriptFile
echo "            sudo mv /opt/appimages/%{executable}*.AppImage \$file" >> $scriptFile
echo "        fi" >> $scriptFile
echo "    else" >> $scriptFile
echo "        #echo echo size is under \$minimumsize kilobytes" >> $scriptFile
echo "        echo Downloading %{executable}.AppImage..." >> $scriptFile
echo "        sleep 1" >> $scriptFile
echo "        sudo wget -O \$file %{APPIMAGE}" >> $scriptFile
echo "    fi" >> $scriptFile
echo "else" >> $scriptFile
echo "    echo Downloading %{executable}.AppImage..." >> $scriptFile
echo "    sleep 1" >> $scriptFile
echo "    sudo wget -O \$file %{APPIMAGE}" >> $scriptFile
echo "fi" >> $scriptFile
echo "if [ -f \$file ]; then" >> $scriptFile
echo "    sudo chmod 755 \$file" >> $scriptFile
echo "fi" >> $scriptFile
echo "echo" >> $scriptFile
echo "echo \"Done.\"" >> $scriptFile
echo "exit 0" >> $scriptFile
# Make script executable
chmod +x "$scriptFile"

echo "--- List files that will be packaged ---"
find %{buildroot} | sed "s|%{buildroot}||g"
echo "--- End list files that will be packaged ---"
echo
echo "--- End section %%install ---"
echo

%post
#!/usr/bin/bash
umask 007
/sbin/ldconfig > /dev/null 2>&1
DISTRO=$(awk -F= '/^NAME/{print $2}' /etc/os-release | cut -d'=' -f2)
opensusetumbleweed="\"openSUSE Tumbleweed\""
opensuseleap="\"openSUSE Leap\""
fedora="Fedora"
if [ "$DISTRO" == "$opensusetumbleweed" ]; then
    ISOPENSUSE=true
elif [ "$DISTRO" == "$opensuseleap" ]; then
    ISOPENSUSE=true
else
    ISOPENSUSE=false
fi
if [ "$DISTRO" == "$fedora" ]; then
    ISFEDORA=true
else
    ISFEDORA=false
fi
echo "killing Zoom if it is running..."
pkill AppRun.wrapped
killall %{launcher}
echo "wait a few seconds to terminate %{executable}.AppImage ..."
sleep 5s
# Remove traces of unfinished downloads
rm -f /opt/appimages/*.AppImage.part*
# Download %%{AppName} AppImage file to the correct location
file="/opt/appimages/%{executable}.AppImage"
minimumsize=90
if [ -f "$file" ]; then
    echo "found $file"
    actualsize=$(du -k "$file" | cut -f 1)
    if [ $actualsize -ge $minimumsize ]; then
        #echo size is over $minimumsize kilobytes
        echo "appimageupdatetool $file"
        sleep 1
        appimageupdatetool "$file"
        iFiles=`ls /opt/appimages | grep '%{executable}.*\.AppImage' | wc -l`
        if [ $iFiles -gt 1 ]; then
            rm -f $file
            mv /opt/appimages/%{executable}*.AppImage $file
        fi
    else
        #echo size is under $minimumsize kilobytes
        echo "Downloading %{executable}.AppImage..."
        sleep 1
        wget -O "$file" %{APPIMAGE}
    fi
else
    echo "Downloading %{executable}.AppImage..."
    sleep 1
    wget -O "$file" %{APPIMAGE}
fi
if [ -f "$file" ]; then
    chmod 755 "$file"
fi
# Users on the system
USERS=$(awk -F':' '{ print $1 }' /etc/passwd)
# echo USERS=$USERS
for user in $USERS; do
    # In zoom version 5.17.5 an issue was detected that may reoccur in subsequent releases
    # due to mismatch in user configuration files. Those files need to be removed.
    if [ -d "/home/$user/.zoom" ]; then
        rm -rf /home/$user/.zoom
    fi
    if [ -d "/home/$user/.cache" ]; then
        rm -rf /home/$user/.cache
    fi
    if [ -d "/home/$user/.config" ]; then
        rm -f /home/$user/.config/zoom*
    fi
done

%postun
# Note that %%postun also gets called when upgrading.  We have to check the
# argument passed to %%postun (the number of copies of the RPM installed after
# this is run) to determine whether this is an upgrade, or a removal.  "0"
# means removal, and >0 means upgrade
umask 007
/sbin/ldconfig > /dev/null 2>&1
# Remove $EXECUTABLE_TAG.desktop from existing URI sip handler
# sed -i 's/$EXECUTABLE_TAG.desktop//g' /usr/share/applications/mimeapps.list
# Update mime database
# update-desktop-database /usr/share/applications
# update-mime-database /usr/share/mime
if [ "$1" = "0" ]; then
    echo "postun uninstall $1"
    rm -fv /opt/appimages/%{executable}.AppImage
else
    echo "postun upgrade $1"
fi

%files
# Format:
# %%attr(<mode>, <user>, <group>) file
# %%defattr(file perms, user, group, dir perms)
# %%defattr(-,root,root,-)
# or
# %%defattr(-,root,root)
#
%attr(-,root,root) /usr/bin
%attr(-,root,root) /usr/local/bin
%attr(-,root,root) /usr/share/applications
%attr(-,root,root) /usr/share/icons/hicolor/scalable/apps
%if 0%{?include_dummy_appimage}
%attr(-,root,root) /opt/appimages
%endif

#
# %%changelog format example:
# * Sat Mar 9 2024 Name <email@domain.org> - 5.17.1
# - Initial release.
#
%changelog
* %{today} %{packager} <%{packagerEmail}> - %{version}
- New build.
openSUSE Build Service is sponsored by