summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 755d0ce54f47a3860cca2151cfd4d121abf1ddc4 (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
# Maintainer: mitchpk <kphctim at gmail dot com>
# Thanks to https://aur.archlinux.org/packages/factorio/ for authentication code

pkgname=fmodstudio
pkgver=2.02.20
pkgrel=1
pkgdesc="Desktop application for adaptive audio content creation"
arch=('x86_64')
url="https://fmod.com"
license=('custom')
depends=('alsa-lib' 'libxcursor' 'libxcomposite' 'freetype2' 'nss' 'hicolor-icon-theme' 'libxtst')
source=('LICENSE.html')
sha256sums=('f828e794ce468d1aa47f1a4436af9fbf2e95eac0e3051c1eefa44ab1a7c9eab8')
makedepends=('jq')
_filename=fmodstudio20220linux64-installer.deb

build() {
    echo "Downloading FMOD Studio requires an FMOD.com account"
    local file="${SRCDEST}/${_filename}"
    local username=$FMOD_LOGIN
    local password=$FMOD_PASSWORD
    local token
    local completed=0

    while [[ $completed -eq 0 ]]; do
        if [[ -z $username || -z $password ]]; then
            [[ ! -t 0 ]] && return 1
            echo "Please enter your username/email and password"
            read -rp "Username or email: " username
            [[ -z $username ]] && continue

            read -rsp "Password: " password; echo
            [[ -z $password ]] && continue
        fi

        echo "Logging in..."

        local output
        if output=$(curl --silent -X POST https://fmod.com/api-login --user $username:$password
            ) && token=$(echo "$output" | jq -r '.token | strings') && [[ -n $token ]]
        then
            echo "Successfully authenticated with token"
        else
            echo "Login failed"

            [[ ! -t 0 ]] && return 1
            read -n1 -p "Retry login? (Y/n) " try_again ; echo
            if [[ "${try_again,,*}" == "n" ]]; then
                return 1
            else
                continue
            fi
        fi

        echo "Downloading $_filename..."
        if output=$(curl -G "https://fmod.com/api-get-download-link" \
                    --data-urlencode path="files/fmodstudio/tool/Linux/" \
                    --data-urlencode filename="$_filename" \
                    -H "Authorization: FMOD $token") &&
                    downloadurl=$(echo "$output" | jq -r '.url | strings') && [[ -n $downloadurl ]]
        then
            code=$(curl -G --retry 10 --retry-delay 3 \
                 --fail --location \
                 --continue-at - \
                 --output "${file}.part" \
                 "$downloadurl" \
                 --write-out '%{http_code}'
            ) || rm -f "${file}.part"

            if [[ ! -f "${file}.part" ]]; then
                echo "Download failed"
                return 1
            fi

            echo "Download successful"
            mv "${file}"{.part,}
            completed=1
        else
            echo "Failed to fetch download link"
            return 1
        fi
    done
}

package() {
    echo "Unpacking..."
    ar p "${SRCDEST}/${_filename}" data.tar.xz | tar -C "${pkgdir}" -Jx
    chmod +x ${pkgdir}/opt/fmodstudio/fmodstudio
    chmod +x ${pkgdir}/opt/fmodstudio/fmodstudiocl
    chmod +x ${pkgdir}/opt/fmodstudio/libexec/QtWebEngineProcess
    install -d "${pkgdir}/usr/bin"
    ln -s /opt/fmodstudio/fmodstudio "${pkgdir}/usr/bin"
    ln -s /opt/fmodstudio/fmodstudiocl "${pkgdir}/usr/bin"

    install -Dm644 LICENSE.html "$pkgdir/usr/share/licenses/$pkgname/LICENSE.html"
}