diff --git a/Makefile b/Makefile index b0d4908..18995f2 100644 --- a/Makefile +++ b/Makefile @@ -26,12 +26,23 @@ BUILDOPTS :=$(BUILDOPTS)"$(GOBUILDOPTS) -ldflags \"-X main.version=$(VERSION)$(M #endif SUBPKGS = logger spinsult xsnet -TOOLS = xspasswd xs xsd +TOOLS = xs xsd SUBDIRS = $(LIBS) $(TOOLS) +ifeq ($(GOOS),) + GOOS=$(shell go env GOOS) +endif + +ifeq ($(GOOS),windows) +ifeq ($(MSYSTEM),MSYS) +WIN_MSYS=1 +endif +endif + + INSTPREFIX = /usr/local -all: common client server passwd +all: common client server clean: @echo "Make: $(MAKE)" @@ -60,21 +71,12 @@ client: common $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xs -ifeq ($(MSYSTEM),) -ifneq ($(GOOS),windows) server: common +ifeq ($(MSYSTEM),MSYS) + echo "Build of xsd server for Windows not yet supported" +else $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xsd -else - echo "Cross-build of xsd server for Windows not yet supported" endif -else -server: common - echo "xsd server not (yet) supported on Windows" -endif - - -passwd: common - $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xspasswd vis: @which go-callvis >/dev/null 2>&1; \ @@ -83,38 +85,30 @@ vis: else \ $(MAKE) -C xs vis;\ $(MAKE) -C xsd vis;\ - $(MAKE) -C xspasswd vis; \ fi lint: - $(MAKE) -C xspasswd lint $(MAKE) -C xsd lint $(MAKE) -C xs lint reinstall: uninstall install install: - cp xs/xs $(INSTPREFIX)/bin -ifeq ($(MSYSTEM),) -ifneq ($(GOOS),windows) - cp xsd/xsd xspasswd/xspasswd $(INSTPREFIX)/sbin -else - mv $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/_xs + echo "WIN_MSYS:" $(WIN_MSYS) +ifdef WIN_MSYS cp xs/mintty_wrapper.sh $(INSTPREFIX)/bin/xs - echo "Cross-build of xsd server for Windows not yet supported" -endif + cp xs/mintty_wrapper.sh $(INSTPREFIX)/bin/xc + cp xs/xs $(INSTPREFIX)/bin/_xs + cp xs/xs $(INSTPREFIX)/bin/_xc + echo "Install of xsd server for Windows not yet supported" else - echo "Cross-build of xsd server for Windows not yet supported" -endif + cp xs/xs $(INSTPREFIX)/bin cd $(INSTPREFIX)/bin && ln -s xs xc && cd - - +endif uninstall: - rm -f $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/xc $(INSTPREFIX)/bin/_xs -ifeq ($(MSYSTEM),) -ifneq ($(GOOS),windows) - rm -f $(INSTPREFIX)/sbin/xsd $(INSTPREFIX)/sbin/xspasswd -else -endif -else + rm -f $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/xc \ + $(INSTPREFIX)/bin/_xs $(INSTPREFIX)/bin/_xc +ifndef $(WIN_MSYS) + rm -f $(INSTPREFIX)/sbin/xsd endif diff --git a/README.freebsd b/README.freebsd deleted file mode 100644 index 968d79c..0000000 --- a/README.freebsd +++ /dev/null @@ -1,6 +0,0 @@ -## The Makefile(s) to build require GNU make (gmake). -## Please install and invoke build via: -## $ gmake -## eg., -## $ gmake clean all - diff --git a/README.md b/README.md index 084104f..f6b8543 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ [![GoDoc](https://godoc.org/blitter.com/go/xs?status.svg)](https://godoc.org/blitter.com/go/xs) - # XS -- @@ -198,3 +197,9 @@ Example, tunnelling ssh through xs * [client side, term A] ```$ xs -T=6002:7002 user@server``` * [client side, term B] ```$ ssh user@localhost -p 6002``` + +### Building for FreeBSD + +The Makefile(s) to build require GNU make (gmake). +Please install and invoke build via: +```$ gmake clean all``` diff --git a/termmode_windows.go b/termmode_windows.go index 7d6abbb..c8931c9 100644 --- a/termmode_windows.go +++ b/termmode_windows.go @@ -37,7 +37,7 @@ func MakeRaw(fd uintptr) (*State, error) { // GetState returns the current state of a terminal which may be useful to // restore the terminal after a signal. -func GetState(fd int) (*State, error) { +func GetState(fd uintptr) (*State, error) { return &State{}, nil } diff --git a/xs/mintty_wrapper.sh b/xs/mintty_wrapper.sh index cef7de8..9cba8ff 100755 --- a/xs/mintty_wrapper.sh +++ b/xs/mintty_wrapper.sh @@ -28,10 +28,12 @@ cleanup() { stty sane } +me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" + if [ ${1}x == "-hx" ]; then - ./hkexsh -h + _${me} -h else stty -echo raw icrnl - ./hkexsh $@ + _${me} $@ fi diff --git a/xs/xs.go b/xs/xs.go index 9862dfa..bfb7bcf 100755 --- a/xs/xs.go +++ b/xs/xs.go @@ -722,7 +722,10 @@ func main() { // Find out what program we are (shell or copier) myPath := strings.Split(os.Args[0], string(os.PathSeparator)) - if myPath[len(myPath)-1] != "xc" && myPath[len(myPath)-1] != "xc.exe" { + if myPath[len(myPath)-1] != "xc" && + myPath[len(myPath)-1] != "_xc" && + myPath[len(myPath)-1] != "xc.exe" && + myPath[len(myPath)-1] != "_xc.exe" { // xs accepts a command (-x) but not // a srcpath (-r) or dstpath (-t) flag.StringVar(&cmdStr, "x", "", "run <`command`> (if not specified, run interactive shell)") @@ -766,7 +769,7 @@ func main() { var uname string if remoteUser == "" { u, _ := user.Current() // nolint: gosec - uname = u.Username + uname = localUserName(u) } else { uname = remoteUser } @@ -1040,6 +1043,19 @@ func main() { exitWithStatus(int(rec.Status())) } +// currentUser returns the current username minus any OS-specific prefixes +// such as MS Windows workgroup prefixes (eg. workgroup\user). +func localUserName(u *user.User) string { + if u == nil { + log.Fatal("null User?!") + } + + // WinAPI: username may have CIFS prefix %USERDOMAIN%\ + userspec := strings.Split(u.Username, `\`) + username := userspec[len(userspec)-1] + return username +} + func restoreTermState(oldState *xs.State) { _ = xs.Restore(os.Stdin.Fd(), oldState) // nolint: errcheck,gosec }