From b2f16dc3e3e8225a51b12d408a39f44715dcda2c Mon Sep 17 00:00:00 2001 From: ihexon <14349453+ihexon@users.noreply.github.com> Date: Tue, 13 May 2025 17:06:15 +0800 Subject: [PATCH] refactor(installer): re-write installer.sh --- scripts/installer.sh | 96 ++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/scripts/installer.sh b/scripts/installer.sh index 56f7de3..79f232d 100644 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -3,79 +3,81 @@ set -e set -u log() { - msg="LOG: $S_NAME> $*" - echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2 + 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 + 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 + msg="WARN: $S_NAME> $*" + echo "$(date +'%Y-%m-%dT%H:%M:%S.%3N%z'):" "$msg" >&2 } get_platform() { - arch=$(uname -m) - platform=unknown + arch=$(uname -m) + platform=unknown - if [[ -z "$arch" ]]; then - warn "uname -m return empty" - return - fi + 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 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-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 + # For MacOS-aarch64 + if [[ "$arch" == aarch64 ]] || [[ $arch == arm64 ]]; then + platform="macos-$arch" + return + fi } # Setup ffmpeg binaries logic setup_ffmpeg_for_macos_aarch64() { - echo "skip" + wget https://github.com/oomol/sshexec/releases/download/v1.0.6/caller-arm64 --output-document=/usr/bin/caller + ln -sf /usr/bin/caller /usr/bin/ffmpeg + ln -sf /usr/bin/caller /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" + 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 + 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 + get_platform + if [[ "$platform" == "unknown" ]]; then + err "unknown platform" + fi + setup_ffmpeg } main