summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: eab9623fea24a1d281aed3ce24fa18ce44e1bee0 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Maintainer: Colin Wallace <wallacoloo@gmail.com>
# Download links to other u-he VSTs can be found here: http://www.kvraudio.com/forum/viewtopic.php?f=31&t=424953
# Note: These VSTs require purchase/activation.

_vstname=TripleCheese
_vstdir=/usr/lib/vst # Note: these are Linux VSTs (.so files)

pkgname=uhe-triplecheese-vst
pkgver=4408
pkgrel=1
pkgdesc='Freeware virtual-analog synthesizer from u-he'
arch=('x86_64' 'i686')
url='http://www.u-he.com/cms/triple-cheese'
license=('custom')
depends=('gtk3')
makedepends=('xxd')
_untardir=$_vstname-$pkgver
_tarname=$_untardir.tar.gz
source=("http://uhedownloads.heckmannaudiogmb.netdna-cdn.com/penguin/release/$pkgver/$_tarname")
md5sums=('e6984805d8a38ab558acc71317ea6c54')
install=user.install

_bits=$(echo "$CARCH" | sed "s/x86_64/64/" | sed "s/i686/32/")
_binaryname=$_vstname.$_bits.so


function patch_strings_in_file() {
    # Source (Johan Hedin): http://everydaywithlinux.blogspot.com/2012/11/patch-strings-in-binary-files-with-sed.html
    # Slight modification by Colin Wallace to force the pattern to capture the entire line
    # Usage: patch_strings_in_file <file> <pattern> <replacement>
    # replaces all occurances of <pattern> with <replacement> in <file>, padding
    # <replacement> with null characters to match the length
    # Unlike sed or patch, this works on binary files
    local FILE="$1"
    local PATTERN="$2"
    local REPLACEMENT="$3"

    # Find all unique strings in FILE that contain the pattern 
    STRINGS=$(strings ${FILE} | grep "^${PATTERN}$" | sort -u -r)

    if [ "${STRINGS}" != "" ] ; then
        echo "File '${FILE}' contains strings equal to '${PATTERN}':"

        for OLD_STRING in ${STRINGS} ; do
            # Create null terminated ASCII HEX representations of the strings
            OLD_STRING_HEX="$(echo -n ${OLD_STRING} | xxd -g 0 -u -ps -c 256)00"
            NEW_STRING_HEX="$(echo -n ${REPLACEMENT} | xxd -g 0 -u -ps -c 256)00"

            if [ ${#NEW_STRING_HEX} -le ${#OLD_STRING_HEX} ] ; then
                # Pad the replacement string with null terminations so the
                # length matches the original string
                while [ ${#NEW_STRING_HEX} -lt ${#OLD_STRING_HEX} ] ; do
                    NEW_STRING_HEX="${NEW_STRING_HEX}00"
                done

                # Now, replace every occurrence of OLD_STRING with NEW_STRING 
                echo -n "Replacing ${OLD_STRING} with ${REPLACEMENT}... "
                hexdump -ve '1/1 "%.2X"' ${FILE} | \
                sed "s/${OLD_STRING_HEX}/${NEW_STRING_HEX}/g" | \
                xxd -r -p > ${FILE}.tmp
                chmod --reference ${FILE} ${FILE}.tmp
                mv ${FILE}.tmp ${FILE}
                echo "Done!"
            else
                echo "New string '${NEW_STRING}' is longer than old" \
                     "string '${OLD_STRING}'. Skipping."
            fi
        done
    fi
}


build() {
    cd "$srcdir/$_untardir/$_vstname"

    # The binaries use a scheme that causes paths to all be ~/.uhe/$_vstname
    # This includes paths to the plugin's own static resources (images, fonts)
    # Patch the binary such that static resources will be loaded from a system dir:
    # Note: these paths can be located in the binary by hand via `strings $_binaryname`
    patch_strings_in_file "$_binaryname" "%s/.%s/%s/Data" "/opt/%3\$s/Data"
    patch_strings_in_file "$_binaryname" "%s/.%s/%s/Modules" "/opt/%3\$s/Modules"
    # This is for accessing the user guide & the dialog binaries
    patch_strings_in_file "$_binaryname" "%s/.%s/%s/" "/opt/%3\$s/"

    # The vst will work OK w/o the presets directory, but it must be manually
    # created if the user wishes to save his/her presets
    # NOTE: mixing positional and non-positional printf arguments like this is
    # against the spec, but doing differently would not meet the length limit
    patch_strings_in_file "$_binaryname" "%s/.%s/%s/Presets/%s" "%s/.local/share/%3\$s"

    # These other directories need to already exist and also be persistent
    patch_strings_in_file "$_binaryname" "%s/.%s/%s/Tunefiles" "%s/.local/share"
    # CCMaps is set via [settings wheel] -> Midi Table
    patch_strings_in_file "$_binaryname" "%s/.%s/%s/CCMaps" "%s/.local/share"
    # Support includes logs & license info
    patch_strings_in_file "$_binaryname" "%s/.%s/%s/Support" "%s/.local/share"
}

package() {
    local instdir=/opt/$_vstname

    cd "$srcdir/$_untardir/$_vstname"
    # Install custom license
    install -Dm644 license.txt "$pkgdir/usr/share/licenses/$pkgname/license.txt"

    # Install the binary and the correct dialog version
    install -D "$_binaryname" "$pkgdir/$instdir/$_binaryname"
    install -D "dialog.$_bits" "$pkgdir/$instdir/dialog.$_bits"
    # Link the binary onto the path
    mkdir -p "$pkgdir/usr/lib/vst"
    ln -s "$instdir/$_binaryname" "$pkgdir/usr/lib/vst/$_vstname.so"

    # Install all the directories (empty directories are required)
    find Data/ Modules/ Presets/ -type d -exec install -dm755 {} $pkgdir/$instdir/{} \;
    # Install all the files
    find Data/ Modules/ Presets/ -type f -exec install -Dm644 {} $pkgdir/$instdir/{} \;
}

# vim: set tabstop=4 shiftwidth=4 expandtab: