Skip to content

Commit 19cbd75

Browse files
committed
refactor(caller): re-write caller
1 parent 45f8a90 commit 19cbd75

File tree

7 files changed

+67
-66
lines changed

7 files changed

+67
-66
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ jobs:
3434
uses: 'actions/upload-artifact@v4'
3535
with:
3636
name: sshexec
37-
path: |
38-
out/sshexec-amd64
39-
out/sshexec-arm64
40-
out/installer.sh
41-
out/caller.sh
37+
path: out/
4238
if-no-files-found: error
4339
overwrite: true
4440

@@ -48,10 +44,8 @@ jobs:
4844
with:
4945
generate_release_notes: true
5046
files: |
51-
out/sshexec-amd64
52-
out/sshexec-arm64
53-
out/installer.sh
54-
out/caller.sh
47+
out/sshexec*
48+
out/caller*
5549
append_body: true
5650
draft: false
5751
prerelease: false

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ BINARY_NAME=sshexec
77
# All target
88
all: build
99

10-
build: build-arm64 build-amd64 script
10+
build: build-arm64 build-amd64
1111

1212
build-arm64:
1313
GOARCH=arm64 $(GOBUILD) -o out/$(BINARY_NAME)-arm64 -v sshd/cmd/
14+
GOOS=linux GOARCH=arm64 $(GOBUILD) -o out/caller-arm64 -v scripts/caller.go
15+
1416

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

1821
lint:
1922
golangci-lint run
@@ -23,13 +26,6 @@ clean:
2326
$(GOCLEAN)
2427
rm -f $(BINARY_NAME)
2528

26-
# Format the code
27-
script:
28-
cp scripts/caller.sh out/
29-
chmod +x out/caller.sh
30-
cp scripts/installer.sh out/
31-
chmod +x out/installer.sh
32-
3329
fmt:
3430
$(GOCMD) fmt ./...
3531

pkg/handler/ffmpeg/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func Run(next ssh.Handler) ssh.Handler {
1616
return func(s ssh.Session) {
1717
targetBin := s.Command()[0]
1818
if targetBin == define.FFPROBEBin || targetBin == define.FFMPEGBin {
19-
logrus.Infof("run middleware: %q\r\n", RunFFMPEGStage)
19+
logrus.Infof("run middleware: %q\n", RunFFMPEGStage)
2020
stubber := ffmpeg.NewVersion6(s)
2121
args, err := exec.DoArgsSanitizers(s.Command()[1:])
2222
if err != nil {

pkg/logger/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func SetupLogger() error {
3333
logrus.SetFormatter(&logrus.TextFormatter{
3434
FullTimestamp: true,
3535
ForceColors: false,
36-
DisableColors: true,
36+
DisableColors: false,
3737
TimestampFormat: "2006-01-02 15:04:05.000",
3838
})
3939
homeDir, err := os.UserHomeDir()

scripts/caller.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/sirupsen/logrus"
6+
"os"
7+
"os/exec"
8+
"path/filepath"
9+
"strings"
10+
)
11+
12+
func init() {
13+
logrus.SetFormatter(&logrus.TextFormatter{
14+
FullTimestamp: true,
15+
ForceColors: false,
16+
DisableColors: true,
17+
TimestampFormat: "2006-01-02 15:04:05.000",
18+
})
19+
logrus.SetOutput(os.Stderr)
20+
}
21+
22+
const (
23+
addr = "127.0.0.1"
24+
user = "oomol"
25+
port = "5322"
26+
endpoint = user + "@" + addr
27+
)
28+
29+
func main() {
30+
targetName := filepath.Base(os.Args[0])
31+
32+
fullFFMPEGArgsList := append([]string{targetName}, os.Args[1:]...)
33+
34+
var argsBuilder strings.Builder
35+
// Wrap the arguments with single quotes
36+
for _, arg := range fullFFMPEGArgsList {
37+
str := fmt.Sprintf("%s%s%s", "'", arg, "'")
38+
argsBuilder.WriteString(str)
39+
argsBuilder.WriteString(" ")
40+
}
41+
fullFFMPEGArgString := argsBuilder.String()
42+
_, _ = fmt.Fprintf(os.Stderr, "ffmpeg cmdline: %q\n", fullFFMPEGArgString)
43+
44+
var finalArgs strings.Builder
45+
finalArgs.WriteString(fullFFMPEGArgString)
46+
fullArgs := finalArgs.String()
47+
48+
cmd := exec.Command("ssh", "-q", "-o", "StrictHostKeyChecking=no",
49+
"-p", port, endpoint, fullArgs)
50+
cmd.Stdout = os.Stdout
51+
cmd.Stderr = os.Stderr
52+
cmd.Stdin = os.Stdin
53+
_, _ = fmt.Fprintf(os.Stderr, "full cmdline: %q\n", cmd.Args)
54+
if err := cmd.Run(); err != nil {
55+
_, _ = fmt.Fprintf(os.Stderr, "%v", err)
56+
}
57+
}

scripts/caller.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

scripts/installer.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,7 @@ get_platform() {
4848

4949
# Setup ffmpeg binaries logic
5050
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
51+
echo "skip"
6152
}
6253

6354
setup_ffmpeg_for_wsl2_x86_64() {

0 commit comments

Comments
 (0)