File wsl-appx.spec of Package wsl-appx

#
# spec file for package wsl-appx
#
# Copyright (c) 2017 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#

Name:           wsl-appx
# an appx version needs to match
# '(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){3}'
# found in the error log if you don't set the proper version
Version:        1.1.0.0
Release:        0
License:        MIT
Summary:        SUSE on Windows application
Url:            https://gitlab.suse.de/cbosdonnat/wsl-app
Group:          Productivity/Other
Source:         openSUSE.tar.gz
Patch0:         substitutable.patch
BuildRequires:  mingw64-filesystem
BuildRequires:  wsl-launcher
BuildRequires:  wsl-launcher-debug
BuildRequires:  fb-util-for-appx
%if 0%{?is_opensuse}
BuildRequires:  opensuse-wsl-image
BuildRequires:  openSUSE-release
%else
BuildRequires:  sles-release
BuildRequires:  suse-wsl-image
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch

%description
Windows Store application providing SLES or openSUSE.

%prep
%setup -q -n openSUSE
%patch0 -p1

os_release_file="/usr/lib/os-release"
if [ -e "/etc/os-release" ]; then
	os_release_file="/etc/os-release"
fi

# This is dirty. The CN of the AppxManifest needs to match the
# signing certificate's CN. In OBS the CN is the project name. The
# project itself may not have a cert so we can't use %_project. So
# we abuse %vendor which is the project whith the key.
PROJECT="%vendor"
PROJECT="${PROJECT##*/}"
OBS="%vendor"
OBS="${OBS#*//}"
OBS="${OBS%/*}"
PUBLISHER="E=$PROJECT@$OBS, CN=$PROJECT OBS Project"
. "$os_release_file"
APPID="${PRETTY_NAME//[^[:alnum:]]/}"
LAUNCHERNAME="${PRETTY_NAME//[^[:alnum:].]/-}.exe"
sed -i -e "s/@PRETTY_NAME@/${PRETTY_NAME}/g;s/@APPID@/$APPID/g;s/@PUBLISHER@/$PUBLISHER/g;s/@VERSION@/%{version}/g;s/@LAUNCHERNAME@/$LAUNCHERNAME/g" AppxManifest.xml
cat AppxManifest.xml

# Get the binary
cp %{_mingw64_bindir}/DistroLauncher.exe "$LAUNCHERNAME"

%build
## Get the rootfs tarball
mkdir docker
tar -xf /usr/share/suse-docker-images/native/*.tar.xz -C docker
tarball=$(find docker -size +10M)
mv ${tarball} install.tar
# XXX for some reason the file from the docker archive has 0 epoch
touch -d "@${SOURCE_DATE_EPOCH:-`date +%%s`}" install.tar
ls -al install.tar
# XXX for some reason it's gzip'd on SLE12 but not in newer distros.
# Bug in containment-rpm-docker?
case "`file install.tar`" in
	*gzip*) mv install.tar install.tar.gz ;;
	*) gzip install.tar ;;
esac
rm -rf docker

# Create a filemap
find * -type f | awk 'BEGIN { print "[Files]" } /filemap.txt/ { next; } { print "\"" $0 "\" \"" $0 "\"" }' > filemap.txt

# TODO So far .pri files are generated by VS and added to the source
# it would be way better to have them generated here with an opensource tool

os_release_file="/usr/lib/os-release"
if [ -e "/etc/os-release" ]; then
	os_release_file="/etc/os-release"
fi

eval `grep ^PRETTY_NAME $os_release_file`
APPXNAME="${PRETTY_NAME//[^[:alnum:].]/-}.appx"

appx -o "$APPXNAME" -f filemap.txt

mkdir r
%if 0%{?suse_version} > 1315
tar -C r -xzf $PWD/install.tar.gz usr/lib/sysimage/rpm/Packages
%else
tar -C r -xzf $PWD/install.tar.gz var/lib/rpm/Packages
%endif
rpm --root $PWD/r -qa --qf '%%{size} %%{name}\n' | sort -n > "$APPXNAME.packages.sizes"
rpm --root $PWD/r -qa --qf '%%{name}|%%{epoch}|%%{version}|%%{release}|%%{arch}|%%{disturl}\n' | sort > "$APPXNAME.packages"
rm -rf r

echo -n "### APPX size: "
du -h "$APPXNAME"

%install
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/appx
cp *.appx* $(dirname $RPM_SOURCE_DIR)/OTHER/

%files
# store package list just for reference
%doc *.appx.*

%changelog