summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 415514047f7f77a2bd5de35d36e0b4a759005b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Maintainer: detiam <dehe_tian <at> outlook <dot> com>

# shellcheck disable=SC1090
pkgname=nvidia-patch-git
pkgver=r1083.ac0afeb
pkgrel=1
pkgdesc="apply nvidia-patch by keylase automatically, unlock nvfbc and nvenc limit"
arch=('x86_64')
url="https://github.com/keylase/${pkgname/-git}"
license=('unknown')
provides=('nvidia-patch')
conflicts=('nvidia-patch')
depends=("nvidia-utils")
makedepends=('git')
source=("git+$url.git")
sha1sums=('SKIP')

pkgver() {
	cd "${pkgname/-git}" || exit 1
	printf "r%s.%s" \
		"$(git rev-list --count HEAD)" \
		"$(git rev-parse --short HEAD)"
}

package() {
	enc_patch_list_text=$(sed -n '/.*patch_list=($/,/^)$/p' ${pkgname/-git}/patch.sh | sed 's|patch_list|enc_patch_list|')
	fbc_patch_list_text=$(sed -n '/.*patch_list=($/,/^)$/p' ${pkgname/-git}/patch-fbc.sh | sed 's|patch_list|fbc_patch_list|')

	mkdir -p "$pkgdir/usr/share/$pkgname/"
	cat <<- EOF > "$pkgdir/usr/share/$pkgname/simple_patcher.sh"
		#!/bin/env bash

		$enc_patch_list_text

		$fbc_patch_list_text

		encso=\$(readlink -es /lib/libnvidia-encode.so)
		fbcso=\$(readlink -es /lib/libnvidia-fbc.so)

		encver=\$(echo "\$encso" | grep -oP '[0-9]..*[0-9]$')
		fbcver=\$(echo "\$fbcso" | grep -oP '[0-9]..*[0-9]$')

		if [ -z "\${enc_patch_list[\$encver]}" ]; then
			echo "error: No valid NVENC patch was found."
			need_update=1
		fi
		if [ -z "\${fbc_patch_list[\$fbcver]}" ]; then
			echo "error: No valid NVFBC patch was found."
			need_update=1
		fi
		if [ "\$need_update" == 1 ]; then
			echo "Please update '$pkgname'. if it's already done, maybe the upstream haven't update."
			exit 2
		fi

		sed -i "\${enc_patch_list[\$encver]}" "\$encso"
		sed -i "\${fbc_patch_list[\$fbcver]}" "\$fbcso"

	EOF

	mkdir -p "$pkgdir/usr/share/libalpm/hooks/"
	cat <<- EOF > "$pkgdir/usr/share/libalpm/hooks/nvidia-patch.hook"
		[Trigger]
		Type = Package
		Operation = Install
		Operation = Upgrade
		Target = ${depends[0]%=*}
		Target = ${pkgname}

		[Action]
		Description = Patching Nvidia libraries...
		When = PostTransaction
		Exec = /usr/bin/bash "/usr/share/$pkgname/simple_patcher.sh"

	EOF
}