forked from squillace/sysext-bakery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_wasmedge_sysext.sh
executable file
·72 lines (55 loc) · 3.58 KB
/
create_wasmedge_sysext.sh
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
#!/bin/bash
set -euo pipefail
set -x
export ARCH="${ARCH-x86_64}"
export FILE_ARCH="x86-64"
SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")"
if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 VERSION SYSEXTNAME"
echo "The script will download the wasmedge release tar ball (e.g., for 4.0.0) and create a sysext squashfs image with the name SYSEXTNAME.raw in the current folder."
echo "A temporary directory named SYSEXTNAME in the current folder will be created and deleted again."
echo "All files in the sysext image will be owned by root."
echo "To use arm64 pass 'ARCH=aarch64' as environment variable (current value is '${ARCH}')."
"${SCRIPTFOLDER}"/bake.sh --help
exit 1
fi
VERSION="$1"
SYSEXTNAME="$2"
# clean and obtain the specified version
rm -f "WasmEdge-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
curl -o "WasmEdge-${VERSION}-ubuntu20.04_${ARCH}.tar.gz" -L "https://github.com/WasmEdge/WasmEdge/releases/download/${VERSION}/WasmEdge-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
rm -f "WasmEdge-plugin-wasi_nn-ggml-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
curl -o "WasmEdge-plugin-wasi_nn-ggml-${VERSION}-ubuntu20.04_${ARCH}.tar.gz" -L "https://github.com/WasmEdge/WasmEdge/releases/download/${VERSION}/WasmEdge-plugin-wasi_nn-ggml-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
rm -f "WasmEdge-plugin-wasi_nn-whisper-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
curl -o "WasmEdge-plugin-wasi_nn-whisper-${VERSION}-ubuntu20.04_${ARCH}.tar.gz" -L "https://github.com/WasmEdge/WasmEdge/releases/download/${VERSION}/WasmEdge-plugin-wasi_nn-whisper-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
# clean earlier SYSEXTNAME directory and recreate
rm -rf "${SYSEXTNAME}"
mkdir -p "${SYSEXTNAME}"
# extract wasmedge into SYSEXTNAME/
tar --force-local -xvf "WasmEdge-${VERSION}-ubuntu20.04_${ARCH}.tar.gz" -C "${SYSEXTNAME}"
# ends up in WasmEdge-${VERSION}-Linux/bin/wasmedge -- there's bin/ include/ lib/ to clean up
# clean downloaded tarball
rm "WasmEdge-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
# create deployment directory in SYSEXTNAME/ and move wasmtime into it
mkdir -p "${SYSEXTNAME}"/usr/bin # binary
mkdir -p "${SYSEXTNAME}"/usr/lib/wasmedge # .so files
mkdir -p "${SYSEXTNAME}"/usr/lib/plugin-ggml # wasi-nn-ggml
mkdir -p "${SYSEXTNAME}"/usr/lib/plugin-whisper # wasi-nn-whisper
# extract plugins
tar --force-local -xvf "WasmEdge-plugin-wasi_nn-ggml-${VERSION}-ubuntu20.04_${ARCH}.tar.gz" -C "${SYSEXTNAME}/usr/lib/plugin-ggml"
tar --force-local -xvf "WasmEdge-plugin-wasi_nn-whisper-${VERSION}-ubuntu20.04_${ARCH}.tar.gz" -C "${SYSEXTNAME}/usr/lib/plugin-whisper"
rm -f "WasmEdge-plugin-wasi_nn-ggml-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
rm -f "WasmEdge-plugin-wasi_nn-whisper-${VERSION}-ubuntu20.04_${ARCH}.tar.gz"
mv "${SYSEXTNAME}"/WasmEdge-"${VERSION}"-Linux/bin/wasmedge "${SYSEXTNAME}"/usr/bin/
mv "${SYSEXTNAME}"/WasmEdge-"${VERSION}"-Linux/lib/* "${SYSEXTNAME}"/usr/lib/wasmedge/
# clean up any extracted mess # currently in WasmEdge-"${VERSION}"-Linux/bin/wasmedge -- there's bin/ include/ lib/ to clean up
rm -rf "${SYSEXTNAME}"/WasmEdge-"${VERSION}"-Linux/bin/ "${SYSEXTNAME}"/WasmEdge-"${VERSION}"-Linux/include/ "${SYSEXTNAME}"/WasmEdge-"${VERSION}"-Linux/lib
echo "============= Show the current sysext contents ============="
tree "${SYSEXTNAME}"
echo "============================================================"
# bake the .raw. This process uses the generic binary name for layer metadata
"${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}"
# rename the file to the specific version and arch.
mv "./${SYSEXTNAME}.raw" "./${SYSEXTNAME}-v${VERSION}-${FILE_ARCH}.raw"
# clean again just in case
rm -rf "${SYSEXTNAME}"