diff --git a/README.md b/README.md index 953164a..c5dad08 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,11 @@ The best way to install Muscadine is to head over to our [Releases](https://gith ## Build -If you'd like to build Muscadine, make sure you have Go installed. Then run: +If you'd like to build Muscadine, make sure you have [Go](https://golang.org/) and [dep](https://github.com/golang/dep) installed. Clone this repository, then run: ``` -go get -u github.com/arborchat/muscadine +cd muscadine +./build.sh ``` ## Use diff --git a/build-releases.sh b/build-releases.sh index c59f7c2..83575f9 100755 --- a/build-releases.sh +++ b/build-releases.sh @@ -42,7 +42,7 @@ for os in darwin linux windows openbsd; do for arch in ${arch_for_os["$os"]}; do archive_name="$project-$os-$arch.tar.gz" echo "Building $project for $os on $arch" - env GOOS="$os" GOARCH="$arch" CGO_ENABLED=0 go build -o "$bin_name" &&\ + env GOOS="$os" GOARCH="$arch" CGO_ENABLED=0 ./build.sh -o "$bin_name" &&\ tar czf "$archive_name" "$bin_name" &&\ rm "$bin_name" echo "Adding $archive_name to release $tag" diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..2188ba1 --- /dev/null +++ b/build.sh @@ -0,0 +1,33 @@ +#!/bin/sh +#usage: ./build.sh + +# find the directory containing this script +script_dir="$(dirname "$(command -v "$0")")" + +# ensure that git commands are run from within this repository +cd "$script_dir" || exit 1 + +commit="$(git rev-parse HEAD)" +suffix="" +version_file="$(pwd)/version.go" + +# check if git is clean. If not, notify user and taint the build +if ! git diff --exit-code > /dev/null 2>&1 ||\ + ! git diff --cached --exit-code > /dev/null 2>&1 ; then + suffix="-modified" + echo "Warning: your current working directory contains unstaged or uncommitted changes. +Building a \"modified\" binary +Run 'git diff && git diff --cached' to see your unmodified changes" +fi + +# write the file and format it +echo "package main; const Version = \"$commit$suffix\"" > "$version_file" +gofmt -s -w "$version_file" + +# show the user +echo "Wrote file $version_file" + +# ensure dependencies are clean +dep ensure + +go build "$@" diff --git a/main.go b/main.go index ee46035..875eaad 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "log" "os" "os/user" @@ -70,11 +71,17 @@ func main() { username string histfile, logfile string histfileTemplate = getDefaultHistFileTemplate() + version bool ) flag.StringVar(&username, "username", "muscadine", "Set your username on the server") flag.StringVar(&histfile, "histfile", histfileTemplate, "Load/Store history in this file") flag.StringVar(&logfile, "logfile", getDefaultLogFile(), "Write logs to this file") + flag.BoolVar(&version, "version", false, "Print version number and exit") flag.Parse() + if version { + fmt.Printf("Muscadine %s\n", Version) + return + } if len(flag.Args()) < 1 { log.Fatal("Usage: " + os.Args[0] + " :") } diff --git a/version.go b/version.go new file mode 100644 index 0000000..504192d --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package main + +const Version = "go-get (unstable, use ./build.sh instead)"