PORT = 2022
SRCS = %.go
+VERSION := $(shell git describe --long --tags --dirty --always)
+LDFLAGS = LDFLAGS="-X main.Version=$(VERSION)"
all: $(BINARY)
$(BINARY): deps **/**/*.go **/*.go *.go
- go build -ldflags "-X main.buildCommit=`git describe --long --tags --dirty --always`" ./cmd/ssh-chat
+ go build $(BUILDFLAGS) ./cmd/ssh-chat
deps:
go get ./...
test:
go test ./...
golint ./...
+
+release:
+ ENV=GOOS=linux GOARCH=amd64 $(LDFLAGS) ./build_release "github.com/shazow/ssh-chat/cmd/ssh-chat" README.md LICENSE
+ ENV=GOOS=linux GOARCH=386 $(LDFLAGS) ./build_release "github.com/shazow/ssh-chat/cmd/ssh-chat" README.md LICENSE
+ ENV=GOOS=darwin GOARCH=amd64 $(LDFLAGS) ./build_release "github.com/shazow/ssh-chat/cmd/ssh-chat" README.md LICENSE
--- /dev/null
+#!/usr/bin/env bash
+
+usage() {
+ echo "Build and bundle Go releases with the current dir as the build dir."
+ echo "Usage: $0 PACKAGE [ASSETS...]"
+}
+
+main() {
+ set -eo pipefail
+ [[ "$TRACE" ]] && set -x
+
+ if [[ ! "$1" ]]; then
+ usage
+ exit 1
+ fi
+
+ if [[ ! "$GOOS" ]]; then
+ export GOOS="linux"
+ fi
+ if [[ ! "$GOARCH" ]]; then
+ export GOARCH="amd64"
+ fi
+ if [[ ! "$BUILDDIR" ]]; then
+ export BUILDDIR="build"
+ fi
+
+ build "$@"
+}
+
+build() {
+ local package="$1"; shift
+ local assets="$@"
+
+ local bin="$(basename $package)"
+ local tarball="${bin}-${GOOS}_${GOARCH}.tgz"
+ local outdir="$BUILDDIR/$bin"
+
+ if [[ -d "$outdir" ]]; then
+ echo "err: outdir already exists: $PWD/$outdir"
+ fi
+ mkdir -p "$outdir"
+
+ go build -ldflags "$LDFLAGS" -o "$outdir/$bin" "$package"
+
+ # Stage asset bundle
+ if [[ "$assets" ]]; then
+ ln -f $assets "$outdir"
+ fi
+
+ # Create tarball
+ tar -C "$BUILDDIR" -czvf "$BUILDDIR/$tarball" "$bin"
+
+ # Cleanup
+ rm -rf "$outdir"
+
+ echo "Packaged: $tarball"
+}
+
+main "$@"
)
import _ "net/http/pprof"
+// Version of the binary, assigned during build.
+var Version string = "dev"
+
// Options contains the flag options
type Options struct {
Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."`
+ Version bool `long:"version" description:"Print version and exit."`
Identity string `short:"i" long:"identity" description:"Private key to identify server with." default:"~/.ssh/id_rsa"`
Bind string `long:"bind" description:"Host and port to listen on." default:"0.0.0.0:2022"`
Admin string `long:"admin" description:"File of public keys who are admins."`
}()
}
+ if options.Version {
+ fmt.Println(Version)
+ os.Exit(0)
+ }
+
// Figure out the log level
numVerbose := len(options.Verbose)
if numVerbose > len(logLevels) {
host := sshchat.NewHost(s, auth)
host.SetTheme(message.Themes[0])
+ host.Version = Version
err = fromFile(options.Admin, func(line []byte) error {
key, _, _, _, err := ssh.ParseAuthorizedKey(line)
"github.com/shazow/ssh-chat/sshd"
)
-var buildCommit string
-
const maxInputLength int = 1024
// GetPrompt will render the terminal prompt string based on the user.
auth *Auth
count int
+ // Version string to print on /version
+ Version string
+
// Default theme
theme message.Theme
}
c.Add(chat.Command{
Prefix: "/version",
Handler: func(room *chat.Room, msg message.CommandMsg) error {
- room.Send(message.NewSystemMsg(buildCommit, msg.From()))
+ room.Send(message.NewSystemMsg(h.Version, msg.From()))
return nil
},
})