sshtools: 非交互 SSH 工具集(golink / goscp)
golink: 一条命令在远端执行,退出码原样透传,从不提示、不分配终端。 goscp: 用 SCP 协议上传,-files 一个参数同时接受文件和目录。 - 纯 Go,唯一依赖 golang.org/x/crypto,可离线交叉编译到六个桌面平台 - internal/sshx 统一建连、认证(password + keyboard-interactive)与主机密钥策略 - smoketest/ 自带迷你 sshd,57 项端到端测试(golink 38 + goscp 19)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Cross-compile the sshtools binaries for the three desktop platforms.
|
||||
#
|
||||
# ./build.sh cross-compile every program and target
|
||||
# ./build.sh local only the host binaries, at dist/golink and dist/goscp
|
||||
#
|
||||
# Everything is pure Go (CGO disabled), so no cross toolchain is needed and the
|
||||
# build works offline: the only dependency, golang.org/x/crypto, is already in
|
||||
# the local module cache.
|
||||
|
||||
set -euo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
version="${VERSION:-1.0.0}"
|
||||
export CGO_ENABLED=0
|
||||
export GOCACHE="${GOCACHE:-$PWD/.gocache}"
|
||||
export GOFLAGS="${GOFLAGS:--mod=mod}"
|
||||
|
||||
ldflags="-s -w -X main.version=$version"
|
||||
programs="golink goscp"
|
||||
targets="linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64"
|
||||
|
||||
mkdir -p dist
|
||||
|
||||
build() { # <program> <goos> <goarch> <output>
|
||||
GOOS="$2" GOARCH="$3" go build -trimpath -ldflags "$ldflags" -o "$4" "./cmd/$1"
|
||||
printf ' %-32s %7s %s\n' "$4" "$(du -h "$4" | cut -f1)" "$(file -b "$4" 2>/dev/null | cut -c1-58)"
|
||||
}
|
||||
|
||||
hostos="$(go env GOOS)"
|
||||
hostarch="$(go env GOARCH)"
|
||||
|
||||
if [ "${1:-all}" = local ]; then
|
||||
for program in $programs; do
|
||||
ext=""
|
||||
[ "$hostos" = windows ] && ext=".exe"
|
||||
build "$program" "$hostos" "$hostarch" "dist/${program}${ext}"
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "sshtools $version"
|
||||
for program in $programs; do
|
||||
for target in $targets; do
|
||||
os="${target%%/*}"
|
||||
arch="${target##*/}"
|
||||
ext=""
|
||||
[ "$os" = windows ] && ext=".exe"
|
||||
build "$program" "$os" "$arch" "dist/${program}_${os}_${arch}${ext}"
|
||||
done
|
||||
done
|
||||
|
||||
# convenience copies for the machine running this script
|
||||
ext=""
|
||||
[ "$hostos" = windows ] && ext=".exe"
|
||||
for program in $programs; do
|
||||
native="dist/${program}_${hostos}_${hostarch}${ext}"
|
||||
if [ -f "$native" ]; then
|
||||
cp "$native" "dist/${program}${ext}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
( cd dist && sha256sum golink_* goscp_* > SHA256SUMS && cat SHA256SUMS )
|
||||
Reference in New Issue
Block a user