Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# install.sh 说明

`install.sh` 会使用标准的 ssh client 发送 `install_ffmpeg` 给 `sshexec`, `sshexec` 会安装 oomol 提供的 ffmpeg 二进制文件
`install.sh` 会将 `caller.sh` 链接到 `/usr/bin/ffmpeg` 和 `/usr/bin/ffprobe`,在 Container 中调用 `ffmpeg` 和 `ffprobe` 时,会通过 sshexec 被转发到 Host 端的 ffmpeg 和 ffprobe。

# caller.sh 说明

`caller.sh` 运行在 Container 中,用于呼叫 Host 端的二进制文件,目前支持的二进制文件有 `ffmpeg` 和 `whisper`。

Caller.sh 需要被链接为 Host 端所支持的二进制文件名,例如 `ffmpeg` 或者 `whisper`。

```shell
ln -s /path/to/caller.sh /usr/local/bin/ffmpeg
ln -s /path/to/caller.sh /usr/local/bin/whisper
```

Container 调用方直接调用 `ffmpeg` 或者 `whisper`,Host 端对应的二进制文件会被直接调起,sshexec 会保证 `stdin/stdout` 传输到与 Container 完全同步。
17 changes: 11 additions & 6 deletions scripts/caller.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#! /usr/bin/env bash
set -e
USER=ihexon
IP_ADDR=192.168.1.250
PORT=22
set -u
cmd_file="/tmp/.cmd"
# Default is oomol
USER=oomol
# https://github.com/containers/gvisor-tap-vsock/blob/f0f18025e5b7c7c281a11dfd81034641b40efe18/cmd/gvproxy/main.go#L56
IP_ADDR=192.168.127.254
# https://github.com/oomol/sshexec/blob/f6e0e1583fc874727d68cc5cc3213dff6867dd0e/pkg/define/const.go#L21
PORT=5322

arg0="$(basename "$0")"

expand-q() {
Expand All @@ -22,7 +28,6 @@ write_cmd() {
echo -n ' '
output_args "$arg0" "$@"
}
write_cmd "$@" >"$cmd_file"

write_cmd "$@" >/tmp/.cmd

chmod +x /tmp/.cmd && /tmp/.cmd
chmod +x "$cmd_file" && "$cmd_file"
90 changes: 90 additions & 0 deletions scripts/installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /usr/bin/env bash
set -e
set -u

log() {
msg="LOG: $S_NAME> $*"
echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2
}

err() {
msg="ERROR: $S_NAME> $*"
echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2
exit 100
}

warn() {
msg="WARN: $S_NAME> $*"
echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2
}

get_platform() {
arch=$(uname -m)
platform=unknown

if [[ -z "$arch" ]]; then
warn "uname -m return empty"
return
fi

# For wsl2
if [[ "$arch" == x86_64 ]] && [[ -d "/usr/lib/wsl" ]]; then
platform="wsl2-$arch"
return
fi

# For MacOS-x86_64
if [[ "$arch" == x86_64 ]]; then
platform="macos-$arch"
return
fi

# For MacOS-aarch64
if [[ "$arch" == aarch64 ]] || [[ $arch == arm64 ]]; then
platform="macos-$arch"
return
fi
}

# Setup ffmpeg binaries logic
setup_ffmpeg_for_macos_aarch64() {
caller_script="/usr/bin/caller.sh"
wget https://github.com/oomol/sshexec/raw/refs/heads/main/scripts/caller.sh --output-document "$caller_script"
chmod +x "$caller_script"

ln -sf "$caller_script" /usr/bin/install_ffmpeg # used to install_ffmpeg
/usr/bin/install_ffmpeg # do install ffmpeg

# Link caller.sh to <binary_name>
ln -sf "$caller_script" /usr/bin/ffmpeg
ln -sf "$caller_script" /usr/bin/ffprobe
}

setup_ffmpeg_for_wsl2_x86_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
tar -xvf /tmp/ffmpeg-wsl2_x86_64.tar.xz -C /tmp/
echo "Install ffmpeg"
cp /tmp/ffmpeg/ffmpeg /usr/bin/
cp /tmp/ffmpeg/ffprobe /usr/bin/
echo "Install ffmpeg done"
}

setup_ffmpeg() {
if [[ "$platform" == macos-aarch64 ]]; then
setup_ffmpeg_for_macos_aarch64
elif [[ "$platform" == wsl2-x86_64 ]]; then
setup_ffmpeg_for_wsl2_x86_64
else
err "unsupport platform: $platform"
fi
}

main() {
get_platform
if [[ "$platform" == "unknown" ]]; then
err "unknown platform"
fi
setup_ffmpeg
}

main