mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-22 19:50:33 +03:00
Build/release script and fix version annotation.
This commit is contained in:
parent
838f58e648
commit
39ac1f44ed
9
Makefile
9
Makefile
@ -3,11 +3,13 @@ KEY = host_key
|
||||
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 ./...
|
||||
@ -29,3 +31,8 @@ debug: $(BINARY) $(KEY)
|
||||
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
|
||||
|
59
build_release
Executable file
59
build_release
Executable file
@ -0,0 +1,59 @@
|
||||
#!/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 "$@"
|
@ -22,9 +22,13 @@ import (
|
||||
)
|
||||
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."`
|
||||
@ -63,6 +67,11 @@ func main() {
|
||||
}()
|
||||
}
|
||||
|
||||
if options.Version {
|
||||
fmt.Println(Version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Figure out the log level
|
||||
numVerbose := len(options.Verbose)
|
||||
if numVerbose > len(logLevels) {
|
||||
@ -111,6 +120,7 @@ func main() {
|
||||
|
||||
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)
|
||||
|
7
host.go
7
host.go
@ -13,8 +13,6 @@ import (
|
||||
"github.com/shazow/ssh-chat/sshd"
|
||||
)
|
||||
|
||||
var buildCommit string
|
||||
|
||||
const maxInputLength int = 1024
|
||||
|
||||
// GetPrompt will render the terminal prompt string based on the user.
|
||||
@ -37,6 +35,9 @@ type Host struct {
|
||||
auth *Auth
|
||||
count int
|
||||
|
||||
// Version string to print on /version
|
||||
Version string
|
||||
|
||||
// Default theme
|
||||
theme message.Theme
|
||||
}
|
||||
@ -324,7 +325,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
|
||||
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
|
||||
},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user