Skip to content

Commit

Permalink
hs
Browse files Browse the repository at this point in the history
  • Loading branch information
shoce committed Aug 27, 2023
1 parent b748638 commit 47c0f17
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://docs.github.com/en/actions/learn-github-actions/contexts
name: release
permissions:
contents: write
id-token: write
on:
push:
branches: [ "main" ]
jobs:
build-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: version
run: |
VERSION=$( date '+%y%m%d.%H%M.0' )
echo "VERSION:$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: '^1.21.0'
- name: go build
run: GOOS=linux GOARCH=amd64 go build -o hs.linux.amd64 -trimpath -ldflags '-X main.Version='$VERSION hs.go
- name: gzip
run: gzip hs.linux.amd64
- run: ls -l -a
- name: gh release
run: gh release create $VERSION hs.linux.amd64.gz

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

.DS_Store

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module src.iriy.de/hs
module github.com/shoce/hs

go 1.20
go 1.21.0

require (
github.com/ipfs/go-cid v0.4.1
Expand Down
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g=
github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE=
github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI=
github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM=
github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0=
github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g=
github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk=
github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U=
github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM=
github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY=
github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8=
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
Expand All @@ -26,5 +40,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
lukechampine.com/blake3 v1.1.6 h1:H3cROdztr7RCfoaTpGZFQsrqvweFLrqS73j7L7cmR5c=
lukechampine.com/blake3 v1.1.6/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
72 changes: 68 additions & 4 deletions hs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ Oct 28 21:37:28 ci sshd[3685911]: error: session_signal_req: session signalling
020/357 UserKeyFile support
021/0502 InReaderBufferSize
021/1117 Silent
023/0827 Verbose
023/0827 keepalive
rm -f go.mod go.sum
go mod init src.iriy.de/hs
go mod init github.com/shoce/hs
go get -a -u -v
go mod tidy
GoFmt
GoBuildNull
GoBuild
GoRelease
GoFmt GoBuildNull GoBuild GoRelease
GoRun put a '<' <readme.text
Kill GoRun
Expand Down Expand Up @@ -89,6 +93,8 @@ var (
Hostname string
Host string // host network address to run commands on: empty or localhost to run with exec() and hostname[:port] to use ssh transport

SshKeepAliveInterval time.Duration = 12 * time.Second

SshClientConfig *ssh.ClientConfig
SshConn *ssh.Conn
SshClient *ssh.Client
Expand Down Expand Up @@ -177,6 +183,10 @@ func init() {
os.Exit(0)
}

if os.Getenv("Verbose") != "" {
Verbose = true
}

if os.Getenv("Silent") != "" {
Silent = true
}
Expand Down Expand Up @@ -245,7 +255,7 @@ func init() {
}

if UserAuthMethod == nil {
log("No user auth method provided: no password and no user key", err)
log("No user auth method provided: no password and no user key")
os.Exit(1)
}

Expand Down Expand Up @@ -331,6 +341,45 @@ func connectssh() (err error) {
return nil
}

// https://github.com/golang/go/issues/21478
// https://github.com/golang/go/issues/19338
// https://pkg.go.dev/golang.org/x/crypto/ssh
func keepalive(cl *ssh.Client, conn net.Conn, done <-chan bool) error {
if Verbose {
log("keepalive start")
}
t := time.NewTicker(SshKeepAliveInterval)
defer t.Stop()
for {
err := conn.SetDeadline(time.Now().Add(2 * SshKeepAliveInterval))
if err != nil {
if Verbose {
log("keepalive failed to set deadline: %v", err)
}
return fmt.Errorf("failed to set deadline: %w", err)
}
select {
case <-t.C:
_, _, err = cl.SendRequest("keepalive@github.com/shoce/hs", true, nil)
if Verbose {
if err == nil {
log("keepalive request sent and confirmed")
} else {
log("keepalive failed to send request: %v", err)
}
}
if err != nil {
return fmt.Errorf("failed to send keep alive: %w", err)
}
case <-done:
if Verbose {
log("keepalive done")
}
return nil
}
}
}

func runssh(cmds string, cmd []string, stdin io.Reader) (status string, err error) {
if SshClient == nil {
err = connectssh()
Expand Down Expand Up @@ -367,6 +416,14 @@ func runssh(cmds string, cmd []string, stdin io.Reader) (status string, err erro
}
*/

/*
if err := session.Setenv("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"); err != nil {
// ( echo ; echo AcceptEnv PATH ) >>/etc/ssh/sshd_config && systemctl reload sshd
log("Session.Setenv PATH: %v", err)
return "", err
}
*/

if stdin != nil {
stdinpipe, err := session.StdinPipe()
if err != nil {
Expand Down Expand Up @@ -412,6 +469,9 @@ func runssh(cmds string, cmd []string, stdin io.Reader) (status string, err erro
return "", err
}

keepalivedonechan := make(chan bool)
go keepalive(SshClient, ProxyConn, keepalivedonechan)

InterruptChan = make(chan bool)

go func() {
Expand All @@ -427,6 +487,10 @@ func runssh(cmds string, cmd []string, stdin io.Reader) (status string, err erro

err = session.Wait()

keepalivedonechan <- true
close(keepalivedonechan)
keepalivedonechan = nil

close(InterruptChan)
InterruptChan = nil

Expand Down

0 comments on commit 47c0f17

Please sign in to comment.