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
12 changes: 3 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ jobs:
uses: 'actions/upload-artifact@v4'
with:
name: sshexec
path: |
out/sshexec-amd64
out/sshexec-arm64
out/installer.sh
out/caller.sh
path: out/
if-no-files-found: error
overwrite: true

Expand All @@ -48,10 +44,8 @@ jobs:
with:
generate_release_notes: true
files: |
out/sshexec-amd64
out/sshexec-arm64
out/installer.sh
out/caller.sh
out/sshexec*
out/caller*
append_body: true
draft: false
prerelease: false
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ BINARY_NAME=sshexec
# All target
all: build

build: build-arm64 build-amd64 script
build: build-arm64 build-amd64

build-arm64:
GOARCH=arm64 $(GOBUILD) -o out/$(BINARY_NAME)-arm64 -v sshd/cmd/
GOOS=linux GOARCH=arm64 $(GOBUILD) -o out/caller-arm64 -v scripts/caller.go


build-amd64:
GOARCH=amd64 $(GOBUILD) -o out/$(BINARY_NAME)-amd64 -v sshd/cmd/
GOOS=linux GOARCH=amd64 $(GOBUILD) -o out/caller-amd64 -v scripts/caller.go

lint:
golangci-lint run
Expand All @@ -23,13 +26,6 @@ clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)

# Format the code
script:
cp scripts/caller.sh out/
chmod +x out/caller.sh
cp scripts/installer.sh out/
chmod +x out/installer.sh

fmt:
$(GOCMD) fmt ./...

Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/ffmpeg/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Run(next ssh.Handler) ssh.Handler {
return func(s ssh.Session) {
targetBin := s.Command()[0]
if targetBin == define.FFPROBEBin || targetBin == define.FFMPEGBin {
logrus.Infof("run middleware: %q\r\n", RunFFMPEGStage)
logrus.Infof("run middleware: %q\n", RunFFMPEGStage)
stubber := ffmpeg.NewVersion6(s)
args, err := exec.DoArgsSanitizers(s.Command()[1:])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func SetupLogger() error {
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
ForceColors: false,
DisableColors: true,
DisableColors: false,
TimestampFormat: "2006-01-02 15:04:05.000",
})
homeDir, err := os.UserHomeDir()
Expand Down
57 changes: 57 additions & 0 deletions scripts/caller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"fmt"
"github.com/sirupsen/logrus"
"os"
"os/exec"
"path/filepath"
"strings"
)

func init() {
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
ForceColors: false,
DisableColors: true,
TimestampFormat: "2006-01-02 15:04:05.000",
})
logrus.SetOutput(os.Stderr)
}

const (
addr = "192.168.127.254"
user = "oomol"
port = "5322"
endpoint = user + "@" + addr
)

func main() {
targetName := filepath.Base(os.Args[0])

fullFFMPEGArgsList := append([]string{targetName}, os.Args[1:]...)

var argsBuilder strings.Builder
// Wrap the arguments with single quotes
for _, arg := range fullFFMPEGArgsList {
str := fmt.Sprintf("%s%s%s", "'", arg, "'")
argsBuilder.WriteString(str)
argsBuilder.WriteString(" ")
}
fullFFMPEGArgString := argsBuilder.String()
_, _ = fmt.Fprintf(os.Stderr, "ffmpeg cmdline: %q\n", fullFFMPEGArgString)

var finalArgs strings.Builder
finalArgs.WriteString(fullFFMPEGArgString)
fullArgs := finalArgs.String()

cmd := exec.Command("ssh", "-q", "-o", "StrictHostKeyChecking=no",
"-p", port, endpoint, fullArgs)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
_, _ = fmt.Fprintf(os.Stderr, "full cmdline: %q\n", cmd.Args)
if err := cmd.Run(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v", err)
}
}
37 changes: 0 additions & 37 deletions scripts/caller.sh

This file was deleted.

109 changes: 52 additions & 57 deletions scripts/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,83 @@ 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() {
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
wget https://github.com/oomol/sshexec/releases/download/v1.0.6/caller-arm64 --output-document=/usr/bin/caller
chmod +x /usr/bin/caller
ln -sf /usr/bin/caller /usr/bin/ffmpeg
ln -sf /usr/bin/caller /usr/bin/ffprobe
ln -sf /usr/bin/caller /usr/bin/install_ffmpeg_6
/usr/bin/install_ffmpeg_6
}

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