name='max'
version='26.24.0~75261'
release=1
summary='MAX messenger client, sandboxed with Firejail'
summary_ru='Клиент мессенджера MAX в песочнице Firejail'
group='Networking/Instant messaging'
desc='MAX is the Russian state-affiliated instant messaging client. This package always launches it inside a Firejail sandbox that hides the rest of the home directory and blocks the standalone crash-report uploader, since the app has no independent security track record and no reason to see the whole system.'
desc_ru='MAX — российский государственно-аффилированный клиент мгновенных сообщений. Пакет всегда запускает его в песочнице Firejail, которая скрывает остальной домашний каталог и блокирует отдельный процесс отправки крэш-дампов — у приложения нет независимой истории аудита безопасности и нет причин видеть всю систему.'
homepage='https://max.ru/'
maintainer='max.ru <https://max.ru/>'

architectures=('amd64')

license=('Custom')
nonfree=1
nonfree_msg='MAX является проприетарным приложением. Использование мессенджера, учетной записи и сетевых функций регулируется условиями MAX.'
nonfree_url='https://legal.max.ru/ps'

provides=()
replaces=('max')
conflicts=()

auto_reqprov_method="dirty"
auto_req=0
auto_prov=0

deps=('firejail')
deps_debian=('firejail' 'libxcb-xinerama0' 'libxcb-composite0' 'libxcb-ewmh2' 'libva-x11-2' 'libva-drm2' 'libvdpau1' 'libnotify4' 'libxcb-dri2-0' 'libopengl0' 'libxcb-cursor0' 'libxkbcommon-x11-0' 'libxcb-icccm4' 'libxcb-keysyms1' 'libxss1' 'libglib2.0-0' 'gsettings-desktop-schemas' 'ca-certificates')
deps_ubuntu=("${deps_debian[@]}")
deps_fedora=('firejail' 'libxcb' 'libva' 'libvdpau' 'libnotify' 'libglvnd-opengl' 'xcb-util-cursor' 'libxkbcommon-x11' 'xcb-util-wm' 'xcb-util-keysyms' 'libXScrnSaver' 'glib2' 'gsettings-desktop-schemas' 'ca-certificates')
deps_arch=('firejail' 'libxcb' 'libva' 'libvdpau' 'libnotify' 'libglvnd' 'xcb-util-cursor' 'libxkbcommon-x11' 'xcb-util-wm' 'xcb-util-keysyms' 'libxss' 'glib2' 'gsettings-desktop-schemas' 'ca-certificates')
deps_opensuse=('firejail' 'libxcb1' 'libva2' 'libvdpau1' 'libnotify4' 'libxcb-cursor0' 'libxkbcommon-x11-0' 'xcb-util-wm0' 'xcb-util-keysyms0' 'libXss1' 'libglib-2_0-0' 'gsettings-desktop-schemas' 'ca-certificates')
deps_altlinux=('firejail' 'libxcb' 'libxcbutil-cursor' 'libxcbutil-icccm' 'libxcbutil-keysyms' 'libXScrnSaver' 'libva' 'libvdpau' 'libnotify' 'libOpenGL' 'libxkbcommon-x11' 'glib2' 'gsettings-desktop-schemas' 'ca-certificates')

opt_deps=()
opt_deps_debian=('desktop-file-utils' 'hicolor-icon-theme' 'pipewire')
opt_deps_ubuntu=("${opt_deps_debian[@]}")
opt_deps_fedora=('desktop-file-utils' 'hicolor-icon-theme' 'pipewire')
opt_deps_arch=('desktop-file-utils' 'hicolor-icon-theme' 'pipewire')
opt_deps_opensuse=('desktop-file-utils' 'hicolor-icon-theme' 'pipewire')
opt_deps_altlinux=('desktop-file-utils' 'icon-theme-hicolor' 'pipewire')

build_deps=('binutils')

sources=(
	"https://download.max.ru/linux/deb/pool/main/m/max/MAX-26.24.0.75261.deb?~archive=false&~name=max.deb"
	'local:///max.desktop'
	'local:///max.profile'
	'local:///LICENSE'
)

checksums=(
	'sha256:7151aa2559e5fe22dd4dd6cf037b5d5cd38d302f84e49d4c4be94e1c4fe1f7d5'
	'sha256:80ec5c0f4777ab00c433c25ffa70ef23d1752785e6584288d189518b8b43d613'
	'sha256:cf8c986f7f1a9841be33b43cfd8e34e6c75dac6ffea07aad07869177fc7768c7'
	'sha256:ddfcad273084c8b5690f6276fb29d8990ff4a7114db8a89b3f46255f8675e6b6'
)

scripts=(
	['postinstall']='postinstall.sh'
	['postremove']='postremove.sh'
)

package() {
	cd "${srcdir}"

	mkdir -p "${srcdir}/extracted"
	ar x max.deb
	tar -xf data.tar.* -C "${srcdir}/extracted"

	install -dm755 "${pkgdir}/usr/share"
	cp -a "${srcdir}/extracted/usr/share/max" "${pkgdir}/usr/share/max"
	install -Dm644 "${srcdir}/extracted/usr/share/pixmaps/max.png" \
		"${pkgdir}/usr/share/pixmaps/max.png"

	for icon in "${srcdir}"/extracted/usr/share/icons/hicolor/*/apps/max.png; do
		size="$(basename "$(dirname "$(dirname "$icon")")")"
		install -Dm644 "$icon" \
			"${pkgdir}/usr/share/icons/hicolor/${size}/apps/max.png"
	done

	install -Dm644 max.profile "${pkgdir}/etc/firejail/max.profile"

	# The desktop file and every other launch path go through this wrapper —
	# MAX never runs unsandboxed regardless of how it's started.
	install -Dm755 /dev/stdin "${pkgdir}/usr/bin/max" <<'EOF'
#!/bin/sh
exec firejail --profile=max -- /usr/share/max/bin/max "$@"
EOF

	install -Dm644 max.desktop "${pkgdir}/usr/share/applications/max.desktop"

	install-license "${srcdir}/LICENSE" "max/LICENSE.nivora"
}

files() {
	files-find-binary
	files-find-desktop
	files-find-license
	files-find \
		"/etc/firejail/max.profile" \
		"/usr/share/max/**/*" \
		"/usr/share/pixmaps/max.png" \
		"/usr/share/icons/hicolor/*/apps/max.png"
}
