Skip to content

Commit 707ebec

Browse files
authored
feat(script): add caller and installer script for ffmpeg (#16)
* refact(caller): using hostip from containers/gvisor-tap-vsock * feat(exec): add a install script for container
1 parent f6e0e15 commit 707ebec

File tree

3 files changed

+118
-6
lines changed

3 files changed

+118
-6
lines changed

scripts/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# install.sh 说明
2+
3+
`install.sh` 会使用标准的 ssh client 发送 `install_ffmpeg``sshexec`, `sshexec` 会安装 oomol 提供的 ffmpeg 二进制文件
4+
`install.sh` 会将 `caller.sh` 链接到 `/usr/bin/ffmpeg``/usr/bin/ffprobe`,在 Container 中调用 `ffmpeg``ffprobe` 时,会通过 sshexec 被转发到 Host 端的 ffmpeg 和 ffprobe。
5+
6+
# caller.sh 说明
7+
8+
`caller.sh` 运行在 Container 中,用于呼叫 Host 端的二进制文件,目前支持的二进制文件有 `ffmpeg``whisper`
9+
10+
Caller.sh 需要被链接为 Host 端所支持的二进制文件名,例如 `ffmpeg` 或者 `whisper`
11+
12+
```shell
13+
ln -s /path/to/caller.sh /usr/local/bin/ffmpeg
14+
ln -s /path/to/caller.sh /usr/local/bin/whisper
15+
```
16+
17+
Container 调用方直接调用 `ffmpeg` 或者 `whisper`,Host 端对应的二进制文件会被直接调起,sshexec 会保证 `stdin/stdout` 传输到与 Container 完全同步。

scripts/caller.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#! /usr/bin/env bash
22
set -e
3-
USER=ihexon
4-
IP_ADDR=192.168.1.250
5-
PORT=22
3+
set -u
4+
cmd_file="/tmp/.cmd"
5+
# Default is oomol
6+
USER=oomol
7+
# https://github.com/containers/gvisor-tap-vsock/blob/f0f18025e5b7c7c281a11dfd81034641b40efe18/cmd/gvproxy/main.go#L56
8+
IP_ADDR=192.168.127.254
9+
# https://github.com/oomol/sshexec/blob/f6e0e1583fc874727d68cc5cc3213dff6867dd0e/pkg/define/const.go#L21
10+
PORT=5322
11+
612
arg0="$(basename "$0")"
713

814
expand-q() {
@@ -22,7 +28,6 @@ write_cmd() {
2228
echo -n ' '
2329
output_args "$arg0" "$@"
2430
}
31+
write_cmd "$@" >"$cmd_file"
2532

26-
write_cmd "$@" >/tmp/.cmd
27-
28-
chmod +x /tmp/.cmd && /tmp/.cmd
33+
chmod +x "$cmd_file" && "$cmd_file"

scripts/installer.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#! /usr/bin/env bash
2+
set -e
3+
set -u
4+
5+
log() {
6+
msg="LOG: $S_NAME> $*"
7+
echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2
8+
}
9+
10+
err() {
11+
msg="ERROR: $S_NAME> $*"
12+
echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2
13+
exit 100
14+
}
15+
16+
warn() {
17+
msg="WARN: $S_NAME> $*"
18+
echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2
19+
}
20+
21+
get_platform() {
22+
arch=$(uname -m)
23+
platform=unknown
24+
25+
if [[ -z "$arch" ]]; then
26+
warn "uname -m return empty"
27+
return
28+
fi
29+
30+
# For wsl2
31+
if [[ "$arch" == x86_64 ]] && [[ -d "/usr/lib/wsl" ]]; then
32+
platform="wsl2-$arch"
33+
return
34+
fi
35+
36+
# For MacOS-x86_64
37+
if [[ "$arch" == x86_64 ]]; then
38+
platform="macos-$arch"
39+
return
40+
fi
41+
42+
# For MacOS-aarch64
43+
if [[ "$arch" == aarch64 ]] || [[ $arch == arm64 ]]; then
44+
platform="macos-$arch"
45+
return
46+
fi
47+
}
48+
49+
# Setup ffmpeg binaries logic
50+
setup_ffmpeg_for_macos_aarch64() {
51+
caller_script="/usr/bin/caller.sh"
52+
wget https://github.com/oomol/sshexec/raw/refs/heads/main/scripts/caller.sh --output-document "$caller_script"
53+
chmod +x "$caller_script"
54+
55+
ln -sf "$caller_script" /usr/bin/install_ffmpeg # used to install_ffmpeg
56+
/usr/bin/install_ffmpeg # do install ffmpeg
57+
58+
# Link caller.sh to <binary_name>
59+
ln -sf "$caller_script" /usr/bin/ffmpeg
60+
ln -sf "$caller_script" /usr/bin/ffprobe
61+
}
62+
63+
setup_ffmpeg_for_wsl2_x86_64() {
64+
wget https://github.com/oomol/builded/releases/download/v1.7/ffmpeg-wsl2_x86_64.tar.xz --output-document=/tmp/ffmpeg-wsl2_x86_64.tar.xz
65+
tar -xvf /tmp/ffmpeg-wsl2_x86_64.tar.xz -C /tmp/
66+
echo "Install ffmpeg"
67+
cp /tmp/ffmpeg/ffmpeg /usr/bin/
68+
cp /tmp/ffmpeg/ffprobe /usr/bin/
69+
echo "Install ffmpeg done"
70+
}
71+
72+
setup_ffmpeg() {
73+
if [[ "$platform" == macos-aarch64 ]]; then
74+
setup_ffmpeg_for_macos_aarch64
75+
elif [[ "$platform" == wsl2-x86_64 ]]; then
76+
setup_ffmpeg_for_wsl2_x86_64
77+
else
78+
err "unsupport platform: $platform"
79+
fi
80+
}
81+
82+
main() {
83+
get_platform
84+
if [[ "$platform" == "unknown" ]]; then
85+
err "unknown platform"
86+
fi
87+
setup_ffmpeg
88+
}
89+
90+
main

0 commit comments

Comments
 (0)