summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 06a0d90b4e019155cadb193a105ce0e626e6831c (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: Nikolay Bryskin <nbryskin@gmail.com>
# Contributor: Pellegrino Prevete <pellegrinoprevete@gmail.com>

# shellcheck disable=SC2034
pkgbase=metamask
pkgname=(
  "${pkgbase}-chromium"
  "${pkgbase}-firefox"
  "${pkgbase}-google-chrome"
)
pkgver=12.1.3
pkgrel=1
pkgdesc='Browser extension that enables browsing Ethereum blockchain enabled websites'
url="https://github.com/MetaMask/metamask-extension"
license=('LicenseRef-ConsenSys')
groups=('firefox-addons')
arch=('any')
depends=()
makedepends=('git' 'nvm' 'yarn-berry' 'chromium')
source=(
  "${pkgbase}::git+$url.git#tag=v${pkgver}"
  "chrome.pem"
)
sha512sums=(
  'SKIP'
  '6732e47d2431484e084512e815e44590c6693d9a1f7a192c0de2f11561fdfd6d87769a375650c4025ab8e2049fd7694ff2c45e19a03991d65c9b8a241bd7292a'
)
_chromium_extension_id="cfcbhkcbidaoaeljekeilbnebipmnkjm"

_ensure_local_nvm() {
    # let's be sure we are starting clean
    which nvm >/dev/null 2>&1 && nvm deactivate && nvm unload
    export NVM_DIR="${srcdir}/.nvm"

    # The init script returns 3 if version specified
    # in ./.nvrc is not (yet) installed in $NVM_DIR
    # but nvm itself still gets loaded ok
    source /usr/share/nvm/init-nvm.sh || [[ $? != 1 ]]
}

prepare() {
  cd "${srcdir}/${pkgbase}"
  cp .metamaskrc.dist .metamaskrc
  # set infura project id
  sed -i -e 's/00000000000/2f8ebfee0f81453d83fe6219b9a59754/g' .metamaskrc
  # nodejs 20.15 fails with:
  # TypeError: Cannot read properties of undefined (reading '0')
  _ensure_local_nvm
  nvm install 20.14
}

build() {
  cd "${srcdir}/${pkgbase}"
  _ensure_local_nvm
  yarn # setup
  yarn dist:mv2
  chromium \
    --disable-gpu \
    --disable-namespace-sandbox \
    --pack-extension="${srcdir}/${pkgbase}/dist/chrome" \
    --pack-extension-key="${srcdir}/chrome.pem"
}

package_metamask-chromium() {
  crx_path="/usr/lib/chromium-extension-metamask/metamask-${pkgver}.crx"
  cat > "${srcdir}/${_chromium_extension_id}.json" <<EOF
{
	"external_crx": "${crx_path}",
	"external_version": "${pkgver}"
}
EOF
  install -Dm644 "${srcdir}/${pkgbase}/dist/chrome.crx" "${pkgdir}${crx_path}"
  install -Dm644 "${srcdir}/${_chromium_extension_id}.json" \
                 "${pkgdir}/usr/share/chromium/extensions/${_chromium_extension_id}.json"
  install -Dm644 "${srcdir}/${pkgbase}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_metamask-google-chrome() {
  crx_path="/usr/lib/google-chrome-extension-metamask/metamask-${pkgver}.crx"
  cat > "${srcdir}/${_chromium_extension_id}.json" <<EOF
{
	"external_crx": "${crx_path}",
	"external_version": "${pkgver}"
}
EOF
  install -Dm644 "${srcdir}/${pkgbase}/dist/chrome.crx" "${pkgdir}${crx_path}"
  install -Dm644 "${srcdir}/${_chromium_extension_id}.json" \
                 "${pkgdir}/usr/share/google-chrome/extensions/${_chromium_extension_id}.json"
  install -Dm644 "${srcdir}/${pkgbase}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_metamask-firefox() {
  install -Dm644 "${srcdir}/${pkgbase}/builds/metamask-firefox-${pkgver}.zip" \
                 "${pkgdir}/usr/lib/firefox/browser/extensions/webextension@metamask.io.xpi"
  install -Dm644 "${srcdir}/${pkgbase}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}