summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 03b7a402fff8d4df7166f9205e6b157f14ea8dd1 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Maintainer: billli11
# Contributor: marmis
# Contributor: gee

pkgname=reshade-shaders-git
pkgver=r118.67603ed
pkgrel=1
pkgdesc='A collection of post-processing shaders written in the ReShade FX shader language, to be used by vkBasalt'
arch=('any')
url='https://github.com/crosire/reshade-shaders'
license=('custom')
makedepends=('git' 'curl' 'libarchive' 'parallel')
source=("git+https://github.com/crosire/reshade-shaders.git#branch=list")
sha256sums=(SKIP)
options=(!strip)
install=reshade-shaders.install

pkgver() {
    cd "reshade-shaders"
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() (
    [ -d "${srcdir}/build" ] && rm -r "${srcdir}/build"
    mkdir -p "${srcdir}/build/"{shaders,textures,extract}
    cd "${srcdir}/build"

    extract_effect() {
        local -A ini_array
        local line license shaders textures

        read -r
        while read -r line; do
            case "$line" in
            "PackageName="*)
                ini_array[name]="${line#PackageName=}";;
            "InstallPath="*)
                ini_array[shaders]="${line#*reshade-shaders\\}"
                ini_array[shaders]="${ini_array[shaders],S}"
                ini_array[shaders]="${ini_array[shaders]//\\/\/}";;
            "TextureInstallPath="*)
                ini_array[textures]="${line#*reshade-shaders\\}"
                ini_array[textures]="${ini_array[textures],T}"
                ini_array[textures]="${ini_array[textures]//\\/\/}";;
            "DownloadUrl="*)
                ini_array[url]="${line#DownloadUrl=}";;
            esac
        done

        # Set fallback name if empty
        ini_array[name]="${ini_array[name]:-${ini_array[url]##*/}}"
        ini_array[shaders]="${ini_array[shaders]:-shaders}"
        ini_array[textures]="${ini_array[textures]:-textures}"

        msg "Getting ${ini_array[name]}"
        mkdir -p "extract/${ini_array[name]}" "${ini_array[shaders]}" "${ini_array[textures]}"

        (   cd "extract/${ini_array[name]}"
            if ! /usr/bin/curl -L "${ini_array[url]}" -o "${ini_array[name]}.zip"; then
                error "Failed to download ${ini_array[url]}"
                exit 1
            fi
            if ! /usr/bin/bsdunzip "${ini_array[name]}.zip"; then
                error "Failed to extract ${ini_array[name]}.zip"
                exit 1
            fi

            shaders="$(find . -mindepth 1 -type d -iname 'shaders'|head -n 1)"
            [ -d "$shaders" ] && mv "$shaders/"* -t "../../${ini_array[shaders]}"

            while read -d '' -r license; do
                mv "$license" -t "../../${ini_array[shaders]}"
            done < <(find . -type f -iregex '.*/\(license.*\|.*\.md\)' -print0)

            textures="$(find . -mindepth 1 -type d -iname 'textures'|head -n 1)"
            [ -d "$textures" ] && mv "$textures/"* -t "../../${ini_array[textures]}"

            msg done
        )
    }

    export -f extract_effect msg error
    export ALL_OFF BOLD BLUE GREEN RED YELLOW

    cat ../reshade-shaders/EffectPackages.ini |\
        SHELL=$(type -p bash) parallel -N1 --pipe --regexp --recstart '^\[[^\]]*\]' \
            extract_effect
)

package() {
    local file
    cd "${srcdir}/build"

    install -dm 755 "${pkgdir}/opt/reshade/shaders"
    install -dm 755 "${pkgdir}/opt/reshade/textures"
    while read -d '' -r file; do
        install -Dm 644 "$file" "${pkgdir}/opt/reshade/${file}"
    done < <(find "shaders" "textures" -type f -print0)
}